How do I copy only some variables from an online dataset
I am trying to download GFS data from NOAA’s DODS Nomads Server and then make a copy of the dataset for offline use. I am able to access the data with either library in small chunks successfully by accessing individual variables. However, I am unable to download the entire dataset and convert it to a local netcdf file. I have tried with both netcdf4 and xarray using examples from this post but keep getting runtime errors.
With the following code
import xarray as xr url = u'https://nomads.ncep.noaa.gov:9090/dods/gfs_0p25/gfs20200714/gfs_0p25_12z' ds = xr.open_dataset(url, engine='netcdf4') ds.to_netcdf('test.nc')
I get the error:
RuntimeError: NetCDF: file not found
I then tried to load the entire dataset before writing to a file and received a different runtime error.
with xr.open_dataset(url) as ds: ds.load() ds.to_netcdf('test.nc')
Produces the error:
RuntimeError: NetCDF: DAP failure
Is there a workaround to this timeout issue (if that’s what the issue is) with the DODS server or a way to generate a trimmed netcdf file from the server by only copying variables I need instead, of the 40+ that are included in the online dataset.