Getting MERRA-2 data into R

Use this Forum to find information on, or ask a question about, NASA Earth Science data.
Post Reply
kodiologist
Posts: 8
Joined: Wed Oct 07, 2020 9:09 am America/New_York
Answers: 0

Getting MERRA-2 data into R

by kodiologist » Wed Oct 07, 2020 9:26 am America/New_York

I'd like to retrieve MERRA-2's PM_{2.5} product over the coterminous US over a range of years. I think I've worked out how to construct OPeNDAP URLs for the slices of data I want, but I'm using R for analysis and I'm having trouble finding a file format that GrADS Data Server can produce and R can read. It seems that other OPeNDAP servers, like Hyrax, can produce NetCDF, but not GrADS Data Server.

My best lead seems to be that GDAL, which is accessible through R as rgdal, claims to have DODS support, but:

> wget 'http://opendap.nccs.nasa.gov/dods/merra2_gmi/tavg1_2d_aer_Nx.dods?pm25[1:3][1:3][1:3]' -O out.dods
> gdalinfo out.dods
ERROR 4: `out.dods' not recognized as a supported file format.
gdalinfo failed - unable to open 'out.dods'.

Tags:

GES DISC - mgreene
User Services
User Services
Posts: 186
Joined: Wed Sep 25, 2019 9:35 am America/New_York
Answers: 2
Been thanked: 1 time

Re: Getting MERRA-2 data into R

by GES DISC - mgreene » Wed Oct 07, 2020 1:41 pm America/New_York

Thank you for your interest in MERRA-2 data. To better assist with your request regarding data download could you please send an email to the NASA GES DISC Help Desk,
at gsfc-help-disc@lists.nasa.gov
thank you

kodiologist
Posts: 8
Joined: Wed Oct 07, 2020 9:09 am America/New_York
Answers: 0

Re: Getting MERRA-2 data into R

by kodiologist » Wed Oct 07, 2020 1:57 pm America/New_York

Thanks. I've dropped them a line.

kodiologist
Posts: 8
Joined: Wed Oct 07, 2020 9:09 am America/New_York
Answers: 0

Re: Getting MERRA-2 data into R

by kodiologist » Tue Oct 27, 2020 11:43 am America/New_York

For posterity, here was how I ended up handling this. Luke Oman of NASA/GSFC kindly pointed me to a command-line program, `ncks`, that can retrieve a netCDF file from an OPeNDAP server, even one that doesn't seem to produce netCDF otherwise, so I guess `ncks` processes the DODS internally. Instead of constructing OPeNDAP URLs yourself, you use command-line arguments to specify what to retrieve. `ncks`, the netCDF Kitchen Sink, is part of NCO (http://nco.sourceforge.net/), which can be installed with the Debian package `nco`. I use R code like

function(target.path) repeat
# Use `ncks` to download a netCDF file for the study
# region in this month. The download may need to be
# retried.
{r = system2('ncks', stdout = F, stderr = F, paste(
'-v pm25 -O --no_tmp_fl',
sprintfv('-d lon,%s,%s -d lat,%s,%s', shQuote(
geo.ix - 1)),
sprintfv('-d time,%s,%s', shQuote(
range(which(m.ix$times %in% fetch.times)) - 1)),
shQuote('https://opendap.nccs.nasa.gov/dods/merra2_gmi/tavg1_2d_aer_Nx'),
shQuote(target.path)))
if (r == 0)
return(T)}

The netCDF file can then be read with `raster::stack` or `rgdal::readGDAL`.

GES DISC - mgreene
User Services
User Services
Posts: 186
Joined: Wed Sep 25, 2019 9:35 am America/New_York
Answers: 2
Been thanked: 1 time

Re: Getting MERRA-2 data into R

by GES DISC - mgreene » Tue Oct 27, 2020 4:50 pm America/New_York

Thank you so much for this information.
Best regards,

Post Reply