Skip to content

Commit

Permalink
formatting tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sandypreiss committed Mar 20, 2024
1 parent e84a903 commit f19ace9
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 47 deletions.
36 changes: 18 additions & 18 deletions crcsim/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -1263,15 +1263,15 @@ def test_diagnostic(self, symptomatic: bool = False):

# Store number of polyps found by size. These counts influence how
# soon the person needs to be retested.
self.previous_test_small[self.diagnostic_test] = (
num_detected_polyps_small
)
self.previous_test_medium[self.diagnostic_test] = (
num_detected_polyps_medium
)
self.previous_test_large[self.diagnostic_test] = (
num_detected_polyps_large
)
self.previous_test_small[
self.diagnostic_test
] = num_detected_polyps_small
self.previous_test_medium[
self.diagnostic_test
] = num_detected_polyps_medium
self.previous_test_large[
self.diagnostic_test
] = num_detected_polyps_large

# check whether test resulted in perforation
if self.rng.random() < test_params["proportion_perforation"]:
Expand Down Expand Up @@ -1537,15 +1537,15 @@ def test_surveillance(self, symptomatic: bool = False):

# Store number of polyps found by size. These counts influence how
# soon the person needs to be retested.
self.previous_test_small[self.surveillance_test] = (
num_detected_polyps_small
)
self.previous_test_medium[self.surveillance_test] = (
num_detected_polyps_medium
)
self.previous_test_large[self.surveillance_test] = (
num_detected_polyps_large
)
self.previous_test_small[
self.surveillance_test
] = num_detected_polyps_small
self.previous_test_medium[
self.surveillance_test
] = num_detected_polyps_medium
self.previous_test_large[
self.surveillance_test
] = num_detected_polyps_large

# check whether test resulted in perforation
if self.rng.random() < test_params["proportion_perforation"]:
Expand Down
46 changes: 23 additions & 23 deletions crcsim/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ def summarize(self):
]
unscreened_undiagnosed_40yos = unscreened_undiagnosed_40yo_deaths.person_id
n_unscreened_undiagnosed_40yos = len(unscreened_undiagnosed_40yos)
replication_output_row["n_unscreened_undiagnosed_40yos"] = (
n_unscreened_undiagnosed_40yos
)
replication_output_row[
"n_unscreened_undiagnosed_40yos"
] = n_unscreened_undiagnosed_40yos
thousands_of_40yos = n_unscreened_undiagnosed_40yos / 1_000

# Number of times an individual entered the polyp state
Expand Down Expand Up @@ -161,9 +161,9 @@ def summarize(self):
discounted_expected_lifespans_over_40 = self.discount_ages(
expected_lifespans_over_40.time
)
replication_output_row["discounted_lifeexp_if_unscreened_undiagnosed_at_40"] = (
np.mean(discounted_expected_lifespans_over_40)
)
replication_output_row[
"discounted_lifeexp_if_unscreened_undiagnosed_at_40"
] = np.mean(discounted_expected_lifespans_over_40)

# Mean observed lifespan among all individuals
replication_output_row["lifeobs"] = np.mean(deaths.time)
Expand All @@ -179,9 +179,9 @@ def summarize(self):
discounted_lifespans_over_40 = self.discount_ages(
unscreened_undiagnosed_40yo_deaths.time
)
replication_output_row["discounted_lifeobs_if_unscreened_undiagnosed_at_40"] = (
np.mean(discounted_lifespans_over_40)
)
replication_output_row[
"discounted_lifeobs_if_unscreened_undiagnosed_at_40"
] = np.mean(discounted_lifespans_over_40)

