Skip to content

Commit 8a55556

Browse files
Resolve "The behavior for data sets with different temporal resolution are not uniform" (#100)
1 parent cdace26 commit 8a55556

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ Please refer to the official documentation for more information about these
108108
methods as well as sample scripts:
109109
https://python-cmethods.readthedocs.io/en/stable/
110110

111+
## Best Practices and important Notes
112+
113+
- The training data should have the same temporal resolution.
114+
111115
- Except for the variance scaling, all methods can be applied on stochastic and
112116
non-stochastic climate variables. Variance scaling can only be applied on
113117
non-stochastic climate variables.

cmethods/core.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,21 @@ def apply_ufunc(
6060
'input_core_dims must have three key-value pairs like: {"obs": "time", "simh": "time", "simp": "time"}',
6161
)
6262

63-
input_core_dims = kwargs["input_core_dims"]
63+
input_core_dims = kwargs.pop("input_core_dims")
6464
else:
6565
input_core_dims = {"obs": "time", "simh": "time", "simp": "time"}
6666

6767
result: XRData = xr.apply_ufunc(
6868
__METHODS_FUNC__[method],
6969
obs,
7070
simh,
71-
# Need to spoof a fake time axis since 'time' coord on full dataset is different
72-
# than 'time' coord on training dataset.
71+
# Need to spoof a fake time axis since 'time' coord on full dataset is
72+
# different than 'time' coord on training dataset.
7373
simp.rename({input_core_dims["simp"]: "__t_simp__"}),
7474
dask="parallelized",
7575
vectorize=True,
76-
# This will vectorize over the time dimension, so will submit each grid cell
77-
# independently
76+
# This will vectorize over the time dimension, so will submit each grid
77+
# cell independently
7878
input_core_dims=[
7979
[input_core_dims["obs"]],
8080
[input_core_dims["simh"]],
@@ -89,9 +89,9 @@ def apply_ufunc(
8989
# Rename to proper coordinate name.
9090
result = result.rename({"__t_simp__": input_core_dims["simp"]})
9191

92-
# ufunc will put the core dimension to the end (time), so want to preserve original
93-
# order where time is commonly first.
94-
return result.transpose(*obs.dims)
92+
# ufunc will put the core dimension to the end (time), so want to preserve
93+
# original order where time is commonly first.
94+
return result.transpose(*obs.rename({input_core_dims["obs"]: input_core_dims["simp"]}).dims)
9595

9696

9797
def adjust(

doc/getting_started.rst

+7-6
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,17 @@ dimensions of ``obs`` and ``simp`` have the length, but the time dimension of
149149
import xarray as xr
150150
151151
obs = xr.open_dataset("examples/input_data/observations.nc")["tas"]
152-
simp = xr.open_dataset("examples/input_data/control.nc")["tas"]
153152
simh = simp.copy(deep=True)[3650:]
153+
simp = xr.open_dataset("examples/input_data/control.nc")["tas"]
154154
155155
bc = adjust(
156156
method="quantile_mapping",
157157
obs=obs,
158158
simh=simh.rename({"time": "t_simh"}),
159-
simp=simh,
159+
simp=simp,
160160
kind="+",
161-
input_core_dims={"obs": "time", "simh": "t_simh", "simp": "time"}
161+
input_core_dims={"obs": "time", "simh": "t_simh", "simp": "time"},
162+
n_quantiles=100,
162163
)
163164
164165
In case you are applying a scaling based technique using grouping, you have to
@@ -172,15 +173,15 @@ adjust the group names accordingly to the time dimension names.
172173
import xarray as xr
173174
174175
obs = xr.open_dataset("examples/input_data/observations.nc")["tas"]
175-
simp = xr.open_dataset("examples/input_data/control.nc")["tas"]
176176
simh = simp.copy(deep=True)[3650:]
177+
simp = xr.open_dataset("examples/input_data/control.nc")["tas"]
177178
178179
bc = adjust(
179180
method="linear_scaling",
180181
obs=obs,
181182
simh=simh.rename({"time": "t_simh"}),
182-
simp=simh,
183+
simp=simp,
183184
kind="+",
184185
group={"obs": "time.month", "simh": "t_simh.month", "simp": "time.month"},
185-
input_core_dims={"obs": "time", "simh": "t_simh", "simp": "time"}
186+
input_core_dims={"obs": "time", "simh": "t_simh", "simp": "time"},
186187
)

doc/introduction.rst

+5
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ Please refer to the official documentation for more information about these
7474
methods as well as sample scripts:
7575
https://python-cmethods.readthedocs.io/en/stable/
7676

77+
Best Practices and important Notes
78+
----------------------------------
79+
80+
- The training data should have the same temporal resolution.
81+
7782
- Except for the variance scaling, all methods can be applied on stochastic and
7883
non-stochastic climate variables. Variance scaling can only be applied on
7984
non-stochastic climate variables.

0 commit comments

Comments
 (0)