Skip to content

Commit fa8d411

Browse files
add methods to save population data every 'n' timesteps
1 parent bb4a9cf commit fa8d411

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

config.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ def __init__(self, *args, **kwargs):
1414
self.verbose = False #whether to print infections, recoveries and fatalities to the terminal
1515
self.simulation_steps = 10000 #total simulation steps performed
1616
self.tstep = 0 #current simulation timestep
17-
self.save_data = True #whether to dump data
18-
self.save_timesteps = True #dumps population data every time step
17+
self.save_data = False #whether to dump data at end of simulation
18+
self.save_pop = False #whether to save population matrix every 'save_pop_freq' timesteps
19+
self.save_pop_freq = 10 #population data will be saved every 'n' timesteps. Default: 10
20+
self.save_pop_folder = 'pop_data/' #folder to write population timestep data to
1921
self.endif_no_infections = True #whether to stop simulation if no infections remain
2022

2123
#scenario flags

population.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,30 @@ def save_data(population, pop_tracker):
179179
num_files = len(glob('data/*'))
180180
check_folder('data/%i' %num_files)
181181
np.save('data/%i/population.npy' %num_files, population)
182-
np.save('data/%i/infected.npy' %num_files, pop_tacker.infectious)
182+
np.save('data/%i/infected.npy' %num_files, pop_tracker.infectious)
183183
np.save('data/%i/recovered.npy' %num_files, pop_tracker.recovered)
184184
np.save('data/%i/fatalities.npy' %num_files, pop_tracker.fatalities)
185185

186186

187+
def save_population(population, tstep=0, folder='data_tstep'):
188+
'''dumps population data at given timestep to disk
189+
190+
Function that dumps the simulation data to specific files on the disk.
191+
Saves final state of the population matrix, the array of infected over time,
192+
and the array of fatalities over time
193+
194+
Keyword arguments
195+
-----------------
196+
population : ndarray
197+
the array containing all the population information
198+
199+
tstep : int
200+
the timestep that will be saved
201+
'''
202+
check_folder('%s/' %(folder))
203+
np.save('%s/population_%i.npy' %(folder, tstep), population)
204+
205+
187206
class Population_trackers():
188207
'''class used to track population parameters
189208

0 commit comments

Comments
 (0)