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

Wet spell max length indicator broken #1834

Closed
2 tasks done
aulemahal opened this issue Jul 10, 2024 · 0 comments · Fixed by #1838
Closed
2 tasks done

Wet spell max length indicator broken #1834

aulemahal opened this issue Jul 10, 2024 · 0 comments · Fixed by #1838
Assignees
Labels
bug Something isn't working

Comments

@aulemahal
Copy link
Collaborator

Setup Information

  • Xclim version: 0.50.0
  • Python version: 3.11
  • Operating System: Linux

Description

Computing the wet spell max length spell turned out to be incorrect.

Steps To Reproduce

import numpy as np
import xarray as xr
import xclim as xc

a = np.zeros(366)
a[10:13] = 3
a[40:45] = 3
pr = xr.DataArray(a, dims=('time',), coords={'time': xr.date_range('2000-01-01', periods=366, freq='D')}, attrs={'units': 'mm/d'}

xc.atmos.wet_spell_max_length(pr, window=1, op='min')

Returns : 321. The answer should be 5.

Additional context

The issue is here

wet = (mask.rolling(time=window).sum() < 1).shift(time=-(window - 1))
.

It looks like the code was directly copied from dry_spell_max_length with all comparison operators inverted. But on that line, the comparison has to do with the number of days, so it should be ">=" instead. The current function completely inverts the run mask, so we get the longest run that is not a wet spell.

I'd note that a fast path for the window=1 case might be of interest here. Also, the documentation was not completely adapted when it was copied from dry_spell to wet_spell. For example, "max" as an "op" here makes no sense. It should be "min".

Contribution

  • I would be willing/able to open a Pull Request to address this bug.

Code of Conduct

  • I agree to follow this project's Code of Conduct
@aulemahal aulemahal added the bug Something isn't working label Jul 10, 2024
@aulemahal aulemahal self-assigned this Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant