Source code for buckpy.buckpy

"""
This is the main module of BuckPy.
"""
from . import buckpy_gui
from . import buckpy_preprocessing_legacy
from . import buckpy_preprocessing_current
from . import buckpy_solver
from . import buckpy_postprocessing
from . import buckpy_visualisation

[docs] def main() -> None: """ Run the full BuckPy workflow from GUI-provided inputs. The function opens the BuckPy GUI, reads user selections, validates required inputs, parses scenario identifiers, and executes the processing pipeline for each scenario. Returns ------- None Notes ----- Workflow: 1. Launch GUI and collect configuration. 2. Validate working directory and input file selection. 3. Parse scenario IDs from comma-separated text. 4. Run legacy or current preprocessing depending on Excel format. 5. Run the solver. 6. Run postprocessing and visualization. Side Effects: 1. Starts a GUI event loop. 2. Reads input files from the selected working directory. 3. Writes output artifacts through postprocessing and visualization modules. 4. Prints progress messages to stdout. """ # Load user inputs from the GUI interface gui = buckpy_gui.GUI() gui.root.mainloop() # Retrieve user selections from the GUI user_config = { "excel_format": gui.excel_format, "work_dir": gui.work_dir, "input_file_name": gui.input_file_name, "pipeline_id": gui.pipeline_id, "scenario_id": gui.scenario_id, "bl_verbose": gui.bl_verbose, "output_combination": gui.output_combination, } # Check if the user selected a file and provided required info if not user_config["work_dir"] or not user_config["input_file_name"]: print('No input file selected. Exiting.') return # Parse scenario IDs as a list of integers scenario_list_id = [ int(s.strip()) for s in user_config["scenario_id"].split(',') if s.strip().isdigit() ] # Print start message print('====================== Start Processing ========================') for scenario_id in scenario_list_id: # Print current scenario being processed print(f'== Processing Pipeline: {user_config["pipeline_id"]}, Scenario ID: {scenario_id}') # Load and preprocess scenario data from the input Excel file if user_config["excel_format"] == "Legacy": np_distr, np_scen, np_ends, df_scen, df_route, df_pp = buckpy_preprocessing_legacy.run( user_config["work_dir"], user_config["input_file_name"], user_config["pipeline_id"], scenario_id, user_config["bl_verbose"] ) else: preprocessor = buckpy_preprocessing_current.PreProcessor( user_config["work_dir"], user_config["input_file_name"], user_config["pipeline_id"], scenario_id, user_config["bl_verbose"] ) np_scen, np_distr, np_ends, df_scen, df_route, df_pp = preprocessor.run() # Run BuckPy solver for deterministic and Monte Carlo simulations df_pp_plot, df_vap_plot, df_pp_buckle_prop = buckpy_solver.exec_buckpy( np_scen, np_distr, np_ends, df_scen["Simulations"].values[0], df_scen["Friction Sampling"].values[0], user_config["bl_verbose"] ) # Post-process simulation results and generate summary outputs buckpy_postprocessing.pp_buckpy( user_config["work_dir"], user_config["input_file_name"], df_scen, df_route, df_pp, df_pp_plot, df_vap_plot, df_pp_buckle_prop, user_config["output_combination"], user_config["bl_verbose"], user_config["excel_format"] ) # Generate additional plots and visualizations for BuckPy results buckpy_visualisation.plot_buckpy( user_config["work_dir"], user_config["input_file_name"], df_scen, df_route, df_pp, user_config["bl_verbose"] ) # Print end message print('======================= End Processing =========================')
if __name__ == '__main__': # Run the main function to execute the BuckPy workflow main()