Skip to content

Commit f26157d

Browse files
CMethods must not be instantiated to call the methods - removed this from all examples
1 parent a4c85ea commit f26157d

File tree

6 files changed

+48
-60
lines changed

6 files changed

+48
-60
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pre-commit:
4646
## Clean the workspace
4747
##
4848
clean:
49-
rm -rf .pytest_cache build/ dist/ python_cmethods.egg-info docs/_build
49+
rm -rf .pytest_cache build/ dist/ python_cmethods.egg-info docs/_build examples/.ipynb_checkpoints
5050
rm -f .coverage cmethods/_version.py
5151

5252
find tests -name "__pycache__" | xargs rm -rf

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

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

23-
The documentation can be found here: [https://python-kraken-sdk.readthedocs.io/en/stable/](https://python-kraken-sdk.readthedocs.io/en/stable/)
23+
The documentation is available at: [https://python-kraken-sdk.readthedocs.io/en/stable/](https://python-kraken-sdk.readthedocs.io/en/stable/)
2424

2525
> ⚠️ For the application of bias corrections on _lage data sets_ it is recomanded to use the command-line tool [BiasAdjustCXX](https://github.com/btschwertfeger/BiasAdjustCXX) since bias corrections are complex statistical transformation which are very slow in Python compared to the C++ implementation.
2626
@@ -96,8 +96,7 @@ python3 -m pip install python-cmethods
9696

9797
```python
9898
import xarray as xr
99-
from cmethods.CMethods import CMethods
100-
cm = CMethods()
99+
from cmethods.CMethods import CMethods as cm
101100

102101
obsh = xr.open_dataset('input_data/observations.nc')
103102
simh = xr.open_dataset('input_data/control.nc')

cmethods/CMethods.py

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ def __init__(self, method: str, available_methods: list):
4848
class CMethods:
4949
"""
5050
The CMethods class serves a collection of bias correction procedures to adjust
51-
time-series of climate data. It accept no parameters but must be instantiated
52-
to apply the bias correction techniques.
51+
time-series of climate data.
5352
5453
The following bias correction techniques are available:
5554
Scaling-based techniques:
@@ -91,8 +90,9 @@ def get_available_methods(cls) -> list:
9190
:linenos:
9291
:caption: Example: Get available methods
9392
94-
>>> from cmethods.CMethods import CMethods
95-
>>> CMethods().get_available_methods()
93+
>>> from cmethods.CMethods import CMethods as cm
94+
95+
>>> cm.get_available_methods()
9696
[
9797
"linear_scaling", "variance_scaling", "delta_method",
9898
"quantile_mapping", "quantile_delta_mapping"
@@ -169,7 +169,7 @@ def adjust_3d(
169169
:caption: Example application - 3-dimensinoal bias correction
170170
171171
>>> import xarray as xr
172-
>>> from cmethods.CMethods import CMethods
172+
>>> from cmethods.CMethods import CMethods as cm
173173
174174
>>> # Note: The data sets must contain the dimensions "time", "lat", and "lon"
175175
>>> # for the respective variable.
@@ -178,8 +178,6 @@ def adjust_3d(
178178
>>> simp = xr.open_dataset("path/to/the_dataset_to_adjust-scenario_period.nc")
179179
>>> variable = "tas" # temperatures
180180
181-
>>> cm = CMethods()
182-
183181
'''
184182
In the following the Quantile Delta Mapping techniques is applied on
185183
3-dimensional time-series data sets containing the variable "tas". The
@@ -422,7 +420,7 @@ def linear_scaling(
422420
:caption: Example: Linear Scaling
423421
424422
>>> import xarray as xr
425-
>>> from cmethods.CMethods import CMethods
423+
>>> from cmethods.CMethods import CMethods as cm
426424
427425
>>> # Note: The data sets must contain the dimension "time"
428426
>>> # for the respective variable.
@@ -431,7 +429,6 @@ def linear_scaling(
431429
>>> simp = xr.open_dataset("path/to/the_dataset_to_adjust-scenario_period.nc")
432430
>>> variable = "tas" # temperatures
433431
434-
>>> cm = CMethods()
435432
>>> ls_adjusted = cm.linear_scaling(
436433
... obs=obs[variable],
437434
... simh=simh[variable],
@@ -543,7 +540,7 @@ def variance_scaling(
543540
:caption: Example: Variance Scaling
544541
545542
>>> import xarray as xr
546-
>>> from cmethods.CMethods import CMethods
543+
>>> from cmethods.CMethods import CMethods as cm
547544
548545
>>> # Note: The data sets must contain the dimension "time"
549546
>>> # for the respective variable.
@@ -552,7 +549,6 @@ def variance_scaling(
552549
>>> simp = xr.open_dataset("path/to/the_dataset_to_adjust-scenario_period.nc")
553550
>>> variable = "tas" # temperatures
554551
555-
>>> cm = CMethods()
556552
>>> vs_adjusted = cm.variance_scaling(
557553
... obs=obs[variable],
558554
... simh=simh[variable],
@@ -663,7 +659,7 @@ def delta_method(
663659
:caption: Example: Delta Method
664660
665661
>>> import xarray as xr
666-
>>> from cmethods.CMethods import CMethods
662+
>>> from cmethods.CMethods import CMethods as cm
667663
668664
>>> # Note: The data sets must contain the dimension "time"
669665
>>> # for the respective variable.
@@ -672,7 +668,6 @@ def delta_method(
672668
>>> simp = xr.open_dataset("path/to/the_dataset_to_adjust-scenario_period.nc")
673669
>>> variable = "tas" # temperatures
674670
675-
>>> cm = CMethods()
676671
>>> dm_adjusted = cm.delta_method(
677672
... obs=obs[variable],
678673
... simh=simh[variable],
@@ -775,7 +770,7 @@ def quantile_mapping(
775770
:caption: Example: Quantile Mapping
776771
777772
>>> import xarray as xr
778-
>>> from cmethods.CMethods import CMethods
773+
>>> from cmethods.CMethods import CMethods as cm
779774
780775
>>> # Note: The data sets must contain the dimension "time"
781776
>>> # for the respective variable.
@@ -784,7 +779,6 @@ def quantile_mapping(
784779
>>> simp = xr.open_dataset("path/to/the_dataset_to_adjust-scenario_period.nc")
785780
>>> variable = "tas" # temperatures
786781
787-
>>> cm = CMethods()
788782
>>> qm_adjusted = cm.quantile_mapping(
789783
... obs=obs[variable],
790784
... simh=simh[variable],
@@ -1005,7 +999,7 @@ def quantile_delta_mapping(
1005999
:caption: Example: Quantile Delta Mapping
10061000
10071001
>>> import xarray as xr
1008-
>>> from cmethods.CMethods import CMethods
1002+
>>> from cmethods.CMethods import CMethods as cm
10091003
10101004
>>> # Note: The data sets must contain the dimension "time"
10111005
>>> # for the respective variable.
@@ -1014,7 +1008,6 @@ def quantile_delta_mapping(
10141008
>>> simp = xr.open_dataset("path/to/the_dataset_to_adjust-scenario_period.nc")
10151009
>>> variable = "tas" # temperatures
10161010
1017-
>>> cm = CMethods()
10181011
>>> qdm_adjusted = cm.quantile_delta_mapping(
10191012
... obs=obs[variable],
10201013
... simh=simh[variable],
@@ -1089,8 +1082,8 @@ def get_pdf(x: Union[list, np.array], xbins: Union[list, np.array]) -> np.array:
10891082
:linenos:
10901083
:caption: Compute the probability density function :math:`P(x)`
10911084
1092-
>>> from cmethods.CMethods import CMethods
1093-
>>> cm = CMethods()
1085+
>>> from cmethods.CMethods import CMethods as cm
1086+
10941087
>>> x = [1, 2, 3, 4, 5, 5, 5, 6, 7, 8, 9, 10]
10951088
>>> xbins = [0, 3, 6, 10]
10961089
>>> print(cm.get_pdf(x=x, xbins=xbins))
@@ -1117,8 +1110,8 @@ def get_cdf(x: Union[list, np.array], xbins: Union[list, np.array]) -> np.array:
11171110
:linenos:
11181111
:caption: Compute the cmmulative distribution function :math:`F(x)`
11191112
1120-
>>> from cmethods.CMethods import CMethods
1121-
>>> cm = CMethods()
1113+
>>> from cmethods.CMethods import CMethods as cm
1114+
11221115
>>> x = [1, 2, 3, 4, 5, 5, 5, 6, 7, 8, 9, 10]
11231116
>>> xbins = [0, 3, 6, 10]
11241117
>>> print(cm.get_cdf(x=x, xbins=xbins))

docs/src/getting_started.rst

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ method specific documentation.
2323
:caption: Apply the Linear Scaling bias correction technique on 1-dimensional data
2424
2525
import xarray as xr
26-
from cmethods.CMethods import CMethods
27-
cm = CMethods()
26+
from cmethods.CMethods import CMethods as cm
2827
2928
obsh = xr.open_dataset('input_data/observations.nc')
3029
simh = xr.open_dataset('input_data/control.nc')
@@ -42,8 +41,7 @@ method specific documentation.
4241
:caption: Apply the Quantile Delta Mapping bias correction technique on 1-dimensional data
4342
4443
import xarray as xr
45-
from cmethods.CMethods import CMethods
46-
cm = CMethods()
44+
from cmethods.CMethods import CMethods as cm
4745
4846
obsh = xr.open_dataset('input_data/observations.nc')
4947
simh = xr.open_dataset('input_data/control.nc')
@@ -57,5 +55,3 @@ method specific documentation.
5755
n_quaniles = 1000,
5856
kind = '+'
5957
)
60-
61-
```

examples/examples.ipynb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@
160160
"metadata": {},
161161
"outputs": [],
162162
"source": [
163-
"from cmethods.CMethods import CMethods\n",
164-
"cm = CMethods()"
163+
"from cmethods.CMethods import CMethods as cm\n"
165164
]
166165
},
167166
{

0 commit comments

Comments
 (0)