Skip to content

Commit

Permalink
Merge branch 'python_box_model' of https://github.com/NCAR/music-box
Browse files Browse the repository at this point in the history
…into python_box_model
  • Loading branch information
eadlg2 committed Mar 28, 2024
2 parents e29aa38 + 1b69d32 commit ec067c1
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 3,643 deletions.
9 changes: 6 additions & 3 deletions src/box_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ def solve(self, path_to_output = None):
headers.append("time")
headers.append("ENV.temperature")
headers.append("ENV.pressure")

for spec in self.species_list.species:
headers.append("CONC." + spec.name)

Expand Down Expand Up @@ -450,11 +451,13 @@ def readConditionsFromJson(self, path_to_json):
# Set box model options
self.box_model_options = BoxModelOptions.from_config_JSON(data)

# Set species list
self.species_list = SpeciesList.from_config_JSON(path_to_json, data)

# Set initial conditions
self.initial_conditions = Conditions.from_config_JSON(data)
self.initial_conditions = Conditions.from_config_JSON(data, self.species_list )

# Set species list
self.species_list = SpeciesList.from_config_JSON(data)



# for testing purposes
Expand Down
1 change: 0 additions & 1 deletion src/configs/test_config_2/camp_data/config.json

This file was deleted.

1 change: 0 additions & 1 deletion src/configs/test_config_2/camp_data/reactions.json

This file was deleted.

1 change: 0 additions & 1 deletion src/configs/test_config_2/camp_data/species.json

This file was deleted.

1 change: 0 additions & 1 deletion src/configs/test_config_2/my_config.json

This file was deleted.

7 changes: 6 additions & 1 deletion src/music_box_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def from_UI_JSON(cls, UI_JSON, species_list, reaction_list):
return cls(pressure, temperature, species_concentrations, reaction_rates)

@classmethod
def from_config_JSON(cls, config_JSON):
def from_config_JSON(cls, config_JSON, species_list):
pressure = utils.convert_pressure(config_JSON['environmental conditions']['pressure'], 'initial value')

temperature = utils.convert_temperature(config_JSON['environmental conditions']['temperature'], 'initial value')
Expand All @@ -91,6 +91,11 @@ def from_config_JSON(cls, config_JSON):
concentration = utils.convert_concentration(config_JSON['chemical species'][chem_spec], 'initial value')

species_concentrations.append(SpeciesConcentration(species, concentration))

for species in species_list.species:
if not any(conc.species.name == species.name for conc in species_concentrations):
species_concentrations.append(SpeciesConcentration(species, 0))


#TODO: may or may not be necessary
# Set initial reaction rates
Expand Down
42 changes: 35 additions & 7 deletions src/music_box_species_list.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json
import os
from typing import List
from music_box_species import Species

Expand Down Expand Up @@ -46,17 +48,43 @@ def from_UI_JSON(cls, UI_JSON):
return cls(species_from_json)

@classmethod
def from_config_JSON(cls, config_JSON):
def from_config_JSON(cls, path_to_json, config_JSON):

species_from_json = []

for name, properties in config_JSON['chemical species'].items():
absolute_tolerance = properties.get('absolute tolerance')
molecular_weight = properties.get('molecular weight')
#gets config file path
config_file_path = os.path.dirname(path_to_json) + "/" + config_JSON['model components'][0]['configuration file']

#opnens config path to read species file
with open(config_file_path, 'r') as json_file:
config = json.load(json_file)

#assumes species file is first in the list
if(len(config['camp-files']) > 0):
species_file_path = os.path.dirname(config_file_path) + "/" + config['camp-files'][0]
with open(species_file_path, 'r') as species_file:
species_data = json.load(species_file)
#loads species by names from camp files
for properties in species_data['camp-data']:
name = properties.get('name')
species_from_json.append(Species(name, None, None, None, None))


#chceks if species are in the config file and updates attributes accordingly
for chem_spec in config_JSON['chemical species']:
for species in species_from_json:
if species.name == chem_spec:
# Add attributes to species
if 'absolute tolerance' in chem_spec:
species.absolute_tolerance = chem_spec['absolute tolerance']
if 'molecular weight' in chem_spec:
species.molecular_weight = chem_spec['molecular weight']
if 'density' in chem_spec:
species.density = chem_spec['density']
if 'phase' in chem_spec:
species.phase = chem_spec['phase']


# TODO: Add phase and density to species

species_from_json.append(Species(name, absolute_tolerance, None, molecular_weight, None))

return cls(species_from_json)

Expand Down
26 changes: 0 additions & 26 deletions src/python_test_2.py

This file was deleted.

Loading

0 comments on commit ec067c1

Please sign in to comment.