Skip to main content

Collection of bias adjustment procedures for multidimensional climate data

Project description

Bias correction/adjustment procedures for climatic reasearch

GitHub Generic badge License: GPL v3 Downloads

ql-workflow python-package codecov

DOI

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

📍 For the application of bias corrections on lage data sets it is recomanded to use the C++ tool BiasAdjustCXX since bias corrections are complex statistical transformation which are very slow in Python compared to the C++ implementation.


Table of Contents

  1. About
  2. Available Methods
  3. Installation
  4. Usage and Examples
  5. Notes
  6. References

1. About

These programs and data structures are designed to help minimize discrepancies between modeled and observed climate data. Data from past periods are used to adjust variables from current and future time series so that their distributional properties approximate possible actual values.

Schematic representation of a bias adjustment procedure
Figure 1: Schematic representation of a bias adjustment procedure

In this way, for example, modeled data, which on average represent values that are too cold, can be adjusted by applying an adjustment procedure. The following figure shows the observed, the modeled, and the adjusted values. It is directly visible that the delta adjusted time series ($T^{*DM}{sim,p}$) are much more similar to the observed data ($T{obs,p}$) than the raw modeled data ($T_{sim,p}$).

Temperature per day of year in modeled, observed and bias-adjusted climate data
Figure 2: Temperature per day of year in observed, modeled, and bias-adjusted climate data

2. Available methods

All methods except the adjust_3d function requires the application on one time series.

Function name Description
linear_scaling Linear Scaling (additive and multiplicative)
variance_scaling Variance Scaling (additive)
delta_method Delta (Change) Method (additive and multiplicative)
quantile_mapping Quantile Mapping (additive and multiplicative) and Detrended Quantile Mapping (additive and multiplicative; to use DQM, set parameter detrended to True)
quantile_delta_mapping Quantile Delta Mapping (additive and multiplicative)
adjust_3d requires a method name and the respective parameters to adjust all time series of a 3-dimensional data set

3. Installation

python3 -m pip install python-cmethods

4. Usage and Examples

import xarray as xr
from cmethods.CMethods import CMethods
cm = CMethods()

obsh = xr.open_dataset('input_data/observations.nc')
simh = xr.open_dataset('input_data/control.nc')
simp = xr.open_dataset('input_data/scenario.nc')

ls_result = cm.linear_scaling(
    obs = obsh['tas'][:,0,0],
    simh = simh['tas'][:,0,0],
    simp = simp['tas'][:,0,0],
    kind = '+'
)

qdm_result = cm.adjust_3d( # 3d = 2 spatial and 1 time dimension
    method = 'quantile_delta_mapping',
    obs = obsh['tas'],
    simh = simh['tas'],
    simp = simp['tas'],
    n_quaniles = 1000,
    kind = '+'
)
# to calculate the relative rather than the absolute change,
# '*' can be used instead of '+' (this is prefered when adjusting
# ratio based variables like precipitation)

Notes:

  • When using the adjust_3d method you have to specify the method by name.
  • For the multiplicative linear scaling and the delta method as well as the variance scaling method a maximum scaling factor of 10 is defined. This can be changed by the parameter max_scaling_factor.

Examples (see repository on GitHub)

Notebook with different methods and plots: /examples/examples.ipynb

Example script for adjusting climate data: /examples/do_bias_correction.py

python3 do_bias_correction.py         \
    --obs input_data/observations.nc  \
    --contr input_data/control.nc     \
    --scen input_data/scenario.nc     \
    --method linear_scaling           \
    --variable tas                    \
    --unit '°C'                       \
    --group 'time.month'              \
    --kind +
  • Linear and variance, as well as delta change method require --group time.month as argument.
  • Adjustment methods that apply changes in distributional biases (QM, QDM, DQM, ...) require the --nquantiles argument set to some integer.
  • Data sets must have the same spatial resolutions.

5. Notes

  • Computation in Python takes some time, so this is only for demonstration. When adjusting large datasets, its best to use the C++ tool BiasAdjustCXX.
  • Formulas and references can be found in the implementations of the corresponding functions.

Space for improvements:

Since the scaling methods implemented so far scale by default over the mean values of the respective months, unrealistic long-term mean values may occur at the month transitions. This can be prevented either by selecting group='time.dayofyear'. Alternatively, it is possible not to scale using long-term mean values, but using a 31-day interval, which takes the 31 surrounding values over all years as the basis for calculating the mean values. This is not yet implemented in this module, but is available in the C++ implementation here.


6. References

  • Schwertfeger, Benjamin Thomas (2022) The influence of bias corrections on variability, distribution, and correlation of temperatures in comparison to observed and modeled climate data in Europe (https://epic.awi.de/id/eprint/56689/)
  • Linear Scaling and Variance Scaling based on: Teutschbein, Claudia and Seibert, Jan (2012) Bias correction of regional climate model simulations for hydrological climate-change impact studies: Review and evaluation of different methods (https://doi.org/10.1016/j.jhydrol.2012.05.052)
  • Delta Method based on: Beyer, R. and Krapp, M. and Manica, A.: An empirical evaluation of bias correction methods for palaeoclimate simulations (https://doi.org/10.5194/cp-16-1493-2020)
  • Quantile and Detrended Quantile Mapping based on: Alex J. Cannon and Stephen R. Sobie and Trevor Q. Murdock Bias Correction of GCM Precipitation by Quantile Mapping: How Well Do Methods Preserve Changes in Quantiles and Extremes? (https://doi.org/10.1175/JCLI-D-14-00754.1)
  • Quantile Delta Mapping based on: Tong, Y., Gao, X., Han, Z. et al. Bias correction of temperature and precipitation over China for RCM simulations using the QM and QDM methods. Clim Dyn 57, 1425–1443 (2021). (https://doi.org/10.1007/s00382-020-05447-4)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-cmethods-0.6.3.tar.gz (27.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_cmethods-0.6.3-py2.py3-none-any.whl (22.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file python-cmethods-0.6.3.tar.gz.

File metadata

  • Download URL: python-cmethods-0.6.3.tar.gz
  • Upload date:
  • Size: 27.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.8.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7

File hashes

Hashes for python-cmethods-0.6.3.tar.gz
Algorithm Hash digest
SHA256 f7dae1f7456a43d9598f8530b3ebfc02b92cda677a720a317b6d9b538893e3e5
MD5 eb4ea8854148b54277d2c9b08aff3115
BLAKE2b-256 8c34fa5a2bd22904d02294e19a38d6081469cf92a45d857ed858d775c87a5e66

See more details on using hashes here.

File details

Details for the file python_cmethods-0.6.3-py2.py3-none-any.whl.

File metadata

  • Download URL: python_cmethods-0.6.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 22.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.8.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7

File hashes

Hashes for python_cmethods-0.6.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 6d6ec3e219ec73bd76ad14904943613f552320a7fd9243562ae3f280b65590fb
MD5 0342649ae80b2424279c87628d7a3269
BLAKE2b-256 f5b025ef206a98f5a72072acb5711cd86ce22b79598f465fb1eb0c8f6f386e4c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page