<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Testing WOFpy LBR sample DB
Emilio Mayorga. Run on my conda environment uwapl_em_mc_1aui.
3/5,4/2017. Test Don's Amazon cloud deployment
Step1:  CUAHSI WaterOneFlow
Step2:  Get site information
one of two sites in the LBR sample DB
Step3:  Get Values
Step4:  'odm2timeseries
Step5:  site_values['values'] is a list of individual time series values (timestamp and data value)
Step6:  Start and end timestamps (local time with time offset vs utc; iso8601 format)
Step7:  Set a nice, user-friendly variable name string.
Step8:  Hmm, this failed
<ASSISTANT_TASK:>
Python Code:
%matplotlib inline
import pytz
import matplotlib.pyplot as plt
import pandas as pd
import ulmo
from ulmo.util import convert_datetime
Explanation: Testing WOFpy LBR sample DB
Emilio Mayorga. Run on my conda environment uwapl_em_mc_1aui.
3/5,4/2017. Test Don's Amazon cloud deployment
End of explanation
print(ulmo.cuahsi.wof.__doc__)
print([obj for obj in dir(ulmo.cuahsi.wof) if not obj.startswith('__')])
# WaterML/WOF WSDL endpoints
wsdlurl = 'http://54.186.36.247:8080/mysqlodm2timeseries/soap/cuahsi_1_0/.wsdl'  # WOF 1.0
# 'network code'
networkcd = 'mysqlodm2timeseries'
Explanation: CUAHSI WaterOneFlow: ulmo, SOAP endpoint, and other general info
End of explanation
sitecd = 'USU-LBR-Mendon'
siteinfo = ulmo.cuahsi.wof.get_site_info(wsdlurl, networkcd+':'+sitecd)
type(siteinfo), siteinfo.keys()
siteinfo['network'], siteinfo['code'], siteinfo['name']
print(siteinfo['location'])
type(siteinfo['series']), len(siteinfo['series']), siteinfo['series'].keys()
siteinfo['series']['mysqlodm2timeseries:USU33'].keys()
siteinfo['series']['mysqlodm2timeseries:USU33']
Explanation: Get site information
one of two sites in the LBR sample DB
End of explanation
def site_series_values_to_df(series_values, variable_name):
    # Create a clean timeseries list of (dt, val) tuples
    tsdt_tuplst = [
        (convert_datetime(valdict['datetime']).replace(tzinfo=pytz.utc),
         float(valdict['value'])) for valdict in series_values['values']
    ]
    dt, val = zip(*tsdt_tuplst)
    ts_df = pd.DataFrame({'time': dt, variable_name: val})
    ts_df.set_index('time', inplace=True)
    ts_df.sort_index(ascending=True, inplace=True)
    return ts_df
print(
    ulmo.cuahsi.wof.get_values.__doc__.replace('<', '').replace('>', '')
)
Explanation: Get Values
End of explanation
variablecd = 'USU33'
site_values = ulmo.cuahsi.wof.get_values(wsdlurl, networkcd+':'+sitecd, networkcd+':'+variablecd)
site_values.keys()
sitevariable = site_values['variable']
sitevariable
Explanation: 'odm2timeseries:USU33' is 'Oxygen, dissolved percent of saturation'
End of explanation
type(site_values['values']), site_values['values'][0].keys()
Explanation: site_values['values'] is a list of individual time series values (timestamp and data value)
End of explanation
site_values['values'][0]['datetime'], site_values['values'][-1]['datetime']
Explanation: Start and end timestamps (local time with time offset vs utc; iso8601 format)
End of explanation
variable_name = '%s (%s)' % (sitevariable['name'], sitevariable['value_type'])
variable_name
dtstr_last = site_values['values'][-1]['datetime']
convert_datetime(dtstr_last).replace(tzinfo=pytz.utc)
Explanation: Set a nice, user-friendly variable name string.
End of explanation
ts_df = site_series_values_to_df(site_values, variable_name)
ts_df.tail()
type(ts_df), ts_df.columns, ts_df.index.dtype, ts_df.index.min(), ts_df.index.max()
fig, ax = plt.subplots(figsize=(10, 4))
varlabel = ts_df.columns[0]
ts_df[varlabel].plot(style='-', ax=ax)
ax.set_ylabel(varlabel + ', ' + sitevariable['units']['abbreviation']);
Explanation: Hmm, this failed:
python
convert_datetime(dtstr_last).astimezone(pytz.utc)
ValueError: astimezone() cannot be applied to a naive datetime
End of explanation
<END_TASK>