Integrating GeoRegions.jl with NASAPrecipitation.jl

When downloading and analysing the NASA Precipitation data, we are often not interested in global data. Instead, we are interest in the statistics and trends, etc., in a specific geographic region. We use the functionality of GeoRegions.jl, and the exported GeoRegion and RegionGrid Types to manipulate and extract out data from our region of interest from the datasets provided.

For ease of use, NASAPrecipitation.jl reexports all the functionality of GeoRegions.jl.

Reexporting GeoRegions.jl

For ease of use, NASAPrecipitation.jl reexports all the functionality of GeoRegions.jl., so all the functions that support the creation and retrieval of GeoRegion information, and the extraction and manipulation of data using RegionGrids, can be used by calling using NASAPrecipitation

Below, we give a brief rundown of the functionality of GeoRegions.jl, but for a full description and tutorial of how to use this package, please refer to the documentation

What is a GeoRegion?

In essence, a GeoRegion is:

  • a geographical region that can be either rectilinear region (RectRegion), or a polygonal shape within a specified rectilinear bound (PolyRegion).
  • identified by a regID
  • itself a subregion of a parent GeoRegion (identified by parID, which must itself be a valid ID)
Default GeoRegions

When using GeoRegions.jl, the default GeoRegion should generally be the global domain, specified by GLB and given by the [N,S,E,W] coordinates [90,-90,360,0]. The Global GeoRegion GLB is considered to be a subset of itself.

An Example of a GeoRegion

Let us plot an example GeoRegion. When a GeoRegion is called, NASAPrecipitation.jl will create a grid that spans the bounds of the GeoRegion (red dots), but will only download valid data in the shape of the GeoRegion (blue dots).

regiongrid

Predefined GeoRegions in NASAPrecipitation.jl

By default, NASAPrecipitation.jl will download all available data. This means

  • For IMERGDatasets, the data spans 89.95ºS to 89.95ºN
  • For TRMMDatasets, the data spans 49.875ºS to 49.875ºN
  • For the TRMM Land-Sea Mask, the data spans 89.875ºS to 89.875ºN

