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

Refactor first_day indices into generics #1186

Merged
merged 15 commits into from Sep 30, 2022
Merged

Conversation

Zeitsperre
Copy link
Collaborator

@Zeitsperre Zeitsperre commented Sep 19, 2022

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)
    • (If applicable) 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
  • The relevant author information has been added to AUTHORS.rst and .zenodo.json

What kind of change does this PR introduce?

  • Uses DayOfYearStr from same file source
  • Refactors indices into generics that compose temperature-based indices and indicators unique to variables
  • Adds deprecation notices where needed

Does this PR introduce a breaking change?

Yes. first_day_threshold_reached is a new generic indice, and users must transition to using first_day_temperature_below and first_day_temperature_above for previous behaviour. For previous indices/indicators (first_day_above|below), they remain available, but will show DeprecationWarnings when called by user and will be removed in xclim>=0.40.0

Other information:

The first_day_XX_above|below indices all perform local imports of generic first_day_above and first_day_below. This was needed to ensure that the deprecated versionsof these indices remain available without overwriting the newer generics. This will no longer be needed in xclim>=0.40.0 - no longer relevant

…iables they work upon, source DayOfYearStr from same source, add deprecation notices
@Zeitsperre Zeitsperre added enhancement New feature or request standards / conventions Suggestions on ways forward API Interfacing and User Concerns labels Sep 19, 2022
@Zeitsperre Zeitsperre added this to the v0.39 milestone Sep 19, 2022
@Zeitsperre Zeitsperre self-assigned this Sep 19, 2022
Copy link
Collaborator

@aulemahal aulemahal left a comment

Choose a reason for hiding this comment

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

Suggestion, if you like it : To further generalize this, we could use the indicator-creation "input" arg to transform the generic function directly into an indicator. This way, you wouldn't need all the indices.

Example:

first_day_tn_below = Temp(
    identifier="first_day_tn_below",
    units="",
    standard_name="day_of_year",
    long_name="First day of year with minimum temperature below {threshold}",
    description="First day of year with minimum temperature below {threshold} for at least {window} days.",
    title="First day of year with minimum temperature below a threshold.",
    abstract="Returns first day of period where minimum temperature is inferior to a threshold over a given number of days, limited to a starting calendar date.",
    compute=indices.generic.first_day_below,
    input={'data': 'tasmin'},
    parameters=dict(threshold={"default": "0 degC"}, after_date={"default": "07-01"}),
)

Also. We already have "tn_days_below", wouldn't it be coherent to name the new indicators like: "tn_first_day_below" ?

xclim/indicators/atmos/_temperature.py Outdated Show resolved Hide resolved
@@ -808,3 +813,107 @@ def degree_days(tas: xr.DataArray, threshold: str, op: str) -> xr.DataArray:
raise NotImplementedError(f"Condition not supported: '{op}'.")

return to_agg_units(out, tas, op="delta_prod")


def first_day_above(
Copy link
Contributor

Choose a reason for hiding this comment

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

To go one step further into generification you could have instead a first_day_threshold_reached with an operator parameter taking either > or < as a valid value.
It would reduce the duplication of code and doc.
This would also ease the adding of new operators such as >=, <=, ==
It similar to what is done on degree_days for example.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Absolutely! Will make changes. Thanks!

@coveralls
Copy link

coveralls commented Sep 20, 2022

Coverage Status

Coverage increased (+0.01%) to 92.217% when pulling 4250edc on generic_first_days into 2eef291 on master.

@Zeitsperre
Copy link
Collaborator Author

This is now ready for final review

Copy link
Contributor

@bzah bzah left a comment

Choose a reason for hiding this comment

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

lgtm!

HISTORY.rst Outdated Show resolved Hide resolved
Co-authored-by: Abel Aoun <aoun@cerfacs.fr>
Copy link
Collaborator

@aulemahal aulemahal left a comment

Choose a reason for hiding this comment

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

I believe the french translations are missing ;)!

Otherwise, this looks good!

@Zeitsperre Zeitsperre merged commit bc6dd74 into master Sep 30, 2022
@Zeitsperre Zeitsperre deleted the generic_first_days branch September 30, 2022 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Interfacing and User Concerns enhancement New feature or request standards / conventions Suggestions on ways forward
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The first_day_below and first_day_above indices should be made into generics
4 participants