Skip to content
This repository has been archived by the owner on Dec 23, 2021. It is now read-only.

Commit

Permalink
Merge pull request #12 from bird-house/add-wps-parameter
Browse files Browse the repository at this point in the history
added WPSParameter
  • Loading branch information
cehbrecht committed Jul 5, 2019
2 parents 3823a5b + 4af672d commit 28496ff
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 36 deletions.
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ channels:
- conda-forge
dependencies:
- owslib>=0.17
- pyyaml
# tests
- pytest
- flake8
7 changes: 0 additions & 7 deletions examples/notebooks/aims-llnl-wps-demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,6 @@
"for output in exec.processOutputs:\n",
" print(output.identifier, output.reference)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
11 changes: 2 additions & 9 deletions examples/notebooks/pelican-wps-demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@
"metadata": {},
"outputs": [],
"source": [
"# client = WebProcessingService('https://bovec.dkrz.de/ows/proxy/pelican', headers=headers, verify=True)\n",
"client = WebProcessingService('http://localhost:5000/wps', headers=headers, verify=True)"
"client = WebProcessingService('https://bovec.dkrz.de/ows/proxy/pelican', headers=headers, verify=True)\n",
"# client = WebProcessingService('http://localhost:5000/wps', headers=headers, verify=True)"
]
},
{
Expand Down Expand Up @@ -388,13 +388,6 @@
"source": [
"outputs.outputs[0].uri"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
45 changes: 25 additions & 20 deletions owslib_esgfwps.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
__version__ = '0.1.0'

import json
import yaml
from uuid import uuid4

from owslib.wps import ComplexDataInput
Expand All @@ -34,13 +35,9 @@ class ParameterError(Exception):
pass


class Parameter(ComplexDataInput):
class Parameter(object):
def __init__(self):
super(Parameter, self).__init__(
value=None,
mimeType="application/json",
encoding=None,
schema=None)
pass

@property
def json(self):
Expand All @@ -50,15 +47,6 @@ def json(self):
def from_json(cls, data):
return cls(**data)

@property
def value(self):
return json.dumps(self.json)

@value.setter
def value(self, value):
if value:
self.from_json(json.loads(value))

@property
def params(self):
return {}
Expand All @@ -70,6 +58,24 @@ def __repr__(self):
return "{}({})".format(self.__class__.__name__, params.strip(","))


class WPSParameter(ComplexDataInput, Parameter):
def __init__(self):
super(WPSParameter, self).__init__(
value=None,
mimeType="application/json",
encoding=None,
schema=None)

@property
def value(self):
return json.dumps(self.json)

@value.setter
def value(self, value):
if value:
self.from_json(yaml.safe_load(value))


class Output(Parameter):
def __init__(self, id=None, uri=None, domain=None, mimetype=None):
super(Output, self).__init__()
Expand Down Expand Up @@ -142,10 +148,9 @@ def from_json(cls, data):

@classmethod
def from_owslib(cls, process_outputs):
import yaml
for output in process_outputs:
if output.identifier == 'output':
return cls.from_json(data=yaml.load(output.data[0]))
return cls.from_json(data=yaml.safe_load(output.data[0]))
return cls(outputs=[])

@property
Expand Down Expand Up @@ -207,7 +212,7 @@ def params(self):
return dict(id=self.id)


class Variables(Parameter):
class Variables(WPSParameter):
def __init__(self, variables=None):
super(Variables, self).__init__()
self._variables = variables or []
Expand Down Expand Up @@ -314,7 +319,7 @@ def params(self):
return dict(id=self.id)


class Domains(Parameter):
class Domains(WPSParameter):
def __init__(self, domains=None):
super(Domains, self).__init__()
self._domains = domains or []
Expand Down Expand Up @@ -397,7 +402,7 @@ def params(self):
return dict(name=self.name)


class Operations(Parameter):
class Operations(WPSParameter):
def __init__(self, operations=None):
super(Operations, self).__init__()
self._operations = operations or []
Expand Down
7 changes: 7 additions & 0 deletions tests/test_espfwps.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def test_domains():
domains = Domains([d0])
assert Domains.from_json(domains.json).domains[0].id == d0.id
assert d0.id in str(domains)
assert 'time' in domains.value


def test_variable_compat():
Expand Down Expand Up @@ -132,6 +133,11 @@ def test_variables():
vars = Variables([tas])
assert Variables.from_json(vars.json).variables[0].var_name == 'tas'
assert 'tas' in str(vars)
assert 'tas' in vars.value
new_value = Variables()
new_value.value = vars.value
# TODO: not working
# assert new_value.variables[0].var_name == 'tas'


def test_operation_compat():
Expand Down Expand Up @@ -171,3 +177,4 @@ def test_operations():
operations = Operations([operation])
assert Operations.from_json(operations.json).operations[0].name == operation.name
assert operation.name in str(operations)
assert 'subset' in operations.value

0 comments on commit 28496ff

Please sign in to comment.