PyPartMC

logo

PyPartMC

PyPartMC is a Python interface to PartMC, a particle-resolved Monte-Carlo code for atmospheric aerosol simulation. Development of PyPartMC has been intended to remove limitations to the use of Fortran-implemented PartMC. PyPartMC facilitates the dissemination of computational research results by streamlining independent execution of PartMC simulations (also during peer-review processes). Additionally, the ability to easily package examples, simple simulations, and results in a web-based notebook allows PyPartMC to support the efforts of many members of the scientific community, including researchers, instructors, and students, with nominal software and hardware requirements.

Documentation of PyPartMC is hosted at https://open-atmos.github.io/PyPartMC. PyPartMC is implemented in C++ and it also constitutes a C++ API to the PartMC Fortran internals. The Python API can facilitate using PartMC from other environments - see, e.g., Julia and Matlab examples below.

For an outline of the project, rationale, architecture, and features, refer to: D'Aquino et al., 2024 (SoftwareX) (please cite if PyPartMC is used in your research). For a list of talks and other relevant resources, please see project Wiki. If interested in contributing to PyPartMC, please have a look a the notes for developers.

US Funding PL Funding

License: GPL v3 Copyright tests+pypi API docs codecov DOI PyPI version Project Status: Active – The project has reached a stable, usable state and is being actively developed. pyOpenSci Peer-Reviewed

Python 3 Linux OK macOS OK Windows OK Jupyter

Installation

Using the command-line pip tool (also applies to conda environments)

pip install PyPartMC

Note that, depending on the environment (OS, hardware, Python version), the pip-install invocation may either trigger a download of a pre-compiled binary, or trigger compilation of PyPartMC. In the latter case, a Fortran compiler and some development tools includiong CMake, m4 and perl are required (while all non-Python dependencies are included in the PyPartMC source archive). In both cases, all Python dependencies will be resolved by pip.

In a Jupyter notebook cell (also on Colab or jupyter-hub instances)

! pip install PyPartMC
import PyPartMC

Jupyter notebooks with examples

Note: clicking the badges below redirects to cloud-computing platforms. The mybinder.org links allow anonymous execution, Google Colab requires logging in with a Google account, ARM JupyerHub requires logging in with an ARM account (and directing Jupyter to a particular notebook within the examples folder).

The example notebooks feature additional dependencies that can be installed with:

pip install PyPartMC[examples]
  • Urban plume scenario demo (as in PartMC):
    View notebook Open In Colab Binder ARM JupyterHub
  • Dry-Wet Particle Size Equilibration with PartMC and PySDM:
    View notebook Open In Colab Binder ARM JupyterHub Voila
  • Simulation output processing example (loading from netCDF files using PyPartMC):
    View notebook Open In Colab Binder ARM JupyterHub
  • Optical properties calculation using external Python package (PyMieScatt):
    View notebook Open In Colab Binder ARM JupyterHub
  • Cloud parcel example featuring supersaturation-evolution-coupled CCN activation and drop growth:
    View notebook Open In Colab Binder ARM JupyterHub
  • Coagulation model intercomparison for additive (Golovin) kernel with: PyPartMC, PySDM, Droplets.jl and dustpy:
    View notebook Open In Colab Binder ARM JupyterHub

Features

  • works on Linux, macOS and Windows (compatibility assured with CI builds)
  • hassle-free installation using pip (prior PartMC installation not needed)
  • works out of the box on mybinder.org, Google Colab and alike
  • ships with a set of examples maintained in a form of Jupyter notebooks
  • Pythonic API (but retaining PartMC jargon) incl. Python GC deallocation of Fortran objects
  • specification of parameters using native Python datatypes (lists, dicts) in place of PartMC spec files
  • code snippets in README depicting how to use PyPartMC from Julia and Matlab (also executed on CI)
  • auto-generated API docs on the web
  • support for [de]serialization of selected wrapped structures using JSON
  • based on unmodified PartMC code
  • does not use or require shell or any pre-installed libraries
  • aiming at 100% unit test coverage

Usage examples

The listings below depict how the identical task of randomly sampling particles from an aerosol size distribution in PartMC can be done in different programming languages.

For a Fortran equivalent of the Python, Julia and Matlab programs below, see the readme_fortran folder.

Python

import numpy as np

import PyPartMC as ppmc
from PyPartMC import si

aero_data = ppmc.AeroData((
    #      [density, ions in solution, molecular weight, kappa]
    {"OC": [1000 *si.kg/si.m**3, 0, 1e-3 *si.kg/si.mol, 0.001]},
    {"BC": [1800 *si.kg/si.m**3, 0, 1e-3 *si.kg/si.mol, 0]},
))

aero_dist = ppmc.AeroDist(
    aero_data,
    [{
        "cooking": {
            "mass_frac": [{"OC": [1]}],
            "diam_type": "geometric",
            "mode_type": "log_normal",
            "num_conc": 3200 / si.cm**3,
            "geom_mean_diam": 8.64 * si.nm,
            "log10_geom_std_dev": 0.28,
        },
        "diesel": {
            "mass_frac": [{"OC": [0.3]}, {"BC": [0.7]}],
            "diam_type": "geometric",
            "mode_type": "log_normal",
            "num_conc": 2900 / si.cm**3,
            "geom_mean_diam": 50 * si.nm,
            "log10_geom_std_dev": 0.24,
        }
    }],
)

n_part = 100
aero_state = ppmc.AeroState(aero_data, n_part, "nummass_source")
aero_state.dist_sample(aero_dist)
print(np.dot(aero_state.masses(), aero_state.num_concs), "# kg/m3")

Julia (using PyCall.jl)

using Pkg
Pkg.add("PyCall")

using PyCall
ppmc = pyimport("PyPartMC")
si = ppmc["si"]

aero_data = ppmc.AeroData((
  #       (density, ions in solution, molecular weight, kappa)
  Dict("OC"=>(1000 * si.kg/si.m^3, 0, 1e-3 * si.kg/si.mol, 0.001)),
  Dict("BC"=>(1800 * si.kg/si.m^3, 0, 1e-3 * si.kg/si.mol, 0))
))

aero_dist = ppmc.AeroDist(aero_data, (
  Dict( 
    "cooking" => Dict(
      "mass_frac" => (Dict("OC" => (1,)),),
      "diam_type" => "geometric",
      "mode_type" => "log_normal",
      "num_conc" => 3200 / si.cm^3,
      "geom_mean_diam" => 8.64 * si.nm,
      "log10_geom_std_dev" => .28,
    ),
    "diesel" => Dict(
      "mass_frac" => (Dict("OC" => (.3,)), Dict("BC" => (.7,))),
      "diam_type" => "geometric",
      "mode_type" => "log_normal",
      "num_conc" => 2900 / si.cm^3,
      "geom_mean_diam" => 50 * si.nm,
      "log10_geom_std_dev" => .24,
    )
  ),
))

n_part = 100
aero_state = ppmc.AeroState(aero_data, n_part, "nummass_source")
aero_state.dist_sample(aero_dist)
print(aero_state.masses()'aero_state.num_concs, "# kg/m3")

Matlab (using Matlab's built-in Python interface)

notes (see the PyPartMC Matlab CI workflow for an example on how to achieve it on Ubuntu 20):

  • Matlab ships with convenience copies of C, C++ and Fortran runtime libraries which are dlopened() by default; one way to make PyPartMC OK with it is to [pip-]install by compiling from source using the very same version of GCC that Matlab borrowed these libraries from (e.g., GCC 9 for Matlab R2022a, etc);
  • Matlab needs to use the same Python interpretter/venv as the pip invocation used to install PyPartMC;
  • a single-line pybind11_builtins.py file with just pybind11_type=type inside needs to be placed within Matlab's PYTHONPATH to sort out a Matlab-pybind11 incompatibility.
ppmc = py.importlib.import_module('PyPartMC');
si = py.importlib.import_module('PyPartMC').si;

aero_data = ppmc.AeroData(py.tuple({ ...
  py.dict(pyargs("OC", py.tuple({1000 * si.kg/si.m^3, 0, 1e-3 * si.kg/si.mol, 0.001}))), ...
  py.dict(pyargs("BC", py.tuple({1800 * si.kg/si.m^3, 0, 1e-3 * si.kg/si.mol, 0}))) ...
}));

aero_dist = ppmc.AeroDist(aero_data, py.tuple({ ...
  py.dict(pyargs( ...
    "cooking", py.dict(pyargs( ...
      "mass_frac", py.tuple({py.dict(pyargs("OC", py.tuple({1})))}), ...
      "diam_type", "geometric", ...
      "mode_type", "log_normal", ...
      "num_conc", 3200 / si.cm^3, ...
      "geom_mean_diam", 8.64 * si.nm, ...
      "log10_geom_std_dev", .28 ...
    )), ...
    "diesel", py.dict(pyargs( ...
      "mass_frac", py.tuple({ ...
        py.dict(pyargs("OC", py.tuple({.3}))), ...
        py.dict(pyargs("BC", py.tuple({.7}))), ...
      }), ...
      "diam_type", "geometric", ...
      "mode_type", "log_normal", ...
      "num_conc", 2900 / si.cm^3, ...
      "geom_mean_diam", 50 * si.nm, ...
      "log10_geom_std_dev", .24 ...
    )) ...
  )) ...
}));

n_part = 100;
aero_state = ppmc.AeroState(aero_data, n_part, "nummass_source");
aero_state.dist_sample(aero_dist);
masses = cell(aero_state.masses());
num_concs = cell(aero_state.num_concs);
fprintf('%g # kg/m3\n', dot([masses{:}], [num_concs{:}]))

usage in other projects

PyPartMC is used within the test workflow of the PySDM project.

Other packages with relevant feature scope

  • aerosolGDEFoam: OpenFOAM CFD-coupled aerosol dynamics including nucleation, coagulation, and surface growth
  • AIOMFAC and AIOMFAC-web: Fortran-implemented aerosol thermodynamic model for calculation of activity coefficients in organic-inorganic mixtures – from simple binary solutions to complex multicomponent systems
  • DustPy: Python package for modelling dust evolution in protoplanetary disks (differences: focus on astrophysical applications vs. atmospheric aerosol)
  • multilayerpy: kinetic multi-layer model for aerosol particles and films
  • PyBox: aerosol simulation model featuring gas and particle chamistry (differences: PyBox focuses on chemical mechanisms; PyPartMC is an interface to PartMC which focuses on physics - e.g., collisions of aerosol particles - while chemical processes are handled with external software, e.g., CAMP or MOSAIC)
  • PyCHAM: CHemistry with Aerosol Microphysics in Python Box Model for modelling of indoor environments, including aerosol chambers
  • PySDM: particle-based Monte-Carlo aerosol-cloud simulation package (differences: PySDM focuses on growth and breakup processes relevant to cloud droplets; PyPartMC focuses on processes relevant to air pollutants and their chemical and physical transformations)
  • SSH-aerosol: C++/Fortran package for simulating evolution of primary and secondary atmospheric aerosols

FAQ

  • Q: How to install PyPartMC with MOSAIC enabled?
    A: Installation can be done using pip, however, pip needs to be instructed not to use binary packages available at pypi.org but rather to compile from source (pip will download the source from pip.org), and the path to compiled MOSAIC library needs to be provided at compile-time; the following command should convey it:
MOSAIC_HOME=<<PATH_TO_MOSAIC_LIB>> pip install --force-reinstall --no-binary=PyPartMC PyPartMC
  • Q: Why pip install PyPartMC triggers compilation on my brand new Apple machine, while it quickly downloads and installs binary packages when executed on older Macs, Windows or Linux?
    A: We are providing binary wheels on PyPI for Apple-silicon (arm64) machines for selected macOS version made available by Github. In case the macOS version you are using is newer, compilation from source is triggered.

  • Q: Why some of the constructors expect data to be passed as lists of single-entry dictionaries instead of multi-element dictionaries?
    A: This is intentional and related with PartMC relying on the order of elements within spec-file input; while Python dictionaries preserve ordering (insertion order), JSON format does not, and we intend to make these data structures safe to be [de]serialized using JSON.

  • Q: How to check the version of PartMC that PyPartMC was compiled against?
    A: Version numbers of compile-time dependencies of PyPartMC, including PartMC, can be accessed as follows:

import PyPartMC
PyPartMC.__versions_of_build_time_dependencies__['PartMC']
  • Q: Why m4 and perl are required at compile time?
    A: PyPartMC includes parts of netCDF and HDF5 codebases which depend on m4 and perl, respectively, for generating source files before compilation.

Troubleshooting

Common installation issues

error: [Errno 2] No such file or directory: 'cmake'

Try rerunning after installing CMake, e.g., using apt-get install cmake (Ubuntu/Debian), brew install cmake (homebrew on macOS) or using MSYS2 on Windows.

No CMAKE_Fortran_COMPILER could be found.

Try installing a Fortran compiler (e.g., brew reinstall gcc with Homebrew on macOS or using MSYS2 on Windows).

Could not find NC_M4 using the following names: m4, m4.exe

Try installing m4 (e.g., using MSYS2 on Windows).

Acknowledgement and citations

We would greatly appreciate citation of the PartMC model description paper (Riemer et al., 2009) and the PyPartMC description paper (D’Aquino et al., 2024) if PyPartMC was used in your study. The citations are:

  • Riemer, N., M. West, R. A. Zaveri, R. C. Easter: Simulating the evolution of soot mixing-state with a particle-resolved aerosol model
    J. Geophys. Res., 114, D09202, 2009, DOI: 10.1029/2008JD011073
  • D’Aquino, Z., S. Arabas, J. H. Curtis, A. Vaishnav, N. Riemer, M. West: PyPartMC: A pythonic interfact to a particle-resolved, Monte Carlo aerosol simulation framework
    SoftwareX, 25, 101613, 2024, DOI: 10.1016/j.softx.2023.101613

The following paragraph provides a more substantial description of PartMC (text released into the public domain and can be freely copied by anyone for any purpose):

PartMC is a stochastic, particle-resolved aerosol box model. It tracks the composition of many computational particles (104 to 106) within a well-mixed air volume, each represented by a composition vector that evolves based on physical and chemical processes. The physical processes—including Brownian coagulation, new particle formation, emissions, dilution, and deposition—are simulated using a stochastic Monte Carlo approach via a Poisson process while chemical processes are simulated deterministically for each computational particle. The weighted flow algorithm (DeVille, Riemer, and West, 2011, 2019) enhances efficiency and reduces ensemble variance. Detailed numerical methods are described in Riemer et al. (2009), DeVille et al. (2011, 2019), and Curtis et al. (2016). PartMC is open-source under the GNU GPL v2 and available at github.com/compdyn/partmc.

References:

  • Curtis, J. H., M. D. Michelotti, N. Riemer, M. T. Heath, M. West: Accelerated simulation of stochastic particle removal processes in particle-resolved aerosol models, J. Computational Phys., 322, 21-32, 2016, DOI: 10.1016/j.jcp.2016.06.029
  • DeVille, L., N. Riemer, M. West, Convergence of a generalized weighted flow algorithm for stochastic particle coagulation, J. Computational Dynamics, 6, 69-94, 2019, DOI: 10.3934/jcd.2019003
  • DeVille, R. E. L., N. Riemer, M. West, The Weighted Flow Algorithm (WFA) for stochastic particle coagulation, J. Computational Phys., 230, 8427-8451, 2011, DOI: 10.1016/j.jcp.2011.07.027
  • Riemer, N., M. West, R. A. Zaveri, R. C. Easter, Simulating the evolution of soot mixing-state with a particle-resolved aerosol model, J. Geophys. Res., 114, D09202, 2009., DOI: 10.1029/2008JD011073

Credits

PyPartMC:

authors: PyPartMC developers
funding: US Department of Energy Atmospheric System Research programme, Polish National Science Centre
copyright: University of Illinois at Urbana-Champaign
licence: GPL v3

PartMC:

authors: Nicole Riemer, Matthew West, Jeff Curtis et al.
licence: GPL v2 or later

 1"""
 2.. include::../README.md
 3"""
 4
 5# pylint: disable=invalid-name,wrong-import-position
 6import os
 7from collections import namedtuple
 8from contextlib import contextmanager
 9from pathlib import Path
10
11
12# https://github.com/diegoferigo/cmake-build-extension/blob/master/src/cmake_build_extension/__init__.py
13@contextmanager
14def __build_extension_env():
15    cookies = []
16    # https://docs.python.org/3/whatsnew/3.8.html#bpo-36085-whatsnew
17    if hasattr(os, "add_dll_directory"):
18        basepath = os.path.dirname(os.path.abspath(__file__))
19        dllspath = os.path.join(basepath, "..")
20        os.environ["PATH"] = dllspath + os.pathsep + os.environ["PATH"]
21        for path in os.environ.get("PATH", "").split(os.pathsep):
22            if path and Path(path).is_absolute() and Path(path).is_dir():
23                cookies.append(os.add_dll_directory(path))
24    try:
25        yield
26    finally:
27        for cookie in cookies:
28            cookie.close()
29
30
31def __generate_si():
32    prefixes = {
33        "T": 1e12,
34        "G": 1e9,
35        "M": 1e6,
36        "k": 1e3,
37        "h": 1e2,
38        "da": 1e1,
39        "": 1e0,
40        "d": 1e-1,
41        "c": 1e-2,
42        "m": 1e-3,
43        "u": 1e-6,
44        "n": 1e-9,
45        "p": 1e-12,
46    }
47    units = {
48        "m": 1e0,
49        "g": 1e-3,
50        "s": 1e0,
51        "K": 1e0,
52        "Pa": 1e0,
53        "mol": 1e0,
54        "W": 1e0,
55        "J": 1e0,
56        "N": 1e0,
57    }
58    return namedtuple("SI", [prefix + unit for prefix in prefixes for unit in units])(
59        **{
60            prefix_k + unit_k: prefix_v * unit_v
61            for prefix_k, prefix_v in prefixes.items()
62            for unit_k, unit_v in units.items()
63        }
64    )
65
66
67si = __generate_si()
68""" a utility namedtuple aimed at clrifying physics-related code by providing
69    SI-prefix-aware unit multipliers, resulting in e.g.: `p = 1000 * si.hPa`
70    notation. Note: no dimensional analysis is done! """
71
72with __build_extension_env():
73    import _PyPartMC
74    from _PyPartMC import *
75    from _PyPartMC import __all__ as _PyPartMC_all  # pylint: disable=no-name-in-module
76    from _PyPartMC import __version__, __versions_of_build_time_dependencies__
77
78    __all__ = tuple([*_PyPartMC_all, "si"])
__version__ = '0.0.post1'
class AeroBinned(pybind11_builtins.pybind11_object):

Aerosol number and volume distributions stored per size bin. These quantities are densities both in volume (per m^3) and in radius (per log_width).

AeroBinned()

__init__(args, *kwargs) Overloaded function.

  1. __init__(self: _PyPartMC.AeroBinned, arg0: AeroData) -> None

  2. __init__(self: _PyPartMC.AeroBinned, arg0: AeroData, arg1: BinGrid) -> None

num_conc

(arg0: _PyPartMC.AeroBinned) -> List[float]

vol_conc

(arg0: _PyPartMC.AeroBinned) -> List[List[float]]

def add_aero_dist(unknown):

add_aero_dist(self: _PyPartMC.AeroBinned, arg0: BinGrid, arg1: AeroDist) -> None

Adds an AeroDist to an AeroBinned

class AeroData(pybind11_builtins.pybind11_object):

Aerosol material properties and associated data.

The data in this structure is constant, as it represents physical quantities that cannot change over time.

Each aerosol species is identified by an index i = 1,...,aero_data_n_spec(aero_data). Then \c name(i) is the name of that species, \c density(i) is its density, etc. The ordering of the species is arbitrary and should not be relied upon (currently it is the order in the species data file). The only exception is that it is possible to find out which species is water from the \c i_water variable.

The names of the aerosol species are not important to PartMC, as only the material properties are used. The names are used for input and output, and also for communication with MOSAIC. For the MOSAIC interface to work correctly the species must be named the same, but without the \c _a suffix.

AeroData()

__init__(self: _PyPartMC.AeroData, arg0: json) -> None

def spec_by_name(unknown):

spec_by_name(self: _PyPartMC.AeroData, arg0: str) -> int

Returns the number of the species in AeroData with the given name

n_source

(arg0: _PyPartMC.AeroData) -> int

sources

(arg0: _PyPartMC.AeroData) -> tuple

frac_dim

(arg0: _PyPartMC.AeroData) -> float

vol_fill_factor

(arg0: _PyPartMC.AeroData) -> float

prime_radius

(arg0: _PyPartMC.AeroData) -> float

densities

(arg0: _PyPartMC.AeroData) -> List[float]

kappa

(arg0: _PyPartMC.AeroData) -> List[float]

molecular_weights

(arg0: _PyPartMC.AeroData) -> List[float]

def density(unknown):

density(self: _PyPartMC.AeroData, arg0: str) -> float

Return density of an aerosol species

def rad2vol(unknown):

rad2vol(self: _PyPartMC.AeroData, arg0: float) -> float

Convert geometric radius (m) to mass-equivalent volume (m^3).

def vol2rad(unknown):

vol2rad(self: _PyPartMC.AeroData, arg0: float) -> float

Convert mass-equivalent volume (m^3) to geometric radius (m)

def diam2vol(unknown):

diam2vol(self: _PyPartMC.AeroData, arg0: float) -> float

Convert geometric diameter (m) to mass-equivalent volume (m^3).

def vol2diam(unknown):

vol2diam(self: _PyPartMC.AeroData, arg0: float) -> float

Convert mass-equivalent volume (m^3) to geometric diameter (m).

species

(arg0: _PyPartMC.AeroData) -> tuple

class AeroDist(pybind11_builtins.pybind11_object):
AeroDist()

__init__(self: _PyPartMC.AeroDist, arg0: _PyPartMC.AeroData, arg1: json) -> None

n_mode

(arg0: _PyPartMC.AeroDist) -> int

num_conc

(arg0: _PyPartMC.AeroDist) -> float

def mode(unknown):

mode(self: _PyPartMC.AeroDist, arg0: int) -> _PyPartMC.AeroMode

returns the mode of a given index

class AeroMode(pybind11_builtins.pybind11_object):
AeroMode()

__init__(self: _PyPartMC.AeroMode, arg0: _PyPartMC.AeroData, arg1: json) -> None

num_conc

(arg0: _PyPartMC.AeroMode) -> float

def num_dist(unknown):

num_dist(self: _PyPartMC.AeroMode, arg0: _PyPartMC.BinGrid, arg1: _PyPartMC.AeroData) -> List[float]

returns the binned number concenration of a mode

vol_frac

(arg0: _PyPartMC.AeroMode) -> List[float]

vol_frac_std

(arg0: _PyPartMC.AeroMode) -> List[float]

char_radius

(arg0: _PyPartMC.AeroMode) -> float

gsd

(arg0: _PyPartMC.AeroMode) -> float

def set_sample(unknown):

set_sample(self: _PyPartMC.AeroMode, arg0: List[float], arg1: List[float]) -> None

sample_num_conc

(arg0: _PyPartMC.AeroMode) -> List[float]

sample_radius

(arg0: _PyPartMC.AeroMode) -> List[float]

type

(arg0: _PyPartMC.AeroMode) -> str

name

(arg0: _PyPartMC.AeroMode) -> str

class AeroState(pybind11_builtins.pybind11_object):

The current collection of aerosol particles.

The particles in \c aero_state_t are stored in a single flat array (the \c apa data member), with a sorting into size bins and weight groups/classes possibly stored in the \c aero_sorted data member (if \c valid_sort is true).

Every time we remove particles we keep track of the particle ID and the action performed in the aero_info_array_t structure. This is typically cleared each time we output data to disk.

AeroState()

__init__(self: _PyPartMC.AeroState, arg0: _PyPartMC.AeroData, arg1: float, arg2: str) -> None

total_num_conc

(arg0: _PyPartMC.AeroState) -> float

total_mass_conc

(arg0: _PyPartMC.AeroState) -> float

num_concs

(arg0: _PyPartMC.AeroState) -> List[float]

def masses(unknown):

masses(self: _PyPartMC.AeroState, include: Optional[List[str]] = None, exclude: Optional[List[str]] = None) -> List[float]

returns the total mass of each particle in the population

def volumes(unknown):

volumes(self: _PyPartMC.AeroState, include: Optional[List[str]] = None, exclude: Optional[List[str]] = None) -> List[float]

returns the volume of each particle in the population

dry_diameters

(arg0: _PyPartMC.AeroState) -> List[float]

def mobility_diameters(unknown):

mobility_diameters(self: _PyPartMC.AeroState, arg0: EnvState) -> List[float]

returns the mobility diameter of each particle in the population

def diameters(unknown):

diameters(self: _PyPartMC.AeroState, include: Optional[List[str]] = None, exclude: Optional[List[str]] = None) -> List[float]

returns the diameter of each particle in the population

def crit_rel_humids(unknown):

crit_rel_humids(self: _PyPartMC.AeroState, arg0: EnvState) -> List[float]

returns the critical relative humidity of each particle in the population

def make_dry(unknown):

make_dry(self: _PyPartMC.AeroState) -> None

Make all particles dry (water set to zero).

ids

(arg0: _PyPartMC.AeroState) -> List[int]

def mixing_state(unknown):

mixing_state(self: _PyPartMC.AeroState, include: Optional[List[str]] = None, exclude: Optional[List[str]] = None, group: Optional[List[str]] = None) -> Tuple[float, float, float]

returns the mixing state parameters (d_alpha, d_gamma, chi) of the population

def bin_average_comp(unknown):

bin_average_comp(self: _PyPartMC.AeroState, arg0: BinGrid) -> None

composition-averages population using BinGrid

def particle(unknown):

particle(self: _PyPartMC.AeroState, arg0: int) -> _PyPartMC.AeroParticle

returns the particle of a given index

def rand_particle(unknown):

rand_particle(self: _PyPartMC.AeroState) -> _PyPartMC.AeroParticle

returns a random particle from the population

def dist_sample(unknown):

dist_sample(self: _PyPartMC.AeroState, AeroDist: AeroDist, sample_prop: float = 1.0, create_time: float = 0.0, allow_doubling: bool = True, allow_halving: bool = True) -> int

sample particles for AeroState from an AeroDist

def add_particle(unknown):

add_particle(self: _PyPartMC.AeroState, arg0: _PyPartMC.AeroParticle) -> None

add a particle to an AeroState

def add(unknown):

add(self: _PyPartMC.AeroState, arg0: _PyPartMC.AeroState) -> None

aero_state += aero_state_delta, including combining the weights, so the new concentration is the weighted average of the two concentrations.

def add_particles(unknown):

add_particles(self: _PyPartMC.AeroState, arg0: _PyPartMC.AeroState) -> None

aero_state += aero_state_delta, with the weight left unchanged so the new concentration is the sum of the two concentrations.

def sample(unknown):

sample(self: _PyPartMC.AeroState, arg0: _PyPartMC.AeroState, arg1: float) -> None

Generates a random sample by removing particles from aero_state_from and adding them to aero_state_to, transfering weight as well. This is the equivalent of aero_state_add().

def sample_particles(unknown):

sample_particles(self: _PyPartMC.AeroState, arg0: _PyPartMC.AeroState, arg1: float) -> None

!> Generates a random sample by removing particles from aero_state_from and adding them to aero_state_to, which must be already allocated (and should have its weight set).

       None of the weights are altered by this sampling, making this the
       equivalent of aero_state_add_particles().
def copy_weight(unknown):

copy_weight(self: _PyPartMC.AeroState, arg0: _PyPartMC.AeroState) -> None

copy weighting from another AeroState

def remove_particle(unknown):

remove_particle(self: _PyPartMC.AeroState, arg0: int) -> None

remove particle of a given index

def zero(unknown):

zero(self: _PyPartMC.AeroState) -> None

remove all particles from an AeroState

class AeroParticle(pybind11_builtins.pybind11_object):

Single aerosol particle data structure.

The \c vol array stores the total volumes of the different species that make up the particle. This array must have length equal to aero_data%%n_spec, so that \c vol(i) is the volume (in m^3) of the i'th aerosol species.

AeroParticle()

__init__(self: _PyPartMC.AeroParticle, arg0: _PyPartMC.AeroData, arg1: List[float]) -> None

volumes

(arg0: _PyPartMC.AeroParticle) -> List[float]

volume

(arg0: _PyPartMC.AeroParticle) -> float

def species_volume(unknown):

species_volume(args, *kwargs) Overloaded function.

  1. species_volume(self: _PyPartMC.AeroParticle, arg0: int) -> float

Volume of a single species in the particle (m^3).

  1. species_volume(self: _PyPartMC.AeroParticle, arg0: str) -> float

Volume of a single species in the particle (m^3).

dry_volume

(arg0: _PyPartMC.AeroParticle) -> float

radius

(arg0: _PyPartMC.AeroParticle) -> float

dry_radius

(arg0: _PyPartMC.AeroParticle) -> float

diameter

(arg0: _PyPartMC.AeroParticle) -> float

dry_diameter

(arg0: _PyPartMC.AeroParticle) -> float

mass

(arg0: _PyPartMC.AeroParticle) -> float

def species_mass(unknown):

species_mass(args, *kwargs) Overloaded function.

  1. species_mass(self: _PyPartMC.AeroParticle, arg0: int) -> float

Mass of a single species in the particle (kg).

  1. species_mass(self: _PyPartMC.AeroParticle, arg0: str) -> float

Mass of a single species in the particle (kg).

species_masses

(arg0: _PyPartMC.AeroParticle) -> List[float]

solute_kappa

(arg0: _PyPartMC.AeroParticle) -> float

moles

(arg0: _PyPartMC.AeroParticle) -> float

absorb_cross_sect

(arg0: _PyPartMC.AeroParticle) -> float

scatter_cross_sect

(arg0: _PyPartMC.AeroParticle) -> float

asymmetry

(arg0: _PyPartMC.AeroParticle) -> float

refract_shell

(arg0: _PyPartMC.AeroParticle) -> complex

refract_core

(arg0: _PyPartMC.AeroParticle) -> complex

sources

(arg0: _PyPartMC.AeroParticle) -> List[int]

least_create_time

(arg0: _PyPartMC.AeroParticle) -> float

greatest_create_time

(arg0: _PyPartMC.AeroParticle) -> float

id

(arg0: _PyPartMC.AeroParticle) -> int

def mobility_diameter(unknown):

mobility_diameter(self: _PyPartMC.AeroParticle, arg0: EnvState) -> float

Mobility diameter of the particle (m).

density

(arg0: _PyPartMC.AeroParticle) -> float

def approx_crit_rel_humid(unknown):

approx_crit_rel_humid(self: _PyPartMC.AeroParticle, arg0: EnvState) -> float

Returns the approximate critical relative humidity (1).

def crit_rel_humid(unknown):

crit_rel_humid(self: _PyPartMC.AeroParticle, arg0: EnvState) -> float

Returns the critical relative humidity (1).

def crit_diameter(unknown):

crit_diameter(self: _PyPartMC.AeroParticle, arg0: EnvState) -> float

Returns the critical diameter (m).

def coagulate(unknown):

coagulate(self: _PyPartMC.AeroParticle, arg0: _PyPartMC.AeroParticle) -> _PyPartMC.AeroParticle

Coagulate two particles together to make a new one. The new particle will not have its ID set.

def zero(unknown):

zero(self: _PyPartMC.AeroParticle) -> None

Resets an aero_particle to be zero.

def set_vols(unknown):

set_vols(self: _PyPartMC.AeroParticle, arg0: List[float]) -> None

Sets the aerosol particle volumes.

class BinGrid(pybind11_builtins.pybind11_object):
BinGrid()

__init__(self: _PyPartMC.BinGrid, arg0: float, arg1: str, arg2: float, arg3: float) -> None

edges

(arg0: _PyPartMC.BinGrid) -> List[float]

centers

(arg0: _PyPartMC.BinGrid) -> List[float]

widths

(arg0: _PyPartMC.BinGrid) -> List[float]

class CampCore(pybind11_builtins.pybind11_object):

An interface between PartMC and the CAMP

CampCore()

__init__(self: _PyPartMC.CampCore) -> None

class EnvState(pybind11_builtins.pybind11_object):

Current environment state.

All quantities are instantaneous, describing the state at a particular instant of time. Constant data and other data not associated with the current environment state is stored in scenario_t.

EnvState()

__init__(self: _PyPartMC.EnvState, arg0: json) -> None

def set_temperature(unknown):

set_temperature(self: _PyPartMC.EnvState, arg0: float) -> None

sets the temperature of the environment state

temp

(arg0: _PyPartMC.EnvState) -> float

rh

(arg0: _PyPartMC.EnvState) -> float

elapsed_time

(arg0: _PyPartMC.EnvState) -> float

start_time

(arg0: _PyPartMC.EnvState) -> float

height

(arg0: _PyPartMC.EnvState) -> float

pressure

(arg0: _PyPartMC.EnvState) -> float

air_density

(arg0: _PyPartMC.EnvState) -> float

additive_kernel_coefficient

(arg0: _PyPartMC.EnvState) -> float

class GasData(pybind11_builtins.pybind11_object):

Constant gas data.

Each gas species is identified by an integer \c i between 1 and \c gas_data_n_spec(gas_data). Species \c i has name \c gas_data%%name(i). The variable gas data describing the current mixing ratios is stored in the gas_state_t structure, so the mixing ratio of species \c i is gas_state%%mix_rat(i).

GasData()

__init__(self: _PyPartMC.GasData, arg0: tuple) -> None

n_spec

(arg0: _PyPartMC.GasData) -> int

def spec_by_name(unknown):

spec_by_name(self: _PyPartMC.GasData, arg0: str) -> int

returns the number of the species in gas with the given name

species

(arg0: _PyPartMC.GasData) -> tuple

class GasState(pybind11_builtins.pybind11_object):

Current state of the gas mixing ratios in the system.

The gas species are defined by the gas_data_t structure, so that \c gas_state%%mix_rat(i) is the current mixing ratio of the gas with name \c gas_data%%name(i), etc.

By convention, if gas_state_is_allocated() return \c .false., then the gas_state is treated as zero for all operations on it. This will be the case for new \c gas_state_t structures.

GasState()

__init__(self: _PyPartMC.GasState, arg0: _PyPartMC.GasData) -> None

instantiates and initializes based on GasData

n_spec

(arg0: _PyPartMC.GasState) -> int

def set_size(unknown):

set_size(self: _PyPartMC.GasState) -> None

sets the GasState to the size of GasData

def mix_rat(unknown):

mix_rat(self: _PyPartMC.GasState, arg0: str) -> float

returns the mixing ratio of a gas species

mix_rats

(arg0: _PyPartMC.GasState) -> List[float]

class Photolysis(pybind11_builtins.pybind11_object):

PartMC interface to a photolysis module

Photolysis()

__init__(self: _PyPartMC.Photolysis) -> None

class RunPartOpt(pybind11_builtins.pybind11_object):

Options controlling the execution of run_part().

RunPartOpt()

__init__(self: _PyPartMC.RunPartOpt, arg0: json) -> None

t_max

(arg0: _PyPartMC.RunPartOpt) -> float

del_t

(arg0: _PyPartMC.RunPartOpt) -> float

class RunSectOpt(pybind11_builtins.pybind11_object):

Options controlling the execution of run_sect().

RunSectOpt()

__init__(self: _PyPartMC.RunSectOpt, arg0: json, arg1: _PyPartMC.EnvState) -> None

t_max

(arg0: _PyPartMC.RunSectOpt) -> float

del_t

(arg0: _PyPartMC.RunSectOpt) -> float

class RunExactOpt(pybind11_builtins.pybind11_object):

Options controlling the execution of run_exact().

RunExactOpt()

__init__(self: _PyPartMC.RunExactOpt, arg0: json, arg1: _PyPartMC.EnvState) -> None

t_max

(arg0: _PyPartMC.RunExactOpt) -> float

class Scenario(pybind11_builtins.pybind11_object):

This is everything needed to drive the scenario being simulated.

The temperature, pressure, emissions and background states are profiles prescribed as functions of time by giving a number of times and the corresponding data. Simple data such as temperature and pressure is linearly interpolated between times, with constant interpolation outside of the range of times. Gases and aerosols are interpolated with gas_state_interp_1d() and aero_dist_interp_1d(), respectively.

Scenario()

__init__(self: _PyPartMC.Scenario, arg0: _PyPartMC.GasData, arg1: _PyPartMC.AeroData, arg2: json) -> None

instantiates and initializes from a JSON object

def init_env_state(unknown):

init_env_state(self: _PyPartMC.Scenario, arg0: _PyPartMC.EnvState, arg1: float) -> None

initializes the EnvState

def aero_emissions(unknown):

aero_emissions(self: _PyPartMC.Scenario, arg0: _PyPartMC.AeroData, arg1: int) -> AeroDist

returns aero_emissions AeroDists at a given index

aero_emissions_n_times

(arg0: _PyPartMC.Scenario) -> int

aero_emissions_rate_scale

(arg0: _PyPartMC.Scenario) -> List[float]

aero_emissions_time

(arg0: _PyPartMC.Scenario) -> List[float]

def aero_background(unknown):

aero_background(self: _PyPartMC.Scenario, arg0: _PyPartMC.AeroData, arg1: int) -> AeroDist

returns aero_background AeroDists at a given index

aero_dilution_n_times

(arg0: _PyPartMC.Scenario) -> int

aero_dilution_rate

(arg0: _PyPartMC.Scenario) -> List[float]

aero_dilution_time

(arg0: _PyPartMC.Scenario) -> List[float]

def condense_equilib_particles(unknown):

condense_equilib_particles(arg0: EnvState, arg1: AeroData, arg2: AeroState) -> None

Call condense_equilib_particle() on each particle in the aerosol to ensure that every particle has its water content in equilibrium.

def run_part(unknown):

run_part(arg0: Scenario, arg1: EnvState, arg2: AeroData, arg3: AeroState, arg4: GasData, arg5: GasState, arg6: RunPartOpt, arg7: CampCore, arg8: Photolysis) -> None

Do a particle-resolved Monte Carlo simulation.

def run_part_timeblock(unknown):

run_part_timeblock(arg0: Scenario, arg1: EnvState, arg2: AeroData, arg3: AeroState, arg4: GasData, arg5: GasState, arg6: RunPartOpt, arg7: CampCore, arg8: Photolysis, arg9: int, arg10: int, arg11: float, arg12: float, arg13: float, arg14: int) -> Tuple[float, float, int]

Do a time block

def run_part_timestep(unknown):

run_part_timestep(arg0: Scenario, arg1: EnvState, arg2: AeroData, arg3: AeroState, arg4: GasData, arg5: GasState, arg6: RunPartOpt, arg7: CampCore, arg8: Photolysis, arg9: int, arg10: float, arg11: float, arg12: float, arg13: int) -> Tuple[float, float, int]

Do a single time step

def run_sect(unknown):

run_sect(arg0: BinGrid, arg1: GasData, arg2: AeroData, arg3: AeroDist, arg4: Scenario, arg5: EnvState, arg6: RunSectOpt) -> None

Do a 1D sectional simulation (Bott 1998 scheme).

def run_exact(unknown):

run_exact(arg0: BinGrid, arg1: GasData, arg2: AeroData, arg3: AeroDist, arg4: Scenario, arg5: EnvState, arg6: RunExactOpt) -> None

Do an exact solution simulation.

def pow2_above(unknown):

pow2_above(arg0: int) -> int

Return the least power-of-2 that is at least equal to n.

def condense_equilib_particle(unknown):

condense_equilib_particle(arg0: EnvState, arg1: AeroData, arg2: AeroParticle) -> None

Determine the water equilibrium state of a single particle.

def histogram_1d(unknown):

histogram_1d(arg0: _PyPartMC.BinGrid, arg1: List[float], arg2: List[float]) -> List[float]

Return a 1D histogram with of the given weighted data, scaled by the bin sizes.

def histogram_2d(unknown):

histogram_2d(arg0: _PyPartMC.BinGrid, arg1: List[float], arg2: _PyPartMC.BinGrid, arg3: List[float], arg4: List[float]) -> List[List[float]]

Return a 2D histogram with of the given weighted data, scaled by the bin sizes.

def sphere_vol2rad(unknown):

sphere_vol2rad(arg0: float) -> float

Convert mass-equivalent volume (m^3) to geometric radius (m) for spherical particles.

def rad2diam(unknown):

rad2diam(arg0: float) -> float

Convert radius (m) to diameter (m).

def sphere_rad2vol(unknown):

sphere_rad2vol(arg0: float) -> float

Convert geometric radius (m) to mass-equivalent volume for spherical particles.

def diam2rad(unknown):

diam2rad(arg0: float) -> float

Convert diameter (m) to radius (m).

def loss_rate_dry_dep(unknown):

loss_rate_dry_dep(arg0: float, arg1: float, arg2: _PyPartMC.AeroData, arg3: _PyPartMC.EnvState) -> float

Compute and return the dry deposition rate for a given particle.

def loss_rate(unknown):

loss_rate(arg0: _PyPartMC.Scenario, arg1: float, arg2: float, arg3: _PyPartMC.AeroData, arg4: _PyPartMC.EnvState) -> float

Evaluate a loss rate function.

def output_state(unknown):

output_state(arg0: str, arg1: _PyPartMC.AeroData, arg2: _PyPartMC.AeroState, arg3: _PyPartMC.GasData, arg4: _PyPartMC.GasState, arg5: _PyPartMC.EnvState) -> None

Output current state to netCDF file.

def input_state(unknown):

input_state(arg0: str) -> Tuple[_PyPartMC.AeroData, _PyPartMC.AeroState, _PyPartMC.GasData, _PyPartMC.GasState, _PyPartMC.EnvState]

Read current state from run_part netCDF output file.

def input_sectional(unknown):

input_sectional(arg0: str) -> Tuple[_PyPartMC.AeroData, _PyPartMC.BinGrid, _PyPartMC.AeroBinned, _PyPartMC.GasData, _PyPartMC.GasState, _PyPartMC.EnvState]

Read current state from run_sect netCDF output file.

def input_exact(unknown):

input_exact(arg0: str) -> Tuple[_PyPartMC.AeroData, _PyPartMC.BinGrid, _PyPartMC.AeroBinned, _PyPartMC.GasData, _PyPartMC.GasState, _PyPartMC.EnvState]

Read current state from run_exact netCDF output file.

def rand_init(unknown):

rand_init(arg0: int) -> None

Initializes the random number generator to the state defined by the given seed. If the seed is 0 then a seed is auto-generated from the current time

def rand_normal(unknown):

rand_normal(arg0: float, arg1: float) -> float

Generates a normally distributed random number with the given mean and standard deviation

si = SI(Tm=1000000000000.0, Tg=1000000000.0, Ts=1000000000000.0, TK=1000000000000.0, TPa=1000000000000.0, Tmol=1000000000000.0, TW=1000000000000.0, TJ=1000000000000.0, TN=1000000000000.0, Gm=1000000000.0, Gg=1000000.0, Gs=1000000000.0, GK=1000000000.0, GPa=1000000000.0, Gmol=1000000000.0, GW=1000000000.0, GJ=1000000000.0, GN=1000000000.0, Mm=1000000.0, Mg=1000.0, Ms=1000000.0, MK=1000000.0, MPa=1000000.0, Mmol=1000000.0, MW=1000000.0, MJ=1000000.0, MN=1000000.0, km=1000.0, kg=1.0, ks=1000.0, kK=1000.0, kPa=1000.0, kmol=1000.0, kW=1000.0, kJ=1000.0, kN=1000.0, hm=100.0, hg=0.1, hs=100.0, hK=100.0, hPa=100.0, hmol=100.0, hW=100.0, hJ=100.0, hN=100.0, dam=10.0, dag=0.01, das=10.0, daK=10.0, daPa=10.0, damol=10.0, daW=10.0, daJ=10.0, daN=10.0, m=1.0, g=0.001, s=1.0, K=1.0, Pa=1.0, mol=1.0, W=1.0, J=1.0, N=1.0, dm=0.1, dg=0.0001, ds=0.1, dK=0.1, dPa=0.1, dmol=0.1, dW=0.1, dJ=0.1, dN=0.1, cm=0.01, cg=1e-05, cs=0.01, cK=0.01, cPa=0.01, cmol=0.01, cW=0.01, cJ=0.01, cN=0.01, mm=0.001, mg=1e-06, ms=0.001, mK=0.001, mPa=0.001, mmol=0.001, mW=0.001, mJ=0.001, mN=0.001, um=1e-06, ug=1e-09, us=1e-06, uK=1e-06, uPa=1e-06, umol=1e-06, uW=1e-06, uJ=1e-06, uN=1e-06, nm=1e-09, ng=1.0000000000000002e-12, ns=1e-09, nK=1e-09, nPa=1e-09, nmol=1e-09, nW=1e-09, nJ=1e-09, nN=1e-09, pm=1e-12, pg=1e-15, ps=1e-12, pK=1e-12, pPa=1e-12, pmol=1e-12, pW=1e-12, pJ=1e-12, pN=1e-12)

a utility namedtuple aimed at clrifying physics-related code by providing SI-prefix-aware unit multipliers, resulting in e.g.: p = 1000 * si.hPa notation. Note: no dimensional analysis is done!