Refactor duplicated bootstrapping logic in analysis scripts - #14
Conversation
- Created `analysis/08 Bootstrapping/bootstrap_utils.py` to encapsulate shared logic for running bootstrap simulations and plotting results. - Updated `bootstrap_v1.py` and `bootstrap_v2.py` to use `bootstrap_utils.py`, removing code duplication while preserving version-specific configurations (reference stations, sample sizes). - Replaced deprecated `DataFrame.append` with `pd.concat` for compatibility with modern pandas versions. - Added `test_bootstrap.py` with comprehensive unit tests mocking the MATLAB engine to verify functionality without requiring a MATLAB installation. - Cleaned up imports and added error handling for file operations. Co-authored-by: alfieprojectsdev <11991855+alfieprojectsdev@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
This PR addresses the code duplication between
bootstrap_v1.pyandbootstrap_v2.pyin theanalysis/08 Bootstrappingdirectory.Key Changes
New Utility Module: Introduced
bootstrap_utils.pycontaining:run_bootstrap_simulation: The core loop for sampling, running MATLAB scripts, and processing results.plot_histogram: The shared plotting logic.matlab.engineto allow the code to run/test in environments where MATLAB is not installed (graceful failure or mocking).Refactoring:
bootstrap_v1.pyandbootstrap_v2.pynow importbootstrap_utilsand callrun_bootstrap_simulationwith their specific parameters (sample size, reference station data, etc.).sys.pathmodification inv2.Modernization:
df.append()(deprecated) withpd.concat().Testing:
test_bootstrap.pywhich mocksmatlab.engineand verifies that the simulation loop runs, creates expected files (PHm.txt), and processes results correctly.matlabmodule is not present in the environment.Verification
test_bootstrap.pysuccessfully.ruffto ensure code quality.bootstrap_v1.pyandbootstrap_v2.pycan be imported and fail gracefully when input files are missing (as expected in the test environment).PR created automatically by Jules for task 153735260210762914 started by @alfieprojectsdev