Closed DamienIrving closed 7 months ago
Hi @DamienIrving and sorry for the late reply.
To me it seems the error is due to the merge of the 3 ssp370 files.
I guess there is an issue with the coordinates or attributes of tasmax
variable in one of the file.
Or, icclim uses the wrong merge strategy in which case we need to fix this.
I can only find aggregated data for tasmax_day_ACCESS-ESM1-5_ssp370_r6i1p1f1_gn_20650101-21001231.nc. If you have a link to the 3 ssp files that you used, that would be helpful to reproduce the issue. Otherwise I will try to do it with another dataset.
After some experimentation, this is indeed not an issue with icclim. I was able to reproduce the error with the following MRE, using xarray only. The MergeError is raised if the datasets subject to the merge (the 3 ssp370 datasets in your case) have overlapping dimensions and incompatible values for the overlaps.
In the case below, this is cause by the time dimension overlapping for year 2044 in both dataset and by having different values for these overlaps (1 in da1
and 2 in da2
).
import numpy as np
import xarray as xr
import pandas as pd
da1 = xr.DataArray(
data=(np.full(365 * 5, 1).reshape((365 * 2, 1, 1))),
dims=["time", "lat", "lon"],
coords={
"lat": [42],
"lon": [42],
"time": pd.date_range("2043-01-01", periods=365 * 2, freq="D"),
},
attrs={"units": "K"},
name="tas",
)
da2 = xr.DataArray(
data=(np.full(365 * 5, 2).reshape((365 * 2, 1, 1))),
dims=["time", "lat", "lon"],
coords={
"lat": [42],
"lon": [42],
"time": pd.date_range("2043-01-01", periods=365 * 2, freq="D"),
},
attrs={"units": "K"},
name="tas",
)
xr.merge([da1, da2])
# ^ MergeError
Stacktrace:
Traceback (most recent call last):
File "/home/bzah/workspace/cerfacs/icclim/mre_277.py", line 29, in <module>
xr.merge([da1, da2])
File "/home/bzah/micromamba/envs/icclim-dev/lib/python3.11/site-packages/xarray/core/merge.py", line 996, in merge
merge_result = merge_core(
^^^^^^^^^^^
File "/home/bzah/micromamba/envs/icclim-dev/lib/python3.11/site-packages/xarray/core/merge.py", line 720, in merge_core
variables, out_indexes = merge_collected(
^^^^^^^^^^^^^^^^
File "/home/bzah/micromamba/envs/icclim-dev/lib/python3.11/site-packages/xarray/core/merge.py", line 290, in merge_collected
merged_vars[name] = unique_variable(
^^^^^^^^^^^^^^^^
File "/home/bzah/micromamba/envs/icclim-dev/lib/python3.11/site-packages/xarray/core/merge.py", line 144, in unique_variable
raise MergeError(
xarray.core.merge.MergeError: conflicting values for variable 'tas' on objects to be combined. You can skip this check by specifying compat='override'.
Description
I'm trying to use the thresholds functionality described here and not having success, so I was wondering if it would be possible to add an example to the documentation?
Minimal reproducible example
In this example (see full notebook), I want to calculate the
TX90p
index for a future period using the same 90th percentile thresholds that I used for an historical period.Output received