import numpy as npimport pandas as pd
import ulmo
usgs_eldercreek = ulmo.usgs.nwis.get_site_data('11475560',service='instantaneous',start='2012-10-01',end='2013-08-01')
--
You received this message because you are subscribed to the Google Groups "ulmo" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ulmo+uns...@googlegroups.com.
To post to this group, send email to ul...@googlegroups.com.
Visit this group at http://groups.google.com/group/ulmo.
For more options, visit https://groups.google.com/groups/opt_out.
Okay, I have folded your suggestions into a function, since I need to do this for each parameter at a station. Also, I realized the 'values' are objects, not float64, so I had to type them as well. Otherwise I couldn't plot them or do other operations.
def usgs2df(usgs_waterml,parameter):df = pd.DataFrame(usgs_waterml[parameter]['values'])
df.index = pd.DatetimeIndex(df.datetime)
df = df.tz_localize('US/Pacific')
df[['value']] = df[['value']].astype(float)
return df
# Pull Elder Creek into WaterML format
usgs_elder = ulmo.usgs.nwis.get_site_data('11475560',service='iv',start='2012-10-01',end='2013-08-01')
# Using Dharhas/Andy response
eq = usgs2df(usgs_elder,'00060:00011') # discharge
eg = usgs2df(usgs_elder,'00065:00011') # gage height
et = usgs2df(usgs_elder,'00010:00011') # water temperature
This works unless I cross daylight savings time. Then it will throw an error. Looks like I am running into timezone ugliness. The timestamp has the UTC-offset. My own data is in PST without daylight savings, i.e. UTC-8:00. To compare the two datasets I need to somehow define the timezone or offsets in the USGS data. Any thoughts on dealing with this?
def get_timezone(timezone_string):
if 'UTC-' in timezone_string:
minutes = int(timezone_string[3:]) * 60
return pytz.FixedOffset(minutes)
else:
return pytz.timezone(timezone_string)
def usgs2df(usgs_waterml,parameter):
# Using Dharhas/Andy response
df = pd.DataFrame(usgs_waterml[parameter]['values'])
df.index = pd.DatetimeIndex(df.datetime)
utc_8 = get_timezone('UTC-8')
df = df.tz_localize('utc').tz_convert(utc_8)
df[['value']] = df[['value']].astype(float)
return df
# Pull Elder Creek into WaterML format
eq = usgs2df(usgs_elder,'00060:00011') # discharge (q) cubic feet per second
eg = usgs2df(usgs_elder,'00065:00011') # gage height (feet)
et = usgs2df(usgs_elder,'00010:00011') # water temperature (celsius)