-
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
Heat Wave Magnitude Index #994
Comments
Hi @ninglk, You're very welcome to submit a PR for this. Please check the documentation on how to create new indices and indicators here: https://xclim.readthedocs.io/en/stable/contributing.html#implement-features-indices-or-indicators I suspect this is not going to be straightforward, so don't hesitate to reach out for in-depth discussion on the implementation. Don't worry about the french translation, we'll complete that part. |
Hi @ninglk, we're just wondering if you were still interested in contributing a PR to add this indice into the library. The Xclim devs are available if you need help with formatting standards and compliance or getting things working. Please let us know! |
Hey @Zeitsperre @huard, I came across this issue, because I was also in need of a Heatwave Magnitude Index. I have implemented it for myself using some functions from available To briefly elaborate what I did:
Hence, I wanted to ask if this would still be in question for a PR. Kind regards |
Hi @seblehner, thanks for chiming in here. We're always motivated to hear of researchers using our libraries! It sounds like your approach would be compatible with the library, perhaps even more so given some of the changes we've made recently to our generic indices. I'm not the expert on the vectorization code, but I imagine we (@aulemahal) would be more than capable to help you with that step. We would more than welcome a PR for this. Feel free to re-open this issue and send along a PR that we can take a look at. All the best, |
Hi! Thanks for this discussion. If you want to share your code I would be interested to see how you implemented this. Am I understanding this is similar to a function like We have a PR #1778 currently implementing something that could be of use for you I believe. The context in this case is that we compute freeze rain events, and we want various statistics, including: in each spell, what is the total quantity of precipitation. We simply use intermediate results of ds["event_accumulation"] = rl._cumsum_reset(
dataam.where(runs == 1), index="first", reset_on_zero=False
) This gives the accumulation (of freeze rain) in each spell. You can resample this result at the end if you would want the total temperature in the heat waves There are some specificities for the freezing rain, but I think all the logic is already there to compute what you seek. Best |
Hello @coxipi, I am happy to share it already. It sounds like what we want is similar. What I did was
old: d = rle(da, dim=dim, index=index)
d = d.where(d >= window, 0)
if freq is not None:
d = d.resample({dim: freq})
out = d.sum(dim=dim) new (inside a new d_rse = rse(da, dim=dim, index=index)
d_rle = rle(xr.where(da > 0, 1, 0), dim=dim, index=index)
d = d_rse.where(d_rle >= window, 0)
if freq is not None:
d = d.resample({dim: freq})
out = d.max(dim=dim) The The old (from da = da.astype(int)
...
# Keep total length of each series (and also keep 0's), e.g. 100120123 -> 100N20NN3
# Keep numbers with a 0 to the right and also the last number
cs_s = cs_s.where(da.shift({dim: -1}, fill_value=0) == 0)
out = cs_s.where(da == 1, 0) # Reinsert 0's at their original place da = da.astype(float) # changed from int to float because we need absolute values
...
# Keep total length of each series (and also keep 0's), e.g. 100120123 -> 100N20NN3
# Keep numbers with a 0 to the right and also the last number
cs_s = cs_s.where(da.shift({dim: -1}, fill_value=0) == 0)
out = cs_s.where(da > 0, 0) # Reinsert 0's at their original place For this I just changed the And that's essentially it. As mentioned above, I made a new indicator @Zeitsperre Just fyi, I don't have permissions to reopen this issue. Kind regards |
Closes #994 ### Pull Request Checklist: - [x] This PR addresses an already opened issue (for bug fixes / features) - This PR fixes #994 - [x] Tests for the changes have been added (for bug fixes / features) - [ ] (If applicable) Documentation has been added / updated (for bug fixes / features) - [x] CHANGELOG.rst has been updated (with summary of main changes) - [x] Link to issue (:issue:`number`) and pull request (:pull:`number`) has been added ### What kind of change does this PR introduce? * Adds a heat_wave_magnitude indicator based on a variable definition on heat waves (consecutive days of maximum temperature above a given threshold), which yields the highest magnitude in the form of accumulated maximum temperature differences above a threshold along a consecutive heat wave * Adds a windowed_max_run_sum function to indices.run_length which yields the maximum accumulated values of runs per `freq` period * Adds a rse (termed run sum encoding) function which sums positive values for runs ### Does this PR introduce a breaking change? No ### TODO: - [x] one of the test doesn't convert units properly - [x] french translation (need help with that one)
I would like to see the following indice considered as potential contributions to the xclim library:
The Heat Wave Magnitude Index is defined as the maximum magnitude of the heat waves in a year, where heat wave is the period ≥ 3 consecutive days with maximum temperature above the daily threshold for the reference period (https://agupubs.onlinelibrary.wiley.com/doi/10.1002/2014JD022098/)
The text was updated successfully, but these errors were encountered: