Skip to main content

Simple statistical analysis for E-OBS datasets

Project description

Simple_climate_package

The open-source Python package simple_climate_package reads in netcdf E_OBS data, performs simple statistical tests and visualises the outputs.

Statistical tests included in this package:

  • Minimum values
  • Maximum values
  • Mean values
  • mean cliatology values
  • Climate anomaly values
  • Linear regression

Table of Contents

  1. Installation
  2. Features
  3. Contributions
  4. License

1. Installation

Installing without a virtual environment

For general use of this package without a virtual environment, please import using pip install.

pip install simple_climate_package

Installation using a virtual environment

To ensure the use of the same packages and dependencies, please follow these steps when setting up your local environment. This method is preferred for developers.

These commands are for bash.

Step 1: Clone the repository

git clone <repo_url>
cd <repo_name>

Step 2: Create and activate a virtual environment

python3 -m venv env
source env/bin/activate

Step 3: Install dependencies from virtual_environment_requirements.txt

pip install -r virtual_environment_requirements.txt

Installing data

This package was developed to work with E-OBS daily data from 1950 to present.

A sample dataset for data over The United Kingdom from 1950 to present can be found in the Data folder located in the simple_climate_package folder.

To use your own data, please copy this code into a script.

Please note you need a cdsapi API file stored on your computer, see https://cds.climate.copernicus.eu/how-to-api for more information.

import cdsapi

dataset = "insitu-gridded-observations-europe"
request = {
    "product_type": "ensemble_mean",
    "variable": ["<insert_climate_variable>"],
    "grid_resolution": "0_25deg",
    "period": "full_period",
    "version": ["30_0e"]
}

client = cdsapi.Client()
client.retrieve(dataset, request).download()

2. Features

An example analysis script using simple_climate_package is listed in the github repository. Start by specifying the path to your data file. The data path is an input to many of our methods, so is useful to specify at the beginning of your analysis.

data_path = input('Input the path to the data you want to analyse: ')

Calculating the mean

To conduct analysis using mean data, import the class CalcMean from simple_climate_package. Input the path to your data file into CalcMean and label this as 'tm'. 'tm' is your temperature instance and what will be used to conduct your analysis. 'tm' can be subsituted to reflect your selected climate variable e.g. 'precip'.

from simple_climate_package.mean import CalcMean


tm = CalcMean(data_path)

To obtain the dataset of the mean temperature data for each grid pixel over the entire timeseries, call mean_tot_time().

mean_tot = tm.mean_tot_time()

A visualisation of the mean temperature over the entire timeseries can be called using plot_mean_tot_time().

tm.plot_mean_tot_time()

This method saves a plot to a filepath specified in the arguement of the method.

Note that mean_tot_time() does not need to be called to use plot_mean_tot_time().

Instead of getting the total mean, you can specify the dates between which you want to calculate the mean.

mean_between = tm.mean_between(start_date, end_date)
tm.plot_mean_between(start_date, end_date)

To get a dataset for the mean temperature of every grid pixel per year, call yearly_mean(). Calling plot_yearly_mean() creates a plot of the mean temperature for every year in the dataset.

yearly_mean = tm.yearly_mean()
tm.plot_yearly_mean()

For studying monthly climatology (long-term average conditions for each calendar month over the entire timeseries), call monthly_clim(). Monthly_clim() returns a dataset with 12 values (one per month) representing the long-term monthly climatology. Calling tm.plot_monthly_climatology() plots the climatology for each month.

month_clim = tm.monthly_clim()
tm.plot_monthly_climatology()

Instead of monthly trends, daily climatology (daily long-term average conditions over the entire timeseries) can be calculating by calling daily_clim. There is not a plotting function for daily climatology due to the large volume of days in the dataset.

day_clim = tm.daily_clim()

Climatology is used to calculate the climate anomaly. The monthly climate anomaly, calculated by subtracting the long-term monthly climatology from the monthly mean, is called using monthly_clim_Anom(). Monthly_clim_Anom() provides a dataset for climate anomaly of every month in the dataset. The daily climate anomaly, calculated by subtracting the long-term daily climatology from the temperature for each day in the data, is called using daily_climate_Anom()

