Skip to content
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

Merged
merged 54 commits into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
20421cb
add wps_Convolution.py
sum1lim Jul 16, 2020
b22ac3d
wps_convolution added to __init__.py
sum1lim Jul 16, 2020
fd035f7
add rvic to requirements.txt
sum1lim Jul 16, 2020
ebc4d28
add demo_convolution
sum1lim Jul 16, 2020
1d872bd
Add wps_parameters.py
Jul 17, 2020
7e6d7f5
wps_convolution takes .cfg input and produces .nc output
sum1lim Jul 17, 2020
3ca2375
use helper-functions of convolution rather than calling convolution()
sum1lim Jul 17, 2020
1d9eadc
dynamic determination of output filepath
sum1lim Jul 17, 2020
0b4a2cc
back to using convolution()
sum1lim Jul 17, 2020
e96411c
Add test_wps_parameters.py and sample parameters
Jul 17, 2020
5ed025d
modification to fit RVIC 1.1.0.post1
sum1lim Jul 20, 2020
c6efd85
fixed bug in outputting
sum1lim Jul 21, 2020
20799ad
config files in tests/data/configs
sum1lim Jul 21, 2020
de8c13d
add test_wps_convolution.py
sum1lim Jul 22, 2020
b1487e8
dynamic definition for config filepath
sum1lim Jul 22, 2020
b1764e9
run_wps_process moved to common.py
Jul 23, 2020
daab9b0
config input is a str not a file
sum1lim Jul 24, 2020
092de15
delete unnecessary test file
sum1lim Jul 24, 2020
b31f57e
test_wps_convolution marked as slow and online
sum1lim Jul 24, 2020
fd5f6a8
black applied on common.py
sum1lim Jul 24, 2020
a04add0
move demo_requirements to requirements_dev
sum1lim Jul 24, 2020
decb3a5
revert test_wps_caps.py
sum1lim Jul 24, 2020
4df6c62
delete wps_say_hello
sum1lim Jul 24, 2020
51b99c6
different pathways depending on rvic version
sum1lim Jul 24, 2020
9f874ce
pin rvic version
sum1lim Jul 24, 2020
9b3dcd8
use lower case letters for variables
sum1lim Jul 24, 2020
98102d1
logging out messages
sum1lim Jul 24, 2020
0afd3a0
set curr_dir to osprey
sum1lim Jul 24, 2020
0c35042
Add rvic and notebook requirements to requirements files
Jul 24, 2020
0f4ae91
Update imported module names in wps_parameters
Jul 24, 2020
9e2f3c9
Only use local config file in pytest
Jul 24, 2020
699f565
Add demo notebook
Jul 24, 2020
3b1006c
Replace convolution with parameters in comment
Jul 24, 2020
0bb9ef3
Format test_wps_parameters with black
Jul 24, 2020
7c8c2bf
update demo
sum1lim Jul 27, 2020
af5d035
fix typo in jupyter demo
sum1lim Jul 30, 2020
b2a2012
Merge pull request #13 from pacificclimate/i8-wrap-convolution
sum1lim Jul 31, 2020
04b87ae
Add wps_parameters.py
Jul 17, 2020
a3ea52a
Add test_wps_parameters.py and sample parameters
Jul 17, 2020
1976e9f
Update imported module names in wps_parameters
Jul 24, 2020
36f5359
Only use local config file in pytest
Jul 24, 2020
1364423
Add demo notebook
Jul 24, 2020
59d6417
Replace convolution with parameters in comment
Jul 24, 2020
73aac17
Format test_wps_parameters with black
Jul 24, 2020
22e3bb2
Merge branch 'i7-parameters' of https://github.com/pacificclimate/osp…
Aug 4, 2020
fd1e6dc
Use json.loads instead of eval and use fewer percentage steps
Aug 4, 2020
065a8a6
Update wps_parameters to use wps-tools
Aug 11, 2020
6dbed3a
Show successful parameters demo and move to demo_individual directory
Aug 11, 2020
5482670
Remove pytest from CI workflow
Aug 11, 2020
d94c5db
Format with black
Aug 11, 2020
2f04700
Add parameters to test_wps_caps
Aug 11, 2020
2a7c0ef
Comment out instead of remove pytest in CI workflow
Aug 11, 2020
52c68c2
Move version import to top of file
Aug 11, 2020
497e5a3
Use temporary config file for wps_parameters
Aug 11, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions notebooks/demo_parameters.ipynb
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
}
2 changes: 2 additions & 0 deletions osprey/processes/__init__.py
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(),
]
130 changes: 130 additions & 0 deletions osprey/processes/wps_parameters.py
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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor

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.


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] != "{":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain what you are looking for here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm checking to see if the first character is a { since that shows that the input is a dictionary rather than a file path. I'll clarify that.

Copy link
Contributor

Choose a reason for hiding this comment

The 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 type(input) == dict to check if it is a dict. If it comes in as a string in the format of a dict I think there is a way to translate that into a dict.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought, maybe I could try to run eval(config), and if it raises an exception, check to make sure it's a file path in the except block.

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While is good for now to pass config filepath right into RVIC parameters, I think it would be nice to implement a pathway for calling the function with a dictionary argument depending on the RVIC version. We could probably do this later in another PR. I will leave that decision up to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ pywps>=4.2
jinja2
click
psutil
rvic==1.1.0post1
7 changes: 7 additions & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@ twine
cruft
# Changing dependencies above this comment will create merge conflicts when updating the cookiecutter template with cruft. Add extra requirements below this line.
black==19.10b0

# notebook requirements
jupyterlab
ipywidgets
nodejs
birdhouse-birdy
beautifulsoup4
Binary file added tests/data/samples/sample.rvic.h0a.2013-01-01.nc
Binary file not shown.
Binary file not shown.
Loading