Skip to content

Finding first and last day for each grid point that meets a condition #7656

Discussion options

You must be logged in to vote

Would the following work in your case? It would need some adjustment to work in the scenario of multiple years, but it looks like your dataset only spans one year:

ds = xr.open_dataset("check_minmax.nc")
threshold = 50.0
masked_dayofyear = ds.time.dt.dayofyear.where(ds.siconc < threshold)
first = masked_dayofyear.min("time")
last = masked_dayofyear.max("time")
days = last - first

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@axelschweiger
Comment options

@spencerkclark
Comment options

Answer selected by dcherian
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants