Python wrapper for MOPSMAP aerosol optical properties computation
Project description
PyMopsmap
Python wrapper for MOPSMAP — aerosol optical property computation based on Mie, T-matrix, and DDA single-particle scattering (Gasteiger & Wiegner 2018, GMD).
Overview
PyMopsmap drives the MOPSMAP Fortran binary from Python. Given a set of aerosol microphysical parameters (shape, size distribution, refractive index), it:
- resolves and downloads the required optical dataset files,
- writes a MOPSMAP launch file and runs the binary,
- parses the outputs into an
xarray-backedOptiPropsobject, - caches the result on disk keyed by a blake2b hash of the inputs.
Installation
From PyPI
pip install pymopsmap
From source (development)
git clone https://github.com/walcark/pymopsmap.git
cd pymopsmap
pixi install -e dev
| Environment | Dev tools | Command |
|---|---|---|
default |
No | pixi install |
dev |
ruff, mypy, pytest | pixi install -e dev |
MOPSMAP binary
The MOPSMAP Fortran binary must be placed at bin/mopsmap/mopsmap relative to the repository root. Download it from mopsmap.net.
Optical dataset
MOPSMAP requires a pre-computed optical dataset. Set PYMOPSMAP_DATASET_SOURCE to a local path or HTTP base URL pointing to the dataset root:
export PYMOPSMAP_DATASET_SOURCE=/path/to/optical_dataset
# or
export PYMOPSMAP_DATASET_SOURCE=https://your-server.org/mopsmap_dataset
Dataset files are downloaded on demand and cached under ~/.cache/pymopsmap/ (override with PYMOPSMAP_CACHE_DIR).
Verify
pixi run -e dev python -c "import pymopsmap; print('pymopsmap OK')"
Quick start
import pymopsmap as pm
mp = pm.MicroParameters(
wavelength=[0.44, 0.55, 0.67],
n_real=[1.45, 1.45, 1.45],
n_imag=[1e-3, 1e-3, 1e-3],
shape=pm.Sphere(),
psd=pm.LognormalPSD(rm=0.1, sigma=1.5, n=1.0, rmin=0.01, rmax=10.0),
)
op = pm.compute(mp) # → OptiProps (xarray Dataset)
kext = pm.kext(mp) # → DataArray indexed by wavelength
Batch computation over external parameters
sweep = pm.ParametricSweep()
for rh, mp_rh in zip([0, 50, 80], [mp_rh0, mp_rh50, mp_rh80]):
sweep.add(pm.ParticleMixture([mp_rh]), {"rh": rh})
op = pm.compute(sweep) # → OptiProps with an extra 'rh' dimension
CAMS aerosol adapter
from pymopsmap.adapters import cams_to_kext, CamsAerosol, CamsVersion
kext = cams_to_kext(
aerosol=CamsAerosol.SEA_SALT_CAMS,
version=CamsVersion.V49_R1,
wl_microns=[0.44, 0.55, 0.67],
rh=[0, 50, 80, 99],
)
OPAC aerosol adapter
from pymopsmap.adapters.input.opac import OpacMix, OpacMixName, OpacHumidityMode
mix = OpacMix(OpacMixName.CONTINENTAL_AVERAGE)
# GEISA mode: wet PSD and refractive index interpolated from GEISA tables
op = mix.compute(wavelengths=[0.44, 0.55, 0.67], rhs=[0, 50, 80])
# Kappa mode: hygroscopic growth via κ parameterisation (Zieger et al. 2013)
# with volume-weighted refractive index mixing with water
op = mix.compute(
wavelengths=[0.44, 0.55, 0.67],
rhs=[0, 50, 80],
mode=OpacHumidityMode.KAPPA,
)
Output types
op = pm.compute(mp, output_types=frozenset({
pm.OutputType.INTEGRATED,
pm.OutputType.PHASE_FUNCTION,
pm.OutputType.LIDAR,
}))
Available: INTEGRATED, LIDAR, PHASE_FUNCTION, SCATTERING_MATRIX, VOLUME_SCATTERING_FUNCTION, COEFF.
Design philosophy
The adapter layer (adapters/input/) is designed for progressive extension. Each adapter translates an external aerosol description format — CAMS reanalysis tables, OPAC climatology, user-defined files — into the common MicroParameters + ParametricSweep representation that the engine consumes. Adding support for a new data source means implementing one adapter without touching the engine or the cache.
The same extensibility applies to output adapters (adapters/output/): once optical properties are computed as OptiProps, they can be converted to any downstream format (e.g. SMART-G LUT) by adding an output adapter.
Dataset cache
pm.cache_status(mp) # lists cached vs missing dataset files
pm.prefetch(mp) # download without computing
Project structure
src/pymopsmap/
├── models/ # MicroParameters, OptiProps, OutputRequest, particle systems
├── engine/ # MOPSMAP binary interface (launch file, runner, output parser)
├── cache/ # Optical dataset files and result cache
├── adapters/
│ ├── input/ # External data formats → MicroParameters (e.g. CAMS, OPAC)
│ └── output/ # OptiProps → external formats (e.g. SMART-G)
└── utils/ # Logging, types, temp files, caching
Roadmap
- Transparent remote dataset — automatic download of the full optical dataset from a hosted server when
PYMOPSMAP_DATASET_SOURCEis not set, removing the manual setup step. - Article validation — complete reproduction of the figures from Gasteiger & Wiegner (2018) as a test suite, ensuring physical correctness of the computed optical properties across all shape types and size parameters.
Development
pixi run -e dev test # pytest + coverage
pixi run -e dev lint # ruff
pixi run -e dev all # fmt + lint + type-check + test
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pymopsmap-0.3.1.tar.gz.
File metadata
- Download URL: pymopsmap-0.3.1.tar.gz
- Upload date:
- Size: 842.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d2abd6da16def068bed8b6cacf5a88f00ccd35177139ddb0d6edf8da1a049704
|
|
| MD5 |
a3a91a0541d03200aecd863aff3b9b8a
|
|
| BLAKE2b-256 |
f2e31768b27bd1e6984cbb9780b4f877764abd69fd63022b19c84dda18b7242a
|
Provenance
The following attestation bundles were made for pymopsmap-0.3.1.tar.gz:
Publisher:
publish.yml on walcark/pymopsmap
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pymopsmap-0.3.1.tar.gz -
Subject digest:
d2abd6da16def068bed8b6cacf5a88f00ccd35177139ddb0d6edf8da1a049704 - Sigstore transparency entry: 1506067007
- Sigstore integration time:
-
Permalink:
walcark/pymopsmap@a5fc00f6dba883a32f9fe6d03226a3cf18efd8bc -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/walcark
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a5fc00f6dba883a32f9fe6d03226a3cf18efd8bc -
Trigger Event:
release
-
Statement type:
File details
Details for the file pymopsmap-0.3.1-py3-none-any.whl.
File metadata
- Download URL: pymopsmap-0.3.1-py3-none-any.whl
- Upload date:
- Size: 43.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c7cc9bc2f7ddc48eadf04fdda685a413d6d1de5cd798c9a5b5e40d53ffdd9049
|
|
| MD5 |
6780e49d2fa93a3265ef7b8f766f7276
|
|
| BLAKE2b-256 |
82e98259ad03adce54e3d1b9d4c4a13350b42b05d577fd5f77a77ddcdbc2ea46
|
Provenance
The following attestation bundles were made for pymopsmap-0.3.1-py3-none-any.whl:
Publisher:
publish.yml on walcark/pymopsmap
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pymopsmap-0.3.1-py3-none-any.whl -
Subject digest:
c7cc9bc2f7ddc48eadf04fdda685a413d6d1de5cd798c9a5b5e40d53ffdd9049 - Sigstore transparency entry: 1506067081
- Sigstore integration time:
-
Permalink:
walcark/pymopsmap@a5fc00f6dba883a32f9fe6d03226a3cf18efd8bc -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/walcark
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a5fc00f6dba883a32f9fe6d03226a3cf18efd8bc -
Trigger Event:
release
-
Statement type: