Skip to main content

An atmospheric chemistry box model. Powered by MUSICA.

Project description

acom_music_box (Python)

CI Tests codecov PyPI version Binder

Python implementation of the MusicBox atmospheric chemistry box model, built on the MUSICA framework.

Installation

pip install acom_music_box

GPU Support

GPU-accelerated solving requires the NVIDIA PyPI index:

pip install --upgrade setuptools pip wheel
pip install nvidia-pyindex
pip install acom_music_box[gpu]

Quick Start

In-code mechanism

Define species, reactions, and initial conditions entirely in Python:

from acom_music_box import MusicBox, Conditions
import musica.mechanism_configuration as mc

# Define species
A = mc.Species(name="A")
B = mc.Species(name="B")
C = mc.Species(name="C")

gas = mc.Phase(name="gas", species=[A, B, C])

# Define reactions
arr1 = mc.Arrhenius(name="A->B", A=4.0e-3, C=50, reactants=[A], products=[B], gas_phase=gas)
arr2 = mc.Arrhenius(name="B->C", A=1.2e-4, B=2.5, C=75, D=50, E=0.5, reactants=[B], products=[C], gas_phase=gas)

mechanism = mc.Mechanism(name="example", species=[A, B, C], phases=[gas], reactions=[arr1, arr2])

# Create and configure the box model
box = MusicBox()
box.load_mechanism(mechanism)

box.initial_conditions = Conditions(
    temperature=300.0,
    pressure=101000.0,
    species_concentrations={"A": 1.0, "B": 3.0, "C": 5.0},
)

# Optionally add evolving conditions at a specific time (seconds)
box.add_evolving_condition(300.0, Conditions(
    temperature=290.0,
    pressure=100200.0,
    species_concentrations={"A": 1.0, "B": 3.0, "C": 10.0},
))

box.box_model_options.simulation_length = 20   # seconds
box.box_model_options.chem_step_time = 1       # seconds
box.box_model_options.output_step_time = 4     # seconds

df = box.solve()
print(df)

From a JSON configuration file

Load a music-box v1 JSON config from disk:

from acom_music_box import MusicBox

box = MusicBox()
box.readConditionsFromJson("my_config.json")
df = box.solve()
print(df)

Plotting results

import matplotlib.pyplot as plt

df.plot(
    x='time.s',
    y=['CONC.A.mol m-3', 'CONC.B.mol m-3', 'CONC.C.mol m-3'],
    title='Concentration over time',
    ylabel='Concentration (mol m-3)',
    xlabel='Time (s)',
)
plt.show()

Command Line Tool

MusicBox includes a music_box CLI for running configurations and built-in examples.

music_box -h

Run a built-in example (output printed to terminal as CSV):

music_box -e Chapman

Save output to a file:

music_box -e Chapman -o output.csv
music_box -e Chapman -o output.nc        # NetCDF format
music_box -e Analytical -o results.csv -o results.nc   # multiple outputs

Run your own configuration:

music_box -c my_config.json

Plotting from the CLI

Plot species concentrations using matplotlib:

music_box -e Chapman -o output.csv --plot O1D

Plot multiple species groups:

music_box -e TS1 --plot O3 --plot PAN,HF

Change output units (default is mol m-3):

music_box -e TS1 --plot O3 --plot-output-unit ppb

Tool: waccmToMusicBox

Extract chemical species concentrations from WACCM or WRF-Chem output and write them as MusicBox initial conditions:

waccmToMusicBox --waccmDir "./sample_waccm_data" --date "20240904" --time "07:00" --latitude 3.1 --longitude 101.7

waccmToMusicBox --wrfchemDir "./sample_waccm_data" --date "20250820" --time "08:00" --latitude 47.0,49.0 --longitude "'-123.0,-121.0'"

For advanced options including template configs and multiple output formats:

waccmToMusicBox --help

Development

Install as an editable package with dev dependencies:

pip install -e '.[dev]'

Run the test suite:

pytest

Run only unit or integration tests:

pytest python/tests/unit/
pytest python/tests/integration/

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

acom_music_box-3.0.1.tar.gz (809.6 kB view details)

Uploaded Source

Built Distribution

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

acom_music_box-3.0.1-py3-none-any.whl (89.7 kB view details)

Uploaded Python 3

File details

Details for the file acom_music_box-3.0.1.tar.gz.

File metadata

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

File hashes

Hashes for acom_music_box-3.0.1.tar.gz
Algorithm Hash digest
SHA256 ad0963a3236fb9b3fe110f86d7e81b6db8222ad7cf324ba8c0840effe2961885
MD5 17ab04ec83b59499a54980b3ab13cd02
BLAKE2b-256 d4a89dbff8215b55f3722cec2cba2988deccb41a61fc3e7e6f8ea8f97f30cb64

See more details on using hashes here.

Provenance

The following attestation bundles were made for acom_music_box-3.0.1.tar.gz:

Publisher: publish-package.yml on NCAR/music-box

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

File details

Details for the file acom_music_box-3.0.1-py3-none-any.whl.

File metadata

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

File hashes

Hashes for acom_music_box-3.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4f23174764e8f63951d8f5b556a6e8266bdbf624fff265f686941d039d514dea
MD5 c36dd60a7a87c378ac889c8ceca663a7
BLAKE2b-256 bebbe3376fe805e9521857a83d6928a13765881c202a0bca2c11f5ae5bfe29c0

See more details on using hashes here.

Provenance

The following attestation bundles were made for acom_music_box-3.0.1-py3-none-any.whl:

Publisher: publish-package.yml on NCAR/music-box

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