Skip to content

Commit 95da826

Browse files
authored
Merge pull request #344 from NCAR/main
Version 2.8.1
2 parents fb42162 + 9613c00 commit 95da826

37 files changed

+1565
-112
lines changed

.github/workflows/docker_tests.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ jobs:
2121
os: [ubuntu-latest]
2222
dockerfile:
2323
- Dockerfile
24-
build_type: [Release, Debug]
2524
steps:
2625
- name: Checkout code
2726
uses: actions/checkout@v4
@@ -32,7 +31,7 @@ jobs:
3231
run: rm -rf /opt/hostedtoolcache
3332

3433
- name: Build Docker image
35-
run: docker build -t music-box -f docker/${{ matrix.dockerfile }} . --build-arg MUSIC_BOX_GIT_TAG=${{ github.sha }} --build-arg BUILD_TYPE=${{ matrix.build_type }}
34+
run: docker build -t music-box -f docker/${{ matrix.dockerfile }} . --build-arg MUSIC_BOX_GIT_TAG=${{ github.sha }}
3635

3736
- name: Run tests in container
3837
run: docker run --name test-container -t music-box

.github/workflows/gh_pages.yml

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ name: GitHub Pages
33

44
on:
55
push:
6-
branches:
7-
- main
86
pull_request:
97
workflow_dispatch:
108

@@ -86,18 +84,25 @@ jobs:
8684
# _gh-pages/branch/$brname (transforming '/' into '--')
8785
- name: Build and copy documentation (branch)
8886
if: |
89-
contains(github.event_name, 'push') &&
87+
(contains(github.event_name, 'push') ||
88+
contains(github.event_name, 'pull_request')) &&
9089
!contains(github.ref, env.DEFAULT_BRANCH)
9190
run: |
9291
set -x
9392
docker build -t music_box -f docker/Dockerfile.docs .
9493
id=$(docker create music_box)
9594
docker cp $id:/music-box/docs/build/html tmpdocs
9695
docker rm -v $id
97-
brname="${{github.ref}}"
98-
brname="${brname##refs/heads/}"
96+
# Determine branch name for deployment directory
97+
if [ "${{ github.event_name }}" = "pull_request" ]; then
98+
brname="${{ github.head_ref }}"
99+
else
100+
brname="${{ github.ref }}"
101+
brname="${brname##refs/heads/}"
102+
fi
99103
brdir=${brname//\//--} # replace '/' with '--'
100104
rm -rf _gh-pages/branch/${brdir}
105+
mkdir -p _gh-pages/branch/${brdir}
101106
rsync -a tmpdocs/ _gh-pages/branch/${brdir}
102107
103108
# Go through each branch in _gh-pages/branch/, if it's not a
@@ -129,4 +134,23 @@ jobs:
129134
publish_branch: gh-pages
130135
github_token: ${{ secrets.GITHUB_TOKEN }}
131136
publish_dir: _gh-pages/
132-
force_orphan: true
137+
force_orphan: true
138+
139+
comment-doc-link:
140+
name: Comment documentation link on PR
141+
if: ${{ github.event_name == 'pull_request' && github.event.action == 'opened' }}
142+
runs-on: ubuntu-latest
143+
steps:
144+
- name: Post documentation link
145+
uses: actions/github-script@v6
146+
with:
147+
script: |
148+
const branchName = context.payload.pull_request.head.ref;
149+
const docLink = `https://ncar.github.io/music-box/branch/${branchName}/`;
150+
const commentBody = `📄 Documentation for this branch is available at: [${docLink}](${docLink})`;
151+
await github.rest.issues.createComment({
152+
owner: context.repo.owner,
153+
repo: context.repo.repo,
154+
issue_number: context.payload.pull_request.number,
155+
body: commentBody
156+
});

README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,76 @@ Copyright (C) 2020 National Science Foundation - National Center for Atmospheric
1616
# Installation
1717
```
1818
pip install acom-music-box
19+
```
20+
# Using the MusicBox API
21+
22+
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](https://ncar.github.io/music-box/branch/main/index.html) for further tutorials and examples.
23+
```
24+
# Import MusicBox, MusicBox conditions, and Musica mechanisms:
25+
26+
from acom_music_box import MusicBox, Conditions
27+
import musica.mechanism_configuration as mc
28+
29+
30+
# Define the chemical system of interest
31+
32+
# MusicBox uses Musica (https://ncar.github.io/musica/index.html) to create specific chemical species and phases of interest for chemical mechanisms.
33+
34+
A = mc.Species(name="A")
35+
B = mc.Species(name="B")
36+
C = mc.Species(name="C")
37+
38+
species = {"A":A, "B":B, "C":C}
39+
40+
gas = mc.Phase(name="gas", species=list(species.values()))
41+
42+
# Define a mechanism of interest
43+
44+
# Through Musica, several different mechanisms can be explored to define reaction rates. Here, we use the Arrhenius equation as a simple example.
45+
46+
arr1 = mc.Arrhenius(name="A->B", A=4.0e-3, C=50,reactants=[species["A"]], products=[species["B"]], gas_phase=gas)
47+
48+
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)
49+
50+
mechanism = mc.Mechanism(name="test_mechanism", species=list(species.values()),phases=[gas], reactions=[arr1, arr2])
51+
52+
53+
# Create a box model
54+
55+
# To create a box model, including its mechanisms, conditions, length, time, and step times:
56+
57+
box_model = MusicBox()
58+
box_model.load_mechanism(mechanism)
59+
60+
61+
# In the box model, the initial set of conditions represent the starting environment for the reactions.
62+
# Both initial and evolving conditions are typically created alongside the creation of the box model:
63+
64+
box_model.initial_conditions = Conditions(temperature=300.0, pressure=101000.0, species_concentrations={ "A": 1.0, "B": 3.0, "C": 5.0})
65+
66+
67+
# Evolving conditions represent a set of environmental and species values or rate constants that the box model should use at a specific time step.
68+
# The following adds an evolving condition to the model, the first float represents the time when the condition evolves:
69+
70+
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}))
71+
72+
box_model.box_model_options.simulation_length = 20 # total simulation time
73+
box_model.box_model_options.chem_step_time = 1 # time step for chemical reaction
74+
box_model.box_model_options.output_step_time = 4 # time step between each output
75+
76+
77+
# Solve your newly-created box model and view results:
78+
79+
df = box_model.solve()
80+
print(df)
81+
82+
# To visualize specific results:
83+
84+
import matplotlib.pyplot as plt
85+
86+
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)')
87+
plt.show()
88+
1989
```
2090

2191
# Command line tool

docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM fedora:latest
22

33
ARG MUSIC_BOX_TAG=main
4-
ARG MUSICA_TAG=v0.11.1
4+
ARG MUSICA_TAG=v0.11.1.4
55

66
RUN dnf -y update \
77
&& dnf -y install \

docker/Dockerfile.docs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ RUN dnf -y update \
66
gcc \
77
gcc-c++ \
88
make \
9+
pandoc \
910
python3-devel \
1011
python3-pip \
1112
&& dnf clean all
@@ -14,6 +15,7 @@ COPY . /music-box/
1415

1516
WORKDIR /music-box
1617

18+
1719
RUN pip3 install -e .
1820

1921
ARG SUFFIX=""
@@ -23,4 +25,4 @@ RUN echo "The suffix is '$SWITCHER_SUFFIX'"
2325

2426
RUN cd docs \
2527
&& pip install -r requirements.txt \
26-
&& make html
28+
&& make html

docs/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ sphinx
22
sphinx-book-theme
33
sphinx-copybutton
44
sphinx-design
5-
sphinxcontrib-bibtex
5+
sphinxcontrib-bibtex
6+
pydata-sphinx-theme

docs/source/_static/custom.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,16 @@
55
margin-right: auto;
66
margin-top: 10px;
77
}
8+
9+
/* Hide input prompts (e.g., In [1]:) */
10+
div.nbinput .prompt,
11+
div.nboutput .prompt {
12+
display: none;
13+
}
14+
15+
/* Ensure full-width appearance for all code cells */
16+
div.nbinput pre,
17+
div.nboutput pre {
18+
white-space: pre-wrap;
19+
word-break: break-word;
20+
}

docs/source/_static/switcher.json

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
11
[
2-
{
3-
"name": "dev",
4-
"version": "dev",
5-
"url": "https://ncar.github.io/music-box/branch/main/"
6-
}
2+
{
3+
"name": "v2.8.0 (stable)",
4+
"version": "2.8.0",
5+
"url": "https://ncar.github.io/music-box"
6+
},
7+
{
8+
"name": "v2.7.0 (stable)",
9+
"version": "v2.7.0 (stable)",
10+
"url": "https://ncar.github.io/music-box/versions/2.7.0"
11+
},
12+
{
13+
"name": "v2.6.0",
14+
"version": "v2.6.0",
15+
"url": "https://ncar.github.io/music-box/versions/2.6.0"
16+
},
17+
{
18+
"name": "dev",
19+
"version": "dev",
20+
"url": "https://ncar.github.io/music-box/branch/main/"
21+
}
722
]

