Skip to main content

pyrcel: 0D adiabatic cloud parcel model

Project description

pyrcel: cloud parcel model

sample parcel model run

DOIPyPI VersionCIDocumentation Status

pyrcel is a simple, adiabatic cloud parcel model for use in aerosol-cloud interaction studies. Rothenberg and Wang (2016) discuss the model in detail and its improvements over Nenes et al (2001):

  • Implementation of κ-Köhler theory for condensation physics (Petters and Kreidenweis, 2007)
  • Extension of model to handle arbitrary sectional representations of aerosol populations, based on user-controlled empirical or parameterized size distributions
  • JAX/diffrax-based numerical core — differentiable, batchable, GPU-ready, with no Fortran/SUNDIALS dependency

Detailed documentation is available, including a scientific description, installation details, and a basic example.

[!WARNING] Version 2.0 Notice

This is pyrcel v2.0, a major new release with more features, greater flexibility, and a JAX-based differentiable kernel. However, there are several breaking changes compared to version 1.3.x.

Please review the migration guide to update your code.

If you wish to continue using the legacy (v1.3.x) model, you can install it from PyPI by pinning the version:

pip install "pyrcel<2"

Quick Start

The easiest way to run pyrcel from source is with uv:

$ git clone https://github.com/darothen/pyrcel.git && cd pyrcel
$ uv run python examples/basic_run.py

uv will automatically create an isolated environment and install all dependencies. The first call compiles JAX kernels; subsequent calls are fast.

Usage

import pyrcel as pm

sulfate = pm.AerosolSpecies(
    "sulfate", pm.Lognorm(mu=0.05, sigma=2.0, N=1000.0), kappa=0.54, bins=50
)
model = pm.ParcelModel([sulfate], V=1.0, T0=283.0, S0=-0.02, P0=85000.0, console=True)
output = model.run(t_end=300.0, output_dt=10.0, terminate=True, live=True)

print(f"S_max  = {output.summary['S_max']*100:.3f} %")
print(f"N_act  = {output.Nd:.3e} m⁻³")

Key capabilities:

  • Autodiff — exact gradients of S_max w.r.t. updraft speed, initial conditions, accommodation coefficient, and aerosol properties via jax.grad.
  • Batching / GPUjax.vmap runs ensembles of parcels in one compiled call; pass device="gpu" to ParcelModel for CUDA acceleration.
  • Time-varying updraft — pass a pyrcel.InterpolatedUpdraft(ts=..., vs=...) as V.
  • Flexible outputoutput.to_pandas(), .to_xarray(), .to_netcdf(), .to_parquet().

The differentiable core (pyrcel.integrator, pyrcel.equilibrate) is usable directly for jit/grad/vmap; ParcelModel is the interactive convenience layer (console output, progress meter, post-solve summary table).

Installation

From PyPI (recommended):

$ pip install pyrcel

JAX (CPU) is included by default. No extras needed for standard use.

From source:

$ git clone https://github.com/darothen/pyrcel.git && cd pyrcel
$ uv sync
$ uv run python examples/basic_run.py

GPU support (CUDA 12):

$ pip install "pyrcel[gpu]"

Requirements

Development

Clone the repo and install with dev dependencies:

$ git clone https://github.com/darothen/pyrcel.git && cd pyrcel
$ uv sync --extra test
$ prek install   # installs the git pre-commit hook (requires prek: https://prek.j178.dev)

Run the fast test suite:

$ uv run pytest tests/ -m "not slow"

Lint and format are handled automatically by prek on commit, or run manually:

$ prek run --all-files

Please fork this repository if you intend to develop the model further so that the code's provenance can be maintained.

License / Usage

All scientific code should be licensed. This code is released under the New BSD (3-clause) license.

If you use this for any scientific work resulting in a publication, please cite our original publication detailing the model:

@article {
      author = "Daniel Rothenberg and Chien Wang",
      title = "Metamodeling of Droplet Activation for Global Climate Models",
      journal = "Journal of the Atmospheric Sciences",
      year = "2016",
      publisher = "American Meteorological Society",
      address = "Boston MA, USA",
      volume = "73",
      number = "3",
      doi = "10.1175/JAS-D-15-0223.1",
      pages= "1255 - 1272",
      url = "https://journals.ametsoc.org/view/journals/atsc/73/3/jas-d-15-0223.1.xml"
}

Additionally, please consider citing the bespoke DOI for the specific release version of pyrcel that you used during your research (or the base version you modified). This allows us to track adoption and use of specific model versions over time.

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

pyrcel-2.0.0.tar.gz (1.7 MB view details)

Uploaded Source

Built Distribution

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

pyrcel-2.0.0-py3-none-any.whl (176.7 kB view details)

Uploaded Python 3

File details

Details for the file pyrcel-2.0.0.tar.gz.

File metadata

  • Download URL: pyrcel-2.0.0.tar.gz
  • Upload date:
  • Size: 1.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyrcel-2.0.0.tar.gz
Algorithm Hash digest
SHA256 8dff99be3b55f8c19658c78c95a7093a8d4e7c0e48e387496de9f1311972a3fc
MD5 ac3d333522803af4129a355c212120f8
BLAKE2b-256 570a146c92edae2b7343579da2562b1bdad82062df0bb591448edf641fc5cf09

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrcel-2.0.0.tar.gz:

Publisher: publish.yml on darothen/pyrcel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyrcel-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: pyrcel-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 176.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyrcel-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6056c402e0a2299bd3631041cc5ae0a42b65f644719f891120c4f3b990c9c223
MD5 b3be2f3b73d24ab338a7e2f01e4d3297
BLAKE2b-256 0df8d123bcbec4b9aa3627e0dca319e7d78f734fc92f5062a0a08372c6cc4b9a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrcel-2.0.0-py3-none-any.whl:

Publisher: publish.yml on darothen/pyrcel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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