An atmospheric chemistry box model. Powered by MUSICA.
Project description
acom_music_box (Python)
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: modelToMusicBox
This tool allows you to extract chemical species concentrations from WACCM or WRF-Chem model output and write them as MusicBox initial conditions. Use the built-in help to display all options including template configurations and output files:
modelToMusicBox --help
You may specify a single point in space and date-time by passing single values to date, time, latitude, and longitude. Altitude defaults to the surface. You may also specify a rectangle or a cube by specifying pairs of values for latitude, longitude, and altitude. Use a lat-lon variable (PBLH) to bound the vertical dimension at a specific height. Run the following examples from the root level of your github repository, where you can see the sample_waccm_data/ sub-directory.
modelToMusicBox --waccmDir "./sample_waccm_data" --date "20260208" --time "06:00" --latitude 3.1 --longitude 101.7 --verbose
The command above should print two lines of Comma-Separated Values (CSV) to the console. Since this command is run with --verbose, you will see diagnostic output as well.
modelToMusicBox --wrfchemDir "./sample_waccm_data/20250820/wrf" --date "20250820" --time "08:00" --latitude 47.0,49.0 --longitude "'-123.0,-121.0'"
modelToMusicBox uses a MUSICA configuration file to create a list of common chemical species between MusicBox and WACCM or WRF-Chem. The default configuration file is in the ts1 example because that example has many species. Use the --template parameter to specify your own configuration file (usually my_config.json).
modelToMusicBox --wrfchemDir ./sample_waccm_data/20250820/wrf --date 20250820 --time 8:00 --latitude 47.0,49.0 --longitude "'-123.0,-121.0'" --altitude surface,PBLH --template ./examples/ts1 --output conditions/initial_conditions-wrfchem.csv --verbose
If you request a pair of dates and a pair of times, modelToMusicBox will create evolving conditions over time rather than initial conditions. You can expect to generate multiple rows of model output with time in the first column of the CSV file. For multiple date-times there is no time interpolation between the two date-times that you specify for evolving conditions. The script will simply extract variables at whatever model time steps are found between those two bounds.
modelToMusicBox --waccmDir ./sample_waccm_data --date 20260208,20260208 --time 00:00,23:00 --latitude "'-4.0,-2.0'" --longitude 101.0,103.0 --altitude 567.8,4567.8 --template ./examples/ts1 --output conditions/evolving_conditions-waccm.csv --verbose -v
When you specify waccmDir and wrfchemDir, modelToMusicBox will scan all the NetCDF files in that directory to determine the date-time steps that they contain. Then when you specify a date-time for the extraction, modelToMusicBox will look for the time step within 5 minutes of the requested date-time. If you specify a pair of date-times for evolving conditions, modelToMusicBox will use your date window and hour stride to locate the proper time steps. You may specify several directories to scan; for example, WRF-Chem forecast output is often saved into daily directories:
modelToMusicBox --wrfchemDir ./sample_waccm_data/20250820/wrf --wrfchemDir ./sample_waccm_data/20250821/wrf --date 20250820,20250821 --time 08:00,08:00 --stride 24 --latitude 47.0,49.0 --longitude "'-123.0,-121.0'" --template ./examples/ts1 --output conditions/evolving_conditions-wrfchem.csv --verbose
modelToMusicBox will also follow links to NetCDF files, in case you need to avoid copying multi-GB files around.
End-to-end example
In this section we will fully import initial conditions from WRF-Chem and evolving conditions from WACCM. We will run MusicBox after each step to ensure that the model conditions are indeed affecting the output. Begin this exercise with an up-to-date github repository, and move to that root level directory. We will copy sample configuration files into this root level; do not add them to the repository, but leave them Untracked in github.
cp examples/chapman/my_config.json .
cp examples/chapman/*.csv .
Produce MusicBox output from the standard example:
music_box --config my_config.json --output chapman-out-01.csv --verbose
You should now have a file of Comma-Separated-Values in your current directory: chapman-out-01.csv. Since the WRF-Chem Lambert Conformal grid takes longer to extract, let’s use that model for initial conditions and WACCM later for evolving conditions.
modelToMusicBox --template . --wrfchemDir sample_waccm_data/20250820/wrf --date 20250820 --time 08:00 --latitude 40.0 --longitude -105.27 --output initial_concentrations.csv --verbose
Look for a revised file named initial_concentrations.csv in your current directory. Run MusicBox with these new intial conditions derived from WRF-Chem model output.
music_box --config my_config.json --output chapman-out-02.csv --verbose
Use your favorite comparison tool (ls -l, diff, vim, spreadsheet, etc.) to confirm that the MusicBox output has indeed changed between Chapman output files 01 and 02. Then create evolving conditions (with multiple time steps) from WACCM:
modelToMusicBox --template . --waccmDir sample_waccm_data --date 20260208,20260208 --time 00:00,23:00 --stride 6 --latitude 40.0 --longitude -105.27 --output conditions_Boulder.csv --verbose
Run MusicBox with the new evolving conditions:
music_box --config my_config.json --output chapman-out-03.csv --verbose
Finally, confirm that Chapman output file 03 is different from the first two output files.
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
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 acom_music_box-3.1.0.tar.gz.
File metadata
- Download URL: acom_music_box-3.1.0.tar.gz
- Upload date:
- Size: 1.1 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dbdfaf83590935577c161303fa7c4214955bcc4729e543ef20d405fd60ff526b
|
|
| MD5 |
61c7a3e845743afcb689e8106bf71f42
|
|
| BLAKE2b-256 |
9a03821be8f7cad5067fce022548cc267d7cc57ebd6068ad31b86ada66d54a06
|
Provenance
The following attestation bundles were made for acom_music_box-3.1.0.tar.gz:
Publisher:
publish-package.yml on NCAR/music-box
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
acom_music_box-3.1.0.tar.gz -
Subject digest:
dbdfaf83590935577c161303fa7c4214955bcc4729e543ef20d405fd60ff526b - Sigstore transparency entry: 2048699202
- Sigstore integration time:
-
Permalink:
NCAR/music-box@a0a977a9dcdea9b70a2191c0073f119d7729fbdf -
Branch / Tag:
refs/tags/v3.1.0 - Owner: https://github.com/NCAR
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-package.yml@a0a977a9dcdea9b70a2191c0073f119d7729fbdf -
Trigger Event:
release
-
Statement type:
File details
Details for the file acom_music_box-3.1.0-py3-none-any.whl.
File metadata
- Download URL: acom_music_box-3.1.0-py3-none-any.whl
- Upload date:
- Size: 95.6 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 |
c94a1c7f527542b677d5d50a4416bdfdc207a7d84b648e84b76432a0695b5468
|
|
| MD5 |
a9d3fd1510987407b047f2b9bcfa0bf1
|
|
| BLAKE2b-256 |
e63c3e60eae65799e65c270dcd064a153953522c8d8ec7b5264b2d0b77482591
|
Provenance
The following attestation bundles were made for acom_music_box-3.1.0-py3-none-any.whl:
Publisher:
publish-package.yml on NCAR/music-box
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
acom_music_box-3.1.0-py3-none-any.whl -
Subject digest:
c94a1c7f527542b677d5d50a4416bdfdc207a7d84b648e84b76432a0695b5468 - Sigstore transparency entry: 2048699234
- Sigstore integration time:
-
Permalink:
NCAR/music-box@a0a977a9dcdea9b70a2191c0073f119d7729fbdf -
Branch / Tag:
refs/tags/v3.1.0 - Owner: https://github.com/NCAR
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-package.yml@a0a977a9dcdea9b70a2191c0073f119d7729fbdf -
Trigger Event:
release
-
Statement type: