Skip to content

Commit

Permalink
Merge pull request #234 from NCAR/main
Browse files Browse the repository at this point in the history
Version 2.4.0
  • Loading branch information
K20shores committed Sep 6, 2024
2 parents d9070ff + b49fe13 commit c03ea30
Show file tree
Hide file tree
Showing 29 changed files with 9,822 additions and 667 deletions.
20 changes: 20 additions & 0 deletions .devcontainer/Dockerfile.codespace
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM fedora:37

RUN dnf -y update \
&& dnf -y install \
git \
gcc \
gcc-c++ \
gnuplot \
netcdf-devel \
python3 \
python3-pip \
python-devel \
tree \
&& dnf clean all

COPY . /workspaces/music-box

WORKDIR /workspaces/music-box

RUN pip3 install -e '.[dev]'
10 changes: 10 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "MusicBox",
"image": "ghcr.io/ncar/music-box:latest",
"extensions": [
"ms-python.python",
],
"settings": {
},
"postCreateCommand": ""
}
31 changes: 23 additions & 8 deletions .github/workflows/CI_Tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,36 @@ jobs:
python-version: '3.9'
cache: 'pip'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Install this package
run: pip install -e .
run: pip install -e '.[dev]'

- name: Run pytest
run: cd tests && pytest
run: pytest

- name: Run the smoke tests
run: |
music_box -c src/acom_music_box/examples/configs/analytical/my_config.json -o output.csv
music_box -e Analytical -o output.csv
music_box -e Analytical -o output.csv -vv --color-output
waccmToMusicBox waccmDir="./sample_waccm_data" date="20240904" time="07:00" latitude=3.1 longitude=101.7
- name: Check for config.zip
if: runner.os != 'Windows'
run: |
if [ -f "./config.zip" ]; then
echo "config.zip created successfully"
else
echo "config.zip not found"
exit 1
fi
- name: Check for config.zip (Windows)
if: runner.os == 'Windows'
run: |
if (Test-Path -Path "./config.zip") {
Write-Output "config.zip created successfully"
} else {
Write-Output "config.zip not found"
exit 1
}
shell: pwsh
53 changes: 53 additions & 0 deletions .github/workflows/deploy_codespaces_image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Build and Deploy Docker Image

on:
push:
branches:
- main
tags:
- 'v*.*.*'
workflow_dispatch:

jobs:
build-and-push:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build Docker image
uses: docker/build-push-action@v4
with:
context: .
file: .devcontainer/Dockerfile.codespace
push: false
tags: ghcr.io/ncar/music-box:build-temp

- name: Build and push Docker image (latest)
if: github.ref == 'refs/heads/main'
uses: docker/build-push-action@v4
with:
context: .
file: .devcontainer/Dockerfile.codespace
push: true
tags: ghcr.io/ncar/music-box:latest

- name: Build and push Docker image (tagged)
if: startsWith(github.ref, 'refs/tags/')
uses: docker/build-push-action@v4
with:
context: .
file: .devcontainer/Dockerfile.codespace
push: true
tags: ghcr.io/ncar/music-box:${{ github.ref_name }}
58 changes: 26 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,59 +11,53 @@ MusicBox: A MUSICA model for boxes and columns.
Copyright (C) 2020 National Center for Atmospheric Research

# Installation
```
pip install acom_music_box
```

The project is configured to be installed using `pip` by the `pyproject.toml` file.
# 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 if gnuplot is installed.

To install the `music-box` package into a Python environment, run the following command from the root directory:
Checkout the command line options

```
pip install .
music_box -h
```

The package is also available on PyPi and can be installed in any Python environment through:
Run an example. Notice that the output, in csv format, is printed to the terminal.

```
pip install acom_music_box
music_box -e Chapman
```

# Tests
You can also run your own configuration

```
music_box -c my_config.json
```

After installing music box for local development `pip install -e .`
Output can be saved to a file

```
cd tests
pytest
music_box -e Chapman -o output.csv
```

# 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 if gnuplot is installed.
And, if you have gnuplot installed, some basic plots can be made to show some resulting concentrations

```
music_box -h
usage: music_box [-h] [-c CONFIG] [-e {CB5,Chapman,FlowTube,Analytical}] [-o OUTPUT] [-v] [--color-output] [--plot PLOT]
music_box -e Chapman -o output.csv --color-output --plot CONC.O1D
```

# Development and Contributing

MusicBox simulation runner.
For local development, install `music-box` as an editable installation:

optional arguments:
-h, --help show this help message and exit
-c CONFIG, --config CONFIG
Path to the configuration file. If --example is provided, this argument is ignored.
-e {CB5,Chapman,FlowTube,Analytical}, --example {CB5,Chapman,FlowTube,Analytical}
Name of the example to use. Overrides --config.
Available examples:
CB5: Carbon bond 5
Chapman: The Chapman cycle with conditions over Boulder, Colorado
FlowTube: A fictitious flow tube experiment
Analytical: An example of an analytical solution to a simple chemical system
-o OUTPUT, --output OUTPUT
Path to save the output file, including the file name. If not provided, result will be printed to the console.
-v, --verbose Increase logging verbosity. Use -v for info, -vv for debug.
--color-output Enable color output for logs.
--plot PLOT Plot a comma-separated list of species if gnuplot is available (e.g., CONC.A,CONC.B).
```
pip install -e '.[dev]'
```

