Skip to content

Commit

Permalink
extracted concentrations and reaction rates from evolving conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
eadlg2 committed Mar 3, 2024
1 parent 67a45b0 commit a9b0781
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/box_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from music_box_model_options import BoxModelOptions
from music_box_conditions import Conditions
from music_box_species_concentration import SpeciesConcentration
from music_box_reaction_rate import ReactionRate

class BoxModel:
"""
Expand Down Expand Up @@ -398,7 +399,32 @@ def readFromJson(self, path_to_json):
for i in range(1, len(evol_from_json)):
time.append(evol_from_json[i][0])

# TODO: Add species concentrations and reaction rates
if 'ENV.pressure.Pa' in headers:
pressure = float(evol_from_json[i][headers.index('ENV.pressure.Pa')]) / 101325

if 'ENV.temperature.K' in headers:
temperature = float(evol_from_json[i][headers.index('ENV.temperature.K')])

# TODO: make sure species concentrations and reaction rates handle all cases
concentrations = []
concentration_headers = list(filter(lambda x: 'molm-3' in x, headers))
for j in range(len(concentration_headers)):
match = filter(lambda x: x.name == concentration_headers[j].split('.')[1], species_from_json)
species = next(match, None)

concentration = float(evol_from_json[i][headers.index(concentration_headers[j])])
concentrations.append(SpeciesConcentration(species, concentration))

rates = []
rate_headers = list(filter(lambda x: 's-1' in x, headers))
for k in range(len(rate_headers)):
match = filter(lambda x: x.name == rate_headers[k].split('.')[1], reactions)
reaction = next(match, None)

rate = float(evol_from_json[i][headers.index(rate_headers[k])])
rates.append(ReactionRate(reaction, rate))

conditions.append(Conditions(pressure, temperature, concentrations, rates))

# for testing purposes
def __main__():
Expand Down

0 comments on commit a9b0781

Please sign in to comment.