[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[THREDDS #GUY-357996]: Grabbing RAP data with xarray from THREDDS
- Subject: [THREDDS #GUY-357996]: Grabbing RAP data with xarray from THREDDS
- Date: Thu, 06 Feb 2020 14:08:53 -0700
Greetings!
You're close to having it, but there are a couple more steps you need to do to
get the data--and a couple of options on how to proceed. The big difference is
that you're handing XArray URLs to data on the server, but the URLs are not for
services that xarray understands how to use.
Also, I would use siphon to make your life easier:
from siphon.catalog import TDSCatalog
import xarray as xr
from xarray.backends import NetCDF4DataStore
# Open catalog with Siphon
cat =
TDSCatalog('https://www.ncei.noaa.gov/thredds/catalog/ruc130anl/201010/20101026/catalog.xml')
ds = cat.datasets['ruc2anl_130_20101026_1200_000.grb2']
ncss = ds.subset()
# See what variables are available
#print(ncss.variables)
# Use NCSS to download a subset of variables, letting THREDDS convert GRIB to
netCDF
query = ncss.query()
query.variables('Temperature_isobaric', 'Geopotential_height_isobaric')
nc = ncss.get_data(query)
dataset = xr.open_dataset(NetCDF4DataStore(nc))
I was also able to use siphon to download the grib file and open using cfgrib,
but it wasn't immediately clear how to get cfgrib to open without error:
# Use cfgrib
ds.download()
dataset = xr.open_dataset(ds.name, engine='cfgrib',
backend_kwargs={'filter_by_keys':{'typeOfLevel': 'isobaricInhPa'}})
Hope this helps,
Ryan
> Hi,
>
> I am struggling grabbing data from the THREDDS server using xarray. I'm
> not sure if it is a problem accessing the server or if it is a problem
> with cf grib. I thought I would check here first to verify that the
> THREDDS implementation is correct.
>
> If I try the following command (borrowing some of the syntax from
>
> https://www.youtube.com/watch?v=_9j7Y1-lk-o):
>
> ds = xr.open_dataset('https://www.ncei.noaa.gov/thredds/ncss/ruc130anl/
> 201010/20101026/ruc2anl_130_20101026_1200_000.grb2',decode_times
> True,engine=)
>
> It says the file does not exist. Following the link, the path is
> correct. If I remove the https://, it seems to work, prompting me to
> use the cfgrib engine despite grabbing it from the netcdf subset server?
>
> Regardless, if I use the cfgrib engine:
>
> ds = xr.open_dataset('www.ncei.noaa.gov/thredds/ncss/ruc130anl/201010/
> 20101026/ruc2anl_130_20101026_1200_000.grb2',decode_times=True,engine
> 'cfgrib')
>
> Can't create file
> '/home/alex/www.ncei.noaa.gov/thredds/ncss/ruc130anl/201010/20101026/ruc2anl_130_20101026_1200_000.grb2.4cc40.idx'
>
> Followed by an error saying it is unable to open that .idx file. I looked
> into the documentation for cfgrib and it appears that the backend can
> be changed to not create an .idx file, however I end up getting this:
>
> ds = xr.open_dataset('www.ncei.noaa.gov/thredds/ncss/ruc130anl/201010/
> 20101026/ruc2anl_130_20101026_1200_000.grb2',decode_times=True,engine
> 'cfgrib',backend_kwargs={'indexpath':''})
>
> FileNotFoundError: [Errno 2] No such file or directory:
> '/home/alex/www.ncei.noaa.gov/thredds/ncss/ruc130anl/201010/20101026/ruc2anl_130_20101026_1200_000.grb2'
>
> I'm sure somewhere along the way I'm getting tripped up in the syntax, but
> I'm not sure exactly where.
Ticket Details
===================
Ticket ID: GUY-357996
Department: Support THREDDS
Priority: Normal
Status: Closed
===================
NOTE: All email exchanges with Unidata User Support are recorded in the Unidata
inquiry tracking system and then made publicly available through the web. If
you do not want to have your interactions made available in this way, you must
let us know in each email you send to us.