Skip to content

Commit

Permalink
Resampling indicator (#927)
Browse files Browse the repository at this point in the history
* Resampling indicator

* upd hist

* Update xclim/core/indicator.py

Co-authored-by: David Huard <[email protected]>

* Add a few semi-related tests

Co-authored-by: Trevor James Smith <[email protected]>
Co-authored-by: David Huard <[email protected]>
  • Loading branch information
3 people authored Nov 19, 2021
1 parent ce6648f commit cf0515f
Show file tree
Hide file tree
Showing 12 changed files with 294 additions and 184 deletions.
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ Contributors to this version: Pascal Bourgault (:user:`aulemahal`), Travis Logan
New features and enhancements
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Added an optimized pathway for ``xclim.indices.run_length`` functions when ``window=1``. (:pull:`911`, :issue:`910`).
* The data input frequency expected by ``Indicator``s is now in the ``src_freq`` attribute and is thus controlable by subclassing existing indicators. (:issue:`898`, :pull:`927`).

Internal changes
~~~~~~~~~~~~~~~~
* Removed some logging configurations in ``dataflags`` that were polluting python's main logging configuration. (:pull:`909`).
* Synchronized logging formatters in `xclim.ensembles` and `xclim.core.utils`. (:pull:`909`).
* Added a helper function for generating the release notes with dynamically-generated ReStructuredText or Markdown-formatted hyperlinks (:pull:`922`, :issue:`907`).
* Split of resampling-related functionality of ``Indicator``s into a new ``ResamplingIndicator`` subclass. The use of new (private) methods makes it easier to inject functionality in indicator subclasses. (:issue:`867`, :pull:`927`).

Bug fixes
~~~~~~~~~
Expand Down
14 changes: 7 additions & 7 deletions xclim/core/datachecks.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,23 @@ def check_freq(var: xr.DataArray, freq: Union[str, Sequence[str]], strict: bool
exp_base = [parse_offset(frq)[1] for frq in freq]
v_freq = xr.infer_freq(var.time)
if v_freq is None:
raise ValidationError("Unable to infer the frequency of the time series.")
raise ValidationError(
"Unable to infer the frequency of the time series. "
"To mute this, set xclim's option data_validation='log'."
)
v_base = parse_offset(v_freq)[1]
if v_base not in exp_base or (
strict and all(compare_offsets(v_freq, "!=", frq) for frq in freq)
):
raise ValidationError(
f"Frequency of time series not {'strictly' if strict else ''} in {freq}"
f"Frequency of time series not {'strictly' if strict else ''} in {freq}. "
"To mute this, set xclim's option data_validation='log'."
)


@datacheck
def check_daily(var: xr.DataArray):
"""Raise an error if not series has a frequency other that daily, or is not monotonically increasing.
Note that this does not check for gaps in the series.
"""
if xr.infer_freq(var.time) != "D":
raise ValidationError(
"time series is not recognized as daily. You can quiet this error by setting `data_validation` to 'warn' or 'log', in `xclim.set_options`."
)
return check_freq(var, "D")
8 changes: 6 additions & 2 deletions xclim/core/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,8 +541,10 @@ def generate_indicator_docstring(ind):
"""
header = f"{ind.title} (realm: {ind.realm})\n\n{ind.abstract}\n"

special = f'This indicator will check for missing values according to the method "{ind.missing}".\n'
special = ""

if hasattr(ind, "missing"): # Only ResamplingIndicators
special += f'This indicator will check for missing values according to the method "{ind.missing}".\n'
if hasattr(ind.compute, "__module__"):
special += f"Based on indice :py:func:`~{ind.compute.__module__}.{ind.compute.__name__}`.\n"
if ind.injected_parameters:
Expand All @@ -554,7 +556,9 @@ def generate_indicator_docstring(ind):
if ind.keywords:
special += f"Keywords : {ind.keywords}.\n"

parameters = _gen_parameters_section(ind.parameters, ind.allowed_periods)
parameters = _gen_parameters_section(
ind.parameters, getattr(ind, "allowed_periods", None)
)

returns = _gen_returns_section(ind.cf_attrs)

Expand Down
Loading

0 comments on commit cf0515f

Please sign in to comment.