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

Resampling indicator #927

Merged
merged 5 commits into from
Nov 19, 2021
Merged

Resampling indicator #927

merged 5 commits into from
Nov 19, 2021

Conversation

aulemahal
Copy link
Collaborator

@aulemahal aulemahal commented Nov 17, 2021

Pull Request Checklist:

  • This PR addresses an already opened issue (for bug fixes / features)
  • Tests for the changes have been added (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • HISTORY.rst has been updated (with summary of main changes)
    • Link to issue (:issue:number) and pull request (:pull:number) has been added.
  • bumpversion patch has been called on this branch
  • The relevant author information has been added to .zenodo.json

What kind of change does this PR introduce?

  • Split all resampling-related functionalities of the indicators into a new ResamplingIndicator subclass. I did this by creating private pre- and post-processing methods that are called in __call__. This makes it easy to "inject" functionalities in the indicator's processing. The "resampling-related functionalities" are : checking for the allowed "freq" arg and handling of missing values.
  • Have the data input frequency expected by the indicator stored in a class attribute. This makes it easy to modify it when creating indicators. This improves the changes in Better check_freq, complete anuclim #885.

Does this PR introduce a breaking change?

I don't think so.

Other information:

I think that with this change it becomes a bit clearer what are the uses cases for conventional subclassing of the Indicator class:

  1. Add functionality by overriding one of the pre- or post-process methods.
  2. Convenient way of modifying the following attributes : context, src_freq, realm, title, abstract, keywords, references, notes and allowed_periods.
    In both cases, the goal is to create a new base class and then to create multiple indicators.

I'll put this in a "developer's note" section of the doc in a further PR.

This is also a first step towards a way to inject the indexer kwargs as planned in #899.

@aulemahal aulemahal requested a review from huard November 17, 2021 17:10
@aulemahal
Copy link
Collaborator Author

@bzah With this PR, I modified the way one can specifiy which input frequencies are accepted. See the data/anuclim.yml for an example. I hope it doesn't break your code too much!

The good part is that one can now inherit from an indicator created from Daily and still modifiy src_freq. Daily is only a convenience class, it now doesn't hardcode the frequency check, like it did before.

@coveralls
Copy link

coveralls commented Nov 17, 2021

Pull Request Test Coverage Report for Build 1481920829

  • 106 of 110 (96.36%) changed or added relevant lines in 9 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.01%) to 90.257%

Changes Missing Coverage Covered Lines Changed/Added Lines %
xclim/core/datachecks.py 1 2 50.0%
xclim/testing/tests/test_indicators.py 18 19 94.74%
xclim/core/indicator.py 61 63 96.83%
Totals Coverage Status
Change from base Build 1477070386: 0.01%
Covered Lines: 12654
Relevant Lines: 14020

💛 - Coveralls

@bzah
Copy link
Contributor

bzah commented Nov 18, 2021

Thank you for your concern (and for the feature!) @aulemahal, it won't break my code I'm using atmos daily indicators directly and I have simply disabled the daily check for now on icc v5.
After this PR I might inherit them and change src_freq, but there is an ongoing discussion to see which indices/indicators should accept other frequencies.

Copy link
Collaborator

@huard huard left a comment

Choose a reason for hiding this comment

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

Good for me.

@Zeitsperre Zeitsperre added the enhancement New feature or request label Nov 19, 2021
@Zeitsperre Zeitsperre added this to the v0.32 milestone Nov 19, 2021
@aulemahal aulemahal merged commit cf0515f into master Nov 19, 2021
@aulemahal aulemahal deleted the resampling-indicator branch November 19, 2021 17:51
raquelalegre added a commit to UCL/xclim that referenced this pull request Nov 30, 2021
…s/heat_index

* 'indices/heat_index' of github.com:UCL/xclim: (42 commits)
  Added french metadata for heat index.
  Apply changes to fraction indicator
  [sdba] Re-write of Extreme's adjustment (Ouranosinc#914)
  update history
  Update history
  [Ouranosinc#931] Fix indicator for Rxxp index
  Add missing type for `threshold_count`
  Add dev notes - add indexer example - other small changes
  run all available tests in one call for slow builds
  update makefile target black, only install coveralls in tox if coveralls is needed
  Indexing within indicators (Ouranosinc#934)
  Update history
  finish needs doctests
  Remove unnecessary keep_attrs
  Adapt to CF conventions 1.9 - remove gregorian calendar (Ouranosinc#935)
  Bump version: 0.31.2-beta → 0.31.3-beta
  update HISTORY.rst
  suggested corrections
  Apply suggestions from code review
  Resampling indicator (Ouranosinc#927)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allowed input freq as a parameter ResamplingIndicator
5 participants