-
Notifications
You must be signed in to change notification settings - Fork 16
/
Barnegat.py
75 lines (44 loc) · 1.38 KB
/
Barnegat.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# -*- coding: utf-8 -*-
# <nbformat>3.0</nbformat>
# <codecell>
import numpy as np
import pandas as pd
from ulmo.usgs import nwis
%matplotlib inline
# <codecell>
#barnegat
sta_id='394540074062901'
# <codecell>
# 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)
# <codecell>
sit = nwis.hdf5.get_site_data(sta_id, parameter_code='00035')
# <codecell>
# <codecell>
# wind speed and direction
vars=['00035','00036']
# <codecell>
sit
# <codecell>
#Try reading discharge data from another site
# <codecell>
sta_id='06043500'
nwis.hdf5.update_site_data(sta_id)
# read daily mean discharge data from cache (statistics code 00003)
# <codecell>
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
# <codecell>
# 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
# <codecell>
df.plot()
# <codecell>