%matplotlib inline
import xarray as xr
import pandas as pd
start = '2017-01-01'
stop = '2017-03-01'
# Woods Hole, MA
lon0 = -70.67+360 ;
lat0 = 41.5
chunk_size=1
in time¶# URL from HSDS
url_hsds = 'http://149.165.156.174:5101/home/rsignell/tmp2m_2017.nc'
#url_hsds = 'http://149.165.156.174:5101/home/rsignell/tiny_rechunked.nc'
#url_hsds = 'http://149.165.156.174:5101/home/rsignell/tmp2m_2months_rechunked.nc'
# use decode_cf=False because this dataset was written with "hsload", which
# cannot read the time units from this recent netcdf4 file
ds_hsds = xr.open_dataset(url_hsds, engine='h5netcdf', decode_cf=False)
# next two lines are to add back in missing units
ds_hsds['time'].attrs['units']='seconds since 1970-01-01 00:00'
ds_hsds = xr.decode_cf(ds_hsds)
loc_hsds = ds_hsds.sel(longitude=lon0, latitude=lat0, method='nearest')
d_hsds = loc_hsds.sel(time=slice(start,stop))
%time d_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 124 ms, sys: 8 ms, total: 132 ms Wall time: 2.3 s
[<matplotlib.lines.Line2D at 0x7f0c0e0836a0>]
import h5pyd
f = h5pyd.File(url_hsds,'r')
ds = f['TMP_2maboveground']
ds.chunks
[1, 440, 880]
chunk_size=4
in time¶# use URL for the 2 month dataset
url_hsds = 'http://149.165.156.174:5101/home/rsignell/tmp2m_2017_rechunked.nc'
#url_hsds = 'http://149.165.156.174:5101/home/rsignell/tiny_rechunked.nc'
#url_hsds = 'http://149.165.156.174:5101/home/rsignell/tmp2m_2months_rechunked.nc'
# we can use decode_cf=True here because this HSDS dataset was written with
# a python script that used the netcdf4 library to read the attributes
ds_hsds = xr.open_dataset(url_hsds, engine='h5netcdf', decode_cf=True)
loc_hsds = ds_hsds.sel(longitude=lon0, latitude=lat0, method='nearest')
d_hsds = loc_hsds.sel(time=slice(start,stop))
%time d_hsds['TMP_2maboveground'].plot();
CPU times: user 76 ms, sys: 4 ms, total: 80 ms Wall time: 603 ms
[<matplotlib.lines.Line2D at 0x7f0c0dfe25f8>]
import h5pyd
f = h5pyd.File(url_hsds,'r')
ds = f['TMP_2maboveground']
ds.chunks
[4, 220, 440]
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=lon0, latitude=lat0, method='nearest')
d_dap = loc_dap.sel(time=slice(start,stop))
%time d_dap['TMP_2maboveground'].plot();
CPU times: user 76 ms, sys: 0 ns, total: 76 ms Wall time: 14.6 s
[<matplotlib.lines.Line2D at 0x7f0c03fda4a8>]
url_dap_grb2 = 'http://js-170-55.jetstream-cloud.org/thredds/dodsC/grib/CFSr_v2/tmp2m/Best'
ds_dap_grb2 = xr.open_dataset(url_dap_grb2)
loc_dap_grb2 = ds_dap_grb2.sel(lon=lon0, lat=lat0, method='nearest')
d_dap_grb2 = loc_dap_grb2.sel(time=slice(start,stop))
%time d_dap_grb2['Temperature_height_above_ground'].plot();
CPU times: user 128 ms, sys: 0 ns, total: 128 ms Wall time: 8min 39s
[<matplotlib.lines.Line2D at 0x7f0c03f559b0>]
url = ('https://js-170-55.jetstream-cloud.org/thredds'
'/ncss/grib/CFSr_v2/tmp2m/Best?var=Temperature_height_above_ground&'
'latitude={}&longitude={}&time_start={}T01%3A00%3A00Z&time_end={}T00%3A00%3A00Z&'
'vertCoord=&accept=csv'.format(lat0,lon0,start,stop))
%time df = pd.read_csv(url, parse_dates=True, index_col='time')
df['Temperature_height_above_ground[unit="K"]'].plot()
CPU times: user 60 ms, sys: 16 ms, total: 76 ms Wall time: 8min 27s
<matplotlib.axes._subplots.AxesSubplot at 0x7f0c0dfe2518>