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

Add percentage difference to xscen.aggregate.compute_deltas #82

Closed
1 task
mccrayc opened this issue Sep 22, 2022 · 0 comments · Fixed by #90
Closed
1 task

Add percentage difference to xscen.aggregate.compute_deltas #82

mccrayc opened this issue Sep 22, 2022 · 0 comments · Fixed by #90
Labels
enhancement New feature or request

Comments

@mccrayc
Copy link
Collaborator

mccrayc commented Sep 22, 2022

Addressing a Problem?

When we calculate relative changes for climate change, we are often presenting deltas in terms of % change relative to the past climate. Currently, compute_deltas allows for absolute or relative deltas, but relative is a simple ratio future/past (in the case of a future and past climate delta). I believe it would be useful to add a percentage change option to "kind."

Potential Solution

In xscen.aggregate, add a new option for parameter 'kind': '%' associated with _kind = 'percentage' or 'percent'. Something like:

with xr.set_options(keep_attrs=True):
    if _kind == "absolute":
        deltas[v_name] = other_hz[vv] - ref[vv]
    elif _kind == "relative":
        deltas[v_name] = other_hz[vv] / ref[vv]
        deltas[v_name].attrs["units"] = ""
    elif _kind == "percentage":
        deltas[v_name] = (other_hz[vv] - ref[vv]) / ref[vv] * 100
        deltas[v_name].attrs["units"] = "%"

This will lead to NaNs in cases where the reference value is 0 (for example, for certain precipitation variables like prsn). I don't think this should be too much of an issue though, as this is handled well by xarray.

Additional context

The *100 to convert the decimal change to % may not be desired or could be an option.

Contribution

  • I would be willing/able to open a Pull Request to contribute this feature.
@mccrayc mccrayc added the enhancement New feature or request label Sep 22, 2022
@RondeauG RondeauG mentioned this issue Sep 27, 2022
6 tasks
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.

1 participant