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

Conditional string formatting in indicator metadata fields #1174

Open
2 tasks done
Zeitsperre opened this issue Aug 31, 2022 · 1 comment · May be fixed by #1120
Open
2 tasks done

Conditional string formatting in indicator metadata fields #1174

Zeitsperre opened this issue Aug 31, 2022 · 1 comment · May be fixed by #1120
Assignees
Labels
enhancement New feature or request

Comments

@Zeitsperre
Copy link
Collaborator

Zeitsperre commented Aug 31, 2022

Addressing a Problem?

Let's take an indicator that accepts None for a field:

degree_days_exceedance_date = Temp(
    ...
    description="Day of year when the integral of degree days (mean temperature {op} {thresh}) exceeds {sum_thresh}, "
    "with the cumulative sum starting from {after_date}.",
    ...
)

The description field will return:

"Day of year when the integral of degree days (mean temperature > 4 degc) exceeds 200 k days, with the cumulative sum starting from none."

Potential Solution

I haven't delved into the Indicator class code, but if we had access to the call signature keyword arguments, we could perform a string formatting on the fields containing {...} patterns.

This would allow us to provide conditional statements within the metadata fields.

Additional context

No response

Contribution

  • I would be willing/able to open a Pull Request to contribute this feature.

Code of Conduct

  • I agree to follow this project's Code of Conduct
@Zeitsperre Zeitsperre added the enhancement New feature or request label Aug 31, 2022
@Zeitsperre Zeitsperre self-assigned this Aug 31, 2022
@aulemahal
Copy link
Collaborator

This is one of the goals of #1120!

Currently you can pass a function to the indicator's definition, it will receive the pre-formatted arguments.
See

xclim/xclim/core/indicator.py

Lines 1223 to 1224 in 2d6896a

if callable(val):
val = val(**mba)
and lines above to see how mba is filled. But this solution is clunky and we almost never use it. And it is not feasible for the translations, while the jinja method could be!

@Zeitsperre Zeitsperre linked a pull request Sep 13, 2022 that will close this issue
6 tasks
@Zeitsperre Zeitsperre added this to the xclim Long Term Goals milestone Dec 13, 2022
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 a pull request may close this issue.

2 participants