To run one of the examples and plot something you would run
## Tests

```
music_box -e Chapman -o output.csv -vv --color-output --plot CONC.O1D
pytest
```
10 changes: 9 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ dependencies = [
"musica==0.7.3",
"xarray",
"colorlog",
"pandas"
"pandas",
"tqdm",
"netcdf4"
]

[project.urls]
Expand All @@ -33,3 +35,9 @@ Home = "https://github.com/NCAR/music-box"
[project.scripts]
music_box = "acom_music_box.main:main"
waccmToMusicBox = "acom_music_box.tools.waccmToMusicBox:main"

[project.optional-dependencies]
dev = [
"pytest",
"pytest-mock"
]
5 changes: 0 additions & 5 deletions requirements.txt

This file was deleted.

29 changes: 29 additions & 0 deletions sample_waccm_data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# WACCM

This is data downloaded from [ACOM's data repository](https://www.acom.ucar.edu/waccm/DATA/). Each file has been reduced to have only ground level data and only chemical species needed for the IGAC demo.
This brings the file size from 8GB per file to 93MB per file, small enough that it can fit in github and be easily used for the demo. This data is temporary and will be removed after the demo.


The script to reduce the data is this:


```
import xarray as xr
import os
keep = ['ALKNIT', 'AODVISdn', 'BCARY', 'BENZENE', 'BIGALD', 'BIGALD1', 'BIGALD2', 'BIGALD3', 'BIGALD4', 'BIGALK', 'BIGENE', 'C2H2', 'C2H4', 'C2H5OH', 'C2H6', 'C3H6', 'C3H8', 'CH2O', 'CH3CHO', 'CH3CN', 'CH3COCH3', 'CH3COCHO', 'CH3COOH', 'CH3OH', 'CH3OOH', 'CH4', 'CHBR3', 'CO', 'CO01', 'CO02', 'CO03', 'CO04', 'CO05', 'CO06', 'CO07', 'CO08', 'CO09', 'CRESOL', 'DMS', 'GLYOXAL', 'H2O', 'H2O2', 'HCN', 'HCOOH', 'HNO3', 'HO2', 'HO2NO2', 'HONITR', 'HYAC', 'ISOP', 'ISOPNITA', 'ISOPNITB', 'MACR', 'MEK', 'MPAN', 'MTERP', 'MVK', 'M_dens', 'N2O', 'N2O5', 'NH3', 'NH4', 'NO', 'NO2', 'NO3', 'NOA', 'O3', 'O3S', 'OH', 'ONITR', 'P0', 'PAN', 'PBZNIT', 'PHENOL', 'PS', 'Q', 'SO2', 'T', 'TERPNIT', 'TOLUENE', 'XYLENES', 'Z3', 'ap', 'bc_a1', 'bc_a4', 'ch4vmr', 'co2vmr', 'date', 'dst_a1', 'dst_a2', 'dst_a3', 'f107', 'f107a', 'f107p', 'f11vmr', 'f12vmr', 'kp', 'mdt', 'n2ovmr', 'ncl_a1', 'ncl_a2', 'ncl_a3', 'num_a1', 'num_a2', 'num_a3', 'pom_a1', 'pom_a4', 'so4_a1', 'so4_a2', 'so4_a3', 'soa1_a1', 'soa1_a2', 'soa2_a1', 'soa2_a2', 'soa3_a1', 'soa3_a2', 'soa4_a1', 'soa4_a2', 'soa5_a1', 'soa5_a2', 'soa_a1', 'soa_a2', 'sol_tsi',]
for root, _, files in os.walk('data'):
for file in files:
file_path = os.path.join(root, file)
ds = xr.open_dataset(file_path)
# Select the second time index and nearest lev, expand both dimensions
ds_sel = ds[keep].isel(time=1).sel(lev=1000.0, method="nearest").expand_dims(['lev', 'time'])
ds_sel.to_netcdf(f'sample_waccm_data/{file}')
```

You can extract a coniguraiton file with

```
waccmToMusicBox waccmDir="./sample_waccm_data" date="20240904" time="07:00" latitude=3.1 longitude=101.7
```
Binary file not shown.
2 changes: 1 addition & 1 deletion src/acom_music_box/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
This package contains modules for handling various aspects of a music box,
including species, products, reactants, reactions, and more.
"""
__version__ = "2.3.2"
__version__ = "2.4.0"

from .utils import convert_time, convert_pressure, convert_temperature, convert_concentration
from .species import Species
Expand Down
Loading

0 comments on commit c03ea30

Please sign in to comment.