I am working on netcdf dataset that sometimes have a large cloud coverage, materialized by NaN. Is there a way to flag the n neighbors of NaN patches ? Namely, go from this:
array([[0.7, 0.3, 0.9, 0.2, 0.6, 0.5, 0.2, 1. ],
[0.2, 1. , 0.2, 0.2, 0.7, 0. , 1. , 0.2],
[0.6, 0.4, 0.8, 0.1, 0.2, 0.5, 0.8, 0.7],
[0.5, 1. , 0.3, 0.8, 0.2, 0.9, 0.2, 0.1],
[nan, nan, 1. , 0.7, 0.5, 0.7, 0.8, 0.6],
[nan, nan, 0.6, 0.4, 0.3, 0.8, 0.2, 0.8]])
To this (for n = 2):
array([[0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ],
[1. , 1. , 1. , 1. , 0. , 0. , 0. , 0. ],
[1. , 1. , 1. , 1. , 0. , 0. , 0. , 0. ],
[nan, nan, 1. , 1. , 0. , 0. , 0. , 0. ],
[nan, nan, 1. , 1. , 0. , 0. , 0. , 0. ]])
I tried using xarray.dataarray.rolling() but it does not support np.isnan() (see error bellow).
TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
Thanks in advance for your help.