Skip to main content

aggfly: Efficient climate data aggregation

PyPI version

NOTE: aggfly is still in development and may not be stable for new users. Please proceed with caution.

aggfly is a Python package developed to facilitate and harmonize the temporal and spatial aggregation of gridded climate data. It performs linear and nonlinear aggregations of weather data across different time periods — degree days, bins, daily polynomials — and supports spatial aggregation by weighting gridded data according to administrative boundaries and local exposures such as human populations and crop distributions.

The package automates complex and memory-intensive geospatial operations, which are common challenges for researchers dealing with large climate datasets. aggfly is useful for researchers studying the impacts of weather and climate on other variables, such as human health, agriculture, and economic growth.

Installation

pip install aggfly

Requires Python 3.11–3.13. Full instructions — including the uv-based development setup and Jupyter kernels — are in docs/installation.md.

Quickstart

Three inputs: a shapefile of target regions, a climate raster to aggregate, and optionally a secondary weights raster (population, cropland).

import numpy as np
import aggfly as af

# 1. Load regions and a sample raster layer
georegions = af.georegions_from_path("counties.shp", regionid="GEOID")
dataset = af.dataset_from_path(
    "era5_2017.zarr", var="t2m",
    georegions=georegions,
    preprocess=lambda x: x - 273.15,     # Kelvin → Celsius
)

# 2. Compute weights (cached; reused across years)
weights = af.weights_from_objects(dataset, georegions, project_dir="./proj")
weights.calculate_weights()

# 3. Transform and aggregate → a region-by-period panel
df = af.aggregate_dataset(
    dataset=dataset,
    weights=weights,
    tavg=[
        ('aggregate', {'calc': 'mean', 'groupby': 'date'}),
        ('transform', {'transform': 'power', 'exp': np.arange(1, 3)}),
        ('aggregate', {'calc': 'sum', 'groupby': 'year'}),
    ],
    growing_dday=[
        ('aggregate', {'calc': 'dd', 'groupby': 'date', 'ddargs': [10, 30, 0]}),
        ('aggregate', {'calc': 'sum', 'groupby': 'year'}),
    ],
)

See the Quickstart guide for a walkthrough of each step.

Command-line interface

The whole workflow can also be driven from a YAML config file — no Python script required:

aggfly info era5_2017.zarr --var t2m   # discover coords, calendar, lon convention
aggfly validate config.yaml            # check the config, no data read
aggfly run config.yaml                 # aggregate → panel

See the CLI reference and runnable configs in examples/.

Documentation

Documentation home Full table of contents.
Installation pip for users, uv for development.
Concepts How the pipeline works and why weights matter.
Quickstart End-to-end Python API walkthrough.
Weights Area and secondary (population/crop) weighting.
Aggregation The spec DSL: calcs, transforms, degree days, bins.
Execution & scaling Dask backends and recipes by hardware.
Calendars CMIP6 and non-standard CF calendars.
CLI info, validate, weights, run.
API reference The public Python API.

Worked examples live in examples/ (CLI configs).

New to aggfly? quickstart_public_data.ipynb is a standalone notebook that downloads all of its own data (~25 MB, public, no accounts) and runs the full pipeline end to end — no local files required.

Acknowledgements

I gratefully acknowledge the support and funding provided by the Climate & Environment Program at Private Enterprise Development in Low Income Countries (PEDL, CEPR), and stellar research assistance from Giovanni Brocca and Nick Silvis. Research assistance was funded by Professors Colmer, Porzio, and Rossi through their project "The Human (Capital) Side of Climate Change," which was financed by the International Growth Center (XXX-23020) and Columbia Business School. The funding and research assistance provided were instrumental in the development of this package. I sincerely thank them for their commitment to advancing research and innovation.

Metadata

Release files for aggfly 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aggfly 0.3.0
File Size Uploaded Provenance
aggfly-0.3.0.tar.gz 92.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for aggfly 0.3.0
File Interpreter ABI Platform
aggfly-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 197.8 kB

Release files / aggfly-0.3.0.tar.gz

Download URL aggfly-0.3.0.tar.gz
Size 92.3 kB
Tags Source
SHA-256 checksum
How to use checksums
9b349776b13e110f993c65e0a66fb4b34fe49c059c859942398e17ab3d52d2cf
BLAKE2b-256 checksum
How to use checksums
e491b5840046ad4eca37fb78b445aee3d439df8d4a2b92795312e3df1d066e22
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.30 {"installer":{"name":"uv","version":"0.11.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / aggfly-0.3.0-py3-none-any.whl

Download URL aggfly-0.3.0-py3-none-any.whl
Size 105.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
75eb297f63f1e90a9c9469c7f7636425098e128f58e6401d44d8836a42e36894
BLAKE2b-256 checksum
How to use checksums
d8328747894a3c287ff703d4bda5d69a4b15254333906ea4a93902fd06a6f15e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.30 {"installer":{"name":"uv","version":"0.11.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for aggfly 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page