I am trying to take values from t2m_data (a dataarray of lat/lon with associated 2 meter temperatures in chronological order from November 1 1980 through March 31 2021) and index them based on weather regimes in Regimes_cluster (a data array of just the clusters in chronological order from November 1 1980 through March 31 2021). The end result would be a data array of 2 meter temperatures for regime 0 (Arctic Low), regime 1 (Alaskan Ridge), regime 3 (Pacific trough), and regime 4 (Arctic High), which I could then make composites for each.
Regimes_cluster example – 1D array
[[2 2 2 … 0 0 0]]
Start of Code
#Getting t2m data for all years (1980-2021) in as datetime objects for input into regime will then have t2m climatology for each regime
saved = False
if saved == False:
year = [1981+i for i in range(0,41)]
first = True
for yr in (year):
leap = dt.datetime(yr,12,31).timetuple().tm_yday == 366
if leap == True:
endday = 151
else:
endday = 150
dates = [dt.datetime(yr-1,11,1) + dt.timedelta(days=x) for x in range(0,endday)]
for dy in dates:
yyyymmdd = dt.datetime.strftime(dy, '%Y%m%d')
yyyy = dy.year
data = '/curtana/merra2t2m/'+str(yyyy)+'/merra2_T2M_SLP_dly_avg_'+yyyymmdd+'.nc4'
data2 = xr.open_dataset(data)
temp_data = data2.T2M
if first == False:
T_all = xr.concat([T_all,temp_data], dim='time')
else:
T_all = temp_data
first = False
print("Here is t2m", T_all)
t2m_data = T_all
t2m_clim = t2m_data.mean(dim=’time’)
print(t2m_clim)
#Importing regime data
Regimes_data = xr.open_dataset(‘/home/jgeorge32/Regime_Analysis/regime_dates.nc4’)
Regimes_array = Regimes_data.to_array(dim=’cluster’)
#print(Regimes_array)
Regimes_time = Regimes_array.times.data
Regimes_dtime = [dt.datetime.utcfromtimestamp(Regimes_time[i].astype(int) * 1e-9) for i in range(len(Regimes_time))]
Regimes_cluster = Regimes_array.variable.data
print(Regimes_cluster)
for index, Regimes_cluster in enumerate(Regimes_cluster):
if Regimes_cluster == 0:
print(t2m_data[index])
End of Code
I expected this to yield only the indices in t2m_data where they matched indices where the regime value was 0, but that was not the case, because when I ran if Regimes_cluster.any() == 1, the values printed did not change. This suggests either I am misinterpreting what I have written in the for loop at the end of the code or I am not using the correct function. I have tried Regimes_cluster.all() and also an np.where command with no luck.