Skip to main content

Climate diagnostics tools for analyzing and visualizing climate data

Project description

Climate Diagnostics Toolkit

Python Version License Version Status

A Python package for analyzing and visualizing climate data from NetCDF files with a focus on time series and trend analysis, and spatial pattern visualization, integrated directly with xarray via accessors.

Overview

Climate Diagnostics Toolkit provides powerful tools to process, analyze, and visualize climate data using xarray accessors. The package offers functionality for seasonal filtering, spatial averaging with proper area weighting, trend analysis, and time series decomposition to help climate scientists extract meaningful insights from large climate datasets directly from their xarray Dataset objects.

Features

  • Data Loading and Processing:

    • Load NetCDF climate data files using xarray.open_dataset.
    • Access toolkit functions via .climate_timeseries, .climate_trends, and .climate_plots accessors on xarray Datasets.
    • Filter data by meteorological seasons (Annual, DJF, MAM, JJAS, etc.) using accessor methods.
    • Select data by latitude, longitude, level, and time range.
  • Time Series Analysis (via .climate_timeseries):

    • Plot time series with proper area weighting to account for grid cell size differences.
    • Calculate and visualize spatial standard deviations over time.
    • Decompose time series into trend, seasonal, and residual components using STL.
  • Trend Analysis (via .climate_trends):

    • Calculate and visualize spatially averaged trends with statistical significance testing.
    • Compute and plot spatial maps of trends per grid point using STL decomposition.
  • Visualization (via .climate_plots):

    • Generate spatial maps of means and standard deviations using Cartopy.
    • Create publication-quality figures with map projections.
    • Optionally smooth spatial plots using Gaussian filters.
    • Option to plot data only over land.

Installation

From Source

git clone https://github.com/pranay-chakraborty/climate_diagnostics.git 
cd climate_diagnostics
pip install -e .

Usage Examples

Loading Data and Plotting Time Series

import xarray as xr
from climate_diagnostics import accessors

# Load data using xarray
ds = xr.open_dataset("path/to/climate_data.nc")

# Plot time series for a specific region and season using the accessor, given a 3D dataset
ds.climate_timeseries.plot_time_series(
    latitude=slice(40, 6),
    longitude=slice(60,110 ),
    level=850,  # hPa pressure level
    variable="air",
    season="jjas"  # June-July-August-September
)

Analyzing Trends

import xarray as xr
from climate_diagnostics import accessors

# Load data
ds = xr.open_dataset("path/to/climate_data.nc")

# Calculate and visualize trends with area-weighted averaging using the accessor
results = ds.climate_trends.calculate_trend(
    variable="air",
    latitude=slice(40, 6),
    longitude=slice(60,110 ),
    level=850,
    season="annual",
    area_weighted=True,
    plot=True,
    return_results=True
)

# Access trend statistics if return_results=True
if results:
    trend_stats = results['trend_statistics']
    slope = trend_stats.loc[trend_stats['statistic'] == 'slope', 'value'].item()
    p_value = trend_stats.loc[trend_stats['statistic'] == 'p_value', 'value'].item()
    print(f"Trend slope: {slope}")
    print(f"P-value: {p_value}")

# Calculate and plot spatial trends per decade
spatial_trends = ds.climate_trends.calculate_spatial_trends(
    variable="air",
    level=850,
    season="annual",
    frequency="M", # Assuming monthly data
    num_years=10,  # Trend per decade
    plot_map=True,
    n_workers = 8,
    latitude = slice(40,6),
    longitude = slice(60,110)
    
)

Creating Spatial Maps

import xarray as xr
from climate_diagnostics import accessors

# Load data
ds = xr.open_dataset("path/to/climate_data.nc")

# Plot mean of a variable using the accessor
ds.climate_plots.plot_mean(
    variable="air",
    level=850,
    season="djf",  # December-January-February
    latitude = slice(40,6),
    longitude = slice(60,110)
)

# Plot standard deviation over time, smoothed, over land only
ds.climate_plots.plot_std_time(
    variable="air",
    season="jjas",
    gaussian_sigma=1.5, # Apply smoothing
    land_only=True,      # Mask oceans
    latitude = slice(40,6),
    longitude = slice(60,110),
    levels = 500
)

Dependencies

  • xarray
  • dask
  • netCDF4
  • bottleneck
  • matplotlib
  • numpy
  • scipy
  • cartopy
  • statsmodels
  • scikit-learn

Development

Setting up the development environment

git clone https://github.com/pranay-chakraborty/climate_diagnostics.git 
cd climate_diagnostics
conda env create -f environment.yml
conda activate climate-diagnostics
pip install -e ".[dev]"

Running Tests

pytest

License

MIT LICENSE

Citation

If you use Climate Diagnostics Toolkit in your research, please cite:

Chakraborty, P. (2025) & Muhammed I. K., A. (2025). Climate Diagnostics Toolkit: Tools for analyzing and visualizing climate data using xarray accessors. Version 0.1.0. https://github.com/pranay-chakraborty/climate_diagnostics

For LaTeX users:

@software{chakraborty2025climate,
  author = {Chakraborty, Pranay and Muhammed I. K., Adil},
  title = {{Climate Diagnostics Toolkit: Tools for analyzing and visualizing climate data using xarray accessors}},
  year = {2025},
  version = {0.1.0},
  publisher = {GitHub},
  url = {https://github.com/pranay-chakraborty/climate_diagnostics},
  note = {[Computer software]}
}

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

climate_diagnostics-0.2.1.tar.gz (35.5 kB view details)

Uploaded Source

Built Distribution

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

climate_diagnostics-0.2.1-py3-none-any.whl (32.8 kB view details)

Uploaded Python 3

File details

Details for the file climate_diagnostics-0.2.1.tar.gz.

File metadata

  • Download URL: climate_diagnostics-0.2.1.tar.gz
  • Upload date:
  • Size: 35.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for climate_diagnostics-0.2.1.tar.gz
Algorithm Hash digest
SHA256 b1a5dfaa1bc1164a7b662f22790919a28608507fe8992dba32aad971c49d1348
MD5 f854b3ae9e4a4abf1f2b650819dcdcfe
BLAKE2b-256 8222d38cbe5b7f402098319312d2aa2bb75cfec9e78359996a01459f6b35755e

See more details on using hashes here.

File details

Details for the file climate_diagnostics-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for climate_diagnostics-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 da9a102a1c55ccf630f033b938abb6d6b2046fabc3d1fc8aa5b85aae9b0e40ec
MD5 1495fc97719b50f9d717f1baaf525d33
BLAKE2b-256 7013a871a84dc0a8a4368a991670652ad68bc80072c1efb54e3aa367907def33

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