I have 10 years output from the WRF climate model. I am looking for an efficient code which for every grid point in the xarray selects only those number of days where T>0 for more than 2 days. For my plots, I want for each month at each grid point the total number of days where T>2 for more than 2 days.
I am new to xarrays and looking at similar questions, I still couldn't find a proper loop or count function to apply for each grid point and month wise! Would really appreciate any help with this code.
Here is my current code:
import xarray as xr
import pandas as pd
import matplotlib.pyplot as plt
import netCDF4
from netCDF4 import Dataset
import numpy as np
#concatenate the 10year output
dataset=xr.open_mfdataset("\Python files for plotting wrfoutput\era5_1990-2000_output\*.nc",concat_dim='Time', combine='nested', compat='no_conflicts', preprocess=None, engine=None, data_vars='all', coords='all', parallel=False, join='outer', attrs_file=None,)
#dimensions are: Time, south_north, west_east
DS=dataset
DS = DS.assign_coords(Time=pd.to_datetime(DS['Time'].values))
#Select/extract only the mean 2m surface temperature (T2) from the large xarray
DST2=DS.T2
#apply the where function to check at which grid points in each month the T2>0
T2threshold=DST2.groupby('Time.month').where(DST2>0)