Skip to content

Commit 0fad93a

Browse files
authored
Merge pull request #261 from NCAR/176-musicbox-configurations-from-greg-michalski
Set species and rates configured in micm
2 parents f4dc6e7 + f04117c commit 0fad93a

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

src/acom_music_box/evolving_conditions.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import re
44
from .conditions import Conditions
55

6+
import logging
7+
logger = logging.getLogger(__name__)
68

79
class EvolvingConditions:
810
"""
@@ -177,7 +179,17 @@ def read_conditions_from_file(cls, file_path):
177179
species_concentrations = {}
178180

179181
for key in other_keys:
180-
condition_type, label, unit = key.split('.')
182+
parts = key.split('.')
183+
condition_type, label, unit = None, None, None
184+
if len(parts) == 3:
185+
condition_type, label, unit = parts
186+
elif len(parts) == 2:
187+
condition_type, label = parts
188+
else:
189+
error = f"Unexpected format in key: {key}"
190+
logger.error(error)
191+
raise ValueError(error)
192+
181193
if condition_type == 'CONC':
182194
species_concentrations[label] = row[key]
183195
else:

src/acom_music_box/music_box.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,12 @@ def order_reaction_rates(curr_conditions, rate_constant_ordering):
263263
"""
264264
ordered_rate_constants = np.zeros(len(rate_constant_ordering), dtype=np.float64)
265265

266-
for rate_label, value in curr_conditions.reaction_rates.items():
267-
ordered_rate_constants[rate_constant_ordering[rate_label]] = value
266+
for rate_label, _ in rate_constant_ordering.items():
267+
if rate_label not in curr_conditions.reaction_rates:
268+
logger.warning(f"Reaction rate '{rate_label}' not found in current conditions.")
269+
continue
270+
else:
271+
ordered_rate_constants[rate_constant_ordering[rate_label]] = curr_conditions.reaction_rates[rate_label]
268272

269273
return ordered_rate_constants
270274

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

288-
for species, value in curr_conditions.species_concentrations.items():
289-
concentrations[species_constant_ordering[species]] = value
292+
for species, _ in species_constant_ordering.items():
293+
if species not in curr_conditions.species_concentrations:
294+
logger.warning(f"Species '{species}' not found in current conditions.")
295+
continue
296+
else:
297+
concentrations[species_constant_ordering[species]] = curr_conditions.species_concentrations[species]
290298

291299
return concentrations

0 commit comments

Comments
 (0)