# Mean number of life years lost to CRC among all individuals
replication_output_row["lifelost"] = (
Expand Down Expand Up @@ -381,12 +381,12 @@ def summarize(self):
mean_discounted_cost_treatment = (
treatments_in_phase.discounted_cost.sum() / n_individuals
)
replication_output_row[f"cost_treatment_{phase.lower()}"] = (
mean_cost_treatment
)
replication_output_row[f"discounted_cost_treatment_{phase.lower()}"] = (
mean_discounted_cost_treatment
)
replication_output_row[
f"cost_treatment_{phase.lower()}"
] = mean_cost_treatment
replication_output_row[
f"discounted_cost_treatment_{phase.lower()}"
] = mean_discounted_cost_treatment
# per 1k undiagnosed and unscreened 40-year-olds
treatments_in_phase_over_40 = treatments_over_40[
treatments_over_40.role.eq(phase)
Expand Down Expand Up @@ -668,9 +668,9 @@ def summarize(self):
polyp_to_pre["time_polyp_to_pre"] = (
polyp_to_pre["time_cancer"] - polyp_to_pre["time_polyp_formation"]
)
replication_output_row["time_polyp_to_pre"] = (
polyp_to_pre.time_polyp_to_pre.mean()
)
replication_output_row[
"time_polyp_to_pre"
] = polyp_to_pre.time_polyp_to_pre.mean()

# Among all instances of an individual being clinically diagnosed with CRC,
# mean time between the onset of CRC and the diagnosis of CRC.
Expand Down Expand Up @@ -716,9 +716,9 @@ def summarize(self):
clin_to_dead["time_clin_to_dead"] = (
clin_to_dead["time_dead"] - clin_to_dead["time_clin"]
)
replication_output_row["time_clin_to_dead"] = (
clin_to_dead.time_clin_to_dead.mean()
)
replication_output_row[
"time_clin_to_dead"
] = clin_to_dead.time_clin_to_dead.mean()

# Calculate population rates
status_arrays = self.compute_status_arrays()
Expand Down Expand Up @@ -983,11 +983,11 @@ def compute_pop_rates(self, status_arrays: list):
"""
# Sum all of the person status arrays to get an array of counts of the number of
# people in each status for each year.
statuses: np.ndarray = sum(status_arrays)
status_array: np.ndarray = sum(status_arrays)

# Convert to DataFrame so we can index by column name
statuses = pd.DataFrame(
statuses,
status_array,
columns=[
"alive",
"crc_death",
Expand Down
12 changes: 6 additions & 6 deletions tests/test_variable_routine_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ def __init__(self, *args, **kwargs):
self.out = Output(file_name="unused")
# Sex and race_ethnicity are irrelevant to this test but we need to choose an
# arbitrary value for the simulation to run.
self.sex = ("female",)
self.race_ethnicity = ("black_non_hispanic",)
self.sex = "female"
self.race_ethnicity = "black_non_hispanic"

def start(self):
self.choose_tests()
Expand Down Expand Up @@ -166,8 +166,8 @@ def test_testing_year_misalignment(params):
with open("parameters.json", "r") as f:
params = json.load(f)
params["tests"]["Colonoscopy"]["routine_end"] = 85
with TemporaryDirectory() as tmpdir:
tmp_path = Path(tmpdir) / "parameters.json"
with TemporaryDirectory() as tmp_dir:
tmp_path = Path(tmp_dir) / "parameters.json"
with open(tmp_path, "w") as f:
json.dump(params, f)
with pytest.raises(ValueError):
Expand Down Expand Up @@ -196,7 +196,7 @@ def test_one_colonoscopy_equivalence(params, test_switching_scenarios):
]

p1 = TestPerson(
id=1,
id=None,
sex=None,
race_ethnicity=None,
params=params_one_colonoscopy_v1,
Expand All @@ -208,7 +208,7 @@ def test_one_colonoscopy_equivalence(params, test_switching_scenarios):
p1.simulate()

p2 = TestPerson(
id=2,
id=None,
sex=None,
race_ethnicity=None,
params=params_one_colonoscopy_v1,
Expand Down

0 comments on commit f19ace9

Please sign in to comment.