Downloading and Reading NASA Precipitation Datasets
In this page we show how you can download data for a given NASAPrecipitation dataset.
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]
nothingRequired dependencies
Since we are downloading from NASA's EOSDIS OPeNDAP servers, you are required to perform the following:
You need to register an account with Earthdata and allow access to the NASA EOSDISC on it.
Create a
.netrcfile with the following information:machine urs.earthdata.nasa.gov login <your login> password <your password>Create a
.dodsrcfile with the following lines: (1)HTTP.COOKIEJAR=/<home directory>/.urs_cookiesand (2)HTTP.NETRC=/<home directory>/.netrc
If this sounds complicated however, fear not! You need only perform the first step yourself (i.e. create your own account), for NASAPrecipitation.jl will automatically set up the .dodsrc file (if you don't already have one), and once you have your <login> and <password>, you can use the function setup() to set up your .netrc file.
setup(
login = <username>
password = <password>
)Downloading NASAPrecipitationDatasets
Downloading NASA Precipitation data is as simple as
npd = NASAPrecipitationDataset(args...)
geo = GeoRegion(args...)
download(npd,geo)Let us download the IMERGMonthly Dataset for 2020 over the Caribbean (as defined by the AR6 IPCC), for example
# npd = IMERGMonthly(start=Date(2020),stop=Date(2020),path=pwd())
# geo = GeoRegion("AR6_CAR")
hroot = "https://gpm1.gesdisc.eosdis.nasa.gov/opendap/AUXILIARY"
npdnc = "GPM_IMERG_LandSeaMask.2/GPM_IMERG_LandSeaMask.2.nc4"
npdds = NCDataset(joinpath(hroot,npdnc),"r")
npdds["landseamask"][1]
# lsd = getLandSea(npd,geo)
# download(npd,geo)Reading data for a downloaded NASAPrecipitationDataset
And now that you have downloaded the data, you can use the function read() to call the NCDataset that points towards the downloaded data.
ds = read(npd,geo,Date(2020))As shown in the printout of the NCDataset, the precipitation data is saved under the field name precipitation, and is in units of kg m**-2 s**-1, or alternatively mm s**-1.
prcp = ds["precipitation"][:,:,:] * 3600
close(ds)
fig = Figure()
_,_,slon,slat = coordGeoRegion(geo)
aspect = (maximum(slon)-minimum(slon))/(maximum(slat)-minimum(slat))
ax = Axis(
fig[1,1],width=350,height=350/aspect,
title="February 2020",xlabel="Longitude / º",ylabel="Latitude / º",
limits=(minimum(slon)-2,maximum(slon)+2,minimum(slat)-2,maximum(slat)+2)
)
contourf!(
ax,lsd.lon,lsd.lat,prcp[:,:,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)
ax = Axis(
fig[1,2],width=350,height=350/aspect,
title="August 2020",xlabel="Longitude / º",
limits=(minimum(slon)-2,maximum(slon)+2,minimum(slat)-2,maximum(slat)+2)
)
contourf!(
ax,lsd.lon,lsd.lat,prcp[:,:,8],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)
hideydecorations!(ax, ticks = false,grid=false)
resize_to_layout!(fig)
figWhere is the data saved to?
You can check where the data is saved to for a given dataset, georegion and datetime by using the function npdfnc()
fnc = npdfnc(npd,geo,Date(2020))API
NASAPrecipitation.setup Function
setup(;
login :: AbstractString = "",
password :: AbstractString = "",
overwrite :: Bool = false
)Function that sets up your .ncrc and .netrc files for you. If you do not provide the keyword arguments for login and password, the .netrc file will not be created.
Keyword arguments
login: Your Earthdata username. You need to specify bothloginandpasswordarguments.password: Your Earthdata password. You need to specify bothloginandpasswordarguments.overwrite: Iftrue, overwrite existing.ncrcand.netrcfiles with the data provided.
Base.download Function
download(
npd :: NASAPrecipitationDataset,
geo :: GeoRegion = GeoRegion("GLB");
overwrite :: Bool = false
) -> nothingDownloads a NASA Precipitation dataset specified by npd for a GeoRegion specified by geo
Arguments
npd: aNASAPrecipitationDatasetspecifying the dataset details and date download rangegeo: aGeoRegion(see GeoRegions.jl) that sets the geographic bounds of the data array in lon-lat
Keyword Arguments
overwrite: Iftrue, overwrite any existing files
Base.read Function
read(
npd :: NASAPrecipitationDataset,
geo :: GeoRegion,
dt :: TimeType;
smooth :: Bool = false,
smoothlon :: Real = 0,
smoothlat :: Real = 0,
smoothtime :: Real = 0,
quiet :: Bool = false
) -> NCDatasetReads a NASA Precipitation dataset specified by npd for a GeoRegion specified by geo at a date specified by dt.
Arguments
npd: aNASAPrecipitationDatasetspecifying the dataset details and date download rangegeo: aGeoRegion(see GeoRegions.jl) that sets the geographic bounds of the data array in lon-latdt: A specified date. The NCDataset retrieved may will contain data for the date, although it may also contain data for other dates depending on theNASAPrecipitationDatasetspecified bynpd
Keyword Arguments
smooth:smoothlon:smoothlat:smoothtime:quiet:
NASAPrecipitation.npdfnc Function
npdfnc(
npd :: NASAPrecipitationDataset,
geo :: GeoRegion,
dt :: TimeType
) -> StringReturns of the path of the file for the NASA Precipitation dataset specified by npd for a GeoRegion specified by geo at a date specified by dt.
Arguments
npd: aNASAPrecipitationDatasetspecifying the dataset details and date download rangegeo: aGeoRegion(see GeoRegions.jl) that sets the geographic bounds of the data array in lon-latdt: A specified date. The NCDataset retrieved may will contain data for the date, although it may also contain data for other dates depending on theNASAPrecipitationDatasetspecified bynpd