test xarray with HSDS dataset

In [1]:
%matplotlib inline
import xarray as xr

Read time series from HSDS

In [3]:
url_hsds = 'http://149.165.156.174:5101/home/john/tmp2m_2months.nc'
ds_hsds = xr.open_dataset(url_hsds, engine='h5netcdf')
loc_hsds = ds_hsds.sel(longitude=-72.6+360, latitude=41.55, method='nearest')
%time loc_hsds['TMP_2maboveground'].plot();
/notebooks/rsignell/my-conda-envs/h5pyd/lib/python3.6/site-packages/xarray/plot/utils.py:51: FutureWarning: 'pandas.tseries.converter.register' has been moved and renamed to 'pandas.plotting.register_matplotlib_converters'. 
  converter.register()
CPU times: user 92 ms, sys: 8 ms, total: 100 ms
Wall time: 2.25 s
Out[3]:
[<matplotlib.lines.Line2D at 0x7f8f1dd07780>]

Read time series from OPeNDAP

In [4]:
url_dap = 'http://js-170-55.jetstream-cloud.org/thredds/dodsC/data/CFSR/2017/tmp2m_2months.nc'
ds_dap = xr.open_dataset(url_dap)
loc_dap = ds_dap.sel(longitude=-72.6+360, latitude=41.55, method='nearest')
%time loc_dap['TMP_2maboveground'].plot();
CPU times: user 76 ms, sys: 0 ns, total: 76 ms
Wall time: 14.6 s
Out[4]:
[<matplotlib.lines.Line2D at 0x7f8f10333ef0>]

Read time series from local netcdf4 file

In [5]:
url_nc = '/notebooks/rsignell/data/CFSR/tmp2m_2months.nc'
ds_nc = xr.open_dataset(url_nc)
loc_nc = ds_nc.sel(longitude=-72.6+360, latitude=41.55, method='nearest')
%time loc_nc['TMP_2maboveground'].plot();
CPU times: user 17.2 s, sys: 148 ms, total: 17.4 s
Wall time: 17.4 s
Out[5]:
[<matplotlib.lines.Line2D at 0x7f8f0f3ef908>]

Compare Metadata

In [6]:
loc_hsds['TMP_2maboveground']
Out[6]:
<xarray.DataArray 'TMP_2maboveground' (time: 1416)>
array([ 276.492188,  276.21875 ,  275.921875, ...,  282.929688,  282.132812,
        281.851562])
Coordinates:
    latitude   float64 41.6
    longitude  float64 287.4
  * time       (time) float64 1.483e+09 1.483e+09 1.483e+09 1.483e+09 ...
Attributes:
    least_significant_digit:  [2]
In [7]:
loc_dap['TMP_2maboveground']
Out[7]:
<xarray.DataArray 'TMP_2maboveground' (time: 1416)>
array([ 276.492188,  276.21875 ,  275.921875, ...,  282.929688,  282.132812,
        281.851562])
Coordinates:
    latitude   float64 41.6
  * time       (time) datetime64[ns] 2017-01-01T01:00:00 2017-01-01T02:00:00 ...
    longitude  float64 287.4
Attributes:
    short_name:   TMP_2maboveground
    long_name:    Temperature
    level:        2 m above ground
    units:        K
    _ChunkSizes:  [  1 440 880]
In [8]:
loc_nc['TMP_2maboveground']
Out[8]:
<xarray.DataArray 'TMP_2maboveground' (time: 1416)>
array([ 276.492188,  276.21875 ,  275.921875, ...,  282.929688,  282.132812,
        281.851562])
Coordinates:
    latitude   float64 41.6
    longitude  float64 287.4
  * time       (time) datetime64[ns] 2017-01-01T01:00:00 2017-01-01T02:00:00 ...
Attributes:
    short_name:  TMP_2maboveground
    long_name:   Temperature
    level:       2 m above ground
    units:       K

Read time series using NetCDF Subset Service as Points

In [ ]:
import pandas as pd
url = 'https://js-170-55.jetstream-cloud.org/thredds/ncss/grib/CFSr_v2/tmp2m?latitude=24.&longitude=24.&time_start=2017-01-01T01%3A00%3A00Z&time_end=2017-12-01T00%3A00%3A00Z&vertCoord=&accept=csv'
df = pd.read_csv(url)

Open dataset on OPeNDAP with Xarray

In [ ]:
dap_url = 'http://js-170-55.jetstream-cloud.org/thredds/dodsC/grib/CFSr_v2/tmp2m'
In [ ]:
ds2 = xr.open_dataset(dap_url)