Skip to content

Commit

Permalink
Merge pull request #263 from NCAR/main
Browse files Browse the repository at this point in the history
Version 2.5.4
  • Loading branch information
K20shores authored Oct 14, 2024
2 parents 341203e + 8b403aa commit 515660a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
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.5.3"
__version__ = "2.5.4"

from .utils import convert_time, convert_pressure, convert_temperature, convert_concentration
from .model_options import BoxModelOptions
Expand Down
15 changes: 14 additions & 1 deletion src/acom_music_box/evolving_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import re
from .conditions import Conditions

import logging
logger = logging.getLogger(__name__)


class EvolvingConditions:
"""
Expand Down Expand Up @@ -177,7 +180,17 @@ def read_conditions_from_file(cls, file_path):
species_concentrations = {}

for key in other_keys:
condition_type, label, unit = key.split('.')
parts = key.split('.')
condition_type, label, unit = None, None, None
if len(parts) == 3:
condition_type, label, unit = parts
elif len(parts) == 2:
condition_type, label = parts
else:
error = f"Unexpected format in key: {key}"
logger.error(error)
raise ValueError(error)

if condition_type == 'CONC':
species_concentrations[label] = row[key]
else:
Expand Down
16 changes: 12 additions & 4 deletions src/acom_music_box/music_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,12 @@ def order_reaction_rates(curr_conditions, rate_constant_ordering):
"""
ordered_rate_constants = np.zeros(len(rate_constant_ordering), dtype=np.float64)

for rate_label, value in curr_conditions.reaction_rates.items():
ordered_rate_constants[rate_constant_ordering[rate_label]] = value
for rate_label, _ in rate_constant_ordering.items():
if rate_label not in curr_conditions.reaction_rates:
logger.warning(f"Reaction rate '{rate_label}' not found in current conditions.")
continue
else:
ordered_rate_constants[rate_constant_ordering[rate_label]] = curr_conditions.reaction_rates[rate_label]

return ordered_rate_constants

Expand All @@ -285,7 +289,11 @@ def order_species_concentrations(curr_conditions, species_constant_ordering):
"""
concentrations = np.zeros(len(species_constant_ordering), dtype=np.float64)

for species, value in curr_conditions.species_concentrations.items():
concentrations[species_constant_ordering[species]] = value
for species, _ in species_constant_ordering.items():
if species not in curr_conditions.species_concentrations:
logger.warning(f"Species '{species}' not found in current conditions.")
continue
else:
concentrations[species_constant_ordering[species]] = curr_conditions.species_concentrations[species]

return concentrations

0 comments on commit 515660a

Please sign in to comment.