Read USGS streamflow using PYOOS


In [1]:
from pylab import *
import pandas as pd
import datetime as dt
from pyoos.collectors.usgs.usgs_rest import UsgsRest

Specify a bounding box and time range of interest:


In [2]:
box=[-87,46,-85,48]

In [3]:
# last few days
jd_start = dt.datetime.utcnow()- dt.timedelta(days=3)
jd_stop = dt.datetime.utcnow()

In [4]:
# hurricane sandy time period
jd_start = dt.datetime(2012,10,26)
jd_stop = dt.datetime(2012,11,2)

In [5]:
print jd_start
print jd_stop


2012-10-26 00:00:00
2012-11-02 00:00:00

Get observations from USGS Rest


In [6]:
c = UsgsRest()

In [7]:
c.list_variables()


Out[7]:
'Find variables using this website: http://help.waterdata.usgs.gov/codes-and-parameters/parameters'

In [8]:
c.filter(bbox=tuple(box), start=jd_start, end=jd_stop)
col = c.collect()
col.calculate_bounds()

In [9]:
for sta in col.elements: print sta.name,sta.location.x,sta.location.y


AU TRAIN RIVER AT FOREST LAKE, MI -86.8501514 46.34077908
TAHQUAMENON RIVER NEAR PARADISE, MI -85.2695548 46.57501478
BLACK RIVER NEAR GARNET, MI -85.3653694 46.1180556
MANISTIQUE RIVER NEAR MANISTIQUE, MI -86.161249 46.03052857

In [10]:
type(sta)


Out[10]:
paegan.cdm.dsg.features.station.Station

In [11]:
sta.get_unique_members()


Out[11]:
[{'description': 'Discharge, cubic feet per second',
  'name': 'Streamflow, ft³/s',
  'standard': '00060',
  'unit': 'ft3/s'}]

In [12]:
sta.properties()


Out[12]:
{'county': '26153',
 'horizontal_crs': 'EPSG:4326',
 'huc': '04060106',
 'location_description': [],
 'state': '26',
 'station_type': [],
 'vertical_crs': None,
 'vertical_units': 'm'}

Read Data from a Single Station


In [13]:
type(sta)


Out[13]:
paegan.cdm.dsg.features.station.Station

In [14]:
sta.elements[0].time


Out[14]:
datetime.datetime(2012, 10, 29, 3, 15, tzinfo=<UTC>)

In [15]:
sta.elements[0].members


Out[15]:
[{'description': 'Discharge, cubic feet per second',
  'name': 'Streamflow, ft&#179;/s',
  'standard': '00060',
  'unit': 'ft3/s',
  'value': '1270'}]

In [16]:
d = [float(ele.members[0]['value']) for ele in sta.elements]

In [17]:
jd = [ele.time for ele in sta.elements]

In [18]:
df = pd.Series(d,index=jd)

In [19]:
df.plot()


Out[19]:
<matplotlib.axes.AxesSubplot at 0x33f5410>

In [20]:
df.describe()


Out[20]:
count     673.000000
mean     1181.292719
std        83.462774
min      1020.000000
25%      1120.000000
50%      1190.000000
75%      1260.000000
max      1290.000000
dtype: float64

In [21]:
df.sum()


Out[21]:
795010.0

In [21]: