Skip to content

Commit

Permalink
Auto-format code using pep8 (#302)
Browse files Browse the repository at this point in the history
Co-authored-by: GitHub Actions <actions@github.com>
  • Loading branch information
github-actions[bot] and actions-user authored Jan 30, 2025
1 parent 77c045e commit 2c5646a
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 30 deletions.
19 changes: 8 additions & 11 deletions src/acom_music_box/conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ def from_UI_JSON(self, UI_JSON, species_list, reaction_list):
species_concentrations,
reaction_rates)


@classmethod
def retrieve_initial_conditions_from_JSON(
cls,
Expand All @@ -133,9 +132,9 @@ def retrieve_initial_conditions_from_JSON(

# look for that JSON section
if (not 'initial conditions' in json_object):
return({})
return ({})
if (len(list(json_object['initial conditions'].keys())) == 0):
return({})
return ({})

# retrieve initial conditions from CSV and JSON
initial_csv = {}
Expand Down Expand Up @@ -163,7 +162,7 @@ def retrieve_initial_conditions_from_JSON(
logger.warning(
"Value {}:{} in file {} will override prior value {}"
.format(one_csv, file_initial_csv[one_csv],
initial_conditions_path, initial_csv[one_csv]))
initial_conditions_path, initial_csv[one_csv]))

initial_csv[one_csv] = file_initial_csv[one_csv]

Expand All @@ -173,7 +172,7 @@ def retrieve_initial_conditions_from_JSON(
# read initial conditions from in-place CSV (list of headers and list of values)
dataConditions = initCond['data']
initial_data = Conditions.read_data_values_from_table(dataConditions,
reaction_types)
reaction_types)
logger.debug(f"initial_data = {initial_data}")

# override the CSV species initial values with JSON data
Expand All @@ -183,13 +182,12 @@ def retrieve_initial_conditions_from_JSON(
logger.warning(f"Initial data values ({numData}) from JSON will override initial values ({numCSV}) from CSV.")
for one_data in initial_data:
chem_name_alone = one_data.split(".")[1] # remove reaction type
chem_name_alone = chem_name_alone.split(" ")[0] # remove units
chem_name_alone = chem_name_alone.split(" ")[0] # remove units
initial_csv[chem_name_alone] = initial_data[one_data]

logger.debug(f"Overridden initial_csv = {initial_csv}")

return(initial_csv)

return (initial_csv)

@classmethod
def from_config_JSON(
Expand Down Expand Up @@ -242,7 +240,6 @@ def from_config_JSON(
species_concentrations,
reaction_rates)


@classmethod
def read_initial_conditions_from_file(cls, file_path, react_types=None):
"""
Expand Down Expand Up @@ -291,7 +288,7 @@ def read_initial_conditions_from_file(cls, file_path, react_types=None):
chem_name_alone = f"{reaction_type}.{label}" # reaction
if len(parts) == 2:
chem_name_alone = label.split(' ')[0] # strip off [units] to get chemical
reaction_rates[chem_name_alone] = df.at[0, key] # retrieve (row, column)
reaction_rates[chem_name_alone] = df.at[0, key] # retrieve (row, column)

return reaction_rates

Expand Down Expand Up @@ -326,7 +323,7 @@ def read_data_values_from_table(cls, data_json, react_types=None):
header_row = data_json[0]
value_row = data_json[1]
data_values = {key: float(value) for key, value in zip(header_row, value_row)
if key.split('.')[0] in react_types}
if key.split('.')[0] in react_types}
logger.debug(f"For {react_types} data_values = {data_values}")

return data_values
Expand Down
26 changes: 13 additions & 13 deletions src/acom_music_box/evolving_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ def from_config_JSON(

# Check if 'evolving conditions' is a key in the JSON config
if (not 'evolving conditions' in config_JSON):
return(evolving_conditions)
return (evolving_conditions)
if (len(list(config_JSON['evolving conditions'].keys())) == 0):
return(evolving_conditions)
return (evolving_conditions)

evolveCond = config_JSON['evolving conditions']
logger.debug(f"evolveCond: {evolveCond}")
Expand All @@ -150,7 +150,7 @@ def from_config_JSON(
overrideSet = allReactions.intersection(fileReactions)
if (len(overrideSet) > 0):
logger.warning("File {} will override earlier conditions {}"
.format(file_path, sorted(overrideSet)))
.format(file_path, sorted(overrideSet)))
allReactions = allReactions.union(fileReactions)

return evolving_conditions
Expand All @@ -168,7 +168,7 @@ def add_condition(self, time_point, conditions):
# Work backward from end of list, looking for first time <= this new time.
timeIndex = len(self.times)
while (timeIndex > 0
and self.times[timeIndex - 1] > time_point):
and self.times[timeIndex - 1] > time_point):
timeIndex -= 1

self.times.insert(timeIndex, time_point)
Expand Down Expand Up @@ -226,15 +226,15 @@ def read_conditions_from_file(self, file_path):
reaction_rates[f'{condition_type}.{label}'] = row[key]

self.add_condition(time,
Conditions(
pressure,
temperature,
species_concentrations,
reaction_rates
)
)

return(header_set)
Conditions(
pressure,
temperature,
species_concentrations,
reaction_rates
)
)

return (header_set)

# allows len overload for this class

Expand Down
6 changes: 3 additions & 3 deletions src/acom_music_box/tools/waccmToMusicBox.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,9 @@ def convertWaccm(varDict):
# return True for temperature, pressure, ...
def isEnvironment(varName):
if (varName.lower() in {"temperature", "pressure"}):
return(True)
return (True)

return(False)
return (False)


# Write CSV file suitable for initial_conditions.csv in MusicBox.
Expand All @@ -291,7 +291,7 @@ def writeInitCSV(initValues, filename):
reaction_type = "CONC"
if isEnvironment(key):
reaction_type = "ENV"

fp.write("{}.{} [{}]".format(reaction_type, key, value[unitIndex]))
fp.write("\n")

Expand Down
1 change: 0 additions & 1 deletion tests/integration/test_analytical.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,3 @@ def test_run(self):
logging.basicConfig(level=logging.DEBUG)
test = TestAnalytical()
test.test_run()

1 change: 0 additions & 1 deletion tests/integration/test_mixing_ratios.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,3 @@ def test_ppt(self):
if __name__ == "__main__":
test = TestAnalytical()
test.test_run()

1 change: 0 additions & 1 deletion tests/integration/test_waccm_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,3 @@ def test_waccm_to_music_box_conversion(temp_dir):
assert os.path.exists(os.path.join(os.path.dirname(Examples.WACCM.path), "initial_conditions.csv"))
assert os.path.exists(os.path.join(os.path.dirname(Examples.WACCM.path), "initial_config.json"))
assert os.path.exists(os.path.join(temp_dir, "config.zip"))

0 comments on commit 2c5646a

Please sign in to comment.