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

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

In [ ]:


In [4]:
print wps.identification.title


Flyingpigeon

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


subset_continents : 	 Returns only the selected polygon for each input dataset
subset_countries : 	 Returns only the selected polygon for each input dataset
subset_regionseurope : 	 Returns the selected European administrative region defined in the GADM database (v2.5) for each input dataset.
subset_points : 	 Extract timeseries for specified coordinates from gridded datasets
indices_simple : 	 Climate indices based on one single input variable.
indices_percentile : 	 Climate indices based on one single input variable                             and the percentile of a reference period.
weatherregimes_reanalyse : 	 Weather Regimes based on pressure patterns, fetching selected Realayses Datasets
weatherregimes_model : 	 Weather Regimes based on pressure patterns, fetching selected Realayses Datasets
weatherregimes_projection : 	 Weather Regimes detection based on trained reference statistics
analogs_detection : 	 Search for days with analogue pressure pattern for reanalyses data sets
analogs_model : 	 Search for days with analogue pressure pattern in a climate model data set
analogs_compare : 	 Search in a dataset for days with analogue pressure pattern for a given period in             a reanalyses dataset
analogs_viewer : 	 Visualisation of text output of analogue process
segetalflora : 	 Species biodiversity of segetal flora. Imput files: variable:tas , domain: EUR-11 or EUR-44
sdm_gbiffetch : 	 Species occurence search in Global Biodiversity              Infrastructure Facillity (GBIF)
sdm_getindices : 	 Indices preparation for SDM process
sdm_csvindices : 	 Species distribution model for tree species based on GBIF             presence/absence data and precalculated Indices
sdm_csv : 	 Species distribution model for tree species based on             GBIF presence/absence data and climate model data. Indices will             be calculated while processing
sdm_allinone : 	 Species distribution model for tree species based on             scientific species name and raw model data. GBIF data fetch and             indices calculation will be done within the process
robustness : 	 Calculates the robustness as the ratio of noise to signal in an ensemle of timeseries
plot_timeseries : 	 Outputs some timeseries of the file field means. Spaghetti and uncertainty plot
fetch : 	 This process downloads resources (limited to 50GB)             to the local file system of the birdhouse compute provider
wps_c4i_simple_indice : 	 Computes single input indices of temperature TG, TX, TN, TXx, TXn, TNx, TNn, SU, TR, CSU, GD4, FD, CFD, ID, HD17; of rainfall: CDD, CWD, RR, RR1, SDII, R10mm, R20mm, RX1day, RX5day; and of snowfall: SD, SD1, SD5, SD50. This processes is also available in Climate4Impact and uses ICCLIM.
spatial_analog : 	 Spatial analogs based on climate indices

Step1: Fetching occurence data for Fagus Sylvatica


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


 identifier=taxon_name, title=Tree Species, abstract=Scientific name of tree species, data type=//www.w3.org/TR/xmlschema-2/#string
 Any value allowed
 Default Value: Fagus sylvatica 
 minOccurs=0, maxOccurs=1


 identifier=BBox, title=Bounding Box, abstract=coordinates to define the region for occurence data fetch, data type=BoundingBoxData
 Supported Value: EPSG:4326
 Default Value: EPSG:4326 
 minOccurs=1, maxOccurs=1



In [ ]:
execute = wps.execute(
    identifier="sdm_gbiffetch",
    inputs=[
    ('taxon_name','Fagus sylvatica'),
    ('BBox', '-10.0, 30.0, 10.0, 40.0')
    ],
    #async=False,
    )

In [ ]:


In [7]:
# check process if completed ...
monitorExecution(execute, sleepSecs=5)

for o in execute.processOutputs:
    print o.reference


http://localhost:8090/wpsoutputs/flyingpigeon/output_csv-be40b922-c10d-11e6-86e6-142d277ef1f3.csv
http://localhost:8090/wpsoutputs/flyingpigeon/output_map-be40b922-c10d-11e6-86e6-142d277ef1f3.png

In [8]:
graphic = execute.processOutputs[1].reference
from IPython.display import Image
from IPython.core.display import HTML 
Image(url= graphic)


Out[8]:

Step2: Calculate Indices:


