I have a climatology data array for 41 years over the winter period (defined as November 1 – March 31). From this climatology Xarray DataArray (with over 6,000 days/values), I have grouped the days into four regimes (referring to weather regimes, but we can just simplify this to say 4 groups).
I currently have wrote code that loops through these arrays for each group (regime: 0-4) and gets the mean of all days in that group.
I want to find a way to store the 4 arrays (groups/regime 0-4) from the results of the loop. My arrays are Xarray DataArrays composed of (lat, lon) as shown here:
<xarray.DataArray ‘T2M’ (lat: 361, lon: 576)>
array([[235.43439, 235.43439, 235.43439, …, 235.43439, 235.43439, 235.43439], [234.84496, 234.84561, 234.84587, …, 234.84325, 234.84384, 234.84445], [234.74213, 234.74837, 234.75465, …, 234.72159, 234.72868, 234.7356 ], …, [250.17426, 250.1683 , 250.16286, …, 250.19177, 250.18564, 250.17975], [250.27992, 250.27652, 250.27345, …, 250.29007, 250.28662, 250.28322], [250.3492 , 250.3492 , 250.3492 , …, 250.3492 , 250.3492 , 250.3492 ]], dtype=float32)
Coordinates:
* lon (lon) float64 -180.0 -179.4 -178.8 -178.1 … 178.1 178.8 179.4
* lat (lat) float64 -90.0 -89.5 -89.0 -88.5 -88.0 … 88.5 89.0 89.5 90.0
The code I have currently is looping through each regime/group to get the mean for each group. I thought I could just write a line or two that would store each regime mean into an Xarray DataArray, but that did not work right. The values did not save out. Essentially, I am hoping to have an Xarray DataArray that looks like [reg, lat, lon]. reg = the groups (regimes 0-4) and lat, lon being the corresponding values for the regime mean. Basically I would have the same array structure as above, but that would be the means for just one regime/group. How do I store all of the means by regime/group in one Xarray DataArray?