Testing performed on cloud-based WOFpy endpoints with ODM2 timeseries MySQL and PostgreSQL backends. These resources are managed by WOFpy developers for WOFpy testing and validation.
8/19/2017. Don Setiawan and Emilio Mayorga
Updates:
from urlparse import urljoin
import io
import requests
import ulmo
import sys, traceback
print(ulmo.cuahsi.wof.__doc__)
ulmo.cuahsi.wof ~~~~~~~~~~~~~~~ `CUAHSI WaterOneFlow`_ web services .. _CUAHSI WaterOneFlow: http://his.cuahsi.org/wofws.html
print([obj for obj in dir(ulmo.cuahsi.wof) if not obj.startswith('__')])
['absolute_import', 'core', 'get_site_info', 'get_sites', 'get_values', 'get_variable_info']
def get_exception(exc_info):
exc_type, exc_value, exc_traceback = exc_info
print('*** {}:'.format(exc_type.__name__))
traceback.print_exception(exc_type, exc_value, exc_traceback, file=sys.stdout)
print('')
def site_and_variable_codes(networkcode):
sitecode = '{netcode}:Rio Icacos Trib-IO'.format(netcode=networkcode)
variablecode = '{netcode}:DO Concentration'.format(netcode=networkcode)
return sitecode, variablecode
# server_base_url = 'http://54.186.36.247:8080'
#http://odm2admin.cuahsi.org/odm2timeseries/soap/cuahsi_1_1/.wsdl
#http://odm2admin.cuahsi.org/wofpy/odm2timeseries/soap/cuahsi_1_1/
# http://odm2admin.cuahsi.org/wofpy/odm2timeseries/rest/1_1/GetSites?site=odm2timeseries:Rio%20Icacos%20Trib-IO
server_base_url = 'http://odm2admin.cuahsi.org/wofpy/'
networkcodes = ['odm2timeseries']
#networkcodes = ['odm2timeseries']
wofpy_wsdl_url = '/soap/cuahsi_1_1/.wsdl'
for networkcode in networkcodes:
url = urljoin(server_base_url, networkcode+wofpy_wsdl_url)
sitecode, variablecode = site_and_variable_codes(networkcode)
print('--------------------------')
print('Testing {}'.format(url))
print('--------------------------')
print('SITES-----------------')
try:
sites = ulmo.cuahsi.wof.get_sites(url)
print(sites.keys())
print('')
except:
print('GetSites failed!')
get_exception(sys.exc_info())
print('SITE INFO {}-------------'.format(sitecode))
try:
siteinfo = ulmo.cuahsi.wof.get_site_info(url, site_code=sitecode)
print(siteinfo['name'])
print('')
except:
print('GetSiteInfo failed!')
get_exception(sys.exc_info())
print('VARIABLES-------------')
try:
variables = ulmo.cuahsi.wof.get_variable_info(url)
print(variables.keys())
print('')
except:
print('GetVariables failed!')
get_exception(sys.exc_info())
print('VARIABLE INFO {}-------------'.format(variablecode))
try:
variable = ulmo.cuahsi.wof.get_variable_info(url, variable_code=variablecode)
print(variable['name'])
print('')
except:
print('GetVariableInfo failed!')
get_exception(sys.exc_info())
print('VALUES----------------')
try:
values = ulmo.cuahsi.wof.get_values(url, site_code=sitecode, variable_code=variablecode)
print(len(values['values']))
print('')
except:
print('GetValues failed!')
get_exception(sys.exc_info())
-------------------------- Testing http://odm2admin.cuahsi.org/wofpy/odm2timeseries/soap/cuahsi_1_1/.wsdl -------------------------- SITES----------------- ['odm2timeseries:RESSH', 'odm2timeseries:RESDN', 'odm2timeseries:El Verde Soil Transect-1-3-Upper Slope', 'odm2timeseries:EP1', 'odm2timeseries:El Verde Soil Transect-1-2-Lower Ridge', 'odm2timeseries:El Verde Upper Slope Locations 3', 'odm2timeseries:El Verde Soil Transect-4-18-Mid Slope', 'odm2timeseries:Bisley Q3', 'odm2timeseries:Palm SJH, WS 2015', 'odm2timeseries:Prieta', 'odm2timeseries:El Verde Soil Transect-4-15-Ridge', 'odm2timeseries:El Verde Soil Transect-1-6-Slope Break', 'odm2timeseries:El Verde Soil Transect-3-26-Lower Slope', 'odm2timeseries:El Verde Soil Transect-3-22-Ridge', 'odm2timeseries:QS-Quebrada Sonadora', 'odm2timeseries:El Verde Field Station rooftop', 'odm2timeseries:El Verde Soil Transect-5-29-Ridge', 'odm2timeseries:El Verde Soil Transect-3-23-Lower Ridge', 'odm2timeseries:El Verde Soil Transect-4-21-Valley', 'odm2timeseries:El Verde Soil Transect-2-9-Lower Ridge', 'odm2timeseries:QS', 'odm2timeseries:El Verde Soil Transect-2-12-Lower Slope', 'odm2timeseries:El Verde Soil Transect-3-25-Mid Slope', 'odm2timeseries:El Verde Soil Transect-3-28-Valley', 'odm2timeseries:El Verde Soil Transect-4-20-Slope Break', 'odm2timeseries:El Verde Lower Slope Locations 5', 'odm2timeseries:El Verde Soil Transect-5-31-Upper Slope', 'odm2timeseries:Bisley valleys, 4 locations, SJH, WS 2015', 'odm2timeseries:LGW2B', 'odm2timeseries:Bisley ridges, 4 locations, SJH, WS 2015', 'odm2timeseries:El Verde Soil Transect-5-33-Lower Slope', 'odm2timeseries:El Verde Soil Transect-5-34-Slope Break', 'odm2timeseries:El Verde Soil Transect-5-30-Lower Ridge', 'odm2timeseries:Bisley slopes, 4 locations, SJH, WS 2015', 'odm2timeseries:Icacos Pulse-RI', 'odm2timeseries:El Verde Soil Transect-2-11-Mid Slope', 'odm2timeseries:I-03', 'odm2timeseries:El Verde Mid Slope Locations 4', 'odm2timeseries:Palo colorado SJH, WS 2015', 'odm2timeseries:El Verde Soil Transect-2-13-Slope Break', 'odm2timeseries:I-09', 'odm2timeseries:El Verde Lower Ridge Locations 2', 'odm2timeseries:El Verde Soil Transect-2-8-Ridge', 'odm2timeseries:I-30 well with Hydrolab', 'odm2timeseries:El Verde Soil Transect-3-24-Upper Slope', 'odm2timeseries:El Verde Valley Locations 7', 'odm2timeseries:El Verde Ridge Locations 1', 'odm2timeseries:Rio Icacos Trib-IO', 'odm2timeseries:El Verde Soil Transect-1-4-Mid Slope', 'odm2timeseries:El Verde Soil Transect-1-7-Valley', 'odm2timeseries:El Verde Soil Transect-4-17-Upper Slope', 'odm2timeseries:El Verde Soil Transect-1-5-Lower Slope', 'odm2timeseries:El Verde Soil Transect-3-27-Slope Break', 'odm2timeseries:El Verde Soil Transect-4-16-Lower Ridge', 'odm2timeseries:El Verde Soil Transect-2-10-Upper Slope', 'odm2timeseries:El Verde Soil Transect-2-14-Valley', 'odm2timeseries:El Verde Soil Transect-5-35-Valley', 'odm2timeseries:El Verde Slope Break Locations 6', 'odm2timeseries:Elfin SJH-WS 2015', 'odm2timeseries:Quebrada Toronja', 'odm2timeseries:I-10', 'odm2timeseries:El Verde Soil Transect-1-1-Ridge', 'odm2timeseries:El Verde Soil Transect-5-32-Mid Slope', 'odm2timeseries:El Verde Soil Transect-4-19-Lower Slope'] SITE INFO odm2timeseries:Rio Icacos Trib-IO------------- Rio Icacos Tributary VARIABLES------------- ['odm2timeseries:IBatt', 'odm2timeseries:Wind speed - avg daily', 'odm2timeseries:Nitrate (NO3) - Composite Method Flux', 'odm2timeseries:ORP', 'odm2timeseries:CO2- millivolts', 'odm2timeseries:BP', 'odm2timeseries:Max air temp - daily', 'odm2timeseries:HDO', 'odm2timeseries:DO Percent Saturation-HOBO', 'odm2timeseries:Time min relative humidity - daily', 'odm2timeseries:SpCond', 'odm2timeseries:Record', 'odm2timeseries:rainfall', 'odm2timeseries:Turbidity', 'odm2timeseries:wind rose 46-90 daily', 'odm2timeseries:Temperature - instrument', 'odm2timeseries:Depth_Vy', 'odm2timeseries:Wind direction- sd daily', 'odm2timeseries:LDOPercent', 'odm2timeseries:Chloride (Cl) - Regression Flux', 'odm2timeseries:EBatt', 'odm2timeseries:Time max relative humidity - daily', 'odm2timeseries:Nitrate (NO3)', 'odm2timeseries:Max relative humidity - daily', 'odm2timeseries:pH', 'odm2timeseries:Min air temp - daily', 'odm2timeseries:Absorbance-254', 'odm2timeseries:Solar radiation - daily total', 'odm2timeseries:Water Depth', 'odm2timeseries:wind rose 181-225 daily', 'odm2timeseries:Wind speed - max daily', 'odm2timeseries:rainfall - daily', 'odm2timeseries:Water Temperature', 'odm2timeseries:Wind vector daily', 'odm2timeseries:wind rose 271-315 daily', 'odm2timeseries:Sig Theta', 'odm2timeseries:Time max wind speed - daily', 'odm2timeseries:Light Average', 'odm2timeseries:wind direction - avg daily', 'odm2timeseries:Depth10', 'odm2timeseries:Solar Radiation', 'odm2timeseries:Relative humidity - corrected', 'odm2timeseries:Status of Drought', 'odm2timeseries:Abs Pres', 'odm2timeseries:Soil O2', 'odm2timeseries:Relative humidity', 'odm2timeseries:wind rose 136-180 daily', 'odm2timeseries:Ammonium, NH4', 'odm2timeseries:LDO', 'odm2timeseries:wind rose 91-135 daily', 'odm2timeseries:Absorbance-350', 'odm2timeseries:PPFD', 'odm2timeseries:Bromide', 'odm2timeseries:Total aboveground litterfall', 'odm2timeseries:Wind speed - min daily', 'odm2timeseries:Chloride (Cl) - Composite Method Flux', 'odm2timeseries:Temp C', 'odm2timeseries:DO Adj Conc', 'odm2timeseries:Time max temperature - daily', 'odm2timeseries:pHCount-Raw', 'odm2timeseries:wind rose 226-270 daily', 'odm2timeseries:Volumetric Water Content', 'odm2timeseries:DO Concentration', 'odm2timeseries:RH - min daily', 'odm2timeseries:Light Intensity', 'odm2timeseries:Time min wind speed - daily', 'odm2timeseries:CO2', 'odm2timeseries:Time min temperature - daily', 'odm2timeseries:Ct', 'odm2timeseries:wind rose 1-45 daily', 'odm2timeseries:Nitrate (NO3) - Regression Flux', 'odm2timeseries:CDOM / fDOM', 'odm2timeseries:Conductivity', 'odm2timeseries:CDOM', 'odm2timeseries:wind rose 316-360 daily', 'odm2timeseries:DO Percent Saturation', 'odm2timeseries:PPFD - daily total'] VARIABLE INFO odm2timeseries:DO Concentration------------- Oxygen, dissolved VALUES---------------- 70830
wofpy_rest_url = '/rest/1_1/'
for networkcode in networkcodes:
url = urljoin(server_base_url, networkcode+wofpy_rest_url)
sitecode, variablecode = site_and_variable_codes(networkcode)
print('--------------------------')
print('Testing {}'.format(url))
print('--------------------------')
print('SITES-----------------')
try:
req = requests.get(urljoin(url, 'GetSites'))
response_buffer = io.BytesIO(ulmo.util.to_bytes(req.content))
sites = ulmo.waterml.v1_1.parse_site_infos(response_buffer)
print(sites.keys())
print('')
except:
print('GetSites failed!')
get_exception(sys.exc_info())
print('SITE INFO {}-------------'.format(sitecode))
try:
req = requests.get(urljoin(url, 'GetSiteInfo'), params={'site':sitecode})
response_buffer = io.BytesIO(ulmo.util.to_bytes(req.content))
siteinfo = ulmo.waterml.v1_1.parse_sites(response_buffer)
print(siteinfo[sitecode.split(':')[1]]['name'])
print('')
except:
print('GetSiteInfo failed!')
get_exception(sys.exc_info())
print('VARIABLES-------------')
try:
req = requests.get(urljoin(url, 'GetVariables'))
response_buffer = io.BytesIO(ulmo.util.to_bytes(req.content))
variables = ulmo.waterml.v1_1.parse_variables(response_buffer)
print(variables.keys())
print('')
except:
print('GetVariables failed!')
get_exception(sys.exc_info())
print('VARIABLE INFO {}-------------'.format(variablecode))
try:
req = requests.get(urljoin(url, 'GetVariableInfo'), params={'variable':variablecode})
response_buffer = io.BytesIO(ulmo.util.to_bytes(req.content))
variable = ulmo.waterml.v1_1.parse_variables(response_buffer)
print(variable[variablecode.split(':')[1]]['name'])
print('')
except:
print('GetVariableInfo failed!')
get_exception(sys.exc_info())
print('VALUES----------------')
try:
req = requests.get(urljoin(url, 'GetValues'), params={'location':sitecode,
'variable':variablecode})
response_buffer = io.BytesIO(ulmo.util.to_bytes(req.content))
values = ulmo.waterml.v1_1.parse_site_values(response_buffer)
print(len(values[variablecode.split(':')[1]]['values']))
print('')
except:
print('GetValues failed!')
get_exception(sys.exc_info())
-------------------------- Testing http://odm2admin.cuahsi.org/wofpy/odm2timeseries/rest/1_1/ -------------------------- SITES----------------- ['I-03', 'El Verde Soil Transect-3-23-Lower Ridge', 'El Verde Soil Transect-3-26-Lower Slope', 'El Verde Soil Transect-5-32-Mid Slope', 'El Verde Soil Transect-1-5-Lower Slope', 'I-09', 'El Verde Soil Transect-5-29-Ridge', 'Elfin SJH-WS 2015', 'Bisley slopes, 4 locations, SJH, WS 2015', 'El Verde Soil Transect-3-25-Mid Slope', 'El Verde Soil Transect-5-31-Upper Slope', 'El Verde Field Station rooftop', 'El Verde Soil Transect-1-1-Ridge', 'El Verde Soil Transect-4-19-Lower Slope', 'El Verde Soil Transect-2-11-Mid Slope', 'El Verde Soil Transect-4-18-Mid Slope', 'El Verde Soil Transect-2-8-Ridge', 'El Verde Soil Transect-3-22-Ridge', 'El Verde Soil Transect-1-2-Lower Ridge', 'El Verde Soil Transect-5-33-Lower Slope', 'RESDN', 'El Verde Soil Transect-2-12-Lower Slope', 'El Verde Ridge Locations 1', 'Bisley ridges, 4 locations, SJH, WS 2015', 'El Verde Soil Transect-4-21-Valley', 'Palm SJH, WS 2015', 'Rio Icacos Trib-IO', 'El Verde Soil Transect-2-14-Valley', 'Bisley valleys, 4 locations, SJH, WS 2015', 'El Verde Soil Transect-2-9-Lower Ridge', 'El Verde Soil Transect-1-6-Slope Break', 'El Verde Slope Break Locations 6', 'Bisley Q3', 'EP1', 'El Verde Soil Transect-3-27-Slope Break', 'QS-Quebrada Sonadora', 'El Verde Lower Ridge Locations 2', 'El Verde Soil Transect-5-35-Valley', 'Prieta', 'El Verde Soil Transect-4-17-Upper Slope', 'I-30 well with Hydrolab', 'El Verde Soil Transect-2-13-Slope Break', 'El Verde Soil Transect-4-15-Ridge', 'LGW2B', 'El Verde Mid Slope Locations 4', 'El Verde Valley Locations 7', 'El Verde Soil Transect-1-3-Upper Slope', 'El Verde Soil Transect-5-34-Slope Break', 'El Verde Lower Slope Locations 5', 'El Verde Upper Slope Locations 3', 'Quebrada Toronja', 'Icacos Pulse-RI', 'El Verde Soil Transect-3-28-Valley', 'El Verde Soil Transect-5-30-Lower Ridge', 'I-10', 'Palo colorado SJH, WS 2015', 'El Verde Soil Transect-4-20-Slope Break', 'El Verde Soil Transect-4-16-Lower Ridge', 'QS', 'El Verde Soil Transect-2-10-Upper Slope', 'El Verde Soil Transect-3-24-Upper Slope', 'RESSH', 'El Verde Soil Transect-1-4-Mid Slope', 'El Verde Soil Transect-1-7-Valley'] SITE INFO odm2timeseries:Rio Icacos Trib-IO------------- Rio Icacos Tributary VARIABLES------------- ['Time min relative humidity - daily', 'Abs Pres', 'EBatt', 'Time max relative humidity - daily', 'rainfall - daily', 'Relative humidity - corrected', 'Min air temp - daily', 'Max relative humidity - daily', 'wind rose 271-315 daily', 'PPFD - daily total', 'Time max temperature - daily', 'Absorbance-254', 'CO2- millivolts', 'Sig Theta', 'Bromide', 'BP', 'wind rose 1-45 daily', 'Ammonium, NH4', 'DO Percent Saturation-HOBO', 'HDO', 'pH', 'LDOPercent', 'wind rose 46-90 daily', 'Max air temp - daily', 'Chloride (Cl) - Composite Method Flux', 'Turbidity', 'Time min wind speed - daily', 'Absorbance-350', 'Solar radiation - daily total', 'Wind speed - max daily', 'RH - min daily', 'CDOM / fDOM', 'LDO', 'Relative humidity', 'PPFD', 'SpCond', 'Light Average', 'DO Percent Saturation', 'Depth_Vy', 'Temperature - instrument', 'wind rose 226-270 daily', 'wind direction - avg daily', 'wind rose 316-360 daily', 'Wind speed - avg daily', 'Light Intensity', 'rainfall', 'Time min temperature - daily', 'Nitrate (NO3) - Composite Method Flux', 'DO Concentration', 'wind rose 181-225 daily', 'Water Depth', 'wind rose 136-180 daily', 'Record', 'pHCount-Raw', 'Time max wind speed - daily', 'Nitrate (NO3)', 'Nitrate (NO3) - Regression Flux', 'Status of Drought', 'Soil O2', 'Water Temperature', 'Chloride (Cl) - Regression Flux', 'Solar Radiation', 'CO2', 'Volumetric Water Content', 'Wind vector daily', 'Depth10', 'ORP', 'IBatt', 'wind rose 91-135 daily', 'CDOM', 'Total aboveground litterfall', 'Temp C', 'DO Adj Conc', 'Wind direction- sd daily', 'Wind speed - min daily', 'Ct', 'Conductivity'] VARIABLE INFO odm2timeseries:DO Concentration------------- Oxygen, dissolved VALUES---------------- 70830