#!/usr/bin/env python # coding: utf-8 # # Use HTTP requests for WPS rook # # * rook wps: https://github.com/roocs/rook # * wps documentation: http://geoprocessing.info/wpsdoc/ # # In[1]: import requests url = 'http://rook.dkrz.de/wps' # ## GetCapabilities # In[2]: req_url = f"{url}?service=WPS&request=GetCapabilities" req_url # In[3]: resp = requests.get(req_url) resp.ok # In[4]: print(resp.text) # ## DescribeProcess subset # In[5]: req_url = f"{url}?service=WPS&version=1.0.0&request=DescribeProcess&identifier=subset" req_url # In[6]: resp = requests.get(req_url) resp.ok # In[7]: print(resp.text) # ## Execute subset (sync mode) # **Edit data inputs** # In[8]: collection = "CMIP6.CMIP.IPSL.IPSL-CM6A-LR.historical.r1i1p1f1.Amon.rlds.gr.v20180803" time = "1985-01-01/2014-12-30" # In[9]: datainputs = f"DataInputs=collection={collection};time={time}" req_url = f"{url}?service=WPS&version=1.0.0&request=Execute&identifier=subset&{datainputs}" req_url # In[10]: resp = requests.get(req_url) resp.ok # In[11]: print(resp.text) # **Load metalink result document** # # Replace the metalink output URL. # ```python # metalink_url = '' # ``` # In[12]: metalink_url = 'http://rook4.cloud.dkrz.de/outputs/rook/8c23a070-87f2-11eb-bc89-fa163e1098db/provenance.json' # In[13]: print(requests.get(metalink_url).text) # ## Execute subset (async mode) # In[14]: req_url = f"{url}?service=WPS&version=1.0.0&request=Execute&identifier=subset&{datainputs}" req_url += "&status=true&storeExecuteResponse=true" req_url # In[15]: resp = requests.get(req_url) resp.ok # In[16]: print(resp.text) # **Poll status location** # # Replace the `statusLocation` URL. # ```python # statusLocation = '' # ``` # In[17]: # statusLocation = '' statusLocation = 'http://rook4.cloud.dkrz.de/outputs/rook/bc97d460-87f2-11eb-b8ed-fa163e1098db.xml' # In[18]: resp = requests.get(statusLocation) print(resp.text) # **Load metalink document** # # Replace the metalink output URL. # ```python # metalink_url = '' # ``` # In[19]: metalink_url = 'http://rook4.cloud.dkrz.de:80/outputs/rook/bc97d460-87f2-11eb-b8ed-fa163e1098db/input.meta4' # In[20]: print(requests.get(metalink_url).text) # **Download netCDF output** # # Replace the download URL. # # ```python # download_url = '' # ``` # In[21]: download_url = 'http://rook4.cloud.dkrz.de:80/outputs/rook/bfe9ffee-87f2-11eb-a863-fa163e1098db/rlds_Amon_IPSL-CM6A-LR_historical_r1i1p1f1_gr_19850116-20141216.nc subset collection c3s-cmip6.CMIP.IPSL.IPSL-CM6A-LR.historical.r1i1p1f1.Amon.rlds.gr.v20180803 time 1860-01-01/1900-12-30 output """ # In[24]: resp = requests.post(url, data=xml) resp.ok # In[25]: print(resp.text)