In [13]:
import numpy as np
import pandas as pd
from ulmo.usgs import nwis
%matplotlib inline
In [15]:
#barnegat
sta_id='394540074062901'
In [16]:
# download and cache site data (this will take a long time the first time)
# currently downloads all available parameters
nwis.hdf5.update_site_data(sta_id)
In [17]:
sit = nwis.hdf5.get_site_data(sta_id, parameter_code='00035')
In [18]:
Out[18]:
In [ ]:
# wind speed and direction
vars=['00035','00036']
In [8]:
sit
Out[8]:
In [ ]:
#Try reading discharge data from another site
In [9]:
sta_id='06043500'
nwis.hdf5.update_site_data(sta_id)
# read daily mean discharge data from cache (statistics code 00003)
In [10]:
data = nwis.hdf5.get_site_data(sta_id, parameter_code='00060:00003')['00060:00003']
# convert data to a pandas dataframe
df = pd.DataFrame(data['values']).drop(['last_checked','last_modified','qualifiers'], axis=1).set_index('datetime')
df.value = df.value.apply(np.float)
df.index = pd.to_datetime(df.index).to_period('D')
# mark bad data as NaN
df[df.values == -999999] = np.nan
In [11]:
# group the data by month, day & calculate means
daily_groups = df.groupby((lambda d: d.month, lambda d: d.day))
means = daily_groups.mean()
print 'historic daily mean on March 23rd is %s' % means.ix[3,23].value
In [14]:
df.plot()
Out[14]:
In [ ]: