import os
import requests
url = os.environ.get('ROOK_URL', 'http://localhost:5000/wps')
req_url = f"{url}?service=WPS&request=GetCapabilities"
req_url
'http://cp4cds-cn1.dkrz.de/wps?service=WPS&request=GetCapabilities'
resp = requests.get(req_url)
resp.ok
True
print(resp.text)
<?xml version="1.0" encoding="UTF-8"?> <!-- PyWPS 4.2.8 --> <wps:Capabilities service="WPS" version="1.0.0" xml:lang="en-US" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 ../wpsGetCapabilities_response.xsd" updateSequence="1"> <ows:ServiceIdentification> <ows:Title>rook</ows:Title> <ows:Abstract>A WPS service for roocs.</ows:Abstract> <ows:Keywords> <ows:Keyword>PyWPS</ows:Keyword> <ows:Keyword> WPS</ows:Keyword> <ows:Keyword> OGC</ows:Keyword> <ows:Keyword> processing</ows:Keyword> <ows:Keyword> birdhouse</ows:Keyword> <ows:Keyword> roocs</ows:Keyword> <ows:Keyword> demo</ows:Keyword> <ows:Keyword> cp4cds</ows:Keyword> <ows:Keyword> copernicus</ows:Keyword> <ows:Keyword> ecmwf</ows:Keyword> <ows:Type codeSpace="ISOTC211/19115">theme</ows:Type> </ows:Keywords> <ows:ServiceType>WPS</ows:ServiceType> <ows:ServiceTypeVersion>1.0.0</ows:ServiceTypeVersion> <ows:ServiceTypeVersion>2.0.0</ows:ServiceTypeVersion> <ows:Fees>NONE</ows:Fees> <ows:AccessConstraints> NONE </ows:AccessConstraints> </ows:ServiceIdentification> <ows:ServiceProvider> <ows:ProviderName>rook</ows:ProviderName> <ows:ProviderSite xlink:href="http://rook.readthedocs.org/en/latest/"/> <ows:ServiceContact> <ows:IndividualName>Lastname, Firstname</ows:IndividualName> <ows:PositionName>Position Title</ows:PositionName> <ows:ContactInfo> <ows:Phone> <ows:Voice>+xx-xxx-xxx-xxxx</ows:Voice> <ows:Facsimile></ows:Facsimile> </ows:Phone> <ows:Address> <ows:DeliveryPoint></ows:DeliveryPoint> <ows:City>City</ows:City> <ows:AdministrativeArea></ows:AdministrativeArea> <ows:PostalCode>Zip or Postal Code</ows:PostalCode> <ows:Country>Country</ows:Country> <ows:ElectronicMailAddress>Email Address</ows:ElectronicMailAddress> </ows:Address> </ows:ContactInfo> </ows:ServiceContact> </ows:ServiceProvider> <ows:OperationsMetadata> <ows:Operation name="GetCapabilities"> <ows:DCP> <ows:HTTP> <ows:Get xlink:href="http://compute.mips.copernicus-climate.eu:80/wps"/> </ows:HTTP> </ows:DCP> </ows:Operation> <ows:Operation name="DescribeProcess"> <ows:DCP> <ows:HTTP> <ows:Get xlink:href="http://compute.mips.copernicus-climate.eu:80/wps"/> <ows:Post xlink:href="http://compute.mips.copernicus-climate.eu:80/wps"/> </ows:HTTP> </ows:DCP> </ows:Operation> <ows:Operation name="Execute"> <ows:DCP> <ows:HTTP> <ows:Get xlink:href="http://compute.mips.copernicus-climate.eu:80/wps"/> <ows:Post xlink:href="http://compute.mips.copernicus-climate.eu:80/wps"/> </ows:HTTP> </ows:DCP> </ows:Operation> </ows:OperationsMetadata> <wps:ProcessOfferings> <wps:Process wps:processVersion="1.0"> <ows:Identifier>subset</ows:Identifier> <ows:Title>Subset</ows:Title> <ows:Abstract>Run subsetting on climate data.</ows:Abstract> </wps:Process> <wps:Process wps:processVersion="1.0"> <ows:Identifier>average</ows:Identifier> <ows:Title>Average</ows:Title> <ows:Abstract>Run averaging on climate data.</ows:Abstract> </wps:Process> <wps:Process wps:processVersion="1.0"> <ows:Identifier>orchestrate</ows:Identifier> <ows:Title>Orchestrate</ows:Title> <ows:Abstract>Run a workflow</ows:Abstract> </wps:Process> </wps:ProcessOfferings> <wps:Languages> <wps:Default> <ows:Language>en-US</ows:Language> </wps:Default> <wps:Supported> <ows:Language>en-US</ows:Language> </wps:Supported> </wps:Languages> </wps:Capabilities>
req_url = f"{url}?service=WPS&version=1.0.0&request=DescribeProcess&identifier=subset"
req_url
'http://cp4cds-cn1.dkrz.de/wps?service=WPS&version=1.0.0&request=DescribeProcess&identifier=subset'
resp = requests.get(req_url)
resp.ok
True
print(resp.text)
<?xml version="1.0" encoding="UTF-8"?> <!-- PyWPS 4.2.8 --> <wps:ProcessDescriptions 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 ../wpsDescribeProcess_response.xsd" service="WPS" version="1.0.0" xml:lang="en-US"> <ProcessDescription wps:processVersion="1.0" storeSupported="true" statusSupported="true"> <ows:Identifier>subset</ows:Identifier> <ows:Title>Subset</ows:Title> <ows:Abstract>Run subsetting on climate data.</ows:Abstract> <DataInputs> <Input minOccurs="1" maxOccurs="1"> <ows:Identifier>collection</ows:Identifier> <ows:Title>Collection</ows:Title> <ows:Abstract>c3s-cmip5.output1.ICHEC.EC-EARTH.historical.day.atmos.day.r1i1p1.tas.latest</ows:Abstract> <LiteralData> <ows:DataType ows:reference="http://www.w3.org/TR/xmlschema-2/#string">string</ows:DataType> </LiteralData> </Input> <Input minOccurs="0" maxOccurs="1"> <ows:Identifier>time</ows:Identifier> <ows:Title>Time Period</ows:Title> <ows:Abstract>Example: 1860-01-01/1900-12-30</ows:Abstract> <LiteralData> <ows:DataType ows:reference="http://www.w3.org/TR/xmlschema-2/#string">string</ows:DataType> </LiteralData> </Input> <Input minOccurs="0" maxOccurs="1"> <ows:Identifier>area</ows:Identifier> <ows:Title>Area</ows:Title> <ows:Abstract>Example: 0.,49.,10.,65</ows:Abstract> <LiteralData> <ows:DataType ows:reference="http://www.w3.org/TR/xmlschema-2/#string">string</ows:DataType> </LiteralData> </Input> <Input minOccurs="0" maxOccurs="1"> <ows:Identifier>level</ows:Identifier> <ows:Title>Level</ows:Title> <ows:Abstract>Example: 0/1000</ows:Abstract> <LiteralData> <ows:DataType ows:reference="http://www.w3.org/TR/xmlschema-2/#string">string</ows:DataType> </LiteralData> </Input> <Input minOccurs="1" maxOccurs="1"> <ows:Identifier>pre_checked</ows:Identifier> <ows:Title>Pre-Checked</ows:Title> <ows:Abstract>Use checked data only.</ows:Abstract> <LiteralData> <ows:DataType ows:reference="http://www.w3.org/TR/xmlschema-2/#boolean">boolean</ows:DataType> <DefaultValue>False</DefaultValue> </LiteralData> </Input> </DataInputs> <ProcessOutputs> <Output> <ows:Identifier>output</ows:Identifier> <ows:Title>METALINK v4 output</ows:Title> <ows:Abstract>Metalink v4 document with references to NetCDF files.</ows:Abstract> <ComplexOutput> <Default> <Format> <MimeType>application/metalink+xml; version=4.0</MimeType> <Schema>metalink/4.0/metalink4.xsd</Schema> </Format> </Default> <Supported> <Format> <MimeType>application/metalink+xml; version=4.0</MimeType> <Schema>metalink/4.0/metalink4.xsd</Schema> </Format> </Supported> </ComplexOutput> </Output> </ProcessOutputs> </ProcessDescription> </wps:ProcessDescriptions>
Edit data inputs
collection = "c3s-cmip5.output1.ICHEC.EC-EARTH.historical.day.atmos.day.r1i1p1.tas.latest"
time = "1860-01-01/1900-12-30"
datainputs = f"DataInputs=collection={collection};time={time}"
req_url = f"{url}?service=WPS&version=1.0.0&request=Execute&identifier=subset&{datainputs}"
req_url
'http://cp4cds-cn1.dkrz.de/wps?service=WPS&version=1.0.0&request=Execute&identifier=subset&DataInputs=collection=c3s-cmip5.output1.ICHEC.EC-EARTH.historical.day.atmos.day.r1i1p1.tas.latest;time=1860-01-01/1900-12-30'
resp = requests.get(req_url)
resp.ok
True
print(resp.text)
<?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 ../wpsExecute_response.xsd" service="WPS" version="1.0.0" xml:lang="en-US" serviceInstance="http://compute.mips.copernicus-climate.eu:80/wps?request=GetCapabilities&amp;service=WPS" statusLocation=""> <wps:Process wps:processVersion="1.0"> <ows:Identifier>subset</ows:Identifier> <ows:Title>Subset</ows:Title> <ows:Abstract>Run subsetting on climate data.</ows:Abstract> </wps:Process> <wps:Status creationTime="2020-09-17T09:08:46Z"> <wps:ProcessSucceeded>PyWPS Process Subset finished</wps:ProcessSucceeded> </wps:Status> <wps:ProcessOutputs> <wps:Output> <ows:Identifier>output</ows:Identifier> <ows:Title>METALINK v4 output</ows:Title> <ows:Abstract>Metalink v4 document with references to NetCDF files.</ows:Abstract> <wps:Reference href="http://cp4cds-cn1.dkrz.de:80/outputs/rook/9d61e888-f8b4-11ea-9ea1-f2e4655a10b7/input.meta4" mimeType="application/metalink+xml; version=4.0" encoding="" schema="metalink/4.0/metalink4.xsd"/> </wps:Output> </wps:ProcessOutputs> </wps:ExecuteResponse>
Load metalink result document
Replace the metalink output URL.
metalink_url = ''
metalink_url = 'http://cp4cds-cn1.dkrz.de:80/outputs/rook/2ac0d5d2-f8b4-11ea-96c8-f2e4655a10b7/input.meta4'
print(requests.get(metalink_url).text)
<?xml version="1.0" encoding="UTF-8"?> <metalink xmlns="urn:ietf:params:xml:ns:metalink"> <published>2020-09-17T09:05:34Z</published> <generator>PyWPS/4.2.8</generator> <file name="lon_bounds_day_EC-EARTH_historical_r1i1p1_18600101-19001229.nc"> <identity>NetCDF file</identity> <size>391277</size> <metaurl mediatype="application/x-netcdf">http://cp4cds-cn1.dkrz.de:80/outputs/rook/2e522a8e-f8b4-11ea-96c8-f2e4655a10b7/lon_bounds_day_EC-EARTH_historical_r1i1p1_18600101-19001229.nc</metaurl> <publisher name="None" url="http://compute.mips.copernicus-climate.eu:80/wps"/> </file> </metalink>
req_url = f"{url}?service=WPS&version=1.0.0&request=Execute&identifier=subset&{datainputs}"
req_url += "&status=true&storeExecuteResponse=true"
req_url
'http://cp4cds-cn1.dkrz.de/wps?service=WPS&version=1.0.0&request=Execute&identifier=subset&DataInputs=collection=c3s-cmip5.output1.ICHEC.EC-EARTH.historical.day.atmos.day.r1i1p1.tas.latest;time=1860-01-01/1900-12-30&status=true&storeExecuteResponse=true'
resp = requests.get(req_url)
resp.ok
True
print(resp.text)
<?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 ../wpsExecute_response.xsd" service="WPS" version="1.0.0" xml:lang="en-US" serviceInstance="http://compute.mips.copernicus-climate.eu:80/wps?request=GetCapabilities&amp;service=WPS" statusLocation="http://cp4cds-cn1.dkrz.de:80/outputs/rook/a0fdaa0e-f8b4-11ea-8c8a-f2e4655a10b7.xml"> <wps:Process wps:processVersion="1.0"> <ows:Identifier>subset</ows:Identifier> <ows:Title>Subset</ows:Title> <ows:Abstract>Run subsetting on climate data.</ows:Abstract> </wps:Process> <wps:Status creationTime="2020-09-17T09:08:46Z"> <wps:ProcessAccepted percentCompleted="0">PyWPS Process subset accepted</wps:ProcessAccepted> </wps:Status> </wps:ExecuteResponse>
Poll status location
Replace the statusLocation
URL.
statusLocation = ''
# statusLocation = ''
statusLocation = 'http://cp4cds-cn1.dkrz.de/outputs/rook/f005b850-f8b2-11ea-96c8-f2e4655a10b7.xml'
resp = requests.get(statusLocation)
print(resp.text)
<?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 ../wpsExecute_response.xsd" service="WPS" version="1.0.0" xml:lang="en-US" serviceInstance="http://compute.mips.copernicus-climate.eu:80/wps?request=GetCapabilities&amp;service=WPS" statusLocation="http://cp4cds-cn1.dkrz.de:80/outputs/rook/f005b850-f8b2-11ea-96c8-f2e4655a10b7.xml"> <wps:Process wps:processVersion="1.0"> <ows:Identifier>subset</ows:Identifier> <ows:Title>Subset</ows:Title> <ows:Abstract>Run subsetting on climate data.</ows:Abstract> </wps:Process> <wps:Status creationTime="2020-09-17T08:56:46Z"> <wps:ProcessSucceeded>PyWPS Process Subset finished</wps:ProcessSucceeded> </wps:Status> <wps:ProcessOutputs> <wps:Output> <ows:Identifier>output</ows:Identifier> <ows:Title>METALINK v4 output</ows:Title> <ows:Abstract>Metalink v4 document with references to NetCDF files.</ows:Abstract> <wps:Reference href="http://cp4cds-cn1.dkrz.de:80/outputs/rook/f005b850-f8b2-11ea-96c8-f2e4655a10b7/input.meta4" mimeType="application/metalink+xml; version=4.0" encoding="" schema="metalink/4.0/metalink4.xsd"/> </wps:Output> </wps:ProcessOutputs> </wps:ExecuteResponse>
Load metalink document
Replace the metalink output URL.
metalink_url = ''
metalink_url = 'http://cp4cds-cn1.dkrz.de:80/outputs/rook/f005b850-f8b2-11ea-96c8-f2e4655a10b7/input.meta4'
print(requests.get(metalink_url).text)
<?xml version="1.0" encoding="UTF-8"?> <metalink xmlns="urn:ietf:params:xml:ns:metalink"> <published>2020-09-17T08:56:46Z</published> <generator>PyWPS/4.2.8</generator> <file name="lon_bounds_day_EC-EARTH_historical_r1i1p1_18600101-19001229.nc"> <identity>NetCDF file</identity> <size>391277</size> <metaurl mediatype="application/x-netcdf">http://cp4cds-cn1.dkrz.de:80/outputs/rook/f388dff2-f8b2-11ea-96c8-f2e4655a10b7/lon_bounds_day_EC-EARTH_historical_r1i1p1_18600101-19001229.nc</metaurl> <publisher name="None" url="http://compute.mips.copernicus-climate.eu:80/wps"/> </file> </metalink>
Download netCDF output
Replace the download URL.
download_url = ''
download_url = 'http://cp4cds-cn1.dkrz.de/outputs/rook/f388dff2-f8b2-11ea-96c8-f2e4655a10b7/lon_bounds_day_EC-EARTH_historical_r1i1p1_18600101-19001229.nc'
print(download_url)
http://cp4cds-cn1.dkrz.de/outputs/rook/f388dff2-f8b2-11ea-96c8-f2e4655a10b7/lon_bounds_day_EC-EARTH_historical_r1i1p1_18600101-19001229.nc