Skip to content

Commit

Permalink
Merge pull request #261 from NCAR/176-musicbox-configurations-from-gr…
Browse files Browse the repository at this point in the history
…eg-michalski

Set species and rates configured in micm
  • Loading branch information
K20shores authored Oct 14, 2024
2 parents 8696033 + 2ca8b59 commit 9ac7ab1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
14 changes: 13 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,8 @@
import re
from .conditions import Conditions

import logging
logger = logging.getLogger(__name__)

class EvolvingConditions:
"""
Expand Down Expand Up @@ -177,7 +179,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 9ac7ab1

Please sign in to comment.