In NASAPrecipitation.jl, we therefore define the GeoRegions GPM, TRMM and TRMMLSM in order to ensure that bounds of the GeoRegion we request do not go out of bounds of what is available. Upon loading NASAPrecipitation.jl for the first time during any Julia session, NASAPrecipitation.jl will check if these three GeoRegions exist. However, one can check if they exist at any point (and recreate them if they don't) using the function addNPDGeoRegions()

julia> using NASAPrecipitation
julia> resetGeoRegions() # Clear custom GeoRegions[ Info: 2024-02-17T00:57:15.077 - GeoRegions.jl - Resetting the custom lists of GeoRegions back to the default ┌ Warning: 2024-02-17T00:57:15.077 - GeoRegions.jl - Overwriting /home/runner/.julia/files/GeoRegions/rectlist.txt with original file in /home/runner/.julia/packages/GeoRegions/gU3Zb/src/georegions/../../extra/rectlist.txt ... └ @ GeoRegions ~/.julia/packages/GeoRegions/gU3Zb/src/georegions/read.jl:417 ┌ Warning: 2024-02-17T00:57:15.083 - GeoRegions.jl - Overwriting /home/runner/.julia/files/GeoRegions/polylist.txt with original file in /home/runner/.julia/packages/GeoRegions/gU3Zb/src/georegions/../../extra/polylist.txt ... └ @ GeoRegions ~/.julia/packages/GeoRegions/gU3Zb/src/georegions/read.jl:417
julia> addNPDGeoRegions() # Checking to see if NASAPrecipitation.jl GeoRegions exists[ Info: 2024-02-17T00:57:15.083 - NASAPrecipitation.jl - Checking to see if GeoRegions required by NASAPrecipitation.jl have been added to the list of available GeoRegions [ Info: 2024-02-17T00:57:15.084 - NASAPrecipitation.jl - At least one of the required three GeoRegions (IMERG, TRMM, TRMMLSM) has not been added, proceeding to add them again ... [ Info: 2024-02-17T00:57:15.084 - GeoRegions.jl - Importing user-defined GeoRegions from the file /home/runner/work/NASAPrecipitation.jl/NASAPrecipitation.jl/src/NPDGeoRegions.txt directly into the custom lists [ Info: 2024-02-17T00:57:15.177 - GeoRegions.jl - Checking to see if the ID IMERG is in use ┌ Warning: 2024-02-17T00:57:15.211 - GeoRegions.jl - IMERG is not a valid GeoRegion identifier, use either RectRegion() or PolyRegion() to add this GeoRegion to the list. └ @ GeoRegions ~/.julia/packages/GeoRegions/gU3Zb/src/georegions/read.jl:489 [ Info: 2024-02-17T00:57:15.418 - GeoRegions.jl - Checking to see if the ID IMERG is in use ┌ Warning: 2024-02-17T00:57:15.418 - GeoRegions.jl - IMERG is not a valid GeoRegion identifier, use either RectRegion() or PolyRegion() to add this GeoRegion to the list. └ @ GeoRegions ~/.julia/packages/GeoRegions/gU3Zb/src/georegions/read.jl:489 [ Info: 2024-02-17T00:57:15.418 - GeoRegions.jl - Adding the GeoRegion IMERG to the list. [ Info: 2024-02-17T00:57:15.418 - GeoRegions.jl - Retrieving information for the GeoRegion defined by the ID GLB [ Info: 2024-02-17T00:57:15.419 - GeoRegions.jl - Performing a check to determine if the Global IMERG Dataset GeoRegion (IMERG) is inside the Globe GeoRegion (GLB) [ Info: 2024-02-17T00:57:15.419 - GeoRegions.jl - The GeoRegion IMERG (Global IMERG Dataset) is indeed a subset of the GeoRegion GLB (Globe) [ Info: 2024-02-17T00:57:15.420 - GeoRegions.jl - Checking to see if the ID TRMM is in use ┌ Warning: 2024-02-17T00:57:15.420 - GeoRegions.jl - TRMM is not a valid GeoRegion identifier, use either RectRegion() or PolyRegion() to add this GeoRegion to the list. └ @ GeoRegions ~/.julia/packages/GeoRegions/gU3Zb/src/georegions/read.jl:489 [ Info: 2024-02-17T00:57:15.421 - GeoRegions.jl - Checking to see if the ID TRMM is in use ┌ Warning: 2024-02-17T00:57:15.421 - GeoRegions.jl - TRMM is not a valid GeoRegion identifier, use either RectRegion() or PolyRegion() to add this GeoRegion to the list. └ @ GeoRegions ~/.julia/packages/GeoRegions/gU3Zb/src/georegions/read.jl:489 [ Info: 2024-02-17T00:57:15.421 - GeoRegions.jl - Adding the GeoRegion TRMM to the list. [ Info: 2024-02-17T00:57:15.421 - GeoRegions.jl - Retrieving information for the GeoRegion defined by the ID GLB [ Info: 2024-02-17T00:57:15.422 - GeoRegions.jl - Performing a check to determine if the Global TRMM Dataset GeoRegion (TRMM) is inside the Globe GeoRegion (GLB) [ Info: 2024-02-17T00:57:15.422 - GeoRegions.jl - The GeoRegion TRMM (Global TRMM Dataset) is indeed a subset of the GeoRegion GLB (Globe) [ Info: 2024-02-17T00:57:15.423 - GeoRegions.jl - Checking to see if the ID TRMMLSM is in use ┌ Warning: 2024-02-17T00:57:15.423 - GeoRegions.jl - TRMMLSM is not a valid GeoRegion identifier, use either RectRegion() or PolyRegion() to add this GeoRegion to the list. └ @ GeoRegions ~/.julia/packages/GeoRegions/gU3Zb/src/georegions/read.jl:489 [ Info: 2024-02-17T00:57:15.424 - GeoRegions.jl - Checking to see if the ID TRMMLSM is in use ┌ Warning: 2024-02-17T00:57:15.424 - GeoRegions.jl - TRMMLSM is not a valid GeoRegion identifier, use either RectRegion() or PolyRegion() to add this GeoRegion to the list. └ @ GeoRegions ~/.julia/packages/GeoRegions/gU3Zb/src/georegions/read.jl:489 [ Info: 2024-02-17T00:57:15.424 - GeoRegions.jl - Adding the GeoRegion TRMMLSM to the list. [ Info: 2024-02-17T00:57:15.424 - GeoRegions.jl - Retrieving information for the GeoRegion defined by the ID GLB [ Info: 2024-02-17T00:57:15.425 - GeoRegions.jl - Performing a check to determine if the Global TRMM LandSea Mask Dataset GeoRegion (TRMMLSM) is inside the Globe GeoRegion (GLB) [ Info: 2024-02-17T00:57:15.425 - GeoRegions.jl - The GeoRegion TRMMLSM (Global TRMM LandSea Mask Dataset) is indeed a subset of the GeoRegion GLB (Globe)
julia> GeoRegion("IMERG")[ Info: 2024-02-17T00:57:15.425 - GeoRegions.jl - Retrieving information for the GeoRegion defined by the ID IMERG The Rectilinear Region IMERG has the following properties: Region ID (ID) : IMERG Parent ID (pID) : GLB Name (name) : Global IMERG Dataset Bounds (N,S,E,W) : [89.95, -89.95, 180.0, -180.0] (is180,is360) : (true, false)
NASAPrecipitation.addNPDGeoRegionsMethod
addNPDGeoRegions() -> nothing

Checks for the three GeoRegions (GPM, TRMM, TRMMLSM) required by NASAPrecipitation.jl, and adds them if they do not exist.

source

GeoRegions.jl API

GeoRegions.GeoRegionType
GeoRegion

Abstract supertype for geographical regions, with the following subtypes:

RectRegion{ST<:AbstractString, FT<:Real} <: GeoRegion
PolyRegion{ST<:AbstractString, FT<:Real} <: GeoRegion

Both RectRegion and PolyRegion types contain the following fields:

  • ID - A String Type, the identifier for the GeoRegion
  • pID - A String Type, the identifier for the parent GeoRegion
  • name - A String Type, the full name of the GeoRegion
  • N - A Float Type, the north boundary of the GeoRegion
  • S - A Float Type, the south boundary of the GeoRegion
  • E - A Float Type, the east boundary of the GeoRegion
  • W - A Float Type, the est boundary of the GeoRegion
  • is180 - A Bool Type, is W < 0
  • is360 - A Bool Type, is E > 180

A PolyRegion type will also contain the following field:

  • shape - A vector of Point2 Types, defining a non-rectilinear shape of the GeoRegion
source
GeoRegions.PolyRegionType
PolyRegion(
    RegID :: AbstractString,
    ParID :: AbstractString,
    name  :: AbstractString,
    lonpt :: Vector{<:Real},
    latpt :: Vector{<:Real};
    savegeo :: Bool = true,
    verbose :: Bool = true,
    ST = String,
    FT = Float64
) -> PolyRegion{ST,FT}

Creates a rectilinear GeoRegion RegID.

Arguments

  • RegID : The keyword ID that will be used to identify the GeoRegion. If the ID is already in use, then an error will be thrown.

  • ParID : The ID of the parent GeoRegion where information can be extracted from

  • name : A name for the GeoRegion (meta information, can be used in Logging)

  • lonpt : A vector containing the longitude points

  • latpt : A vector containing the latitude points

Keyword Arguments

  • savegeo : Save the GeoRegion into the master list? Default is true
  • verbose : Verbose logging for ease of monitoring? Default is true
Start and End Points

The 1st and last elements of lonpt and latpt must be equal.

source
GeoRegions.RectRegionType
RectRegion(
    RegID :: AbstractString,
    ParID :: AbstractString,
    name  :: AbstractString,
    bound :: Vector{<:Real};
    savegeo :: Bool = true,
    verbose :: Bool = true,
    ST = String,
    FT = Float64
) -> RectRegion{ST,FT}

Creates a rectilinear GeoRegion RegID.

Arguments

  • RegID : The keyword ID that will be used to identify the GeoRegion. If the ID is already in use, then an error will be thrown.
  • ParID : The ID of the parent GeoRegion where information can be extracted from
  • name : A name for the GeoRegion (meta information, can be used in Logging)
  • bound : The [N,S,E,W] coordinates defining the region

Keyword Arguments

  • savegeo : Save the GeoRegion into the master list? Default is true
  • verbose : Verbose logging for ease of monitoring? Default is true
source
GeoRegions.isinGeoRegionFunction
isinGeoRegion(
    Point  :: Point2{<:Real},
    geo    :: GeoRegion;
    tlon   :: Real = 0,
    tlat   :: Real = 0,
    throw  :: Bool = true
) -> Bool

Check if a geographical point Point is within a GeoRegion defined by geo.

Arguments

  • Point : A geographical point of Type Point2. Pass Point2(plon,plat), where plon and plat are the longitude and latitudes of the point.
  • geo : The GeoRegion struct container

Keyword Arguments

  • tlon : Threshold for the longitude bound
  • tlat : Threshold for the latitude bound
  • throw : If true, then if Point is not within geo, an error is thrown and the program stops running.
source
isinGeoRegion(
    Child  :: GeoRegion,
    polyG  :: PolyRegion;
    domask :: Bool = false,
    throw  :: Bool = true
) -> Bool

Check if a child GeoRegion defined by Child is within a PolyRegion polyG.

Arguments

  • Child : A GeoRegion that we postulate to be a "child", or a subset of the GeoRegion defined by polyG
  • polyG : A GeoRegion that we postulate to be a "parent", or containing the GeoRegion defined by Child

Keyword Arguments

  • throw : If true, then if Child is not within polyG, an error is thrown and the program stops running
  • domask : If throw is false and domask is true, return a mask (with bounds defined by the Child GeoRegion) showing the region where Child and polyG do not overlap
source
isinGeoRegion(
    Child  :: GeoRegion,
    rectG  :: RectRegion;
    throw  :: Bool = true
) -> Bool

Check if a child GeoRegion defined by Child is within a RectRegion rectG.

Arguments

  • Child : A GeoRegion that we postulate to be a "child", or a subset of the GeoRegion defined by polyG
  • polyG : A GeoRegion that we postulate to be a "parent", or containing the GeoRegion defined by Child

Keyword Arguments

  • throw : If true, then if Child is not within polyG, an error is thrown and the program stops running
source
GeoRegions.coordGeoRegionFunction
coordGeoRegion(geo::PolyRegion) ->
    blon::Vector{<:Real}, blat::Vector{<:Real},
    slon::Vector{<:Real}, slat::Vector{<:Real},

For a given RectRegion, extract the [N,S,E,W] bounds and create a longitude and latitude vectors for the bound and the shape of the GeoRegion

Arguments

  • geo : A PolyRegion (i.e. a polygonal GeoRegion)

Returns

  • blon : A vector of longitude points for the bound of the GeoRegion
  • blat : A vector of latitude points for the bound of the GeoRegion
  • slon : A vector of longitude points for the shape of the GeoRegion
  • slat : A vector of latitude points for the shape of the GeoRegion
source
coordGeoRegion(geo::RectRegion) -> blon::Vector{<:Real}, blat::Vector{<:Real}

For a given RectRegion, extract the [N,S,E,W] bounds and create a longitude and latitude vector.

Arguments

  • geo : A RectRegion (i.e. a rectilinear GeoRegion)

Returns

  • blon : A vector of longitude points for the bound of the GeoRegion
  • blat : A vector of latitude points for the bound of the GeoRegion
source
GeoRegions.RegionGridType
RegionGrid

Abstract supertype for geographical region gridded information, with the following subtypes:

RectGrid{FT<:Real} <: RegionGrid
PolyGrid{FT<:Real} <: RegionGrid
RegionMask{FT<:Real} <: RegionGrid

Both RectGrid and PolyGrid types contain the following fields:

  • grid - A vector of Ints defining the gridpoint indices of the [N,S,E,W] points respectively
  • lon - A vector of Floats defining the latitude vector describing the region
  • lat - A vector of Floats defining the latitude vector describing the region
  • ilon - A vector of Ints defining indices of the parent longitude vector describing the region
  • ilat - A vector of Ints defining indices of the parent latitude vector describing the region

A PolyGrid type will also contain the following field:

  • mask - An array of 0s and 1s defining a non-rectilinear shape within a rectilinear grid where data is valid (only available in PolyGrid types)

A RegionMask type will contain the following fields:

  • lon - An array of longitude points
  • lat - An array of latitude points
  • mask - An array of NaNs and 1s defining the region within the original field in which data points are valid
source
GeoRegions.RegionGridMethod
RegionGrid(
    geo :: GeoRegion,
    lon :: Union{Vector{<:Real},AbstractRange{<:Real},
    lat :: Union{Vector{<:Real},AbstractRange{<:Real}
) -> RectGrid, PolyGrid

Creates a RectGrid or PolyGrid type based on the following arguments. This method is suitable for rectilinear grids of longitude/latitude output such as from Isca, or from satellite and reanalysis gridded datasets.

Arguments

  • geo : A GeoRegion of interest
  • lon : A vector or AbstractRange containing the longitude points
  • lat : A vector or AbstractRange containing the latitude points
source
GeoRegions.RegionGridMethod
RegionGrid(
    geo :: GeoRegion,
    lon :: Array{<:Real,2},
    lat :: Array{<:Real,2}
) -> RegionGrid

Creates a RegionMask type based on the following arguments. This method is more suitable for non-rectilinear grids of longitude and latitude points, such as in the output of WRF or CESM.

Arguments

  • geo : A GeoRegion of interest
  • lon : An array containing the longitude points
  • lat : An array containing the latitude points
source
GeoRegions.extractGridFunction
extractGrid(
    odata :: AbstractArray{<:Real,N},
    ggrd  :: RegionGrid
) where N <: Int -> Array{<:Real,N}

Extracts data from odata, an Array of dimension N (where N ∈ 2,3,4) that contains data of a Parent GeoRegion, into another Array of dimension N, containing only within a sub GeoRegion we are interested in.

Warning

Please ensure that the 1st dimension is longitude and 2nd dimension is latitude before proceeding. The order of the 3rd and 4th dimensions (when used), however, is not significant.

Arguments

  • odata : An array of dimension N containing gridded data in the region we are interesting in extracting from
  • ggrd : A RegionGrid containing detailed information on what to extract
source