def _get_roll_nonmissing(self, x: xr.Dataset, mode: str, roll_dim: str, roll_size: int) -> xr.DataArray: """Generate a mask f missing values in a moving window. Parameters ---------- x: xr.Dataset The dataset. mode: str Whether all variables must be present or any. roll_dim : str) The dimension to apply moving window on. roll_size : int The moving window size. Returns ------- xr.DataArray: The mask with 1 for valid, 0 for invalid. """ if mode == 'any': fn = lambda x: x.any('variable') elif mode == 'all': fn = lambda x: x.all('variable') else: raise ValueError( f'arg `mode` must be one of `all` | `any`, is `{mode}`.' ) return fn(x.to_array('variable').notnull()).astype(int).rolling({roll_dim: roll_size}).sum() == roll_size