-
Notifications
You must be signed in to change notification settings - Fork 59
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
ENH: template indicators with jinja #1120
base: main
Are you sure you want to change the base?
Conversation
xclim/core/formatting.py
Outdated
@@ -77,7 +81,8 @@ def format(self, format_string: str, /, *args: Any, **kwargs: dict) -> str: | |||
for k, v in DEFAULT_FORMAT_PARAMS.items(): | |||
if k not in kwargs: | |||
kwargs.update({k: v}) | |||
return super().format(format_string, *args, **kwargs) | |||
kwargs["np"] = np # noqa |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit ugly, maybe there is a better way to add numpy in jinja rendering namespace
"An event occurs when the minimum and maximum daily " | ||
"temperature both exceeds specific thresholds : " | ||
"(Tmin > {thresh_tasmin} and Tmax > {thresh_tasmax}) " | ||
"over a minimum number of days ({window}).", | ||
"{% if np.isscalar(thresh_tasmin) and np.isscalar(thresh_tasmax)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the template for heat_wave_frequency
I tried to mitigate the changes by applying both AttrFormatter and jinja templating.
So, this
prints
|
For the record, I'm working (in icclim) on generic indicators which would fully utilize jinja templating to generate rich metadata. |
Unfortunately, I don't think I will be able to work much more on this PR (or generic indicators in xclim), my contract at cerfacs ends soon and I don't know yet if I will continue working on climate indices afterward. |
Hi Abel, sorry to hear that, we really enjoyed your contributions to the project. Yes, it would be useful for us to get a sense of where things stand so we can work on the xclim port. Let us know when is a good time for you. |
Pull Request Checklist:
number
) and pull request (:pull:number
) has been added.zenodo.json
What kind of change does this PR introduce?
Follow up to discussions in here: #1093
This pr is a proof of concept to get an idea of how jinja can be used to format indicator descriptions.
Does this PR introduce a breaking change?
No, it should not.
Other information:
To illustrate the results with heat_wave_frequency:
prints
"Ys number of heat wave events over a given period. an event occurs when the minimum and maximum daily temperature both exceeds specific thresholds : (tmin > 22.0 degc and tmax > 30 degc)over a minimum number of days (3)."