clim_anom = tm.monthly_clim_Anom()
daily_anom = tm.daily_clim_Anom()

Climate anomalies are not plotted in this package but can be used for further analysis such as fair comparison of global trends.

Calculating extreme values

To conduct analysis using minimum or maximum data, import the class CalcExtremes from simple_climate_package. Input the path to your data file into CalcExtremes and label this as 'tx'. 'tx' is your temperature instance and what will be used to conduct your analysis.

from simple_climate_package.mean import CalcExtremes


tx = CalcExtremes(data_path)

To obtain the dataset of the minimum temperature data for each grid pixel over the entire timeseries, call min_tot(). To obtain the dataset of the maximum temperature data for each grid pixel over the entire timeseries, call max_tot().

min_tot = tx.min_tot()
max_tot = tx.max_tot()

A visualisation of the minimum or maximum temperature over the entire timeseries can be called using plot_min_tot() or plot_max_tot() respectively.

tx.plot_min_tot()
tx.plot_max_tot()

This method saves a plot to a filepath specified in the arguement of the method.

Note that min_tot() and max_tot() do not need to be called to use plot_min_tot() and plot_max_tot() respectively.

Instead of getting the total minimum/maximum value, you can specify the dates between which you want to calculate it.

min_between = tx.min_between(start_date, end_date)
tx.plot_min_between(start_date, end_date)
max_between = tx.max_between(start_date, end_date)
tx.plot_max_between(start_date, end_date)

To get a dataset for the minimum or maximum temperature of every grid pixel per year, call yearly_min() or yearly_max() respectively. Calling plot_yearly_min() or plot_yearly_max() creates a plot of the minimum or maximum temperature for every year in the dataset.

yearly_min = tx.yearly_min()
tx.plot_yearly_min()
yearly_max = tx.yearly_max()
tx.plot_yearly_max()

Linear Regression

To conduct analysis using linear regression data, import the class LinReg from simple_climate_package. Input the path to your data file into LinReg and label this as 'tl'. 'tl' is your temperature instance and what will be used to conduct your analysis.

from simple_climate_package.linear_regression import LinReg


tl = LinReg(data_path)

Calling grid_linear_regression calculates the linear regression for each grid pixel in the entire dataset.

lin_reg = tl.grid_linear_regression()

Note that the dataset is resampled from daily to yearly means for efficiency. This method takes yearly mean as imports and returns arrays of variables.

Variables returned: slope, intercept, t_stat, p_value, r2, rmse, n_obs, per_decade, total_change

These variables can be used for further analysis. Calling quick_plot_signif_stippling() plots the temperature's change per decade

tl.quick_plot_signif_stippling()

3. Authors & Contributions

This package was created by Hannah-Jane Wood, Lucy Harlow, and Ofer Cohen

4. License

The simple_climate_package is licensed under the MIT License - see the LICENSE file for details

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

simple_climate_package-1.0.1.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

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

simple_climate_package-1.0.1-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file simple_climate_package-1.0.1.tar.gz.

File metadata

  • Download URL: simple_climate_package-1.0.1.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for simple_climate_package-1.0.1.tar.gz
Algorithm Hash digest
SHA256 809bc4115850b90dcc0598a9872ebfe7458be4159e72781dacb9229ac237c5db
MD5 cbbc69efc3d9b44f16aa1979409f4f82
BLAKE2b-256 80d8269f874737ea192d28306382dc04e35a166158245c76ec4116d2800902b9

See more details on using hashes here.

File details

Details for the file simple_climate_package-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for simple_climate_package-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3b18048b0cd5b81e24ed51acffbec8a5c79461da59a60ddfa524163fe3e144af
MD5 2ff47686434bf17af5df795a3aebd669
BLAKE2b-256 847b180df2f1e61fb58f158253a214669481ab7f6d4e13f1d780cc4d6ef7e17f

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