Skip to content

fix contemporaneous sampling for wartortle#49

Open
thomaswilliams23 wants to merge 5 commits into
aezarebski:mainfrom
thomaswilliams23:main
Open

fix contemporaneous sampling for wartortle#49
thomaswilliams23 wants to merge 5 commits into
aezarebski:mainfrom
thomaswilliams23:main

Conversation

@thomaswilliams23
Copy link
Copy Markdown
Contributor

No description provided.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements support for contemporaneous (cross-sectional) sampling in the wartortle simulation configuration by adding rho parameter handling to the database storage and analysis workflow.

Key changes:

  • Adds rho parameter storage to the HDF5 database for contemporaneous sampling scenarios
  • Creates new lenient XML template and wartortle configuration for contemporaneous sampling simulations
  • Adds Python script to extract and analyze output distributions including rho values

Reviewed changes

Copilot reviewed 5 out of 7 changed files in this pull request and generated 18 comments.

Show a summary per file
File Description
main.py Adds conditional storage of rho parameter to HDF5 database when contemporaneous sampling is enabled
src/remaster-template-contemporaneous.xml Fixes indentation of rhoReaction element for consistency
src/remaster-template-contemporaneous-lenient.xml New XML template for lenient contemporaneous sampling with higher population threshold
src/get_output_distributions.py New analysis script to extract and report parameter distributions from HDF5 output, including rho handling
config/simulation-wartortle.json New configuration file for wartortle simulation with contemporaneous sampling enabled
config/simulation-charmeleon-alt.json Updates worker count and duration range parameters
.gitignore Adds .DS_Store file patterns to ignore list

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

import h5py
import numpy as np

#look at an hdf5 file, pull out present prevalence and cumulative incidence
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments in Python should have a space after the hash character for readability. The comment style is inconsistent with standard Python conventions (PEP 8).

Copilot uses AI. Check for mistakes.
r0_interval = np.percentile(all_r0_samples, [2.5, 97.5], weights=r0_weights, method='inverted_cdf')
print(f"R0: Median={r0_median:.4f}, 95% interval=({r0_interval[0]:.4f}, {r0_interval[1]:.4f})")

#net removal rate
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments in Python should have a space after the hash character for readability. The comment style is inconsistent with standard Python conventions (PEP 8).

Copilot uses AI. Check for mistakes.



#OUTPUT
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments in Python should have a space after the hash character for readability. The comment style is inconsistent with standard Python conventions (PEP 8).

Copilot uses AI. Check for mistakes.
Comment thread main.py
data=sim["simulation_results"]["present_cumulative"],
)

#put rho in database if doing contemporaneous sampling
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment style is inconsistent with the rest of the codebase. Other comments in this file have a space after the hash character. This comment should follow the same convention.

Suggested change
#put rho in database if doing contemporaneous sampling
# put rho in database if doing contemporaneous sampling

Copilot uses AI. Check for mistakes.
net_removal_interval = np.percentile(all_net_removal_samples, [2.5, 97.5], weights=net_removal_weights, method='inverted_cdf')
print(f"Net Removal Rate: Median={net_removal_median:.4f}, 95% interval=({net_removal_interval[0]:.4f}, {net_removal_interval[1]:.4f})")

#sampling proportion
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments in Python should have a space after the hash character for readability. The comment style is inconsistent with standard Python conventions (PEP 8).

Copilot uses AI. Check for mistakes.
epidemic_duration_interval = np.percentile(epidemic_durations, [2.5, 97.5])
print(f"Epidemic Duration: Median={epidemic_duration_median:.4f}, 95% interval=({epidemic_duration_interval[0]:.4f}, {epidemic_duration_interval[1]:.4f})")

#number of parameter changes
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments in Python should have a space after the hash character for readability. The comment style is inconsistent with standard Python conventions (PEP 8).

Copilot uses AI. Check for mistakes.
Comment thread main.py
Comment on lines +646 to +650

#put rho in database if doing contemporaneous sampling
if "rho" in sim["parameters"].keys():
params_grp.create_dataset("rho", data=sim["parameters"]["rho"]["values"])

Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code block is incorrectly placed outside the 'with open(pf, "rb") as f:' context manager block (which ends at line 645). The variable 'sim' is defined inside that context, and 'params_grp' is created from data read inside that context. This code should be moved inside the with block before line 646, at the same indentation level as the other dataset creation code (lines 638-645).

Suggested change
#put rho in database if doing contemporaneous sampling
if "rho" in sim["parameters"].keys():
params_grp.create_dataset("rho", data=sim["parameters"]["rho"]["values"])
# put rho in database if doing contemporaneous sampling
if "rho" in sim["parameters"]:
params_grp.create_dataset(
"rho", data=sim["parameters"]["rho"]["values"]
)

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thomaswilliams23 the other comment about how the rho is stored appears incorrect but I think copilot is correct on this one about the level of indentation. The sim value may not have the expected value outside of the context.

sampling_prop_interval = np.percentile(all_sampling_prop_samples, [2.5, 97.5], weights=sampling_prop_weights, method='inverted_cdf')
print(f"Sampling Proportion: Median={sampling_prop_median:.4f}, 95% interval=({sampling_prop_interval[0]:.4f}, {sampling_prop_interval[1]:.4f})")

#rho if present
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments in Python should have a space after the hash character for readability. The comment style is inconsistent with standard Python conventions (PEP 8).

Copilot uses AI. Check for mistakes.
#HYPERPARAMS
print("\nHyperparameter Distributions:")

#epidemic duration
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments in Python should have a space after the hash character for readability. The comment style is inconsistent with standard Python conventions (PEP 8).

Copilot uses AI. Check for mistakes.
num_param_changes_interval = np.percentile(num_param_changes, [2.5, 97.5])
print(f"Number of Parameter Changes: Median={num_param_changes_median:.4f}, 95% interval=({num_param_changes_interval[0]:.4f}, {num_param_changes_interval[1]:.4f})")

#change times
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments in Python should have a space after the hash character for readability. The comment style is inconsistent with standard Python conventions (PEP 8).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants