Skip to content

Commit

Permalink
Changed 'New Infections' to New_Infections like a good unix boy and t…
Browse files Browse the repository at this point in the history
…o make post-processing easier.
  • Loading branch information
Jonathan Bloedow committed Jun 18, 2024
1 parent 3a734a6 commit 5858d46
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 18 deletions.
12 changes: 6 additions & 6 deletions jb/src/post_proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ def get_cases(node_id=0):
# Calculate the week number based on Timestep
df_filtered['Week'] = df_filtered['Timestep'] // 7

# Group by Week and sum the New Infections for each week
weekly_new_infections = df_filtered.groupby('Week')['New Infections'].sum().reset_index()
return weekly_new_infections["New Infections"].to_numpy()
# Group by Week and sum the New_Infections for each week
weekly_new_infections = df_filtered.groupby('Week')['New_Infections'].sum().reset_index()
return weekly_new_infections["New_Infections"].to_numpy()

def log_transform(x, debug=1):
"""
Expand Down Expand Up @@ -79,7 +79,7 @@ def analyze_ccs():
cases_df = cases_df[cases_df["Timestep"] > burnin]

# Set the parameters for the binomial distribution
num_trials = cases_df['New Infections'] # Number of trials (events)
num_trials = cases_df['New_Infections'] # Number of trials (events)
prob_success = 0.5 # Probability of success (observation)

cases_df['Observed Infections'] = binom.rvs(num_trials, prob_success)
Expand Down Expand Up @@ -171,7 +171,7 @@ def analyze():
# 1) Total new infections per year...

# Calculate the total number of new infections
total_new_infections = df["New Infections"].sum()
total_new_infections = df["New_Infections"].sum()

# Calculate the number of years
num_years = ( df["Timestep"].max()-burnin) / 365 # Assuming 365 timesteps per year
Expand All @@ -183,7 +183,7 @@ def analyze():
df_london = df[df["Node"] == 0]

# Calculate the total number of new infections in London
total_new_infections_london = df_london["New Infections"].sum()
total_new_infections_london = df_london["New_Infections"].sum()

# Calculate the average number of new infections in London per year
average_new_infections_per_year_london = total_new_infections_london / num_years
Expand Down
2 changes: 1 addition & 1 deletion jb/src/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def init():
else:
csvfile = open( settings.report_filename, 'w', newline='', buffering=int(1024*1024))
csvwriter = csv.writer(csvfile)
csvwriter.writerow(['Timestep', 'Node', 'Susceptible', 'Infected', 'New Infections', 'Recovered', 'Births'])
csvwriter.writerow(['Timestep', 'Node', 'Susceptible', 'Infected', 'New_Infections', 'Recovered', 'Births'])
if publish_report:
global client_sock
client_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Expand Down
2 changes: 1 addition & 1 deletion jb/src/sir_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ def calculate_new_infections( data, inf, sus, totals ):
ret_ni = np.zeros(settings.num_nodes).astype( np.uint32 )
for node in range(settings.num_nodes):
ret_ni[node] = int(sus[node]*inf[node]*settings.base_infectivity*totals[node])
#print( f"New Infections: {new_infections} = {np.array(sorted(sus.values()))} * {np.array(sorted(inf.values()))} * {settings.base_infectivity}" )
#print( f"New_Infections: {new_infections} = {np.array(sorted(sus.values()))} * {np.array(sorted(inf.values()))} * {settings.base_infectivity}" )
return ret_ni

def handle_transmission_by_node( data, new_infections, node=0 ):
Expand Down
4 changes: 2 additions & 2 deletions jb/src/sir_numpy_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def cni_c():
return new_infections

def handle_transmission_by_node( data, new_infections, susceptible_counts, node=0 ):
# print( f"DEBUG: New Infections: {new_infections}" )
# print( f"DEBUG: New_Infections: {new_infections}" )
# print( f"DEBUG: susceptible_counts: {susceptible_counts}" )
if new_infections[node]>susceptible_counts[node]:
raise ValueError( f"ERROR: Asked for {new_infections[node]} new infections but only {susceptible_counts[node]} susceptibles exist in node {node}." )
Expand Down Expand Up @@ -445,7 +445,7 @@ def handle_new_infections_np(new_infections):

def handle_transmission( data_in, new_infections_in, susceptible_counts ):
# We want to do this in parallel;
#print( f"DEBUG: New Infections: {new_infections_in}" )
#print( f"DEBUG: New_Infections: {new_infections_in}" )
update_ages_lib.handle_new_infections_mp(
unborn_end_idx, # we waste a few cycles now coz the first block is immune from maternal immunity
dynamic_eula_idx,
Expand Down
8 changes: 4 additions & 4 deletions jb/tests/test_calc_new_inf_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,8 @@ def test_calculate_new_infections(self):

# Compare with reference results
#self.assert( new_infections_timestep == ref_results[timestep], f"Results mismatch at timestep {timestep}" )
#print( f"New Infections [test] @ {timestep} = {new_infections_timestep}\n" )
#print( f"New Infections [ref][ @ {timestep} = {NI[timestep]}\n" )
#print( f"New_Infections [test] @ {timestep} = {new_infections_timestep}\n" )
#print( f"New_Infections [ref][ @ {timestep} = {NI[timestep]}\n" )
self.assertAlmostEqual( new_infections_timestep, NI[timestep], delta=10 ) # , "Results mismatch at timestep " + str(timestep)

# Call run_ref_model to get reference results
Expand Down Expand Up @@ -505,8 +505,8 @@ def test_calculate_new_infections(self):

# Compare with reference results
#self.assert( new_infections_timestep == ref_results[timestep], f"Results mismatch at timestep {timestep}" )
#print( f"New Infections [test] @ {timestep} = {new_infections_timestep}\n" )
#print( f"New Infections [ref][ @ {timestep} = {NI[timestep]}\n" )
#print( f"New_Infections [test] @ {timestep} = {new_infections_timestep}\n" )
#print( f"New_Infections [ref][ @ {timestep} = {NI[timestep]}\n" )
self.assertAlmostEqual( new_infections_timestep, NI[timestep], delta=10 ) # , "Results mismatch at timestep " + str(timestep)


Expand Down
2 changes: 1 addition & 1 deletion jb/utils/add_observed_inc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
df = pd.read_csv(input_file)

# Set the parameters for the binomial distribution
num_trials = df['New Infections'] # Number of trials (events)
num_trials = df['New_Infections'] # Number of trials (events)
prob_success = 0.5 # Probability of success (observation)

# Generate the binomial distribution
Expand Down
7 changes: 4 additions & 3 deletions jb/utils/folium_animate_from_sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from folium.plugins import HeatMapWithTime

# Connect to the SQLite database (or create it)
conn = sqlite3.connect(':memory:')
#conn = sqlite3.connect(':memory:')
conn = sqlite3.connect('ew.db')
cursor = conn.cursor()

def preproc( sim_report_file ):
Expand All @@ -34,7 +35,7 @@ def preproc( sim_report_file ):
# Create the view
cursor.execute("""
CREATE VIEW cases AS
SELECT Timestep, Node, Name, Latitude, Longitude, "New Infections"
SELECT Timestep, Node, Name, Latitude, Longitude, New_Infections
FROM engwal, cities
WHERE engwal.Node = cities.ID
""")
Expand All @@ -48,7 +49,7 @@ def process( output_file ):
m = folium.Map(location=(birmingham_location[0],birmingham_location[1]), zoom_start=8) # Create a list to store the data for HeatMapWithTime

start_time=800
cursor.execute(f'SELECT CAST(Timestep AS INT), Latitude, Longitude, CAST("New Infections" AS INT) FROM cases WHERE (CAST(Timestep AS INT)>{start_time})')
cursor.execute(f'SELECT CAST(Timestep AS INT), Latitude, Longitude, CAST(New_Infections AS INT) FROM cases WHERE (CAST(Timestep AS INT)>{start_time})')
raw_data = cursor.fetchall()

# Group the data by timestep
Expand Down

0 comments on commit 5858d46

Please sign in to comment.