{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Testing WOFpy SOAP and REST for WOF/WaterML 1.1\n", "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.\n", "\n", "8/19/2017. Don Setiawan and Emilio Mayorga\n", "\n", "Updates:\n", "- 8/21/2017 Added the printing of Exception, and spaces between requests" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from urlparse import urljoin\n", "import io\n", "\n", "import requests\n", "import ulmo\n", "import sys, traceback" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", " ulmo.cuahsi.wof\n", " ~~~~~~~~~~~~~~~\n", "\n", " `CUAHSI WaterOneFlow`_ web services\n", "\n", " .. _CUAHSI WaterOneFlow: http://his.cuahsi.org/wofws.html\n", "\n" ] } ], "source": [ "print(ulmo.cuahsi.wof.__doc__)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['absolute_import', 'core', 'get_site_info', 'get_sites', 'get_values', 'get_variable_info']\n" ] } ], "source": [ "print([obj for obj in dir(ulmo.cuahsi.wof) if not obj.startswith('__')])" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def get_exception(exc_info):\n", " exc_type, exc_value, exc_traceback = exc_info\n", " print('*** {}:'.format(exc_type.__name__))\n", " traceback.print_exception(exc_type, exc_value, exc_traceback, file=sys.stdout)\n", " print('')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Endpoints and testing resources" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def site_and_variable_codes(networkcode):\n", " sitecode = '{netcode}:Rio Icacos Trib-IO'.format(netcode=networkcode)\n", " variablecode = '{netcode}:DO Concentration'.format(netcode=networkcode)\n", " return sitecode, variablecode" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# server_base_url = 'http://54.186.36.247:8080'\n", "\n", "#http://odm2admin.cuahsi.org/odm2timeseries/soap/cuahsi_1_1/.wsdl\n", "#http://odm2admin.cuahsi.org/wofpy/odm2timeseries/soap/cuahsi_1_1/\n", "\n", "# http://odm2admin.cuahsi.org/wofpy/odm2timeseries/rest/1_1/GetSites?site=odm2timeseries:Rio%20Icacos%20Trib-IO\n", "server_base_url = 'http://odm2admin.cuahsi.org/wofpy/' \n", "networkcodes = ['odm2timeseries']\n", "#networkcodes = ['odm2timeseries']" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## SOAP 1.1 Testing" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "scrolled": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "--------------------------\n", "Testing http://odm2admin.cuahsi.org/wofpy/odm2timeseries/soap/cuahsi_1_1/.wsdl\n", "--------------------------\n", "SITES-----------------\n", "['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']\n", "\n", "SITE INFO odm2timeseries:Rio Icacos Trib-IO-------------\n", "Rio Icacos Tributary\n", "\n", "VARIABLES-------------\n", "['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']\n", "\n", "VARIABLE INFO odm2timeseries:DO Concentration-------------\n", "Oxygen, dissolved\n", "\n", "VALUES----------------\n", "70830\n", "\n" ] } ], "source": [ "wofpy_wsdl_url = '/soap/cuahsi_1_1/.wsdl'\n", "for networkcode in networkcodes:\n", " url = urljoin(server_base_url, networkcode+wofpy_wsdl_url)\n", " sitecode, variablecode = site_and_variable_codes(networkcode)\n", "\n", " print('--------------------------')\n", " print('Testing {}'.format(url))\n", " print('--------------------------')\n", " \n", " print('SITES-----------------')\n", " try:\n", " sites = ulmo.cuahsi.wof.get_sites(url)\n", " \n", " print(sites.keys())\n", " print('')\n", " except:\n", " print('GetSites failed!')\n", " get_exception(sys.exc_info())\n", "\n", " \n", " print('SITE INFO {}-------------'.format(sitecode))\n", " try:\n", " siteinfo = ulmo.cuahsi.wof.get_site_info(url, site_code=sitecode)\n", " \n", " print(siteinfo['name'])\n", " print('')\n", " except:\n", " print('GetSiteInfo failed!')\n", " get_exception(sys.exc_info())\n", " \n", " print('VARIABLES-------------')\n", " try:\n", " variables = ulmo.cuahsi.wof.get_variable_info(url)\n", " \n", " print(variables.keys())\n", " print('')\n", " except:\n", " print('GetVariables failed!')\n", " get_exception(sys.exc_info())\n", "\n", " print('VARIABLE INFO {}-------------'.format(variablecode))\n", " try:\n", " variable = ulmo.cuahsi.wof.get_variable_info(url, variable_code=variablecode)\n", " \n", " print(variable['name'])\n", " print('')\n", " except:\n", " print('GetVariableInfo failed!')\n", " get_exception(sys.exc_info())\n", " \n", " \n", " print('VALUES----------------') \n", " try:\n", " values = ulmo.cuahsi.wof.get_values(url, site_code=sitecode, variable_code=variablecode)\n", " \n", " print(len(values['values']))\n", " print('')\n", " except:\n", " print('GetValues failed!')\n", " get_exception(sys.exc_info())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## REST 1.1 Testing" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "--------------------------\n", "Testing http://odm2admin.cuahsi.org/wofpy/odm2timeseries/rest/1_1/\n", "--------------------------\n", "SITES-----------------\n", "['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']\n", "\n", "SITE INFO odm2timeseries:Rio Icacos Trib-IO-------------\n", "Rio Icacos Tributary\n", "\n", "VARIABLES-------------\n", "['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']\n", "\n", "VARIABLE INFO odm2timeseries:DO Concentration-------------\n", "Oxygen, dissolved\n", "\n", "VALUES----------------\n", "70830\n", "\n" ] } ], "source": [ "wofpy_rest_url = '/rest/1_1/'\n", "for networkcode in networkcodes:\n", " url = urljoin(server_base_url, networkcode+wofpy_rest_url)\n", " sitecode, variablecode = site_and_variable_codes(networkcode)\n", "\n", " print('--------------------------')\n", " print('Testing {}'.format(url))\n", " print('--------------------------')\n", " \n", " print('SITES-----------------')\n", " try:\n", " req = requests.get(urljoin(url, 'GetSites'))\n", " response_buffer = io.BytesIO(ulmo.util.to_bytes(req.content))\n", " sites = ulmo.waterml.v1_1.parse_site_infos(response_buffer)\n", " \n", " print(sites.keys())\n", " print('')\n", " except:\n", " print('GetSites failed!')\n", " get_exception(sys.exc_info())\n", " \n", " print('SITE INFO {}-------------'.format(sitecode))\n", " try:\n", " req = requests.get(urljoin(url, 'GetSiteInfo'), params={'site':sitecode})\n", " response_buffer = io.BytesIO(ulmo.util.to_bytes(req.content))\n", " siteinfo = ulmo.waterml.v1_1.parse_sites(response_buffer)\n", " \n", " print(siteinfo[sitecode.split(':')[1]]['name'])\n", " print('')\n", " except:\n", " print('GetSiteInfo failed!')\n", " get_exception(sys.exc_info())\n", " \n", " print('VARIABLES-------------')\n", " try:\n", " req = requests.get(urljoin(url, 'GetVariables'))\n", " response_buffer = io.BytesIO(ulmo.util.to_bytes(req.content))\n", " variables = ulmo.waterml.v1_1.parse_variables(response_buffer)\n", " \n", " print(variables.keys())\n", " print('')\n", " except:\n", " print('GetVariables failed!')\n", " get_exception(sys.exc_info())\n", "\n", " print('VARIABLE INFO {}-------------'.format(variablecode))\n", " try:\n", " req = requests.get(urljoin(url, 'GetVariableInfo'), params={'variable':variablecode})\n", " response_buffer = io.BytesIO(ulmo.util.to_bytes(req.content))\n", " variable = ulmo.waterml.v1_1.parse_variables(response_buffer)\n", " \n", " print(variable[variablecode.split(':')[1]]['name'])\n", " print('')\n", " except:\n", " print('GetVariableInfo failed!')\n", " get_exception(sys.exc_info())\n", " \n", " \n", " print('VALUES----------------') \n", " try:\n", " req = requests.get(urljoin(url, 'GetValues'), params={'location':sitecode, \n", " 'variable':variablecode})\n", " response_buffer = io.BytesIO(ulmo.util.to_bytes(req.content))\n", " values = ulmo.waterml.v1_1.parse_site_values(response_buffer)\n", " \n", " print(len(values[variablecode.split(':')[1]]['values']))\n", " print('')\n", " except:\n", " print('GetValues failed!')\n", " get_exception(sys.exc_info())" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.13" } }, "nbformat": 4, "nbformat_minor": 2 }