-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I7 parameters #14
I7 parameters #14
Changes from 8 commits
20421cb
b22ac3d
fd035f7
ebc4d28
1d872bd
7e6d7f5
3ca2375
1d9eadc
0b4a2cc
e96411c
5ed025d
c6efd85
20799ad
de8c13d
b1487e8
b1764e9
daab9b0
092de15
b31f57e
fd5f6a8
a04add0
decb3a5
4df6c62
51b99c6
9f874ce
9b3dcd8
98102d1
0afd3a0
0c35042
0f4ae91
9e2f3c9
699f565
3b1006c
0bb9ef3
7c8c2bf
af5d035
b2a2012
04b87ae
a3ea52a
1976e9f
36f5359
1364423
59d6417
73aac17
22e3bb2
fd1e6dc
065a8a6
6dbed3a
5482670
d94c5db
2f04700
2a7c0ef
52c68c2
497e5a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from birdy import WPSClient\n", | ||
"from pkg_resources import resource_filename\n", | ||
"\n", | ||
"import requests" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import os \n", | ||
"while os.path.basename(os.getcwd()) != \"osprey\": # Ensure current directory is always 'osprey'\n", | ||
" os.chdir('../')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Set up wps application\n", | ||
"url = 'http://localhost:5002/wps'\n", | ||
"osprey = WPSClient(url=url)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"osprey?" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Check info on `parameters` process\n", | ||
"osprey.parameters?" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"/home/slim/osprey/tests/data/sample_parameter_config.cfg\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"cfg_file = resource_filename(\"tests\", \"data/sample_parameter_config.cfg\")\n", | ||
"print(cfg_file)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# run parameters\n", | ||
"output = osprey.parameters(\n", | ||
" config = cfg_file\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"output.get()" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.6.9" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
from .wps_say_hello import SayHello | ||
from .wps_parameters import Parameters | ||
|
||
processes = [ | ||
SayHello(), | ||
Parameters(), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
# Processor imports | ||
from pywps import ( | ||
Process, | ||
LiteralInput, | ||
) | ||
from pywps.app.Common import Metadata | ||
|
||
# Tool imports | ||
from rvic.parameters import parameters | ||
from rvic.core.config import read_config | ||
from wps_tools.utils import ( | ||
collect_output_files, | ||
log_handler, | ||
) | ||
from wps_tools.io import ( | ||
log_level, | ||
nc_output, | ||
) | ||
|
||
# Library imports | ||
import logging | ||
import os | ||
|
||
pywps_logger = logging.getLogger("PYWPS") | ||
|
||
|
||
class Parameters(Process): | ||
def __init__(self): | ||
self.status_percentage_steps = { | ||
"start": 0, | ||
"dry_run": 5, | ||
"process": 10, | ||
"collect_files": 90, | ||
"build_output": 95, | ||
"complete": 100, | ||
} | ||
inputs = [ | ||
LiteralInput( | ||
"config", | ||
"Configuration", | ||
abstract="Path to input configuration file or input dictionary", | ||
data_type="string", | ||
), | ||
LiteralInput( | ||
"np", | ||
"numofproc", | ||
default=1, | ||
abstract="Number of processors used to run job", | ||
data_type="integer", | ||
), | ||
LiteralInput( | ||
"version", | ||
"Version", | ||
default=True, | ||
abstract="Return RVIC version string", | ||
data_type="boolean", | ||
), | ||
] | ||
outputs = [ | ||
nc_output, | ||
] | ||
|
||
super(Parameters, self).__init__( | ||
self._handler, | ||
identifier="parameters", | ||
title="Parameters", | ||
abstract="Develop impulse response functions using inputs from a " | ||
"configuration file or dictionary", | ||
metadata=[ | ||
Metadata("NetCDF processing"), | ||
Metadata("Climate Data Operations"), | ||
], | ||
inputs=inputs, | ||
outputs=outputs, | ||
store_supported=True, | ||
status_supported=True, | ||
) | ||
|
||
def collect_args(self, request): | ||
config = request.inputs["config"][0].data | ||
np = request.inputs["np"][0].data | ||
return (config_file, np) | ||
|
||
def get_outfile(self, config): | ||
if isinstance(config, dict): | ||
config_dict = config | ||
else: | ||
config_dict = read_config(config) | ||
outdir = os.path.join(config_dict["OPTIONS"]["CASE_DIR"], "params") | ||
(param_file,) = collect_output_files("rvic", outdir) | ||
return os.path.join(outdir, param_file) | ||
|
||
def _handler(self, request, response): | ||
if request.inputs["version"][0].data: | ||
from rvic import version | ||
|
||
pywps_logger.info(version.short_version) | ||
|
||
(config, np) = self.collect_args(request) | ||
log_handler( | ||
self, response, "Starting Process", process_step="start", level=loglevel | ||
) | ||
if config[0] != "{": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain what you are looking for here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm checking to see if the first character is a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there is a better way to go about that. We can use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On second thought, maybe I could |
||
if not os.path.isfile(config): | ||
raise IOError("config_file: {0} does not " "exist".format(config)) | ||
else: # configuration is dictionary of inputs | ||
config = eval(config) | ||
|
||
log_handler( | ||
self, | ||
response, | ||
"Creating parameters", | ||
process_step="process", | ||
level=loglevel, | ||
) | ||
parameters(config, np) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While is good for now to pass config filepath right into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll add this once your config_builder PR is done. |
||
|
||
log_handler( | ||
self, | ||
response, | ||
"Building final output", | ||
process_step="build_output", | ||
level=loglevel, | ||
) | ||
response.outputs["output"].file = self.get_outfile(config) | ||
|
||
log_handler( | ||
self, response, "Process Complete", process_step="complete", level=loglevel, | ||
) | ||
return response |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ pywps>=4.2 | |
jinja2 | ||
click | ||
psutil | ||
rvic==1.1.0post1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we running this import in this manner?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the way it's done in RVIC. I could move the import to the top.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm they do have an arg for it... Ok I think you were right to put it in in this manner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The import statement in
wps_convolution
is placed at the top. Should we be matching the place it is imported?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point @sum1lim, it would be nice to have the files matching. I believe having the imports at the top is standard so we can move them there.