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.
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 RegionGrid
s, 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 byparID
, which must itself be a validID
)
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).
Predefined GeoRegion
s in NASAPrecipitation.jl
By default, NASAPrecipitation.jl will download all available data. This means
- For
IMERGDataset
s, the data spans 89.95ºS to 89.95ºN - For
TRMMDataset
s, 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 GeoRegion
s 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 GeoRegion
s 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.addNPDGeoRegions
— MethodaddNPDGeoRegions() -> nothing
Checks for the three GeoRegions (GPM, TRMM, TRMMLSM) required by NASAPrecipitation.jl, and adds them if they do not exist.
GeoRegions.jl API
GeoRegions.GeoRegion
— TypeGeoRegion
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
- AString
Type, the identifier for the GeoRegionpID
- AString
Type, the identifier for the parent GeoRegionname
- AString
Type, the full name of the GeoRegionN
- AFloat
Type, the north boundary of the GeoRegionS
- AFloat
Type, the south boundary of the GeoRegionE
- AFloat
Type, the east boundary of the GeoRegionW
- AFloat
Type, the est boundary of the GeoRegionis180
- ABool
Type, isW
< 0is360
- ABool
Type, isE
> 180
A PolyRegion
type will also contain the following field:
shape
- A vector ofPoint2
Types, defining a non-rectilinear shape of the GeoRegion
GeoRegions.PolyRegion
— TypePolyRegion(
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 fromname
: A name for the GeoRegion (meta information, can be used in Logging)lonpt
: A vector containing the longitude pointslatpt
: A vector containing the latitude points
Keyword Arguments
savegeo
: Save the GeoRegion into the master list? Default istrue
verbose
: Verbose logging for ease of monitoring? Default istrue
The 1st and last elements of lonpt
and latpt
must be equal.
GeoRegions.RectRegion
— TypeRectRegion(
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 fromname
: 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 istrue
verbose
: Verbose logging for ease of monitoring? Default istrue
GeoRegions.isinGeoRegion
— FunctionisinGeoRegion(
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 TypePoint2
. PassPoint2(plon,plat)
, whereplon
andplat
are the longitude and latitudes of the point.geo
: The GeoRegion struct container
Keyword Arguments
tlon
: Threshold for the longitude boundtlat
: Threshold for the latitude boundthrow
: Iftrue
, then ifPoint
is not withingeo
, an error is thrown and the program stops running.
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 bypolyG
polyG
: A GeoRegion that we postulate to be a "parent", or containing the GeoRegion defined byChild
Keyword Arguments
throw
: Iftrue
, then ifChild
is not withinpolyG
, an error is thrown and the program stops runningdomask
: Ifthrow
isfalse
anddomask
istrue
, return a mask (with bounds defined by theChild
GeoRegion) showing the region whereChild
andpolyG
do not overlap
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 bypolyG
polyG
: A GeoRegion that we postulate to be a "parent", or containing the GeoRegion defined byChild
Keyword Arguments
throw
: Iftrue
, then ifChild
is not withinpolyG
, an error is thrown and the program stops running
GeoRegions.coordGeoRegion
— FunctioncoordGeoRegion(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 GeoRegionblat
: A vector of latitude points for the bound of the GeoRegionslon
: A vector of longitude points for the shape of the GeoRegionslat
: A vector of latitude points for the shape of the GeoRegion
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 GeoRegionblat
: A vector of latitude points for the bound of the GeoRegion
GeoRegions.RegionGrid
— TypeRegionGrid
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 ofInt
s defining the gridpoint indices of the [N,S,E,W] points respectivelylon
- A vector ofFloat
s defining the latitude vector describing the regionlat
- A vector ofFloat
s defining the latitude vector describing the regionilon
- A vector ofInt
s defining indices of the parent longitude vector describing the regionilat
- A vector ofInt
s 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 pointslat
- An array of latitude pointsmask
- An array of NaNs and 1s defining the region within the original field in which data points are valid
GeoRegions.RegionGrid
— MethodRegionGrid(
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 interestlon
: A vector orAbstractRange
containing the longitude pointslat
: A vector orAbstractRange
containing the latitude points
GeoRegions.RegionGrid
— MethodRegionGrid(
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 interestlon
: An array containing the longitude pointslat
: An array containing the latitude points
GeoRegions.extractGrid
— FunctionextractGrid(
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.
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 fromggrd
: ARegionGrid
containing detailed information on what to extract