In [1]:
import xray
import pandas as pd
import numpy as np
%matplotlib inline
In [2]:
url='http://geoport.whoi.edu/thredds/dodsC/usgs/data2/emontgomery/stellwagen/Data/FI14/10001whp-cal.nc'
In [3]:
ds = xray.open_dataset(url)
In [4]:
def convert_epic_time(ds):
""" convert EPIC time and time2 variables to datenum64 """
t1 = np.array(ds.coords['time'].values - 2440000,dtype='int64')*3600*24*1000
t2 = np.array(ds.data_vars['time2'].values, dtype='int64')
dt64 = [np.datetime64('1968-05-23T00:00:00Z') + np.timedelta64(a,'ms') for a in t1+t2]
ds.coords['time'] = dt64
In [5]:
# if we find a time2 variable, convert EPIC time and time2 variables to datetime64 object
if 'time2' in ds.data_vars.keys():
convert_epic_time(ds)
In [7]:
ds.coords['time'][0]
Out[7]:
In [8]:
ds.data_vars
Out[8]:
In [13]:
df = ds.data_vars['hght_18'].to_dataframe()
In [15]:
df.plot(figsize=(12,4))
Out[15]:
In [55]:
t1.dtype()
In [56]:
t1.type
In [57]:
t1.dtype
Out[57]:
In [58]:
t2.dtype
Out[58]:
In [ ]: