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]:
<xray.DataArray 'time' ()>
numpy.datetime64('2014-02-07T09:51:29.999000000-0500')
Coordinates:
    time     datetime64[ns] 2014-02-07T14:51:29.999000

In [8]:
ds.data_vars


Out[8]:
Data variables:
    time2          (time) int32 53489999 57090000 60690000 64289999 67890000 ...
    burst          (time) int32 ...
    dspecfirstdir  (time) int16 ...
    wh_4061        (time, lat, lon) float64 ...
    wp_4060        (time, lat, lon) float64 ...
    mwh_4064       (time, lat, lon) float64 ...
    hght_18        (time, lat, lon) float64 ...
    wp_peak        (time, lat, lon) float64 ...
    wvdir          (time, lat, lon) float64 ...
    dspec          (time, frequency, direction, lat, lon) int32 ...
    pspec          (time, frequency, lat, lon) int32 ...
    sspec          (time, frequency, lat, lon) int32 ...
    vspec          (time, frequency, lat, lon) int32 ...

In [13]:
df = ds.data_vars['hght_18'].to_dataframe()

In [15]:
df.plot(figsize=(12,4))


Out[15]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f532f6b8f90>

In [55]:
t1.dtype()


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-55-2cedeb1df8cf> in <module>()
----> 1 t1.dtype()

TypeError: 'numpy.dtype' object is not callable

In [56]:
t1.type


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-56-d5515c393857> in <module>()
----> 1 t1.type

AttributeError: 'numpy.ndarray' object has no attribute 'type'

In [57]:
t1.dtype


Out[57]:
dtype('int32')

In [58]:
t2.dtype


Out[58]:
dtype('int64')

In [ ]: