run request with owslib


In [1]:
from owslib.wps import WebProcessingService, monitorExecution, printInputOutput

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]:
for process in wps.processes:
    print '%s : \t %s' % (process.identifier, process.abstract, )


visualisation : 	 Just testing a nice script to visualise some variables
extractpoints : 	 Extract Timeseries for specified coordinates from grid data
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

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


 identifier=resource, title=Resource, 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=1000


 identifier=region, title=Region, abstract=None, data type=//www.w3.org/TR/xmlschema-2/#string
 Allowed Value: ABW
 Allowed Value: AFG
 Allowed Value: AGO
 Allowed Value: ALB
 Allowed Value: ALD
 Allowed Value: AND
 Allowed Value: ARE
 Allowed Value: ARG
 Allowed Value: ARM
 Allowed Value: ASM
 Allowed Value: ATA
 Allowed Value: ATF
 Allowed Value: ATG
 Allowed Value: AUS
 Allowed Value: AUT
 Allowed Value: AZE
 Allowed Value: BDI
 Allowed Value: BEL
 Allowed Value: BEN
 Allowed Value: BFA
 Allowed Value: BGD
 Allowed Value: BGR
 Allowed Value: BHR
 Allowed Value: BHS
 Allowed Value: BIH
 Allowed Value: BLR
 Allowed Value: BLZ
 Allowed Value: BOL
 Allowed Value: BRA
 Allowed Value: BRB
 Allowed Value: BRN
 Allowed Value: BTN
 Allowed Value: BWA
 Allowed Value: CAF
 Allowed Value: CAN
 Allowed Value: CHE
 Allowed Value: CHL
 Allowed Value: CHN
 Allowed Value: CIV
 Allowed Value: CMR
 Allowed Value: CNM
 Allowed Value: COD
 Allowed Value: COG
 Allowed Value: COL
 Allowed Value: COM
 Allowed Value: CPV
 Allowed Value: CRI
 Allowed Value: CUB
 Allowed Value: CUW
 Allowed Value: CYM
 Allowed Value: CYN
 Allowed Value: CYP
 Allowed Value: CZE
 Allowed Value: DEU
 Allowed Value: DJI
 Allowed Value: DMA
 Allowed Value: DNK
 Allowed Value: DOM
 Allowed Value: DZA
 Allowed Value: ECU
 Allowed Value: EGY
 Allowed Value: ERI
 Allowed Value: ESB
 Allowed Value: ESP
 Allowed Value: EST
 Allowed Value: ETH
 Allowed Value: FIN
 Allowed Value: FJI
 Allowed Value: FLK
 Allowed Value: FRA
 Allowed Value: FRO
 Allowed Value: FSM
 Allowed Value: GAB
 Allowed Value: GBR
 Allowed Value: GEO
 Allowed Value: GHA
 Allowed Value: GIN
 Allowed Value: GMB
 Allowed Value: GNB
 Allowed Value: GNQ
 Allowed Value: GRC
 Allowed Value: GRD
 Allowed Value: GRL
 Allowed Value: GTM
 Allowed Value: GUM
 Allowed Value: GUY
 Allowed Value: HKG
 Allowed Value: HMD
 Allowed Value: HND
 Allowed Value: HRV
 Allowed Value: HTI
 Allowed Value: HUN
 Allowed Value: IDN
 Allowed Value: IMN
 Allowed Value: IND
 Allowed Value: IRL
 Allowed Value: IRN
 Allowed Value: IRQ
 Allowed Value: ISL
 Allowed Value: ISR
 Allowed Value: ITA
 Allowed Value: JAM
 Allowed Value: JOR
 Allowed Value: JPN
 Allowed Value: KAB
 Allowed Value: KAS
 Allowed Value: KAZ
 Allowed Value: KEN
 Allowed Value: KGZ
 Allowed Value: KHM
 Allowed Value: KIR
 Allowed Value: KNA
 Allowed Value: KOR
 Allowed Value: KOS
 Allowed Value: KWT
 Allowed Value: LAO
 Allowed Value: LBN
 Allowed Value: LBR
 Allowed Value: LBY
 Allowed Value: LCA
 Allowed Value: LIE
 Allowed Value: LKA
 Allowed Value: LSO
 Allowed Value: LTU
 Allowed Value: LUX
 Allowed Value: LVA
 Allowed Value: MAR
 Allowed Value: MDA
 Allowed Value: MDG
 Allowed Value: MEX
 Allowed Value: MKD
 Allowed Value: MLI
 Allowed Value: MLT
 Allowed Value: MMR
 Allowed Value: MNE
 Allowed Value: MNG
 Allowed Value: MNP
 Allowed Value: MOZ
 Allowed Value: MRT
 Allowed Value: MUS
 Allowed Value: MWI
 Allowed Value: MYS
 Allowed Value: NAM
 Allowed Value: NCL
 Allowed Value: NER
 Allowed Value: NGA
 Allowed Value: NIC
 Allowed Value: NIU
 Allowed Value: NLD
 Allowed Value: NOR
 Allowed Value: NPL
 Allowed Value: NZL
 Allowed Value: OMN
 Allowed Value: PAK
 Allowed Value: PAN
 Allowed Value: PER
 Allowed Value: PHL
 Allowed Value: PLW
 Allowed Value: PNG
 Allowed Value: POL
 Allowed Value: PRI
 Allowed Value: PRK
 Allowed Value: PRT
 Allowed Value: PRY
 Allowed Value: PSX
 Allowed Value: PYF
 Allowed Value: QAT
 Allowed Value: ROU
 Allowed Value: RUS
 Allowed Value: RWA
 Allowed Value: SAH
 Allowed Value: SAU
 Allowed Value: SDN
 Allowed Value: SDS
 Allowed Value: SEN
 Allowed Value: SGP
 Allowed Value: SGS
 Allowed Value: SHN
 Allowed Value: SLB
 Allowed Value: SLE
 Allowed Value: SLV
 Allowed Value: SOL
 Allowed Value: SOM
 Allowed Value: SPM
 Allowed Value: SRB
 Allowed Value: STP
 Allowed Value: SUR
 Allowed Value: SVK
 Allowed Value: SVN
 Allowed Value: SWE
 Allowed Value: SWZ
 Allowed Value: SYR
 Allowed Value: TCD
 Allowed Value: TGO
 Allowed Value: THA
 Allowed Value: TJK
 Allowed Value: TKM
 Allowed Value: TLS
 Allowed Value: TON
 Allowed Value: TTO
 Allowed Value: TUN
 Allowed Value: TUR
 Allowed Value: TWN
 Allowed Value: TZA
 Allowed Value: UGA
 Allowed Value: UKR
 Allowed Value: URY
 Allowed Value: USA
 Allowed Value: UZB
 Allowed Value: VCT
 Allowed Value: VEN
 Allowed Value: VIR
 Allowed Value: VNM
 Allowed Value: VUT
 Allowed Value: WSB
 Allowed Value: WSM
 Allowed Value: YEM
 Allowed Value: ZAF
 Allowed Value: ZMB
 Allowed Value: ZWE
 Default Value: DEU 
 minOccurs=0, maxOccurs=220


 identifier=dimension_map, title=Dimension Map, abstract=if not ordered in lon/lat a dimension map has to be provided, data type=//www.w3.org/TR/xmlschema-2/#string
 Any value allowed
 Default Value: None 
 minOccurs=0, maxOccurs=1


 identifier=mosaik, title=Mosaik, abstract=If Mosaik is checked, selected polygons will be merged to one Mosaik for each input file, data type=//www.w3.org/TR/xmlschema-2/#boolean
 Any value allowed
 Default Value: False 
 minOccurs=0, maxOccurs=1



In [4]:
in_file1 = 'file:///home/estimr1/EUCLEIA/indices/RX5day/DJF/RX5day_DJF_HadGEM3-A-N216_historical_r1i1p1_19600101-20131230.nc'
in_file2 = 'file:///home/estimr1/EUCLEIA/indices/RX5day/DJF/RX5day_DJF_HadGEM3-A-N216_historical_r1i1p2_19600101-20131230.nc'

#in_file1 = 'file:///home/pingu/.conda/envs/birdhouse/var/lib/cache/pywps/esgf1.dkrz.de/thredds/fileServer/cordex/cordex/output/EUR-44/MPI-CSC/MPI-M-MPI-ESM-LR/historical/r1i1p1/MPI-CSC-REMO2009/v1/mon/tasmax/v20150609/tasmax_EUR-44_MPI-M-MPI-ESM-LR_historical_r1i1p1_MPI-CSC-REMO2009_v1_mon_199101-200012.nc'
#in_file2 = 'file:///home/pingu/.conda/envs/birdhouse/var/lib/cache/pywps/esgf1.dkrz.de/thredds/fileServer/cordex/cordex/output/EUR-44/MPI-CSC/MPI-M-MPI-ESM-LR/historical/r1i1p1/MPI-CSC-REMO2009/v1/mon/tasmax/v20150609/tasmax_EUR-44_MPI-M-MPI-ESM-LR_historical_r1i1p1_MPI-CSC-REMO2009_v1_mon_200101-200512.nc'

In [6]:
execute = wps.execute(
    identifier="subset_countries", #indices_clipping",
    inputs=[
    ("resource",in_file1),
    ("resource",in_file2),
    ("region",'POL'),
    ("region",'DEU'),
    ("mosaik",'True'),  
           ])

monitorExecution(execute, sleepSecs=5)

print execute.getStatus()

for o in execute.processOutputs:
    print o.reference


ProcessSucceeded
http://localhost:8090/wpsoutputs/flyingpigeon/output-5a18a28e-d405-11e5-8a28-9d33cb3eae7f.tar

In [4]:
# for rotated grids 

rot_file1 = 'file:///home/starmip/tnoel/BCCORDEX/TasAdjust/tasAdjust_EUR-11_MPI-M-MPI-ESM-LR_rcp85_r1i1p1_SMHI-RCA4-LSCE-IPSL-CDFt-EOBS10-1971-2005_day_20860101-20901231.nc' 
rot_file2 = 'file:///home/starmip/tnoel/BCCORDEX/TasAdjust/tasAdjust_EUR-11_MPI-M-MPI-ESM-LR_rcp85_r1i1p1_SMHI-RCA4-LSCE-IPSL-CDFt-EOBS10-1971-2005_day_20910101-20951231.nc'
rot_file3 = 'file:///home/starmip/tnoel/BCCORDEX/TasAdjust/tasAdjust_EUR-11_MPI-M-MPI-ESM-LR_rcp85_r1i1p1_SMHI-RCA4-LSCE-IPSL-CDFt-EOBS10-1971-2005_day_20960101-21001231.nc'

In [5]:
# define a dimensinon_map: 

dimension_map = "{'X': {'variable': 'lon', 'dimension': 'x', 'pos': 2}, 'Y': {'variable': 'lat', 'dimension': 'y', 'pos': 1}, 'T': {'variable': 'time', 'dimension': 'time', 'pos': 0 }}"

In [ ]:
execute = wps.execute(
    identifier="subset_countries", #indices_clipping",
    inputs=[
    ("resource",rot_file1),
   # ("resource",rot_file2),
   # ("resource",rot_file3),
   # ("region",'POL'),
    ("region",'DEU'),
   # ("mosaik",'True'),
    ("dimension_map", dimension_map),
    ("variable",'tasAdjust')
           ])

monitorExecution(execute, sleepSecs=5)

print execute.getStatus()

for o in execute.processOutputs:
    print o.reference

In [ ]:

run sync request with get parameters


In [ ]:
sync_req_url = "{wps_url}?" +\
    "request=Execute" +\
    "&service=WPS" +\
    "&version=1.0.0" +\
    "&identifier=subset_countries" +\
    "&DataInputs=resource={resource1};resource={resource2};region={region}" +\
    "&storeExecuteResponse=false" +\
    "&status=false"

In [ ]:
url=sync_req_url.format(
    wps_url=wps_url,
    resource1=in_file1,
    resource2=in_file2,
    region='FRA')
print url

In [ ]:
import requests
r = requests.get(url)
print r.status_code
print r.text

run async request with get parameters


In [ ]:
async_req_url = "{wps_url}?" +\
    "request=Execute" +\
    "&service=WPS" +\
    "&version=1.0.0" +\
    "&identifier=subset_countries" +\
    "&DataInputs=resource={resource1};resource={resource2};region={region}" +\
    "&storeExecuteResponse=true" +\
    "&status=true"
    #

In [ ]:
url=async_req_url.format(
    wps_url=wps_url,
    resource1=in_file1,
    resource2=in_file2,
    region='FRA')
print url

In [ ]:
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

In [ ]:
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

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

In [ ]:
status_url2 = status_url

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

In [ ]: