Skip to content

Commit 05414cc

Browse files
fixed typos and assertion types in tests
1 parent 5c6e898 commit 05414cc

File tree

4 files changed

+19
-20
lines changed

4 files changed

+19
-20
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# python-cmethods: A collection of bias correction techniques wirtten in Python
1+
# python-cmethods
22

33
<div align="center">
44

@@ -18,7 +18,7 @@
1818

1919
</div>
2020

21-
This Python module contains a collection of different scale- and distribution-based bias adjustment techniques for climatic research (see `/examples/examples.ipynb` for help).
21+
This Python module serves as a collection of different scale- and distribution-based bias correction techniques for climatic research
2222

2323
The documentation is available at: [https://python-kraken-sdk.readthedocs.io/en/stable/](https://python-kraken-sdk.readthedocs.io/en/stable/)
2424

@@ -67,7 +67,7 @@ In this way, for example, modeled data, which on average represent values that a
6767

6868
## 2. Available methods
6969

70-
All methods except the `adjust_3d` function requires the application on one time series.
70+
All methods except the `adjust_3d` function requires that the input data sets only contain one dimension.
7171

7272
| Function name | Description |
7373
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
@@ -149,7 +149,7 @@ Help:
149149
--scen input_data/scenario.nc \
150150
--kind "+" \
151151
--variable "tas" \
152-
-method quantile_mapping
152+
--method quantile_mapping
153153
```
154154

155155
(2.) Example - Linear Scaling bias correction on the provided example data:
@@ -162,7 +162,7 @@ Help:
162162
--kind "+" \
163163
--variable "tas" \
164164
--group "time.month" \
165-
-method linear_scaling
165+
--method linear_scaling
166166
```
167167

168168
Notes:

cmethods/__init__.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class CMethods:
5353
The following bias correction techniques are available:
5454
Scaling-based techniques:
5555
* Linear Scaling :func:`cmethods.CMethods.linear_scaling`
56-
* Vairance Scaling :func:`cmethods.CMethods.variance_scaling`
56+
* Variance Scaling :func:`cmethods.CMethods.variance_scaling`
5757
* Delta (change) Method :func:`cmethods.CMethods.delta_method`
5858
5959
Distribution-based techniques:
@@ -137,7 +137,7 @@ def adjust_3d(
137137
group: Union[str, None] = None,
138138
n_jobs: int = 1,
139139
**kwargs,
140-
) -> xr.core.dataarray.Dataset:
140+
) -> xr.core.dataarray.DataArray:
141141
"""
142142
Function to apply a bias correction method on 3-dimensional climate data.
143143
@@ -166,7 +166,7 @@ def adjust_3d(
166166
:type n_jobs: int, optional
167167
:raises UnknownMethodError: If the correction method is not implemented
168168
:return: The bias-corrected time series
169-
:rtype: xr.core.dataarray.Dataset
169+
:rtype: xr.core.dataarray.DataArray
170170
171171
.. code-block:: python
172172
:linenos:
@@ -348,7 +348,7 @@ def grouped_correction(
348348
for i, index in enumerate(groups[month]):
349349
result[index] = computed_result[i]
350350

351-
return result
351+
return np.array(result)
352352

353353
# ? -----========= L I N E A R - S C A L I N G =========------
354354
@classmethod
@@ -711,7 +711,7 @@ def quantile_mapping(
711711
kind: str = "+",
712712
detrended: bool = False,
713713
**kwargs,
714-
) -> xr.core.dataarray.DataArray:
714+
) -> np.array:
715715
r"""
716716
The Quantile Mapping bias correction technique can be used to minimize distributional
717717
biases between modeled and observed time-series climate data. Its interval-independant
@@ -767,7 +767,7 @@ def quantile_mapping(
767767
:type detrended: bool, optional
768768
:raises NotImplementedError: If the kind is not in (``+``, ``*``, ``add``, ``mult``)
769769
:return: The bias-corrected time series
770-
:rtype: xr.core.dataarray.DataArray
770+
:rtype: np.array
771771
772772
.. code-block:: python
773773
:linenos:
@@ -903,7 +903,7 @@ def quantile_delta_mapping(
903903
n_quantiles: int,
904904
kind: str = "+",
905905
**kwargs,
906-
) -> xr.core.dataarray.DataArray:
906+
) -> np.array:
907907
r"""
908908
The Quantile Delta Mapping bias correction technique can be used to minimize distributional
909909
biases between modeled and observed time-series climate data. Its interval-independant
@@ -1019,7 +1019,6 @@ def quantile_delta_mapping(
10191019
... )
10201020
"""
10211021
if kind in cls.ADDITIVE:
1022-
# res = simp.copy(deep=True)
10231022
obs, simh, simp = (
10241023
np.array(obs),
10251024
np.array(simh),

docs/src/introduction.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Available Methods
4545
The following bias correction techniques are available:
4646
Scaling-based techniques:
4747
* Linear Scaling :func:`cmethods.CMethods.linear_scaling`
48-
* Vairance Scaling :func:`cmethods.CMethods.variance_scaling`
48+
* Variance Scaling :func:`cmethods.CMethods.variance_scaling`
4949
* Delta (change) Method :func:`cmethods.CMethods.delta_method`
5050

5151
Distribution-based techniques:

tests/test_methods.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def test_linear_scaling(self) -> None:
122122
simp=self.data[kind]["simp"][:, 0, 0],
123123
kind=kind,
124124
)
125-
assert isinstance(ls_result, xr.core.dataarray.DataArray)
125+
assert isinstance(ls_result, (np.ndarray, np.generic))
126126
assert mean_squared_error(
127127
ls_result, self.data[kind]["obsp"][:, 0, 0], squared=False
128128
) < mean_squared_error(
@@ -140,7 +140,7 @@ def test_variance_scaling(self) -> None:
140140
simp=self.data[kind]["simp"][:, 0, 0],
141141
kind="+",
142142
)
143-
assert isinstance(vs_result, xr.core.dataarray.DataArray)
143+
assert isinstance(vs_result, (np.ndarray, np.generic))
144144
assert mean_squared_error(
145145
vs_result, self.data[kind]["obsp"][:, 0, 0], squared=False
146146
) < mean_squared_error(
@@ -159,7 +159,7 @@ def test_delta_method(self) -> None:
159159
simp=self.data[kind]["simp"][:, 0, 0],
160160
kind=kind,
161161
)
162-
assert isinstance(dm_result, xr.core.dataarray.DataArray)
162+
assert isinstance(dm_result, (np.ndarray, np.generic))
163163
assert mean_squared_error(
164164
dm_result, self.data[kind]["obsp"][:, 0, 0], squared=False
165165
) < mean_squared_error(
@@ -179,7 +179,7 @@ def test_quantile_mapping(self) -> None:
179179
n_quantiles=100,
180180
kind=kind,
181181
)
182-
assert isinstance(qm_result, xr.core.dataarray.DataArray)
182+
assert isinstance(qm_result, (np.ndarray, np.generic))
183183
assert mean_squared_error(
184184
qm_result, self.data[kind]["obsp"][:, 0, 0], squared=False
185185
) < mean_squared_error(
@@ -200,7 +200,7 @@ def test_detrended_quantile_mapping(self) -> None:
200200
kind=kind,
201201
detrended=True,
202202
)
203-
assert isinstance(dqm_result, xr.core.dataarray.DataArray)
203+
assert isinstance(dqm_result, (np.ndarray, np.generic))
204204
assert mean_squared_error(
205205
dqm_result, self.data[kind]["obsp"][:, 0, 0], squared=False
206206
) < mean_squared_error(
@@ -221,7 +221,7 @@ def test_quantile_delta_mapping(self) -> None:
221221
kind=kind,
222222
)
223223

224-
assert isinstance(qdm_result, xr.core.dataarray.DataArray)
224+
assert isinstance(qdm_result, (np.ndarray, np.generic))
225225
assert mean_squared_error(
226226
qdm_result, self.data[kind]["obsp"][:, 0, 0], squared=False
227227
) < mean_squared_error(

0 commit comments

Comments
 (0)