Extracting data from existing data into a subGeoRegion

One of the drawbacks of retrieving data from the OPeNDAP server is that the connection is slower than using the direct-download method. This cost can become especially noticeable when we are attempting to retrieve data for smaller regions of interest, where the lag caused by opening and closing remote datasets can add up and even take a longer time than doing a direct download.

Thus, drawing upon the functionality of extractGrid() in GeoRegions.jl, we have added in the ability to extract data for a smaller GeoRegion, provided that data for a larger GeoRegion has already been downloaded.

The extraction of data is as easy as

extract(
    <NASAPrecipitation Dataset>,
    <subGeoRegion>,
    <parentGeoRegion>,
)

Setup

using NASAPrecipitation
using CairoMakie
using DelimitedFiles

download("https://raw.githubusercontent.com/natgeo-wong/GeoPlottingData/main/coastline_resl.txt","coast.cst")
coast = readdlm("coast.cst",comments=true)
clon  = coast[:,1]
clat  = coast[:,2]
nothing

An Example: Extracting Data for Southeast Asia from a larger Tropical Domain

Let's define the Tropical Domain and download some NASAPrecipitation data for this region:

npd = TRMMMonthly(start=Date(2015),stop=Date(2015))
pgeo = RectRegion("TRP","GLB","Tropics",[30,-30,360,0],savegeo=false)
download(npd,pgeo)
[ Info: 2024-02-17T00:56:57.553 - NASAPrecipitation.jl - Setting up data structure containing information on TRMM Monthly data to be downloaded
[ Info: 2024-02-17T00:56:57.619 - GeoRegions.jl - Checking to see if the ID TRP is in use
┌ Warning: 2024-02-17T00:56:57.619 - GeoRegions.jl - TRP 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:56:57.619 - GeoRegions.jl - Adding the GeoRegion TRP to the list.
[ Info: 2024-02-17T00:56:57.623 - GeoRegions.jl - Retrieving information for the GeoRegion defined by the ID GLB
[ Info: 2024-02-17T00:56:57.663 - GeoRegions.jl - Performing a check to determine if the Tropics GeoRegion (TRP) is inside the Globe GeoRegion (GLB)
[ Info: 2024-02-17T00:56:57.663 - GeoRegions.jl - The GeoRegion TRP (Tropics) is indeed a subset of the GeoRegion GLB (Globe)
[ Info: 2024-02-17T00:56:58.733 - NASAPrecipitation.jl - Downloading TRMM Monthly (TMPA 3B43) data for the Tropics GeoRegion from 2015-01-01 to 2015-12-31
[ Info: 2024-02-17T00:56:58.733 - GeoRegions.jl - Retrieving information for the GeoRegion defined by the ID TRMM
[ Info: 2024-02-17T00:56:58.734 - GeoRegions.jl - Performing a check to determine if the Tropics GeoRegion (TRP) is inside the Global TRMM Dataset GeoRegion (TRMM)
[ Info: 2024-02-17T00:56:58.734 - GeoRegions.jl - The GeoRegion TRP (Tropics) is indeed a subset of the GeoRegion TRMM (Global TRMM Dataset)
[ Info: 2024-02-17T00:56:58.734 - GeoRegions.jl - Creating a RegionGrid for the Tropics GeoRegion
[ Info: 2024-02-17T00:56:58.734 - GeoRegions.jl - Creating vector of latitude indices to extract ...
[ Info: 2024-02-17T00:56:58.734 - GeoRegions.jl - Creating vector of longitude indices to extract ...
[ Info: 2024-02-17T00:56:58.734 - NASAPrecipitation.jl - Preallocating temporary arrays for extraction of TRMM Monthly (TMPA 3B43) data for the Tropics GeoRegion from the original gridded dataset
[ Info: 2024-02-17T00:56:58.737 - NASAPrecipitation.jl - Downloading TRMM Monthly (TMPA 3B43) data for the Tropics GeoRegion from the NASA Earthdata servers using OPeNDAP protocols for 2015 ...
[ Info: 2024-02-17T00:57:07.402 - NASAPrecipitation.jl - Saving TRMM Monthly (TMPA 3B43) data in the Tropics GeoRegion for 2015-01-01
[ Info: 2024-02-17T00:57:07.402 - NASAPrecipitation.jl - Creating NetCDF file /home/runner/trmmmonthly/TRP/trmmmonthly-TRP-2015.nc ...
[ Info: 2024-02-17T00:57:07.422 - NASAPrecipitation.jl - TRMM Monthly (TMPA 3B43) data in the Tropics GeoRegion for 2015-01-01 has been saved into /home/runner/trmmmonthly/TRP/trmmmonthly-TRP-2015.nc

We then proceed to define a subGeoRegion, and then extract the data

sgeo = GeoRegion("AR6_SEA")
extract(npd,sgeo,pgeo)
[ Info: 2024-02-17T00:57:07.423 - GeoRegions.jl - Retrieving information for the GeoRegion defined by the ID AR6_SEA
[ Info: 2024-02-17T00:57:08.160 - GeoRegions.jl - Performing a check to determine if the Southeast Asia GeoRegion (AR6_SEA) is inside the Tropics GeoRegion (TRP)
[ Info: 2024-02-17T00:57:08.160 - GeoRegions.jl - The GeoRegion AR6_SEA (Southeast Asia) is indeed a subset of the GeoRegion TRP (Tropics)
[ Info: 2024-02-17T00:57:08.160 - NASAPrecipitation.jl - Retrieving GeoRegion and LandSea Dataset information for the parent GeoRegion of "TRP", "GLB"
[ Info: 2024-02-17T00:57:08.160 - NASAPrecipitation.jl - Checking to see if the specified GeoRegion "TRP" is within the "TRMMLSM" GeoRegion
[ Info: 2024-02-17T00:57:08.160 - GeoRegions.jl - Retrieving information for the GeoRegion defined by the ID TRMMLSM
[ Info: 2024-02-17T00:57:08.162 - GeoRegions.jl - Performing a check to determine if the Tropics GeoRegion (TRP) is inside the Global TRMM LandSea Mask Dataset GeoRegion (TRMMLSM)
[ Info: 2024-02-17T00:57:08.162 - GeoRegions.jl - The GeoRegion TRP (Tropics) is indeed a subset of the GeoRegion TRMMLSM (Global TRMM LandSea Mask Dataset)
[ Info: 2024-02-17T00:57:08.162 - NASAPrecipitation.jl - The TRMM Land-Sea mask dataset for the "TRP" GeoRegion is not available, extracting from Global TRMM Land-Sea mask dataset ...
[ Info: 2024-02-17T00:57:08.162 - NASAPrecipitation.jl - The Global TRMM Land-Sea mask dataset for the "TRP" GeoRegion is not available, downloading from the Climate Data Store ...
[ Info: 2024-02-17T00:57:08.162 - NASAPrecipitation.jl - Retrieving the original TRMM-TMPA Land-Sea Mask data from NASA's EOSDIS OPeNDAP servers
[ Info: 2024-02-17T00:57:08.694 - GeoRegions.jl - Retrieving information for the GeoRegion defined by the ID TRMMLSM
[ Info: 2024-02-17T00:57:08.966 - GeoRegions.jl - Creating a RegionGrid for the Tropics GeoRegion
[ Info: 2024-02-17T00:57:08.967 - GeoRegions.jl - Creating vector of latitude indices to extract ...
[ Info: 2024-02-17T00:57:08.967 - GeoRegions.jl - Creating vector of longitude indices to extract ...
[ Info: 2024-02-17T00:57:08.983 - NASAPrecipitation.jl - Extracting regional TRMM Land-Sea mask for the "TRP" GeoRegion from the Global TRMM Land-Sea mask dataset ...
[ Info: 2024-02-17T00:57:09.254 - NASAPrecipitation.jl - Retrieving the regional TRMM Land-Sea mask for the "TRP" GeoRegion ...
[ Info: 2024-02-17T00:57:09.255 - NASAPrecipitation.jl - Creating RegionGrid for "AR6_SEA" based on the longitude and latitude vectors of the parent GeoRegion "GLB"
[ Info: 2024-02-17T00:57:09.255 - GeoRegions.jl - Creating a RegionGrid for the Southeast Asia GeoRegion
[ Info: 2024-02-17T00:57:09.255 - GeoRegions.jl - Creating vector of latitude indices to extract ...
[ Info: 2024-02-17T00:57:09.255 - GeoRegions.jl - Creating vector of longitude indices to extract ...
[ Info: 2024-02-17T00:57:09.255 - GeoRegions.jl - Since the Southeast Asia GeoRegion is a PolyRegion, we need to defined a mask as well ...
[ Info: 2024-02-17T00:57:09.271 - NASAPrecipitation.jl - Opening the TRMM Monthly (TMPA 3B43) NCDataset in the TRP GeoRegion for 2015-01-01
[ Info: 2024-02-17T00:57:09.351 - NASAPrecipitation.jl - Extracting the TRMM Monthly (TMPA 3B43) precipitation data in Southeast Asia GeoRegion from the Tropics GeoRegion for 2015 January
[ Info: 2024-02-17T00:57:09.353 - NASAPrecipitation.jl - Saving TRMM Monthly (TMPA 3B43) data in the Southeast Asia GeoRegion for 2015-01-01
[ Info: 2024-02-17T00:57:09.353 - NASAPrecipitation.jl - Creating NetCDF file /home/runner/trmmmonthly/AR6_SEA/trmmmonthly-AR6_SEA-2015.nc ...
[ Info: 2024-02-17T00:57:09.715 - NASAPrecipitation.jl - TRMM Monthly (TMPA 3B43) data in the Southeast Asia GeoRegion for 2015-01-01 has been saved into /home/runner/trmmmonthly/AR6_SEA/trmmmonthly-AR6_SEA-2015.nc

Now, let us proceed to compare and contrast the two Regions

ds = read(npd,pgeo,Date(2015))
prcp_pgeo = ds["precipitation"][:,:,:] * 3600
lsd_pgeo  = getLandSea(npd,pgeo)
close(ds)
ds = read(npd,sgeo,Date(2015))
prcp_sgeo = ds["precipitation"][:,:,:] * 3600
lsd_sgeo  = getLandSea(npd,sgeo)
close(ds)

fig = Figure()
_,_,slon,slat = coordGeoRegion(sgeo)
aspect = (maximum(slon)-minimum(slon)+90)/(maximum(slat)-minimum(slat)+30)

ax = Axis(
    fig[1,1],width=750,height=750/aspect,
    title="February 2015",xlabel="Longitude / º",ylabel="Latitude / º",
    limits=(minimum(slon)-45,maximum(slon)+45,minimum(slat)-15,maximum(slat)+15)
)
contourf!(
    ax,lsd_pgeo.lon,lsd_pgeo.lat,prcp_pgeo[:,:,2],colormap=:Greens,
    levels=range(0,0.5,length=11),extendlow=:auto,extendhigh=:auto
)
contourf!(
    ax,lsd_sgeo.lon,lsd_sgeo.lat,prcp_sgeo[:,:,2],colormap=:Blues,
    levels=range(0,0.5,length=11),extendlow=:auto,extendhigh=:auto
)
lines!(ax,clon,clat,color=:black)
lines!(ax,slon,slat,color=:red,linewidth=5)

resize_to_layout!(fig)
fig
Example block output

API

NASAPrecipitation.extractFunction
extract(
    npd :: NASAPrecipitationDataset,
    geo :: GeoRegion
) -> nothing

Extracts NASAPrecipitation data for a GeoRegion geo from its parent GeoRegion geo.pID.

Note

Data for the parent GeoRegion identified by geo.pID must already exist.

Arguments

  • npd : a NASAPrecipitationDataset specifying the dataset details and date download range
  • geo : a GeoRegion (see GeoRegions.jl) that sets the geographic bounds of the data array in lon-lat
source
extract(
    npd  :: NASAPrecipitationDataset,
    sgeo :: GeoRegion,
    pgeo :: GeoRegion,
) -> nothing

Extracts NASAPrecipitation data for a GeoRegion sgeo from a bigger GeoRegion pgeo.

Note

Data for the parent GeoRegion identified by pgeo must already exist, and sgeo must be fully within the bounds of pgeo.

Arguments

  • npd : a NASAPrecipitationDataset specifying the dataset details and date download range
  • sgeo : a GeoRegion (see GeoRegions.jl) that sets the geographic bounds of the data array in lon-lat
  • pgeo : a GeoRegion that is a "parent" of the GeoRegion of interest sgeo, in the sense that sgeo must be fully within pgeo.
source