In [14]:
# Define location of input climate data (tas, tasmin, tasmax or pr depending on selected indice)

from os import getenv
HOME = getenv('HOME')

resources = [
    'file://' + HOME + '/birdhouse/var/lib/pywps/cache/malleefowl/esgf1.dkrz.de/thredds/fileServer/cordex/cordex/output/EUR-44/CLMcom/MPI-M-MPI-ESM-LR/historical/r1i1p1/CLMcom-CCLM4-8-17/v1/day/tasmax/v20140520/tasmax_EUR-44_MPI-M-MPI-ESM-LR_historical_r1i1p1_CLMcom-CCLM4-8-17_v1_day_19960101-20001231.nc',
    'file://' + HOME+'/birdhouse/var/lib/pywps/cache/malleefowl/./cordexesg.dmi.dk/thredds/fileServer/cordex_noncommercial/cordex/output/EUR-44/HMS/CNRM-CERFACS-CNRM-CM5/historical/r1i1p1/HMS-ALADIN52/v1/day/tas/v20140804/tas_EUR-44_CNRM-CERFACS-CNRM-CM5_historical_r1i1p1_HMS-ALADIN52_v1_day_20010101-20051231.nc'
    ]

In [15]:
resources


Out[15]:
['file:///home/nils/birdhouse/var/lib/pywps/cache/malleefowl/esgf1.dkrz.de/thredds/fileServer/cordex/cordex/output/EUR-44/CLMcom/MPI-M-MPI-ESM-LR/historical/r1i1p1/CLMcom-CCLM4-8-17/v1/day/tasmax/v20140520/tasmax_EUR-44_MPI-M-MPI-ESM-LR_historical_r1i1p1_CLMcom-CCLM4-8-17_v1_day_19960101-20001231.nc',
 'file:///home/nils/birdhouse/var/lib/pywps/cache/malleefowl/./cordexesg.dmi.dk/thredds/fileServer/cordex_noncommercial/cordex/output/EUR-44/HMS/CNRM-CERFACS-CNRM-CM5/historical/r1i1p1/HMS-ALADIN52/v1/day/tas/v20140804/tas_EUR-44_CNRM-CERFACS-CNRM-CM5_historical_r1i1p1_HMS-ALADIN52_v1_day_20010101-20051231.nc']

In [16]:
p = wps.describeprocess(identifier='sdm_getindices')
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=input_indices, title=Indices, abstract=Climate indices related to growth conditions                 of tree species, data type=//www.w3.org/TR/xmlschema-2/#string
 Allowed Value: CDD_AMJJAS
 Allowed Value: CFD_ONDJFM
 Allowed Value: FD_ONDJFM
 Allowed Value: FD_April
 Allowed Value: FD_May
 Allowed Value: FD_June
 Allowed Value: GD4_yr
 Allowed Value: ID_yr
 Allowed Value: PRCPTOT_yr
 Allowed Value: PRCPTOT_ONDJFM
 Allowed Value: PRCPTOT_AMJJAS
 Allowed Value: PRCPTOT_JJA
 Allowed Value: PRCPTOT_MAM
 Allowed Value: PRCPTOT_JJA
 Allowed Value: RR1_yr
 Allowed Value: SU_yr
 Allowed Value: TG_yr
 Allowed Value: TG_AMJJAS
 Allowed Value: TG_ONDJFM
 Allowed Value: TG_JJA
 Allowed Value: TNn_yr
 Allowed Value: TNn_AMJJAS
 Allowed Value: TG_ONDJFM
 Allowed Value: TNn_Jan
 Default Value: None 
 minOccurs=0, maxOccurs=10


 identifier=archive_format, title=Archive format, abstract=Result files will be compressed into archives.                 Choose an appropriate format, data type=//www.w3.org/TR/xmlschema-2/#string
 Allowed Value: zip
 Allowed Value: tar
 Default Value: tar 
 minOccurs=0, maxOccurs=1



In [17]:
execute = wps.execute(
    identifier="sdm_getindices",
    inputs=[
    ('resources',resources[0]),
    ('resources',resources[1]),
    ('input_indices', 'TG_JJA'),
    ('input_indices', 'SU_yr'),
    ('input_indices', 'ID_yr')
    ],
    #outputs = [('logout', 'True'),('tarout', 'True') ,('anomaliesout', 'True') ]
    )
