In [1]:
"""Python WPS execute"""
from owslib.wps import WebProcessingService, monitorExecution, printInputOutput
from os import system

In [2]:
wps_url = "http://localhost:8093/wps"
#wps_url = "http://birdhouse-lsce.extra.cea.fr:8093/wps"
wps = WebProcessingService(url=wps_url, verbose=False)

In [3]:
print wps.identification.title


Flyingpigeon

In [4]:
for process in wps.processes:
    print '%s : \t %s' % (process.identifier, process.abstract)


visualisation : 	 Just testing a nice script to visualise some variables
sdm : 	 Species distribution model (SDM)
segetalflora : 	 Species biodiversity of segetal flora. Imput files: variable:tas , domain: EUR-11 or EUR-44
indices_single : 	 This process calculates climate indices based on one single variable.
subset_countries : 	 This process returns only the given polygon from input netCDF files.
eobs_to_cordex : 	 downloads EOBS data in adaped CORDEX format
ensembleRobustness : 	 Calculates the robustness as the ratio of noise to signal in an ensemle of timeseries
analogs : 	 Search for days with analog pressure pattern
fetch : 	 This process downloads resources (limited to 50GB) to the local file system and returns a textfile with appropriate pathes

In [5]:
p = wps.describeprocess(identifier='sdm')
for input in p.dataInputs:
    printInputOutput(input)
    print '\n'


 identifier=resources, title=NetCDF File, abstract=NetCDF File, data type=ComplexData
 Supported Value: mimeType=application/x-netcdf, encoding=None, schema=None
 Default Value: mimeType=application/x-netcdf, encoding=None, schema=None 
 minOccurs=1, maxOccurs=500


 identifier=gbif, title=GBIF zip file, abstract=GBIF zip url containing a CSV files with tree locations (e.g.: http://api.gbif.org/v1/occurrence/download/request/0013848-160118175350007.zip), data type=//www.w3.org/TR/xmlschema-2/#string
 Any value allowed
 Default Value:  http://api.gbif.org/v1/occurrence/download/request/0013848-160118175350007.zip 
 minOccurs=0, maxOccurs=1


 identifier=indices, title=Indices, abstract=Climate indices related to growth condition of tree species, data type=//www.w3.org/TR/xmlschema-2/#string
 Allowed Value: TG_JJA
 Allowed Value: TNn_Jan
 Allowed Value: PRCPTOT_JJA
 Default Value: TG_JJA 
 minOccurs=0, maxOccurs=3


 identifier=period, title=Reference period, abstract=Reference period for climate condition (all = entire timeserie), data type=//www.w3.org/TR/xmlschema-2/#string
 Allowed Value: all
 Allowed Value: 1951-1980
 Allowed Value: 1961-1990
 Allowed Value: 1971-2000
 Allowed Value: 1981-2010
 Default Value: all 
 minOccurs=0, maxOccurs=1



In [6]:
resources = ['/home/nils/.conda/envs/birdhouse/var/lib/cache/pywps/esgf1.dkrz.de/thredds/fileServer/cordex/cordex/output/EUR-11/CLMcom/ICHEC-EC-EARTH/historical/r12i1p1/CLMcom-CCLM4-8-17/v1/day/tas/v20140515/tas_EUR-11_ICHEC-EC-EARTH_historical_r12i1p1_CLMcom-CCLM4-8-17_v1_day_20010101-20051231.nc',
'/home/nils/.conda/envs/birdhouse/var/lib/cache/pywps/esgf1.dkrz.de/thredds/fileServer/cordex/cordex/output/EUR-11/CLMcom/ICHEC-EC-EARTH/historical/r12i1p1/CLMcom-CCLM4-8-17/v1/day/pr/v20140515/pr_EUR-11_ICHEC-EC-EARTH_historical_r12i1p1_CLMcom-CCLM4-8-17_v1_day_20010101-20051231.nc',
'/home/nils/.conda/envs/birdhouse/var/lib/cache/pywps/esgf1.dkrz.de/thredds/fileServer/cordex/cordex/output/EUR-11/CLMcom/ICHEC-EC-EARTH/historical/r12i1p1/CLMcom-CCLM4-8-17/v1/day/tasmin/v20140515/tasmin_EUR-11_ICHEC-EC-EARTH_historical_r12i1p1_CLMcom-CCLM4-8-17_v1_day_20010101-20051231.nc']

In [7]:
resources


Out[7]:
['/home/nils/.conda/envs/birdhouse/var/lib/cache/pywps/esgf1.dkrz.de/thredds/fileServer/cordex/cordex/output/EUR-11/CLMcom/ICHEC-EC-EARTH/historical/r12i1p1/CLMcom-CCLM4-8-17/v1/day/tas/v20140515/tas_EUR-11_ICHEC-EC-EARTH_historical_r12i1p1_CLMcom-CCLM4-8-17_v1_day_20010101-20051231.nc',
 '/home/nils/.conda/envs/birdhouse/var/lib/cache/pywps/esgf1.dkrz.de/thredds/fileServer/cordex/cordex/output/EUR-11/CLMcom/ICHEC-EC-EARTH/historical/r12i1p1/CLMcom-CCLM4-8-17/v1/day/pr/v20140515/pr_EUR-11_ICHEC-EC-EARTH_historical_r12i1p1_CLMcom-CCLM4-8-17_v1_day_20010101-20051231.nc',
 '/home/nils/.conda/envs/birdhouse/var/lib/cache/pywps/esgf1.dkrz.de/thredds/fileServer/cordex/cordex/output/EUR-11/CLMcom/ICHEC-EC-EARTH/historical/r12i1p1/CLMcom-CCLM4-8-17/v1/day/tasmin/v20140515/tasmin_EUR-11_ICHEC-EC-EARTH_historical_r12i1p1_CLMcom-CCLM4-8-17_v1_day_20010101-20051231.nc']

In [8]:
gbif_url = 'http://api.gbif.org/v1/occurrence/download/request/0013848-160118175350007.zip'

In [ ]:
indices = ['TG_JJA', 'TNn_Jan', 'PRCPTOT_JJA']

In [26]:
period='all'

build url for asymetric WPS call:


In [10]:
import requests

In [16]:
r = ''
for i in range(1,4):
    r= '%sresource={resource%s};' % (r,i)
r = r + 'gbif={gbif1};'    
l = ''
for i in range(1,4):
    l= '%sindices={indices%s};' % (l,i)
r = r + l 
print r


resource={resource1};resource={resource2};resource={resource3};gbif={gbif1};indices={indices1};indices={indices2};indices={indices3};

In [22]:
async_req_url = "{wps_url}?" +\
    "request=Execute" +\
    "&service=WPS" +\
    "&version=1.0.0" +\
    "&identifier=sdm" +\
    "&DataInputs=resource={resource1};resource={resource2};resource={resource3};gbif={gbif1};period={period}=indices={indices1};indices={indices2};indices={indices3}"+ \
    "&storeExecuteResponse=true" +\
    "&status=true"

In [27]:
url=async_req_url.format(
    wps_url=wps_url,
    resource1=resources[0],
    resource2=resources[1],
    resource3=resources[2],
    gbif1=gbif_url,
    indices1=indices[0],
    indices2=indices[1],
    indices3=indices[2],
    period=period,
    )
print url


http://localhost:8093/wps?request=Execute&service=WPS&version=1.0.0&identifier=sdm&DataInputs=resource=/home/nils/.conda/envs/birdhouse/var/lib/cache/pywps/esgf1.dkrz.de/thredds/fileServer/cordex/cordex/output/EUR-11/CLMcom/ICHEC-EC-EARTH/historical/r12i1p1/CLMcom-CCLM4-8-17/v1/day/tas/v20140515/tas_EUR-11_ICHEC-EC-EARTH_historical_r12i1p1_CLMcom-CCLM4-8-17_v1_day_20010101-20051231.nc;resource=/home/nils/.conda/envs/birdhouse/var/lib/cache/pywps/esgf1.dkrz.de/thredds/fileServer/cordex/cordex/output/EUR-11/CLMcom/ICHEC-EC-EARTH/historical/r12i1p1/CLMcom-CCLM4-8-17/v1/day/pr/v20140515/pr_EUR-11_ICHEC-EC-EARTH_historical_r12i1p1_CLMcom-CCLM4-8-17_v1_day_20010101-20051231.nc;resource=/home/nils/.conda/envs/birdhouse/var/lib/cache/pywps/esgf1.dkrz.de/thredds/fileServer/cordex/cordex/output/EUR-11/CLMcom/ICHEC-EC-EARTH/historical/r12i1p1/CLMcom-CCLM4-8-17/v1/day/tasmin/v20140515/tasmin_EUR-11_ICHEC-EC-EARTH_historical_r12i1p1_CLMcom-CCLM4-8-17_v1_day_20010101-20051231.nc;gbif=http://api.gbif.org/v1/occurrence/download/request/0013848-160118175350007.zip;indices=TG_JJA;indices=TNn_Jan;indices=PRCPTOT_JJA&storeExecuteResponse=true&status=true

In [28]:
r = requests.get(url)
from lxml import etree
from io import BytesIO
tree = etree.parse(BytesIO(r.content))
#print etree.tostring(tree)
status_url = tree.getroot().get("statusLocation")
print status_url


http://localhost:8090/wpsoutputs/flyingpigeon/pywps-d276081e-eba4-11e5-a76c-c960bbeb35c0.xml

In [29]:
r = requests.get(status_url)
print r.status_code
print r.text


200
<?xml version="1.0" encoding="utf-8"?>
<wps:ExecuteResponse xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsExecute_response.xsd" service="WPS" version="1.0.0" xml:lang="en-CA" serviceInstance="http://localhost:8093/wps?service=WPS&amp;request=GetCapabilities&amp;version=1.0.0" statusLocation="http://localhost:8090/wpsoutputs/flyingpigeon/pywps-d276081e-eba4-11e5-a76c-c960bbeb35c0.xml">
    <wps:Process wps:processVersion="0.3">
        <ows:Identifier>sdm</ows:Identifier>
        <ows:Title>Species distribution model</ows:Title>
        <ows:Abstract>Species distribution model (SDM) </ows:Abstract>
        <ows:Metadata xlink:title="SDM" xlink:href="http://localhost:8093/wps?service=WPS&amp;request=DescribeProcess&amp;version=1.0.0&amp;identifier=sdm" />
    </wps:Process>
    <wps:Status creationTime="2016-03-16T19:28:06Z">
        <wps:ProcessFailed>
            <ows:ExceptionReport version="1.0.0">
                <ows:Exception exceptionCode="MissingParameterValue" locator="resources" />
            </ows:ExceptionReport>
        </wps:ProcessFailed>
    </wps:Status>
</wps:ExecuteResponse>


In [ ]:
graphic = 'http://localhost:8090/wpsoutputs/flyingpigeon/output_graphic-5442f43a-ce61-11e5-a317-434222d428b1.png'

from IPython.display import Image
from IPython.core.display import HTML 
Image(url= graphic )