I'm trying to get PM2.5 data from the public NASA data base. Specifically, I'm following all the steps from this guide. I also created the three files just as explained on this requirements website. Still, I'm getting an error message when I'm running following line of code:
ds = xr.open_dataset(URL1).sel(lat=slice(lat1,lat2),lon=slice(lon1,lon2),time=slice(time1,time2))
That's the error message I'm getting:
syntax error, unexpected WORD_WORD, expecting SCAN_ATTR or SCAN_DATASET or SCAN_ERROR context: HTTP^ Basic: Access denied. Output exceeds the size limit. Open the full output data in a text editor--------------------------------------------------------------------------- KeyError Traceback (most recent call last) File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/xarray/backends/file_manager.py:210, in CachingFileManager._acquire_with_cache_info(self, needs_lock)
209 try:
--> 210 file = self._cache[self._key]
211 except KeyError:
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/xarray/backends/lru_cache.py:56, in LRUCache.__getitem__(self, key)
55 with self._lock:
---> 56 value = self._cache[key]
57 self._cache.move_to_end(key)
KeyError: [, ('https://goldsmr4.gesdisc.eosdis.nasa.gov/thredds/dodsC/MERRA2_MONTHLY_aggregation/M2TMNXAER.5.12.4_Aggregation.ncml',), 'r', (('clobber', True), ('diskless', False), ('format', 'NETCDF4'), ('persist', False)), '0847945a-4bb6-4085-8032-785c28de3f80']
During handling of the above exception, another exception occurred:
OSError Traceback (most recent call last) Input In [3], in ()
14 time2 = datetime(2019,12,1,0,30,0) # end date
16 # Read the data for the specified latitude/longitude and date range
---> 17 ds = xr.open_dataset(URL1).sel(lat=slice(lat1,lat2),lon=slice(lon1,lon2),time=slice(time1,time2))
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/xarray/backends/api.py:526, in open_dataset(filename_or_obj, engine, chunks, cache, decode_cf, mask_and_scale, decode_times, decode_timedelta, use_cftime, concat_characters, decode_coords, drop_variables, inline_array, backend_kwargs, **kwargs)
514 decoders = _resolve_decoders_kwargs(
515 decode_cf, ... File src/netCDF4/_netCDF4.pyx:2449, in netCDF4._netCDF4.Dataset.__init__()
File src/netCDF4/_netCDF4.pyx:2012, in netCDF4._netCDF4._ensure_nc_success()
OSError: [Errno -77] NetCDF: Access failure: 'https://goldsmr4.gesdisc.eosdis.nasa.gov/thredds/dodsC
/MERRA2_MONTHLY_aggregation/M2TMNXAER.5.12.4_Aggregation.ncml'
Can you guys give me any clues on what exactly the problem is? I created the three files (".netrc", ".urs_cookies" and ".dodsrc") and put them in my home directory. I also have a NASA account.
It has been a few months, but here is how I do it.
You need to save the script bellow as
nasa_merra2_get.pyand edit the the following variables:USR: your usernamePSW: your passwordglobal_file: the path to a global MERRA2 file downloaded "by hand". This file needs to hold the full global arrays for longitude and latitude. This file is used to get the indexes to perform a spatial subset.get_regionsfunction using a name and[lonmin, lonmax, latmin, latmax]extent./tmpfolder, you can change this if you need it../nasa_merra2_get.py -t YYYYmmdd -r your_region