Describe the bug
The current xlsx output owerwrites the file at each run. We want to only append (overwrite tab) if the file already exists.
This is could be simply achieved by:
file_prefix = f"{country}_ADM{adm_level}_{haz_cat}_{period}"
# Create Excel writer object
excel_file = os.path.join(common.OUTPUT_DIR, f"{file_prefix}_results.xlsx")
# Check if the file exists, if not, create it
if not os.path.exists(excel_file):
wb = Workbook()
wb.save(excel_file)
# Determine the appropriate mode and if_sheet_exists parameter
try:
with pd.ExcelWriter(excel_file, engine='openpyxl', mode='a') as writer:
writer.book.active # This will raise an error if the file is invalid
mode = 'a'
if_sheet_exists = 'replace'
except (InvalidFileException, FileNotFoundError):
mode = 'w'
if_sheet_exists = None
# Use ExcelWriter with 'with' statement to ensure proper closing
with pd.ExcelWriter(excel_file, engine='openpyxl', mode=mode, if_sheet_exists=if_sheet_exists) as excel_writer:
but this throws error as writing excel is occurring in both the GUI_F3.py and the runAnalysis.py and thus conflicting.
The following changes are needed:
The GUI should not execute any function on input data, aside from those strictly functional to the interface iteself (e.g. curve, map, chart plotting).
The run_analysis() should include all steps including data summary and output creation.
This ensure that results are the same from manual_run (minus the chart and map plots).
Note that data summary is used by GUI to plot charts.
I tried, but to no avail - fixing something, breaking something else.
Describe the bug The current xlsx output owerwrites the file at each run. We want to only append (overwrite tab) if the file already exists. This is could be simply achieved by:
but this throws error as writing excel is occurring in both the
GUI_F3.py
and therunAnalysis.py
and thus conflicting.The following changes are needed:
run_analysis()
should include all steps including data summary and output creation.This ensure that results are the same from manual_run (minus the chart and map plots). Note that data summary is used by GUI to plot charts.
I tried, but to no avail - fixing something, breaking something else.