diff --git a/Dockerfile b/Dockerfile index 711fb1c1..615d9f53 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # vim:set ft=dockerfile: FROM continuumio/miniconda3 MAINTAINER https://github.com/bird-house/finch -LABEL Description="Finch WPS" Vendor="Birdhouse" Version="0.4.0" +LABEL Description="Finch WPS" Vendor="Birdhouse" Version="0.4.1" # Update Debian system RUN apt-get update && apt-get install -y \ diff --git a/docs/source/conf.py b/docs/source/conf.py index e34fb355..529bd13e 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -62,7 +62,7 @@ # The short X.Y version. version = '' # The full version, including alpha/beta/rc tags. -release = '0.4.0' +release = '0.4.1' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/finch/__version__.py b/finch/__version__.py index 702eec1a..1a455200 100644 --- a/finch/__version__.py +++ b/finch/__version__.py @@ -6,4 +6,4 @@ __author__ = """David Huard""" __email__ = "huard.david@ouranos.ca" -__version__ = "__version__ = '0.4.0'" +__version__ = "__version__ = '0.4.1'" diff --git a/finch/processes/utils.py b/finch/processes/utils.py index 97d39b66..ad26cce9 100644 --- a/finch/processes/utils.py +++ b/finch/processes/utils.py @@ -136,6 +136,17 @@ def compute_indices( output_dataset = xr.Dataset( data_vars=None, coords=out.coords, attrs=global_attributes ) + + # fix frequency of computed output (xclim should handle this) + if output_dataset.attrs.get("frequency") == "day" and "freq" in kwds: + conversions = { + "YS": "yr", + "MS": "mon", + "QS-DEC": "seasonal", + "AS-JUL": "seasonal", + } + output_dataset.attrs["frequency"] = conversions.get(kwds["freq"], "day") + output_dataset[out.name] = out return output_dataset @@ -155,10 +166,14 @@ def drs_filename(ds: xr.Dataset, variable: str = None): """ if variable is None: variable = [k for k, v in ds.variables.items() if len(v.dims) >= 3][0] + variable = variable.replace("_", "-") + # CORDEX example: tas_EUR-11_ICHEC-EC-EARTH_historical_r3i1p1_DMI-HIRHAM5_v1_day cordex_pattern = "{variable}_{domain}_{driving_model}_{experiment}_{ensemble}_{model}_{version}_{frequency}" + # CMIP5 example: tas_MPI-ESM-LR_historical_r1i1p1 cmip5_pattern = "{variable}_{model}_{experiment}_{ensemble}" + if ds.attrs["project_id"] in ("CORDEX", "EOBS"): filename = cordex_pattern.format( variable=variable, @@ -183,7 +198,16 @@ def drs_filename(ds: xr.Dataset, variable: str = None): ensemble=ensemble, ) else: - raise Exception(f"Unknown project: {ds.attrs['project_id']}") + params = [ + variable, + ds.attrs.get("frequency"), + ds.attrs.get("model_id"), + ds.attrs.get("driving_model_id"), + ds.attrs.get("experiment_id", "").replace(",", "+"), + ds.attrs.get("driving_experiment_id", "").replace(",", "+"), + ] + params = [k for k in params if k] + filename = "_".join(params) if "time" in ds: date_from = ds.time[0].values diff --git a/setup.cfg b/setup.cfg index da2b6789..bb8df802 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.4.0 +current_version = 0.4.1 commit = True tag = True diff --git a/tests/test_utils.py b/tests/test_utils.py index e388370b..c760954c 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -170,6 +170,15 @@ def test_drs_filename(): assert filename == "tasmax_bcc-csm1-1_historical+rcp85_r1i1p1_19500101-19500410.nc" +def test_drs_filename_unknown_project(): + ds = xr.open_dataset( + test_data / "bccaqv2_subset_sample/tasmax_bcc-csm1-1_subset.nc" + ) + ds.attrs["project_id"] = "unknown" + filename = drs_filename(ds) + assert filename == "tasmax_day_bcc-csm1-1_historical+rcp85_19500101-19500410.nc" + + def test_drs_filename_cordex(): ds = xr.open_dataset(test_data / "cordex_subset.nc") filename = drs_filename(ds) diff --git a/tests/test_wps_xclim_indices.py b/tests/test_wps_xclim_indices.py index d0309a47..a6137597 100644 --- a/tests/test_wps_xclim_indices.py +++ b/tests/test_wps_xclim_indices.py @@ -76,7 +76,11 @@ def test_processes(client, netcdf_datasets): date_start = pd.to_datetime(str(ds.time[0].values)) date_end = pd.to_datetime(str(ds.time[-1].values)) - expected = f"{output_variable}_{model}_{experiment}_{ensemble}_{date_start:%Y%m%d}-{date_end:%Y%m%d}.nc" + expected = ( + f"{output_variable.replace('_', '-')}_" + f"{model}_{experiment}_{ensemble}_" + f"{date_start:%Y%m%d}-{date_end:%Y%m%d}.nc" + ) assert Path(outputs[0]).name == expected @@ -128,12 +132,14 @@ def test_heat_wave_frequency_window_thresh_parameters(client, netcdf_datasets): wps_input_file("tasmax", netcdf_datasets["tasmax"]), wps_input_file("tasmin", netcdf_datasets["tasmin"]), wps_literal_input("window", "3"), + wps_literal_input("freq", "YS"), wps_literal_input("thresh_tasmin", "20 degC"), wps_literal_input("thresh_tasmax", "25 degC"), ] outputs = execute_process(client, identifier, inputs) ds = xr.open_dataset(outputs[0]) + assert ds.attrs["frequency"] == "yr" assert ds.heat_wave_frequency.standard_name == _get_output_standard_name(identifier)