Skip to content

Commit fca91c0

Browse files
moved examples; edited readme
1 parent 72a66b8 commit fca91c0

File tree

9 files changed

+800
-771
lines changed

9 files changed

+800
-771
lines changed

README.md

+52-13
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,61 @@
11
# Bias-Adjustment-Python
2+
23
[![Generic badge](https://img.shields.io/badge/license-MIT-green.svg)](https://shields.io/)
34
[![Generic badge](https://img.shields.io/badge/python-3.7+-blue.svg)](https://shields.io/)
45
[![GitHub](https://badgen.net/badge/icon/github?icon=github&label)](https://github.com/btschwertfeger/Bias-Adjustment-Python)
6+
57
Collection of different scale- and distribution-based bias adjustment techniques for climatic research. (see `examples.ipynb` for help)
68

79
Bias adjustment procedures in Python are very slow, so they should not be used on large data sets.
8-
A C++ Implementation that works way faster can be found here: [https://github.com/btschwertfeger/Bias-Adjustment-Cpp](https://github.com/btschwertfeger/Bias-Adjustment-Cpp).
10+
A C++ implementation that works way faster can be found here: [https://github.com/btschwertfeger/Bias-Adjustment-Cpp](https://github.com/btschwertfeger/Bias-Adjustment-Cpp).
11+
12+
## Available methods
13+
- Linear Scaling
14+
- Variance Scaling
15+
- Delta (Change) Method
16+
- Quantile Mapping
17+
- Quantile Delta Mapping
918
____
10-
## Run adjustment:
19+
## Usage
20+
21+
### Installation
22+
```bash
23+
python3 -m pip install python-cmethods
24+
```
25+
### Import and application
26+
```python
27+
from cmethods.CMethods import CMethods
28+
cm = CMethods()
29+
30+
obsh = xr.open_dataset('input_data/obs.nc')
31+
simh = xr.open_dataset('input_data/contr.nc')
32+
simp = xr.open_dataset('input_data/scen.nc')
33+
34+
ls_result = cm.linear_scaling(
35+
method = 'quantile_delta_mapping',
36+
obs = obsh['tas'][:,0,0],
37+
simh = simh['tas'][:,0,0],
38+
simp = simp['tas'][:,0,0],
39+
kind = '+' # *
40+
)
41+
42+
qdm_result = cm.adjust_2d(
43+
method = 'quantile_delta_mapping',
44+
obs = obsh['tas'],
45+
simh = simh['tas'],
46+
simp = simp['tas'],
47+
n_quaniles = 1000,
48+
kind = '+' # *
49+
)
50+
# * to calculate the relative rather than the absolute change, '*' can be used instead of '+' (this is prefered when adjusting precipitation)
51+
```
52+
53+
____
54+
## Examples (see repository on [GitHub](https://github.com/btschwertfeger/Bias-Adjustment-Python))
55+
56+
`/examples/examples.ipynb`: Notebook containing different methods and plots
57+
58+
`/examples/do_bias_correctino.py`: Example script for adjusting climate data
1159
```bash
1260
python3 do_bias_correction.py \
1361
--obs input_data/obs.nc \
@@ -19,19 +67,10 @@ python3 do_bias_correction.py \
1967
--group time.month \
2068
--kind +
2169
```
22-
____
23-
## Methods implemented by Benjamin T. Schwertfeger:
24-
|Method| `--method` parameter|
25-
|-----|-----|
26-
|Linear Scaling| linear_scaling|
27-
|Variance Scaling|variance_scaling|
28-
|Delta Method|delta_method|
29-
|Quantile Mapping|quantile_mapping|
30-
|Quantile Delta Mapping|quantile_delta_mapping|
3170

32-
____
33-
# Notes:
3471
- Linear and variance, as well as delta change method require `--group time.month` as argument.
3572
- Adjustment methods that apply changes in distributional biasses (QM. QDM, DQM; EQM, ...) need the `--nquantiles` argument set to some integer.
3673
- Data sets should have the same spatial resolutions.
74+
____
75+
## Notes:
3776
- Computation in Python takes some time, so this is only for demonstration. When adjusting large datasets, its best to the C++ implementation mentioned above.

cmethods/__version__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
VERSION = (0,5)
2-
__version__ = '.'.join(map(str, VERSION))
1+
VERSION = (0,5,1)
2+
__version__ = '.'.join(map(str, VERSION))

examples.ipynb

-754
This file was deleted.
File renamed without changes.

examples/examples.ipynb

+744
Large diffs are not rendered by default.
File renamed without changes.
File renamed without changes.
File renamed without changes.

test.ipynb examples/test.ipynb

+2-2
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@
314314
],
315315
"metadata": {
316316
"kernelspec": {
317-
"display_name": "Python 3.7.3 64-bit",
317+
"display_name": "Python 3 (ipykernel)",
318318
"language": "python",
319319
"name": "python3"
320320
},
@@ -328,7 +328,7 @@
328328
"name": "python",
329329
"nbconvert_exporter": "python",
330330
"pygments_lexer": "ipython3",
331-
"version": "3.7.3"
331+
"version": "3.9.13"
332332
},
333333
"vscode": {
334334
"interpreter": {

0 commit comments

Comments
 (0)