Skip to content

Commit

Permalink
Removed ACOM Logger. Set up music_box operation as executable script …
Browse files Browse the repository at this point in the history
…and python command line.
  • Loading branch information
carl-drews committed Jul 2, 2024
1 parent b1cd963 commit bf52a88
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 48 deletions.
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ classifiers = ["License :: OSI Approved :: Apache Software License"]
dynamic = ["version", "description"]

dependencies = [
"musica==0.6.1.dev0"
"musica==0.7.0"
]

[project.urls]
Home = "https://github.com/NCAR/music-box"
Home = "https://github.com/NCAR/music-box"

[project.scripts]
music_box = "acom_music_box.music_box_main:main"
1 change: 0 additions & 1 deletion src/acom_music_box/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@
from .music_box_conditions import Conditions

from .music_box_evolving_conditions import EvolvingConditions
from acom_music_box import music_box_logger
from .music_box import MusicBox

25 changes: 17 additions & 8 deletions src/acom_music_box/music_box.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import json
import os

import logging
logger = logging.getLogger(__name__)

from .music_box_evolving_conditions import EvolvingConditions
from .music_box_reaction_list import ReactionList
from .music_box_reaction import Reaction, Branched, Arrhenius, Tunneling, Troe_Ternary
from .music_box_species_list import SpeciesList
from .music_box_model_options import BoxModelOptions
from .music_box_conditions import Conditions
from acom_music_box import music_box_logger

import csv
import musica



class MusicBox:
"""
Represents a box model with attributes such as box model options, species list, reaction list,
Expand Down Expand Up @@ -414,7 +417,7 @@ def create_solver(self, path_to_config):
None
"""
# Create a solver object using the configuration file
self.solver = musica.create_micm(path_to_config)
self.solver = musica.create_solver(path_to_config)


def solve(self, path_to_output = None):
Expand Down Expand Up @@ -519,24 +522,30 @@ def solve(self, path_to_output = None):
next_conditions = None


# calculate air density from the ideal gas law
BOLTZMANN_CONSTANT = 1.380649e-23
AVOGADRO_CONSTANT = 6.02214076e23;
GAS_CONSTANT = BOLTZMANN_CONSTANT * AVOGADRO_CONSTANT
air_density = curr_conditions.pressure / (GAS_CONSTANT * curr_conditions.temperature)

#updates M accordingly
if 'M' in species_constant_ordering:
BOLTZMANN_CONSTANT = 1.380649e-23
AVOGADRO_CONSTANT = 6.02214076e23;
GAS_CONSTANT = BOLTZMANN_CONSTANT * AVOGADRO_CONSTANT
ordered_concentrations[species_constant_ordering['M']] = curr_conditions.pressure / (GAS_CONSTANT * curr_conditions.temperature)
ordered_concentrations[species_constant_ordering['M']] = air_density

#solves and updates concentration values in concentration array
if (not ordered_concentrations):
music_box_logger.progress("Warning: ordered_concentrations list is empty.")
musica.micm_solve(self.solver, self.box_model_options.chem_step_time, curr_conditions.temperature, curr_conditions.pressure, ordered_concentrations, ordered_rate_constants)
logger.info("Warning: ordered_concentrations list is empty.")
musica.micm_solve(self.solver, self.box_model_options.chem_step_time,
curr_conditions.temperature, curr_conditions.pressure, air_density,
ordered_concentrations, ordered_rate_constants)


#increments time
curr_time += self.box_model_options.chem_step_time

#outputs to file if output is present
if(path_to_output != None):
logger.info("path_to_output = {}".format(path_to_output))
with open(path_to_output, 'w', newline='') as output:
writer = csv.writer(output)
writer.writerows(output_array)
Expand Down
28 changes: 0 additions & 28 deletions src/acom_music_box/music_box_logger.py

This file was deleted.

26 changes: 17 additions & 9 deletions src/acom_music_box/music_box_main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from acom_music_box import MusicBox
from acom_music_box import music_box_logger


import math
import datetime
import sys

import logging
logger = logging.getLogger(__name__)



# Retrieve named arguments from the command line and
Expand All @@ -29,12 +31,14 @@ def getArgsDictionary(argPairs):



if __name__ == "__main__":
music_box_logger.progress("{}".format(__file__))
music_box_logger.progress("Start time: {}".format(datetime.datetime.now()))
def main():
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
logger.info("{}".format(__file__))
logger.info("Start time: {}".format(datetime.datetime.now()))

music_box_logger.progress("Hello, MusicBox World!")
logger.info("Hello, MusicBox World!")


# retrieve and parse the command-line arguments
myArgs = getArgsDictionary(sys.argv)

Expand All @@ -46,13 +50,17 @@ def getArgsDictionary(argPairs):
# create and load a MusicBox object
myBox = MusicBox()
myBox.readConditionsFromJson(musicBoxHomeDir + "my_config.json")
music_box_logger.progress("myBox = {}".format(myBox))
logger.info("myBox = {}".format(myBox))

# create solver and solve
myBox.create_solver(musicBoxHomeDir + myBox.config_file)
music_box_logger.progress("myBox.solver = {}".format(myBox.solver))
logger.info("myBox.solver = {}".format(myBox.solver))
mySolution = myBox.solve(musicBoxHomeDir + "my_solution.csv")
music_box_logger.progress("mySolution = {}".format(mySolution))
logger.info("mySolution = {}".format(mySolution))

music_box_logger.progress("End time: {}".format(datetime.datetime.now()))
logger.info("End time: {}".format(datetime.datetime.now()))
sys.exit(0)


if __name__ == "__main__":
main()

0 comments on commit bf52a88

Please sign in to comment.