An atmospheric chemistry box model. Powered by MUSICA.
Project description
MusicBox
MusicBox: A MUSICA model for boxes and columns.
Copyright (C) 2020 National Science Foundation - National Center for Atmospheric Research
Installation
pip install acom_music_box
If you would like GPU support, you must first add the NVIDIA pypi index and then you can specify the gpu install option for music box.
pip install --upgrade setuptools pip wheel
pip install nvidia-pyindex
pip install acom_music_box[gpu]
Using the MusicBox API
MusicBox makes its chemical mechanism analysis and visualization available through a Python API. The following example works through solving a simple chemistry system. Please refer to the official documentation for further tutorials and examples.
# Import MusicBox, MusicBox conditions, and Musica mechanisms:
from acom_music_box import MusicBox, Conditions
import musica.mechanism_configuration as mc
# Define the chemical system of interest
# MusicBox uses Musica (https://ncar.github.io/musica/index.html) to create specific chemical species and phases of interest for chemical mechanisms.
A = mc.Species(name="A")
B = mc.Species(name="B")
C = mc.Species(name="C")
species = {"A":A, "B":B, "C":C}
gas = mc.Phase(name="gas", species=list(species.values()))
# Define a mechanism of interest
# Through Musica, several different mechanisms can be explored to define reaction rates. Here, we use the Arrhenius equation as a simple example.
arr1 = mc.Arrhenius(name="A->B", A=4.0e-3, C=50,reactants=[species["A"]], products=[species["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=[species["B"]], products=[species["C"]], gas_phase=gas)
mechanism = mc.Mechanism(name="test_mechanism", species=list(species.values()),phases=[gas], reactions=[arr1, arr2])
# Create a box model
# To create a box model, including its mechanisms, conditions, length, time, and step times:
box_model = MusicBox()
box_model.load_mechanism(mechanism)
# In the box model, the initial set of conditions represent the starting environment for the reactions.
# Both initial and evolving conditions are typically created alongside the creation of the box model:
box_model.initial_conditions = Conditions(temperature=300.0, pressure=101000.0, species_concentrations={ "A": 1.0, "B": 3.0, "C": 5.0})
# Evolving conditions represent a set of environmental and species values or rate constants that the box model should use at a specific time step.
# The following adds an evolving condition to the model, the first float represents the time when the condition evolves:
box_model.add_evolving_condition(300.0,Conditions(temperature=290.0, pressure=100200.0, species_concentrations={"A": 1.0, "B": 3.0, "C": 10.0}))
box_model.box_model_options.simulation_length = 20 # total simulation time
box_model.box_model_options.chem_step_time = 1 # time step for chemical reaction
box_model.box_model_options.output_step_time = 4 # time step between each output
# Solve your newly-created box model and view results:
df = box_model.solve()
print(df)
# To visualize specific 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 provides a command line tool that can run configurations as well as some pre-configured examples. Basic plotting can be done with matplotlib.
Checkout the command line options
music_box -h
Run an example. Notice that the output, in csv format, is printed to the terminal.
music_box -e Chapman
Output can be saved to a csv file (the default format) and printed to the terminal.
music_box -e Chapman -o output
Output can be saved to a csv file by specifying the .csv extension for Comma-Separated Values.
music_box -e Chapman -o output.csv
Output can be saved to a file as netcdf file by specifying the .nc file extension.
music_box -e Chapman -o output.nc
Output can be saved to a file in csv format when a filename is not specified. In this case a timestamped csv file is made.
music_box -e Chapman
You may also specify multiple output files with different formats, using the file extension.
music_box -e Analytical -o results.csv -o results.nc
You can also run your own configuration
music_box -c my_config.json
Plotting
Some basic plots can be made to show concentrations throughout the simulation using matplotlib.
music_box -e Chapman -o output.csv --plot O1D
You can also make multiple plots by specifying groupings of species
music_box -e TS1 --plot O3 --plot PAN,HF
Note that the windows may overlap each other
By default all plot units are in mol m-3. You can see a list of unit options to specify with --plot-output-unit
music_box -h
It is used like this
music_box -e TS1 --plot O3 --plot-output-unit "ppb"
Development and Contributing
For local development, install music-box as an editable installation:
pip install -e '.[dev]'
Tests
pytest
Tool: waccmToMusicBox
The python script waccmToMusicBox will extract concentrations of chemical species from WACCM and WRF-Chem, and write those values to initial conditions for MusicBox. Here are several examples of its use:
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'"
waccmToMusicBox --waccmDir ~/MusicBox/WACCM/model-output --musicaDir ~/MusicBox/WACCM/csvJsonDir --date 20240301 --time 07:00 --latitude "'-4.0,-2.0'" --longitude 101.0,103.0 --template ~/MusicBox/WACCM/templates/TS1 --output CSV,JSON --verbose
waccmToMusicBox --wrfchemDir ~/MusicBox/WRF-Chem/model-output --musicaDir ~/MusicBox/WRF-Chem/csvJsonDir --date 20250820 --time 08:00 --latitude 47.6 --longitude -122.325 --template ~/MusicBox/WRF-Chem/templates/TS1 --output CSV,JSON --verbose
Use the built-in help function to obtain a list of command-line parameters.
waccmToMusicBox --help
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-2.11.0.tar.gz.
File metadata
- Download URL: acom_music_box-2.11.0.tar.gz
- Upload date:
- Size: 64.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa7ae7e73b3f889ea3b8313c94bf76beade9b2eeda811d0ff1f9f1ebbbd98196
|
|
| MD5 |
8684d72e9a316f3c4ee588fe1fce0dcf
|
|
| BLAKE2b-256 |
8f92e9643af19662b3918ed2c12f4c419a90d6669d7ed747a48ef0a717c66012
|
Provenance
The following attestation bundles were made for acom_music_box-2.11.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-2.11.0.tar.gz -
Subject digest:
aa7ae7e73b3f889ea3b8313c94bf76beade9b2eeda811d0ff1f9f1ebbbd98196 - Sigstore transparency entry: 771494327
- Sigstore integration time:
-
Permalink:
NCAR/music-box@e26bd5cdacb9709eb2c1b6ba004f22a64cd51212 -
Branch / Tag:
refs/tags/v2.11.0 - Owner: https://github.com/NCAR
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-package.yml@e26bd5cdacb9709eb2c1b6ba004f22a64cd51212 -
Trigger Event:
release
-
Statement type:
File details
Details for the file acom_music_box-2.11.0-py3-none-any.whl.
File metadata
- Download URL: acom_music_box-2.11.0-py3-none-any.whl
- Upload date:
- Size: 75.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e24f42fbfbf02e4cd8a5647a474c46457568948a783a2f59b930dd113f15b76
|
|
| MD5 |
12fb1c824b71d03a0050c19073364a81
|
|
| BLAKE2b-256 |
77512c4a50712bdf773187466c8d73ea9faa4de837f295377b5a394190f39b23
|
Provenance
The following attestation bundles were made for acom_music_box-2.11.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-2.11.0-py3-none-any.whl -
Subject digest:
9e24f42fbfbf02e4cd8a5647a474c46457568948a783a2f59b930dd113f15b76 - Sigstore transparency entry: 771494330
- Sigstore integration time:
-
Permalink:
NCAR/music-box@e26bd5cdacb9709eb2c1b6ba004f22a64cd51212 -
Branch / Tag:
refs/tags/v2.11.0 - Owner: https://github.com/NCAR
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-package.yml@e26bd5cdacb9709eb2c1b6ba004f22a64cd51212 -
Trigger Event:
release
-
Statement type: