Skip to main content

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.

Overview

PyMopsmap drives the MOPSMAP Fortran binary from Python. Given a set of aerosol microphysical parameters (shape, size distribution, refractive index), it:

  1. resolves and downloads the required optical dataset files,
  2. writes a MOPSMAP launch file and runs the binary,
  3. parses the outputs into an xarray-backed OptiProps object,
  4. caches the result on disk keyed by a blake2b hash of the inputs.

Requirements

  • Python ≥ 3.11 (managed via pixi)
  • MOPSMAP optical dataset — set PYMOPSMAP_DATASET_SOURCE to a local path or HTTP base URL

Installation

pixi install

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.

Dataset cache

Files are cached under ~/.cache/pymopsmap/ by default.

export PYMOPSMAP_DATASET_SOURCE=/path/to/optical_dataset
export PYMOPSMAP_CACHE_DIR=/custom/cache/dir   # optional
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

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pymopsmap-0.3.0.tar.gz (842.0 kB view details)

Uploaded Source

Built Distribution

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

pymopsmap-0.3.0-py3-none-any.whl (43.0 kB view details)

Uploaded Python 3

File details

Details for the file pymopsmap-0.3.0.tar.gz.

File metadata

  • Download URL: pymopsmap-0.3.0.tar.gz
  • Upload date:
  • Size: 842.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pymopsmap-0.3.0.tar.gz
Algorithm Hash digest
SHA256 597644d1afa3cae388e736bb55dd8123453b55898db5210bc115ff3d8242e907
MD5 d360d8b7663e415601a4313caf7441f9
BLAKE2b-256 fa058eca860f971d17ceb27ed36ac4552e015c8dec48438e1ba3fab00e259317

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymopsmap-0.3.0.tar.gz:

Publisher: publish.yml on walcark/pymopsmap

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

File details

Details for the file pymopsmap-0.3.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for pymopsmap-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c303b20aab20fd08e7984b562c3320e1fe45b1c905d0b7fd4a75e50bf46b212c
MD5 87be33a153a272da26a1442256025e55
BLAKE2b-256 e7cfcb04c4fb3a77b4b9211dc24f5bdfd714fc109b02f3eda961153ecede0a74

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymopsmap-0.3.0-py3-none-any.whl:

Publisher: publish.yml on walcark/pymopsmap

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