Skip to content

Commit

Permalink
tested parsing with example that had every option
Browse files Browse the repository at this point in the history
  • Loading branch information
eadlg2 committed Mar 20, 2024
1 parent ecbe62a commit f34bd93
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions src/box_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def readFromJson(self, path_to_json):
for species in data['mechanism']['species']['camp-data']:
name = species['name']
absolute_tolerance = species['absolute tolerance'] if 'absolute tolerance' in species else None
molecular_weight = species['molecular weight [kg mol-1]'] if 'molecular weight [kg mol-1]' in species else None
molecular_weight = species['molecular weight'] if 'molecular weight' in species else None

# TODO: Add phase and density to species

Expand Down Expand Up @@ -303,12 +303,13 @@ def readFromJson(self, path_to_json):

products = []

for product, product_info in reaction['products'].items():
match = filter(lambda x: x.name == product, species_from_json)
species = next(match, None)
yield_value = product_info['yield'] if 'yield' in product_info else None
if 'products' in reaction:
for product, product_info in reaction['products'].items():
match = filter(lambda x: x.name == product, species_from_json)
species = next(match, None)
yield_value = product_info['yield'] if 'yield' in product_info else None

products.append(Product(species, yield_value))
products.append(Product(species, yield_value))

reactions.append(Reaction(name, reaction_type, reactants, products, A, B, D, E, Ea))

Expand All @@ -317,6 +318,7 @@ def readFromJson(self, path_to_json):

temperature = utils.convert_temperature(data['conditions']['environmental conditions']['temperature'], 'initial value')

# Set initial species concentrations
species_concentrations = []
for chem_spec in data['conditions']['chemical species']:
match = filter(lambda x: x.name == chem_spec, species_from_json)
Expand All @@ -326,16 +328,16 @@ def readFromJson(self, path_to_json):

species_concentrations.append(SpeciesConcentration(species, concentration))

# TODO: verify reaction rates
# Set initial reaction rates
reaction_rates = []

for reaction in data['conditions']['initial conditions']:
match = filter(lambda x: x.name == reaction.split('.')[1], reactions)
reaction = next(match, None)
reaction_from_list = next(match, None)

rate = data['initial conditions'][reaction]
rate = data['conditions']['initial conditions'][reaction]

reaction_rates.append(ReactionRate(reaction, rate))
reaction_rates.append(ReactionRate(reaction_from_list, rate))

self.initial_conditions = Conditions(pressure, temperature, species_concentrations, reaction_rates)

Expand Down Expand Up @@ -367,7 +369,14 @@ def readFromJson(self, path_to_json):
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)
name_to_match = rate_headers[k].split('.')

if name_to_match[0] == 'LOSS' or name_to_match[0] == 'EMIS':
name_to_match = name_to_match[0] + '_' + name_to_match[1]
else:
name_to_match = name_to_match[1]

match = filter(lambda x: x.name == name_to_match, reactions)
reaction = next(match, None)

rate = float(evol_from_json[i][headers.index(rate_headers[k])])
Expand All @@ -380,7 +389,7 @@ def __main__():
# Create a new instance of the BoxModel class.
box_model = BoxModel()

box_model.readFromJson("./pretty_json.json")
box_model.readFromJson("./pretty_test.json")

if __name__ == "__main__":
__main__()

0 comments on commit f34bd93

Please sign in to comment.