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
- Installation
- Features
- Contributions
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file simple_climate_package-1.0.2.tar.gz.
File metadata
- Download URL: simple_climate_package-1.0.2.tar.gz
- Upload date:
- Size: 19.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2fed69f65b9e45199634e9e17c4da977bec5955aacc1e0d071e5a2e4255d7ce5
|
|
| MD5 |
5e67e96d4295863b2568678cd6f2c05d
|
|
| BLAKE2b-256 |
8fbc8425478e115efa4294c0dd506e1ab03535ec9d29d4c3bc8216c9102fae18
|
File details
Details for the file simple_climate_package-1.0.2-py3-none-any.whl.
File metadata
- Download URL: simple_climate_package-1.0.2-py3-none-any.whl
- Upload date:
- Size: 16.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e937a9f878e5f254d41deab65a7546e8bc6ed70e3e2c9f885ea79d524626100
|
|
| MD5 |
ac24a3e52a7d6b163a834cffe1e07eee
|
|
| BLAKE2b-256 |
91ee9406b3f8fde1a980fa1dcc32b51058e6bb5a7809e36e06dcbd5298e831fd
|