Skip to content

Commit

Permalink
Merge pull request #110 from bird-house/implement-date-of-year-inputs
Browse files Browse the repository at this point in the history
- Implement `before_date` and `mid_date` inputs
- Remove realization from csv output
- Update to xclim 0.15.2
- Refresh notebooks
  • Loading branch information
huard authored Apr 7, 2020
2 parents 1f2321f + b5a6404 commit 5a8beba
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 17 deletions.
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Changes
==================

* fix to remove realization coordinate from ensembles
* added chunk datasets for local files also
* update xclim to == 0.15.2

0.5.1 (2020-04-18)
==================
Expand All @@ -23,7 +25,7 @@ Changes

* fix #103 (drs_filename) add defaults when `project_id` is unknown
* drs_filenames: use dash instead of underscores in variable names
* fix #80 frequency attrs of computed datasets
* fix #80 frequency attrs of computed datasets

0.4.0 (2020-03-10)
==================
Expand Down
6 changes: 3 additions & 3 deletions docs/source/notebooks/dap_subset.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@
"Attributes:\n",
" units: mm/day\n",
" cell_methods: time: mean (interval: 30 minutes)\n",
" history: pr=max(0,pr) applied to raw data;\\n[2020-04-04 16:13:21] ...\n",
" history: pr=max(0,pr) applied to raw data;\\n[2020-04-05 10:27:31] ...\n",
" standard_name: lwe_thickness_of_precipitation_amount\n",
" long_name: Average precipitation during wet days (sdii)\n",
" description: Annual simple daily intensity index (sdii) : annual avera...</pre>"
Expand All @@ -576,7 +576,7 @@
"Attributes:\n",
" units: mm/day\n",
" cell_methods: time: mean (interval: 30 minutes)\n",
" history: pr=max(0,pr) applied to raw data;\\n[2020-04-04 16:13:21] ...\n",
" history: pr=max(0,pr) applied to raw data;\\n[2020-04-05 10:27:31] ...\n",
" standard_name: lwe_thickness_of_precipitation_amount\n",
" long_name: Average precipitation during wet days (sdii)\n",
" description: Annual simple daily intensity index (sdii) : annual avera..."
Expand Down Expand Up @@ -610,7 +610,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.7"
"version": "3.8.2"
}
},
"nbformat": 4,
Expand Down
6 changes: 3 additions & 3 deletions docs/source/notebooks/finch-usage.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
" ----------\n",
" tasmin : ComplexData:mimetype:`application/x-netcdf`, :mimetype:`application/x-ogc-dods`\n",
" NetCDF Files or archive (tar/zip) containing netCDF files.\n",
" freq : {'YS', 'MS', 'QS-DEC', 'AS-JUL'}string\n",
" freq : string\n",
" Resampling frequency\n",
" \n",
" Returns\n",
Expand Down Expand Up @@ -104,7 +104,7 @@
"output_type": "stream",
"text": [
"Process status: ProcessSucceeded\n",
"Link to process output: https://pavics.ouranos.ca/wpsoutputs/be502914-76b0-11ea-9d75-0800276e9ee6/frost-days_SRES-A2-experiment_20460101-20650101.nc\n"
"Link to process output: https://pavics.ouranos.ca/wpsoutputs/98bd37b6-7749-11ea-bda5-0800276e9ee6/frost-days_SRES-A2-experiment_20460101-20650101.nc\n"
]
}
],
Expand Down Expand Up @@ -228,7 +228,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.7"
"version": "3.8.2"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ dependencies:
- xarray>=0.14
- sentry-sdk
- siphon
- xclim>=0.15.0, <0.16
- xclim==0.15.2
- pywps==4.2.4
- parse
11 changes: 5 additions & 6 deletions finch/processes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,11 @@ def get_indicators(module):

for i in indicators:
# Todo: remove me after xclim fixes the identifier name
if i.compute.__name__ == 'hot_spell_max_length':
i.identifier = 'hot_spell_max_length'
if i.compute.__name__ == "hot_spell_max_length":
i.identifier = "hot_spell_max_length"

not_implemented = [
"DC", # lat input type is not implemented and start_up_mode argument seems to be missing?
"growing_season_length", # mid_date parameter not implemented
"growing_season_end", # mid_date parameter not implemented
"last_spring_frost", # before_date parameter not implemented
]
indicators = [i for i in indicators if i.identifier not in not_implemented]
ensemble_indicators = [i for i in indicators if uses_accepted_netcdf_variables(i)]
Expand Down Expand Up @@ -114,7 +111,9 @@ def _build_xclim():
processes = get_processes(all_processes=True)
objs = {p.__class__.__name__: p.__class__ for p in processes}

mod = xclim.indicators.build_module("finch.processes.xclim", objs, doc="""XCLIM Processes""")
mod = xclim.indicators.build_module(
"finch.processes.xclim", objs, doc="""XCLIM Processes"""
)
sys.modules["finch.processes.xclim"] = mod
return mod

Expand Down
17 changes: 15 additions & 2 deletions finch/processes/wps_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from typing import Dict, List

from dask.diagnostics import ProgressBar
from dask.diagnostics.progress import format_time
from pywps import ComplexInput, FORMATS, LiteralInput, Process
from pywps.app.Common import Metadata
from sentry_sdk import configure_scope
Expand Down Expand Up @@ -121,9 +120,11 @@ def convert_xclim_inputs_to_pywps(params: Dict) -> List[PywpsInput]:
elif name in ["thresh"]:
inputs.append(make_thresh(name, attrs["default"], attrs["desc"]))
elif name in ["freq"]:
inputs.append(make_freq(name, attrs["default"]))
inputs.append(make_freq(name, attrs["default"], attrs["desc"]))
elif name in ["window"]:
inputs.append(make_window(name, attrs["default"], attrs["desc"]))
elif name in ["mid_date", "before_date"]:
inputs.append(make_date_of_year(name, attrs["default"], attrs["desc"]))
else:
# raise NotImplementedError(name)
LOGGER.warning("not implemented: {}".format(name))
Expand Down Expand Up @@ -168,6 +169,18 @@ def make_window(name, default, abstract=""):
)


def make_date_of_year(name, default, abstract=""):
return LiteralInput(
name,
"Date of the year",
abstract=abstract,
data_type="string",
min_occurs=0,
max_occurs=1,
default=default,
)


def make_nc_input(name):
return ComplexInput(
name,
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pywps>=4.2.0<4.3
xclim>=0.13.0
xclim==0.15.2
geopandas
jinja2
click
Expand Down
2 changes: 2 additions & 0 deletions tests/test_wps_xclim_indices.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def test_processes(client, netcdf_datasets):
literal_inputs = {
"freq": "MS",
"window": "3",
"mid_date": "07-01",
"before_date": "07-01",
}
keep_defaults = ["thresh", "thresh_tasmin", "thresh_tasmax"]

Expand Down

0 comments on commit 5a8beba

Please sign in to comment.