https://github.com/alan-turing-institute/python-cmethods

Bias Correction/Adjustment Tools written in Python for Climatic Research

https://github.com/alan-turing-institute/python-cmethods

Science Score: 33.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
  • .zenodo.json file
  • DOI references
    Found 8 DOI reference(s) in README
  • Academic publication links
    Links to: zenodo.org
  • Committers with academic emails
    1 of 3 committers (33.3%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (16.6%) to scientific vocabulary

Keywords

hut23 hut23-1077
Last synced: 11 months ago · JSON representation

Repository

Bias Correction/Adjustment Tools written in Python for Climatic Research

Basic Info
  • Host: GitHub
  • Owner: alan-turing-institute
  • License: gpl-3.0
  • Language: Python
  • Default Branch: master
  • Homepage:
  • Size: 4.4 MB
Statistics
  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • Open Issues: 1
  • Releases: 0
Fork of btschwertfeger/python-cmethods
Topics
hut23 hut23-1077
Created over 3 years ago · Last pushed over 3 years ago
Metadata Files
Readme License

README.md

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

[![GitHub](https://badgen.net/badge/icon/github?icon=github&label)](https://github.com/btschwertfeger/Bias-Adjustment-Python) [![Generic badge](https://img.shields.io/badge/python-3.8_|_3.9_|_3.10_|_3.11-yellow.svg)](https://shields.io/) [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-orange.svg)](https://www.gnu.org/licenses/gpl-3.0) [![Downloads](https://pepy.tech/badge/python-cmethods)](https://pepy.tech/project/python-cmethods) ![ql-workflow](https://github.com/btschwertfeger/Bias-Adjustment-Python/actions/workflows/codeql.yml/badge.svg) ![python-package](https://github.com/btschwertfeger/Bias-Adjustment-Python/actions/workflows/python-package.yml/badge.svg) [![codecov](https://codecov.io/github/btschwertfeger/python-cmethods/branch/master/graph/badge.svg?token=OSO4PAABPD)](https://codecov.io/github/btschwertfeger/python-cmethods) [![DOI](https://zenodo.org/badge/496160109.svg)](https://zenodo.org/badge/latestdoi/496160109)

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

bash python3 -m pip install python-cmethods


4. Usage and Examples

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

obsh = xr.opendataset('inputdata/observations.nc') simh = xr.opendataset('inputdata/control.nc') simp = xr.opendataset('inputdata/scenario.nc')

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

qdmresult = cm.adjust3d( # 3d = 2 spatial and 1 time dimension method = 'quantiledeltamapping', 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

bash 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)

Owner

  • Name: The Alan Turing Institute
  • Login: alan-turing-institute
  • Kind: organization
  • Email: info@turing.ac.uk

The UK's national institute for data science and artificial intelligence.

GitHub Events

Total
Last Year

Committers

Last synced: over 2 years ago

All Time
  • Total Commits: 50
  • Total Committers: 3
  • Avg Commits per committer: 16.667
  • Development Distribution Score (DDS): 0.08
Past Year
  • Commits: 39
  • Committers: 2
  • Avg Commits per committer: 19.5
  • Development Distribution Score (DDS): 0.077
Top Committers
Name Email Commits
Benjamin Thomas Schwertfeger d****t@b****e 46
crangelsmith c****h@t****k 3
Benjamin T. Schwertfeger 5****r 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: over 2 years ago

All Time
  • Total issues: 1
  • Total pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 1
  • Total pull request authors: 0
  • Average comments per issue: 3.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 1
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 1
  • Pull request authors: 0
  • Average comments per issue: 3.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • crangelsmith (1)
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Dependencies

.github/workflows/codecov.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
  • codecov/codecov-action v3 composite
.github/workflows/codeql.yml actions
  • actions/checkout v3 composite
  • github/codeql-action/analyze v2 composite
  • github/codeql-action/autobuild v2 composite
  • github/codeql-action/init v2 composite
.github/workflows/python-package.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v3 composite
requirements.txt pypi
  • netCDF4 >=1.6.1
  • numpy *
  • tqdm *
  • xarray >=2022.11.0
setup.py pypi
tests/requirements.txt pypi
  • numpy * test
  • scikit-learn * test
  • xarray * test