# check process if completed ...
monitorExecution(execute, sleepSecs=5)
for o in execute.processOutputs:
    print o.reference


http://localhost:8090/wpsoutputs/flyingpigeon/output_indices-94fb1c2e-c09f-11e6-b657-142d277ef1f3.tar

In [6]:
# development extractarchive

arch = '~/birdhouse/var/lib/pywps/outputs/flyingpigeon/output_indices-94fb1c2e-c09f-11e6-b657-142d277ef1f3.tar'

In [7]:
from flyingpigeon import utils


/home/nils/.conda/envs/flyingpigeon/lib/python2.7/site-packages/ocgis/util/environment.py:33: UserWarning: Consider setting the system environment variable "GDAL_DATA=/home/nils/.conda/envs/flyingpigeon/share/gdal" to improve load performance
  warn(msg)
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-7-83d33c25af5f> in <module>()
----> 1 from flyingpigeon import utils

/home/nils/birdhouse/flyingpigeon/flyingpigeon/utils.py in <module>()
      2 import os
      3 import wget
----> 4 from ocgis import RequestDataset  # does not support NETCDF4
      5 from netCDF4 import Dataset, num2date
      6 from netCDF4 import MFDataset  # does not support NETCDF4

/home/nils/.conda/envs/flyingpigeon/lib/python2.7/site-packages/ocgis/__init__.py in <module>()
----> 1 from ocgis.util.environment import env
      2 import osgeo
      3 from osgeo import osr
      4 from osgeo import ogr
      5 from ocgis.interface.base.dimension.base import VectorDimension

/home/nils/.conda/envs/flyingpigeon/lib/python2.7/site-packages/ocgis/util/environment.py in <module>()
     39 import numpy as np
     40 from ocgis import constants
---> 41 from ocgis.util.helpers import get_iter
     42 
     43 # tell ogr/osr to raise exceptions

/home/nils/.conda/envs/flyingpigeon/lib/python2.7/site-packages/ocgis/util/helpers.py in <module>()
     11 import numpy as np
     12 from fiona.crs import from_epsg
---> 13 from shapely.geometry import Point
     14 from shapely.geometry.geo import mapping
     15 from shapely.geometry.polygon import Polygon

/home/nils/.conda/envs/flyingpigeon/lib/python2.7/site-packages/shapely/geometry/__init__.py in <module>()
      2 """
      3 
----> 4 from .base import CAP_STYLE, JOIN_STYLE
      5 from .geo import box, shape, asShape, mapping
      6 from .point import Point, asPoint

/home/nils/.conda/envs/flyingpigeon/lib/python2.7/site-packages/shapely/geometry/base.py in <module>()
      7 from ctypes import pointer, c_size_t, c_char_p, c_void_p
      8 
----> 9 from shapely.coords import CoordinateSequence
     10 from shapely.ftools import wraps
     11 from shapely.geos import lgeos, ReadingError

/home/nils/.conda/envs/flyingpigeon/lib/python2.7/site-packages/shapely/coords.py in <module>()
      6 from ctypes import byref, c_double, c_uint
      7 
----> 8 from shapely.geos import lgeos
      9 from shapely.topology import Validating
     10 

/home/nils/.conda/envs/flyingpigeon/lib/python2.7/site-packages/shapely/geos.py in <module>()
     64 
     65 if sys.platform.startswith('linux'):
---> 66     _lgeos = CDLL(os.path.join(sys.prefix, 'lib', 'libgeos_c.so'))
     67     free = load_dll('c').free
     68     free.argtypes = [c_void_p]

/home/nils/anaconda/lib/python2.7/ctypes/__init__.pyc in __init__(self, name, mode, handle, use_errno, use_last_error)
    360 
    361         if handle is None:
--> 362             self._handle = _dlopen(self._name, mode)
    363         else:
    364             self._handle = handle

OSError: /home/nils/anaconda/lib/libgeos_c.so: cannot open shared object file: No such file or directory

In [ ]: