1290 add ABM visualization from paper to memilio plot#1291
1290 add ABM visualization from paper to memilio plot#1291
Conversation
…rove function structure, and add new plotting capabilities for location types.
There was a problem hiding this comment.
Pull Request Overview
This PR adds new visualization modules to support ABM simulation output analysis for infection states and ICU/death comparisons. Key changes include:
- Introduction of plotAbmInfectionStates.py for visualizing infection states and spatial location types.
- Introduction of plotAbmICUAndDeadComp.py for comparing ICU occupancy and deaths between simulation results and real-world data.
- Addition of helper functions for file loading and axis formatting to support the new visualizations.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pycode/memilio-plot/memilio/plot/plotAbmInfectionStates.py | New module for plotting infection states and location types from simulation HDF5 data. |
| pycode/memilio-plot/memilio/plot/plotAbmICUAndDeadComp.py | New module for plotting and comparing ICU occupancy and cumulative deaths with real-world data. |
Comments suppressed due to low confidence (2)
pycode/memilio-plot/memilio/plot/plotAbmICUAndDeadComp.py:71
- The variable 'age_grous_string' appears to be misspelled. Consider renaming it to 'age_groups_string' for clarity.
age_grous_string = ['Age 0-4', 'Age 5-14', 'Age 15-34', 'Age 35-59', 'Age 60-79', 'Age 80+'] # Adjust as needed
pycode/memilio-plot/memilio/plot/plotAbmICUAndDeadComp.py:30
- Consider using a context manager (e.g., 'with h5py.File(..., 'r') as f:') when opening HDF5 files to ensure they are properly closed after reading.
f_p50 = h5py.File(path+"/infection_state_per_age_group/0/p50/Results.h5", 'r')
… documentation, and improve function argument handling for better usability
…st cases for loading H5 results and plotting functions
…ments for clarity
…th comparison plots
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1291 +/- ##
==========================================
- Coverage 97.39% 97.38% -0.02%
==========================================
Files 188 188
Lines 16539 16539
==========================================
- Hits 16108 16106 -2
- Misses 431 433 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…arguments for better flexibility
|
Thanks for bringing this close to our previous plot style from the assessment paper. @jubicker Could you have a look for the detailed review? |
pycode/memilio-plot/memilio/plot_test/test_plot_plotAbmInfectionStates.py
Outdated
Show resolved
Hide resolved
pycode/memilio-plot/memilio/plot_test/test_plot_plotAbmInfectionStates.py
Outdated
Show resolved
Hide resolved
pycode/memilio-plot/memilio/plot_test/test_plot_plotAbmInfectionStates.py
Outdated
Show resolved
Hide resolved
pycode/memilio-plot/memilio/plot_test/test_plot_plotAbmInfectionStates.py
Outdated
Show resolved
Hide resolved
pycode/memilio-plot/memilio/plot_test/test_plot_plotAbmInfectionStates.py
Outdated
Show resolved
Hide resolved
| # * @brief Log the TimeSeries of the number of Person%s in an #InfectionState. | ||
| # * @param[in] sim The simulation of the abm. | ||
| # * @return A pair of the TimePoint and the TimeSeries of the number of Person%s in an #InfectionState. | ||
| # */ |
| xtick_step=150, | ||
| y05=None, y95=None, show_90=False): | ||
| """ Plots infection states with percentiles and improved styling. """ | ||
| plt.figure('Infection_states') |
| abm.plot_infections_loc_types_average('dummy_path') | ||
| assert mock_ax.plot.called | ||
| assert mock_ax.set_xticks.called | ||
| assert mock_ax.set_xticklabels.called |
| # Check that plot_infection_states was called with correct data structure | ||
| states_call_args = mock_states.call_args | ||
| self.assertIsNotNone(states_call_args) | ||
| self.assertEqual(len(states_call_args[0]), 7) # x, y50, y25, y75 |
There was a problem hiding this comment.
I don't get the comment. There are for arguments but the assertion says 7
| indiv_call_args = mock_indiv.call_args | ||
| self.assertIsNotNone(indiv_call_args) | ||
| # x, p50_bs, p25_bs, p75_bs | ||
| self.assertEqual(len(indiv_call_args[0]), 5) |
| "fill_between should be called for confidence intervals") | ||
| fill_calls = mock_ax.fill_between.call_args_list | ||
| # Should have calls for both 50% and 90% confidence intervals if show_90=True | ||
| self.assertGreater(len(fill_calls), 0) |
There was a problem hiding this comment.
You do not check if it was called for the 90% confidence intervall. Please check if it was called exactly 2 times
| expected_ticks = np.arange(0, len(x), 2) # xtick_step=2 | ||
| np.testing.assert_array_equal(xticks_call, expected_ticks) | ||
|
|
||
| # Verify xticklabels are set correctly |
There was a problem hiding this comment.
You only test whether the xtick labels have the correct size not if they are called correctly
| show90=True | ||
| ) | ||
|
|
||
| # Verify subplot was called with correct dimensions |
|
There is one CI check failing (Which is not failing on the main). |
|
This needs documentation changes |
…from-paper-to-memilio-plot
Changes and Information
Please briefly list the changes (main added features, changed items, or corrected bugs) made:
If need be, add additional information and what the reviewer should look out for in particular:
Merge Request - Guideline Checklist
Please check our git workflow. Use the draft feature if the Pull Request is not yet ready to review.
Checks by code author
Checks by code reviewer(s)