Working with APCC OpenWPS service

Exercise

Getting basic information of OGC WPS service

In [1]:
from owslib.wps import WebProcessingService
In [2]:
from owslib.wps import printInputOutput
In [3]:
service_host = 'http://openwps.apcc21.org/wps'
In [4]:
wps = WebProcessingService(service_host, verbose = False, skip_caps = True)
In [5]:
wps.getcapabilities()
In [6]:
print (wps.identification.type)
WPS
In [7]:
print (wps.identification.title)
OpenWPS OGC WPS Server
In [8]:
print (wps.identification.abstract)
This server is operating by APEC Climate Center
In [9]:
for operation in wps.operations:
    print (operation.name)
GetCapabilities
DescribeProcess
Execute
In [10]:
for process in wps.processes:
    print (process.identifier, process.title)
OpenWPS:CP_MaskWithCF Masking climate data using CF metadata
OpenWPS:CV_VisualizeNonSeries gClimate Visualization Process
OpenWPS:CP_MaskWithISO3166 Masking Climate Data considering ISO-3166 2 or 3 Country Code
OpenWPS:CP_MaskWithCF_OLD Masking climate data using CF metadata

Getting information of WPS processes

In [11]:
wps_process = 'OpenWPS:CP_MaskWithCF'
In [12]:
process = wps.describeprocess(wps_process)
In [13]:
print (process.title)
Masking climate data using CF metadata
In [14]:
print (process.abstract)
This process generates masked data based on gClimateData JSON format
In [15]:
for input in process.dataInputs:
    printInputOutput(input)
 identifier=inputClimateMaskData, title=Input data for masking climate data by region, abstract=None, data type=ComplexData
 Supported Value: mimeType=application/json, encoding=None, schema=None
 Default Value: mimeType=application/json, encoding=None, schema=None
 minOccurs=1, maxOccurs=1
 identifier=inputRegion, title=Input region in GeoJSON format, abstract=None, data type=ComplexData
 Supported Value: mimeType=application/json, encoding=None, schema=None
 Default Value: mimeType=application/json, encoding=None, schema=None
 minOccurs=1, maxOccurs=1
 identifier=inputMaskingOperator, title=Input masking operator, abstract=None, data type=string
 Any value allowed
 Default Value: None
 minOccurs=1, maxOccurs=1
 identifier=inputDistance, title=Input distance of Expanded MBR or spatial resolution, abstract=None, data type=string
 Any value allowed
 Default Value: None
 minOccurs=1, maxOccurs=1

Working with Climate Masking Interface Service

In [16]:
from owslib.wps import WebProcessingService
In [17]:
from owslib.wps import WebProcessingService, monitorExecution
In [18]:
import tutorial_util as util
In [19]:
service_host = 'http://openwps.apcc21.org/wps/wps.wsgi'
In [20]:
wps_process = 'OpenWPS:CP_MaskWithCF'
In [21]:
wps = WebProcessingService(service_host, verbose = False, skip_caps = True)
In [22]:
inputgClimateMask = util.loadText('data/gCliMaskJSON_with_bounds.txt')
inputRegion = util.loadText('data/test.geojson')
inputMaskingOperator = 'RectInterPy' #'PtInExpMBR' #'PtInMBR' #'PtInPy'
inputDistance = "3.5"
In [23]:
inputs = [
          ('inputClimateMaskData', inputgClimateMask),
          ('inputRegion', inputRegion),
          ('inputMaskingOperator', inputMaskingOperator),
          ('inputDistance', inputDistance)
         ]
In [24]:
outputs = [
  ('identifier', 'output'),
  ('reference', False)
]
In [25]:
execution = wps.execute(wps_process, inputs, output=outputs)
In [26]:
monitorExecution(execution)
In [27]:
print (execution.response)
b'<wps:ExecuteResponse xmlns:gml="http://www.opengis.net/gml" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:wps="http://www.opengis.net/wps/1.0.0" 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-US" serviceInstance="http://openwps.apcc21.org/wps/wps.wsgi?service=WPS&amp;request=GetCapabilities" statusLocation="http://openwps.apcc21.org/outputs/1caeaaf0-dcf6-11e7-ad91-001e6749e74c.xml">\n  <wps:Process wps:processVersion="0.1.0">\n    <ows:Identifier>OpenWPS:CP_MaskWithCF</ows:Identifier>\n    <ows:Title>Masking climate data using CF metadata </ows:Title>\n    <ows:Abstract>This process generates masked data based on gClimateData JSON format</ows:Abstract>\n  </wps:Process>\n  <wps:Status creationTime="2017-12-10T00:32:08Z">\n    <wps:ProcessSucceeded>PyWPS Process Masking climate data using CF metadata  finished</wps:ProcessSucceeded>\n  </wps:Status>\n  <wps:ProcessOutputs>\n    <wps:Output>\n      <ows:Identifier>output</ows:Identifier>\n      <ows:Title>Masked data</ows:Title>\n      <wps:Data>\n        <wps:ComplexData mimeType="application/json">\n{\n  "maskresult" : {\n     "version" : "0.1",\n     "dimension" : [60, 128],\n     "method" : "BinaryGzipBase64",\n     "mask" : "H4sIAPgBLFoC/+3NMQ0AAAgDMEvDvzkyDRw8rYEmAAAAAADvpvwAADcLFoL1cgAeAAA="\n  }\n}\n</wps:ComplexData>\n      </wps:Data>\n    </wps:Output>\n  </wps:ProcessOutputs>\n</wps:ExecuteResponse>'
In [28]:
mask_data = execution.processOutputs[0]
In [29]:
print (mask_data.data)
['{\n  "maskresult" : {\n     "version" : "0.1",\n     "dimension" : [60, 128],\n     "method" : "BinaryGzipBase64",\n     "mask" : "H4sIAPgBLFoC/+3NMQ0AAAgDMEvDvzkyDRw8rYEmAAAAAADvpvwAADcLFoL1cgAeAAA="\n  }\n}']