Finding first and last day for each grid point that meets a condition #7656
-
Hi I'm trying to find the first and last day of year that each grid point has a value (in this case ice concentration) below a threshold If tried a number of ways using where and .idxmin() but I don't seem to be able to make this work
Because drop can't reduce the dimension because it varies by grid point. The time coordinate is in cftime.DatetimeNoLeap There are some similar questions out there but the answers seem to be not correct. I suppose this could be a apply_ufunc but I haven't been able to figure that one out either. Array is 365,448,304. Seems like this shouldn't be that hard. Thanks for any help.
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
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 |
Beta Was this translation helpful? Give feedback.
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: