How to deal with obs and simh if they have different time lengths? #65
Replies: 1 comment 2 replies
-
Hey @Pan-Yuxian, thank you! I'm not sure about your data, about have you tried to use less quantiles? If you have 30 years of I assume "daily" data, i.e. 10.950 days in total, having 2000 quantiles, means 2000 bins in which these 10 K values get assigned. That can be a problem as QM uses interpolation (see https://python-cmethods.readthedocs.io/en/latest/src/methods.html#quantile-mapping). I tried to reproduce it on some data of mine, but was not able to plot even something that comes into the direction of yours. Could you provide your obs and simh data sets to [email protected]? These are my tries, for example using the data sets provided in this repository: from cmethods import adjust
from cmethods.distribution import quantile_mapping
import xarray as xr
import matplotlib.pyplot as plt
obs = xr.open_dataset("examples/input_data/observations.nc")["tas"]
simp = xr.open_dataset("examples/input_data/control.nc")["tas"]
simh = simp.copy(deep=True)[3650:]
#bc = adjust(
# method="quantile_mapping",
# obs=obs,
# simh=simh,
# simp=simh,
# n_quantiles=200,
#)
kwargs = {"n_quantiles":2000, "kind":"+"}
qm_adjusted = xr.apply_ufunc(quantile_mapping,
obs,
simh.rename({"time": "t1"}),
simp.rename({"time": "t2"}),
dask = "parallelized",
vectorize = True,
input_core_dims = [["time"], ["t1"], ["t2"]],
output_core_dims = [["t2"]],
kwargs = dict(kwargs)
)
qm_adjusted = qm_adjusted.rename({"t2": "time"}).transpose(*obs.dims)
plt.figure(figsize=(10,5),dpi=216)
obs.groupby("time.dayofyear").mean(...).plot(label="$T_{obs,h}$",color="black")
simh.groupby("time.dayofyear").mean(...).plot(label="$T_{sim,h}$",color="blue")
simp.groupby("time.dayofyear").mean(...).plot(label="$T_{sim,p}$",color="red")
bc["tas"].groupby("time.dayofyear").mean(...).plot(label="$T^{QM}_{sim,p}$",color="green")
plt.title("Historical modeled and obseved temperatures; and corrected temperatures")
plt.xlim(0,365)
plt.gca().grid(alpha=.3)
plt.legend(); Also thanks a lot for bringing my attention to the restriction to equally sized input data for the control period. I will adjust this part to avoid implementing workarounds like yours. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'd like to first express my gratitude to you for building this fancy package.
When I used this package (for example, the QM method) and the provided tas dataArray, I found that the defined obs and simh should be consistent and have the same time lengths. However, I have an obs with 30 years and simh with 20 years. So I try to call quantile_mapping() directly, and the code is like this:
then I plot the results:
I got this figure and I think it is strange:

so could you please help me to explain and solve this problem?
Beta Was this translation helpful? Give feedback.
All reactions