Select a specific OPeNDAP variable to subset and stride, then write the result to a NetCDF file
In [1]:
import xray
In [2]:
xray.__version__
Out[2]:
specify the opendap data url endpoint
In [3]:
url ='http://ecowatch.ncddc.noaa.gov/thredds/dodsC/hycom_sfc/20151007/hycom_glb_sfc_2015100700_t000.nc'
create the xray dataset from an opendap endpoint, but drop the 'tau' variable because it's units are invalid:
In [4]:
ds = xray.open_dataset(url,drop_variables=['tau'])
In [5]:
ds['water_temp']
Out[5]:
subsample the xray dataarray object and promote to a dataset
In [6]:
ds_wt = ds['water_temp'][0,0,::12,::12].to_dataset()
save subsetted data to netcdf, includes coordinate values as well
In [7]:
ds_wt.to_netcdf('water_temp.nc')