pypartmc

Python (and C++) interface to PartMC with Jupyter/Python, Julia and Matlab examples

https://github.com/open-atmos/pypartmc

Science Score: 77.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 25 DOI reference(s) in README
  • Academic publication links
    Links to: zenodo.org
  • Committers with academic emails
    3 of 6 committers (50.0%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.5%) to scientific vocabulary

Keywords

aerosol-modelling atmospheric-modelling atmospheric-physics monte-carlo-simulation particle-system pybind11 python research simulation sundials

Scientific Fields

Materials Science Physical Sciences - 40% confidence
Last synced: 4 months ago · JSON representation ·

Repository

Python (and C++) interface to PartMC with Jupyter/Python, Julia and Matlab examples

Basic Info
Statistics
  • Stars: 30
  • Watchers: 5
  • Forks: 14
  • Open Issues: 56
  • Releases: 0
Topics
aerosol-modelling atmospheric-modelling atmospheric-physics monte-carlo-simulation particle-system pybind11 python research simulation sundials
Created about 4 years ago · Last pushed 4 months ago
Metadata Files
Readme Contributing License Code of conduct Citation Zenodo

README.md

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)

bash 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)

python ! 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: bash 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
  • Particle simulation with multiphase chemistry handled using CAMP (without coagulation):
    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

```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.m3, 0, 1e-3 *si.kg/si.mol, 0.001]}, {"BC": [1800 *si.kg/si.m*3, 0, 1e-3 *si.kg/si.mol, 0]}, ))

aerodist = ppmc.AeroDist( aerodata, [{ "cooking": { "massfrac": [{"OC": [1]}], "diamtype": "geometric", "modetype": "lognormal", "numconc": 3200 / si.cm**3, "geommeandiam": 8.64 * si.nm, "log10geomstddev": 0.28, }, "diesel": { "massfrac": [{"OC": [0.3]}, {"BC": [0.7]}], "diamtype": "geometric", "modetype": "lognormal", "numconc": 2900 / si.cm**3, "geommeandiam": 50 * si.nm, "log10geomstddev": 0.24, } }], )

npart = 100 aerostate = ppmc.AeroState(aerodata, npart, "nummasssource") aerostate.distsample(aerodist) print(np.dot(aerostate.masses(), aerostate.num_concs), "# kg/m3") ```

Julia (using PyCall.jl)

```Julia 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)) ))

aerodist = ppmc.AeroDist(aerodata, ( Dict( "cooking" => Dict( "massfrac" => (Dict("OC" => (1,)),), "diamtype" => "geometric", "modetype" => "lognormal", "numconc" => 3200 / si.cm^3, "geommeandiam" => 8.64 * si.nm, "log10geomstddev" => .28, ), "diesel" => Dict( "massfrac" => (Dict("OC" => (.3,)), Dict("BC" => (.7,))), "diamtype" => "geometric", "modetype" => "lognormal", "numconc" => 2900 / si.cm^3, "geommeandiam" => 50 * si.nm, "log10geomstddev" => .24, ) ), ))

npart = 100 aerostate = ppmc.AeroState(aerodata, npart, "nummasssource") aerostate.distsample(aerodist) print(aerostate.masses()'aerostate.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;

````Matlab ppmc = py.importlib.importmodule('PyPartMC'); si = py.importlib.importmodule('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}))) ... }));

aerodist = ppmc.AeroDist(aerodata, py.tuple({ ... py.dict(pyargs( ... "cooking", py.dict(pyargs( ... "massfrac", py.tuple({py.dict(pyargs("OC", py.tuple({1})))}), ... "diamtype", "geometric", ... "modetype", "lognormal", ... "numconc", 3200 / si.cm^3, ... "geommeandiam", 8.64 * si.nm, ... "log10geomstddev", .28 ... )), ... "diesel", py.dict(pyargs( ... "massfrac", py.tuple({ ... py.dict(pyargs("OC", py.tuple({.3}))), ... py.dict(pyargs("BC", py.tuple({.7}))), ... }), ... "diamtype", "geometric", ... "modetype", "lognormal", ... "numconc", 2900 / si.cm^3, ... "geommeandiam", 50 * si.nm, ... "log10geomstddev", .24 ... )) ... )) ... }));

npart = 100; aerostate = ppmc.AeroState(aerodata, npart, "nummasssource"); aerostate.distsample(aerodist); masses = cell(aerostate.masses()); numconcs = cell(aerostate.numconcs); 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: bash 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: Python 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

Owner

  • Name: open-atmos
  • Login: open-atmos
  • Kind: organization

Citation (CITATION.cff)

cff-version: 1.2.0
title: "PyPartMC"
url: "https://github.com/open-atmos/PyPartMC"
preferred-citation:
  type: article
  authors:
  - family-names: "D'Aquino"
    given-names: "Zachary"
    orcid: "https://orcid.org/0000-0002-4712-8015"
  - family-names: "Arabas"
    given-names: "Sylwester"
    orcid: "https://orcid.org/0000-0003-2361-0082"
  - family-names: "Curtis"
    given-names: "Jeffrey"
    orcid: "https://orcid.org/0000-0002-1447-2127"
  - family-names: "Vaishnav"
    given-names: "Akshunna"
  - family-names: "Riemer"
    given-names: "Nicole"
    orcid: "https://orcid.org/0000-0002-3220-3457"
  - family-names: "West"
    given-names: "Matthew"
  doi: "10.1016/j.softx.2023.101613"
  journal: "SoftwareX"
  title: "PyPartMC: A Pythonic interface to a particle-resolved, Monte Carlo aerosol simulation framework"
  year: 2024

GitHub Events

Total
  • Create event: 53
  • Release event: 23
  • Issues event: 41
  • Watch event: 4
  • Delete event: 11
  • Member event: 1
  • Issue comment event: 97
  • Push event: 97
  • Pull request review event: 19
  • Pull request review comment event: 4
  • Pull request event: 84
  • Fork event: 4
Last Year
  • Create event: 53
  • Release event: 23
  • Issues event: 41
  • Watch event: 4
  • Delete event: 11
  • Member event: 1
  • Issue comment event: 97
  • Push event: 97
  • Pull request review event: 19
  • Pull request review comment event: 4
  • Pull request event: 84
  • Fork event: 4

Committers

Last synced: almost 2 years ago

All Time
  • Total Commits: 558
  • Total Committers: 6
  • Avg Commits per committer: 93.0
  • Development Distribution Score (DDS): 0.296
Past Year
  • Commits: 79
  • Committers: 4
  • Avg Commits per committer: 19.75
  • Development Distribution Score (DDS): 0.494
Top Committers
Name Email Commits
Sylwester Arabas s****s@u****l 393
Jeff Curtis j****2@i****u 58
Zach D'Aquino z****2@g****m 57
Sylwester Arabas s****s@a****l 40
Zach D'Aquino 1****2 9
Juyoung Choi 7****5 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 4 months ago

All Time
  • Total issues: 143
  • Total pull requests: 217
  • Average time to close issues: 9 months
  • Average time to close pull requests: 15 days
  • Total issue authors: 7
  • Total pull request authors: 10
  • Average comments per issue: 3.64
  • Average comments per pull request: 1.77
  • Merged pull requests: 178
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 18
  • Pull requests: 75
  • Average time to close issues: about 1 month
  • Average time to close pull requests: 12 days
  • Issue authors: 4
  • Pull request authors: 7
  • Average comments per issue: 0.39
  • Average comments per pull request: 1.27
  • Merged pull requests: 57
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • slayoo (122)
  • jcurtis2 (14)
  • Griger5 (2)
  • zdaq12 (1)
  • leeanne2 (1)
  • emmacware (1)
  • AgnieszkaZaba (1)
Pull Request Authors
  • slayoo (179)
  • jcurtis2 (39)
  • emmacware (11)
  • zdaq12 (10)
  • Griger5 (4)
  • klee-48 (2)
  • xemlock (2)
  • AgnieszkaZaba (2)
  • jchoi25 (1)
  • a-v (1)
Top Labels
Issue Labels
no-issue-activity (25) no-activity (8) good first issue (6) help wanted (4) enhancement (1) bug (1)
Pull Request Labels
no-activity (3) no-pr-activity (2)

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 14,134 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 80
  • Total maintainers: 2
pypi.org: pypartmc

Python interface to PartMC

  • Versions: 80
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 14,134 Last month
Rankings
Downloads: 4.9%
Dependent packages count: 6.6%
Forks count: 14.5%
Average: 14.9%
Stargazers count: 17.9%
Dependent repos count: 30.6%
Maintainers (2)
Last synced: 4 months ago

Dependencies

.github/workflows/pdoc.yml actions
  • JamesIves/github-pages-deploy-action 4.1.1 composite
  • actions/checkout v2 composite
  • actions/setup-python v2 composite
.github/workflows/pre-commit.yml actions
  • actions/checkout v2 composite
  • actions/setup-python v1 composite
.github/workflows/cancel.yml actions
  • styfle/cancel-workflow-action 0.9.1 composite
.github/workflows/conda.yml actions
  • actions/checkout v3 composite
  • conda-incubator/setup-miniconda v2 composite
.github/workflows/cpplint.yml actions
  • smay1613/clang-tidy-action master composite
.github/workflows/forlint.yml actions
  • NOAA-GFDL/simple_lint v3 composite
  • actions/checkout v2 composite
.github/workflows/pylint.yml actions
  • actions/checkout v2 composite
  • actions/setup-python v2 composite
.github/workflows/stale.yml actions
  • actions/stale v3 composite
setup.py pypi
  • numpy *
.github/workflows/readme_listings.yml actions
  • actions/checkout v2 composite
  • actions/download-artifact v2 composite
  • actions/setup-python v1 composite
  • actions/setup-python v2 composite
  • actions/upload-artifact v2 composite
  • julia-actions/setup-julia v1 composite
  • jwlawson/actions-setup-cmake v1.13 composite
  • matlab-actions/run-command v0 composite
  • matlab-actions/setup-matlab v0 composite
.github/workflows/tests+pypi.yml actions
  • RalfG/python-wheels-manylinux-build v0.7.1-manylinux_2_24_x86_64 composite
  • RalfG/python-wheels-manylinux-build v0.7.1-manylinux2010_x86_64 composite
  • actions/checkout v2 composite
  • actions/download-artifact v2 composite
  • actions/setup-python v1 composite
  • actions/setup-python v2 composite
  • actions/upload-artifact v2 composite
  • jwlawson/actions-setup-cmake v1.13 composite
  • msys2/setup-msys2 v2 composite
  • notiz-dev/github-action-json-property release composite
  • pypa/gh-action-pypi-publish unstable/v1 composite
.binder/requirements.txt pypi
  • PyPartMC >=0.0.19
  • PySDM *
  • ipywidgets *
  • matplotlib *
  • open-atmos-jupyter-utils *
  • voila *