I am currently generating several bioclimatic variables (climatic derivatives) to apply to some biodiversity work using UKCP18 data. I am generating bioclimatic variable "Bio 19": Precipitation of the Coldest Quarter (https://pubs.usgs.gov/ds/691/ds691.pdf) which uses tas and pr.
The task involves finding the 3-month rolling sum of mean temperatures, identifying the minimum of these (constituting the coldest quarter) and then extracting the total precipitation over that 3-month rolling period to obtain "Bio 19".
My issue: I can find the coldest quarter (using tas) without problem, but pr data is dropped by Xarray in the action alongside the time indexing. It means I cannot know which period to extract rainfall from, because the data is not linked in that way across variables (using my method).
Example code:
# previous code here
...
# calculate rolling climatological mean over 3 month period(s)
ds_rolling_3mos_sum = ds_monthly.rolling(time=3, center=True).sum().dropna('time')
ds_rolling_3mos_sum
<xarray.Dataset>
Dimensions: (time: 12, grid_latitude: 606, grid_longitude: 484)
Coordinates:
* time (time) object 1981-01-01 00:00:00 ... 1981-12...
* grid_latitude (grid_latitude) float64 -4.683 -4.647 ... 8.063
* grid_longitude (grid_longitude) float64 353.9 354.0 ... 364.3
latitude (grid_latitude, grid_longitude) float64 dask.array<chunksize=(606, 484), meta=np.ndarray>
longitude (grid_latitude, grid_longitude) float64 dask.array<chunksize=(606, 484), meta=np.ndarray>
Data variables:
pr (time, grid_latitude, grid_longitude) float32 dask.array<chunksize=(2, 606, 484), meta=np.ndarray>
rotated_latitude_longitude (time) float64 -6.442e+09 ... -6.442e+09
grid_latitude_bnds (time, grid_latitude) float64 dask.array<chunksize=(2, 606), meta=np.ndarray>
grid_longitude_bnds (time, grid_longitude) float64 dask.array<chunksize=(2, 484), meta=np.ndarray>
tas (time, grid_latitude, grid_longitude) float32 dask.array<chunksize=(2, 606, 484), meta=np.ndarray>
Find the coldest quarter:
ds_rolling_3mos_sum_tas_min = ds_rolling_3mos_sum.tas.min('time')
I now have neither time index information - which I could use to obtain the correct month for rainfall in a .sel(), nor do I have any connected pr data to access for this variable.
<xarray.DataArray 'tas' (grid_latitude: 606, grid_longitude: 484)>
dask.array<nanmin-aggregate, shape=(606, 484), dtype=float32, chunksize=(606, 484), chunktype=numpy.ndarray>
Coordinates:
* grid_latitude (grid_latitude) float64 -4.683 -4.647 -4.611 ... 8.027 8.063
* grid_longitude (grid_longitude) float64 353.9 354.0 354.0 ... 364.3 364.3
latitude (grid_latitude, grid_longitude) float64 dask.array<chunksize=(606, 484), meta=np.ndarray>
longitude (grid_latitude, grid_longitude) float64 dask.array<chunksize=(606, 484), meta=np.ndarray>
I've tried using a .where statement and a few other hands on techniques but nothing working to date. I feel like there's a recognised Xarray action I'm not aware of! Please help!