Accumulating into a Workspace¶
The default function that is always called by
extract() is
metawards.extractors.output_core().
This core extractor performs the bulk of the work of accumulating all of
the infection data into a single metawards.Workspace object.
This metawards.Workspace object contains;
inf_tot(): The total population size at each of the different disease stages from theworkinfections.pinf_tot(): The total population size at each of the different disease stages from theplayinfections.n_inf_wards(): The number of wards with at least one member for each disease stage.total_inf_ward(): The size of the infected population in each ward (the prevalence).total_new_inf_ward(): The number of new infections on this day in each ward.incidence(): The incidence of infection in each ward.
Output incidence¶
This Workspace contains data that can be easily output,
e.g. the metawards.extractors.output_incidence() supplied extractor
writes the incidence to a file called incidence.dat.bz2. For example,
you can call this from your population.py extractor by changing it
to read;
from metawards.utils import Console
def output_population(population, output_dir, **kwargs):
Console.debug("Hello output_population")
# create an output file called 'population.dat'
popfile = output_dir.open("population.dat",
headers=["day", "date", "S", "E",
"I", "R"])
# write the population to this file
popfile.write(f"{population.day} {population.date.isoformat()} "
f"{population.susceptibles} {population.latent} "
f"{population.total} {population.recovereds}\n")
def extract_population(population, **kwargs):
Console.debug("hello extract_population")
from metawards.extractors import output_incidence
if population.day % 2 == 0:
return [output_population, output_incidence]
else:
return [output_incidence]
Note
See how we are calling output_incidence on every day, but
output_population only on even days.
If you run this extractor using
metawards --extractor population
You will now see that you get a file called incidence.dat.bz2
in the output directory. This will be a big matrix of mostly zeroes,
as no infection has been seeded.
Default outputs¶
The default extractor is extract_default().
This returns;
output_basic(): Writes out basic information to the filesNumberWardsInfected.dat,TotalInfections.datetc.output_dispersal(): Calculates and writes out the geographic disperal of the outbreak toMeanXY.dat,VarXY.dayandDispersal.datoutput_prevalence(): Writes the (large) prevalence matrix toprevalence.dat.output_incidence(): Writes the (large) incidence matrix toincidence.dat.
You can use extract_default()
either by not supplying an extractor
via the --extractor command line argument, or by specifying
--extract-default.
Have a go using;
metawards --extractor extract_default
As well as extract_default(), there is also
extract_small() (only extracting the
“small” files),
“meth:extract_large (extract everything, including
producing large trajectory files) and
extract_none() (extract nothing - useful if
you want to restrict output only to results.csv.bz2).