Skip to content

Commit

Permalink
fixed remove_particles
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholaswogan committed Nov 18, 2024
1 parent d6f2238 commit b7becb7
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions photochem/utils/_format.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import yaml
from photochem_clima_data import DATA_DIR
import copy

try:
from yaml import CLoader as Loader, CDumper as Dumper
Expand Down Expand Up @@ -187,7 +188,9 @@ def species_in_reaction(rx):
react, prod = [a.replace(' ','').split('+') for a in rx1.split('=>')]
return react + prod

def mechanism_dict_with_atoms(dat, atoms_names, exclude_species=[], remove_particles=False, remove_reaction_particles=False):
def mechanism_dict_with_atoms(dat_orig, atoms_names, exclude_species=[], remove_particles=False, remove_reaction_particles=False):

dat = copy.deepcopy(dat_orig)

atoms = []
exclude_atoms = []
Expand Down Expand Up @@ -216,6 +219,8 @@ def mechanism_dict_with_atoms(dat, atoms_names, exclude_species=[], remove_parti
if not exclude:
species.append(sp)

if "particles" in dat and remove_particles:
del dat['particles']
if "particles" in dat:
particles = []
for i,sp in enumerate(dat['particles']):
Expand Down Expand Up @@ -266,7 +271,7 @@ def mechanism_dict_with_atoms(dat, atoms_names, exclude_species=[], remove_parti
out = dat
out['atoms'] = atoms
out['species'] = species
if 'particles' in dat and not remove_particles:
if 'particles' in dat:
out['particles'] = particles
if 'reactions' in dat:
out['reactions'] = reactions
Expand Down Expand Up @@ -314,7 +319,7 @@ def resave_mechanism_with_atoms(
with open(outfile,'w') as f:
yaml.dump(out,f,Dumper=MyDumper,sort_keys=False,width=70)

def generate_zahnle_earth_thermo(outfile='zahnle_earth_thermo.yaml', atoms_names=None, exclude_species=[]):
def generate_zahnle_earth_thermo(outfile='zahnle_earth_thermo.yaml', atoms_names=None, exclude_species=[], remove_particles=False):
"""Generates a thermodynamic file for equilibrium solving that includes
condensible species (e.g., H2O condensate).
Expand All @@ -326,6 +331,8 @@ def generate_zahnle_earth_thermo(outfile='zahnle_earth_thermo.yaml', atoms_names
List of atoms to keep. By default all atoms in the mechanism are kept
exclude_species : list, optional
List of species to exclude.
remove_particles : bool, optional
If True, then particles (i.e. condensates) will be removed, by default False.
"""

rx_folder = DATA_DIR+'/reaction_mechanisms/'
Expand All @@ -342,8 +349,9 @@ def generate_zahnle_earth_thermo(outfile='zahnle_earth_thermo.yaml', atoms_names
del dat['particles']
del dat['reactions']

for i,sp in enumerate(dat1['species']):
dat['species'].append(sp)
if not remove_particles:
for i,sp in enumerate(dat1['species']):
dat['species'].append(sp)

if atoms_names is None:
atoms_names = [a['name'] for a in dat['atoms']]
Expand Down Expand Up @@ -379,7 +387,7 @@ def zahnle_rx_and_thermo_files(
remove_particles : bool, optional
If True, then particles will be removed, by default False.
remove_reaction_particles : bool, optional
If True, then reactions particles are removed, by default True.
If True, then reactions particles are removed, by default False.
"""

zahnle_earth = DATA_DIR+'/reaction_mechanisms/zahnle_earth.yaml'
Expand All @@ -389,4 +397,4 @@ def zahnle_rx_and_thermo_files(

# Thermodynamics
if thermo_filename is not None:
generate_zahnle_earth_thermo(thermo_filename, atoms_names, exclude_species)
generate_zahnle_earth_thermo(thermo_filename, atoms_names, exclude_species, remove_particles)

0 comments on commit b7becb7

Please sign in to comment.