docs/source/api/acom_music_box.rst

Lines changed: 16 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
MusicBox
22
========
33

4-
Submodules
5-
----------
4+
.. automodule:: acom_music_box
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
68

79
acom\_music\_box.music\_box module
810
----------------------------------
@@ -12,90 +14,42 @@ acom\_music\_box.music\_box module
1214
:undoc-members:
1315
:show-inheritance:
1416

15-
acom\_music\_box.music\_box\_conditions module
17+
acom\_music\_box.conditions module
1618
----------------------------------------------
1719

18-
.. automodule:: acom_music_box.music_box_conditions
20+
.. automodule:: acom_music_box.conditions
1921
:members:
2022
:undoc-members:
2123
:show-inheritance:
2224

23-
acom\_music\_box.music\_box\_evolving\_conditions module
25+
acom\_music\_box.evolving\_conditions module
2426
--------------------------------------------------------
2527

26-
.. automodule:: acom_music_box.music_box_evolving_conditions
27-
:members:
28-
:undoc-members:
29-
:show-inheritance:
30-
31-
acom\_music\_box.music\_box\_model\_options module
32-
--------------------------------------------------
33-
34-
.. automodule:: acom_music_box.music_box_model_options
35-
:members:
36-
:undoc-members:
37-
:show-inheritance:
38-
39-
acom\_music\_box.music\_box\_product module
40-
-------------------------------------------
41-
42-
.. automodule:: acom_music_box.music_box_product
28+
.. automodule:: acom_music_box.evolving_conditions
4329
:members:
4430
:undoc-members:
4531
:show-inheritance:
4632

47-
acom\_music\_box.music\_box\_reactant module
48-
--------------------------------------------
49-
50-
.. automodule:: acom_music_box.music_box_reactant
51-
:members:
52-
:undoc-members:
53-
:show-inheritance:
54-
55-
acom\_music\_box.music\_box\_reaction module
56-
--------------------------------------------
33+
acom\_music\_box.data\_output module
34+
----------------------------------------------
5735

58-
.. automodule:: acom_music_box.music_box_reaction
36+
.. automodule:: acom_music_box.data_output
5937
:members:
6038
:undoc-members:
6139
:show-inheritance:
6240

63-
acom\_music\_box.music\_box\_reaction\_list module
64-
--------------------------------------------------
41+
acom\_music\_box.plot_output module
42+
----------------------------------------------
6543

66-
.. automodule:: acom_music_box.music_box_reaction_list
44+
.. automodule:: acom_music_box.plot_output
6745
:members:
6846
:undoc-members:
6947
:show-inheritance:
7048

71-
acom\_music\_box.music\_box\_reaction\_rate module
49+
acom\_music\_box.model\_options module
7250
--------------------------------------------------
7351

74-
.. automodule:: acom_music_box.music_box_reaction_rate
75-
:members:
76-
:undoc-members:
77-
:show-inheritance:
78-
79-
acom\_music\_box.music\_box\_species module
80-
-------------------------------------------
81-
82-
.. automodule:: acom_music_box.music_box_species
83-
:members:
84-
:undoc-members:
85-
:show-inheritance:
86-
87-
acom\_music\_box.music\_box\_species\_concentration module
88-
----------------------------------------------------------
89-
90-
.. automodule:: acom_music_box.music_box_species_concentration
91-
:members:
92-
:undoc-members:
93-
:show-inheritance:
94-
95-
acom\_music\_box.music\_box\_species\_list module
96-
-------------------------------------------------
97-
98-
.. automodule:: acom_music_box.music_box_species_list
52+
.. automodule:: acom_music_box.model_options
9953
:members:
10054
:undoc-members:
10155
:show-inheritance:
@@ -108,10 +62,3 @@ acom\_music\_box.utils module
10862
:undoc-members:
10963
:show-inheritance:
11064

111-
Module contents
112-
---------------
113-
114-
.. automodule:: acom_music_box
115-
:members:
116-
:undoc-members:
117-
:show-inheritance:

docs/source/api/index.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
###
2-
API
3-
###
1+
###############
2+
API Reference
3+
###############
4+
5+
This documentation describes the Python API for MusicBox.
6+
For detailed information on the chemistry-related objects and reaction definitions used in MusicBox via MUSICA, see the :mod:`musica.mechanism_configuration`
47

58
.. toctree::
69
:maxdepth: 4
710

8-
acom_music_box
11+
acom_music_box

0 commit comments

Comments
 (0)