Home

Awesome

Note: This repo is a fork of the python-cmethods, with modifications and bug fixes to make it work as a submodule of the clim-recal project.

Bias correction/adjustment procedures for climatic reasearch

<div align="center">

GitHub Generic badge License: GPL v3 Downloads

ql-workflow python-package codecov

DOI

</div>

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

<a name="about"></a>

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.

<figure> <img src="images/biasCdiagram.png?raw=true" alt="Schematic representation of a bias adjustment procedure" style="background-color: white; border-radius: 7px"> <figcaption>Figure 1: Schematic representation of a bias adjustment procedure</figcaption> </figure>

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}$).

<figure> <img src="images/dm-doy-plot.png?raw=true" alt="Temperature per day of year in modeled, observed and bias-adjusted climate data" style="background-color: white; border-radius: 7px"> <figcaption>Figure 2: Temperature per day of year in observed, modeled, and bias-adjusted climate data</figcaption> </figure>

<a name="methods"></a>

2. Available methods

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

Function nameDescription
linear_scalingLinear Scaling (additive and multiplicative)
variance_scalingVariance Scaling (additive)
delta_methodDelta (Change) Method (additive and multiplicative)
quantile_mappingQuantile Mapping (additive and multiplicative) and Detrended Quantile Mapping (additive and multiplicative; to use DQM, set parameter detrended to True)
quantile_delta_mappingQuantile Delta Mapping (additive and multiplicative)
adjust_3drequires a method name and the respective parameters to adjust all time series of a 3-dimensional data set

<a name="installation"></a>

3. Installation

python3 -m pip install python-cmethods

<a name="examples"></a>

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:

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 +

<a name="notes"></a>

5. Notes

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.


<a name="references"></a>

6. References