diff --git a/pyproject.toml b/pyproject.toml index e9952782..ef84a7a5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" \ No newline at end of file +Home = "https://github.com/NCAR/music-box" + +[project.scripts] +music_box = "acom_music_box.music_box_main:main" diff --git a/src/acom_music_box/__init__.py b/src/acom_music_box/__init__.py index ff481af8..17fdbe40 100644 --- a/src/acom_music_box/__init__.py +++ b/src/acom_music_box/__init__.py @@ -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 diff --git a/src/acom_music_box/music_box.py b/src/acom_music_box/music_box.py index 6cc43374..e1378ed8 100644 --- a/src/acom_music_box/music_box.py +++ b/src/acom_music_box/music_box.py @@ -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, @@ -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): @@ -519,17 +522,22 @@ 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 @@ -537,6 +545,7 @@ def solve(self, path_to_output = None): #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) diff --git a/src/acom_music_box/music_box_logger.py b/src/acom_music_box/music_box_logger.py deleted file mode 100644 index 5cd213c0..00000000 --- a/src/acom_music_box/music_box_logger.py +++ /dev/null @@ -1,28 +0,0 @@ -import sys - -# Class Logger is included here for completeness, -# but not used because progress() is such a lightweight function. -class Logger: - """ - Logs messages to the console, which can then be captured to a log file. - - Attributes: - """ - - def __init__(self): - """ - Initializes a new instance of the Reaction class. - - Args: - name (str): The name of the reaction. - """ - pass - - - -# Display progress message on the console. -# endString = set this to '' for no return -def progress(message, endString='\n'): - if (True): # disable here in production - print(message, end=endString) - sys.stdout.flush() diff --git a/src/acom_music_box/music_box_main.py b/src/acom_music_box/music_box_main.py index fdf2b48b..dd949b8e 100644 --- a/src/acom_music_box/music_box_main.py +++ b/src/acom_music_box/music_box_main.py @@ -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 @@ -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) @@ -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()