4.6. covid19_stats.engine.viz2 module
This module provides visualization methods for seven-day averaged and single-day averaged COVID-19 new cases/day and deaths/day for MSAs, states, and the CONUS. covid19_region_summary_rate is a front-end to the methods in this module. Methods in this module share many similarities to associated methods in the viz
module.
- covid19_stats.engine.viz2.create_plots_rate_daysfrombeginning(inc_data, days_from_beginning=[7], dirname='/usr/WS2/islam5/covid19_stats/docsrc')
This method is similar to
create_plots_daysfrombeginning
in theviz
module. Creates a collection of quad PNG images (see Section 3.4.2) representing state of seven day averaged COVID-19 new cases/day and deaths/day for a geographical region. Like movie mode in covid19_region_summary_rate, the four quadrants are,upper left
is the summary information for the geographical region.lower left
is the running tally of seven-day averaged new cases/day and deaths/day, by day from first incident.upper right
is the logarithmic coloration of new deaths/day, by day from first incident.lower right
is the logarithmic coloration of new cases/day, by day from first incident.
create_summary_rate_movie_frombeginning
uses this functionality in a multiprocessing fashion to create MP4 movie files for geographical regions. It is easier to show rather than tell. Fig. 4.11 is a quad plot of COVID-19 new cases/day and deaths/day for the NYC metro area, 150 days after this metro’s first COVID-19 incident, that is created by this function.The collection of PNG images that this method creates are auto-cropped and, where needed, resized so that their widths and heights are even numbers. FFmpeg, run through
create_summary_rate_movie_frombeginning
, cannot create an MP4 from PNGs unless the images’ widths and heights are divisible by 2.- Parameters:
inc_data (dict) – the data for incidence of COVID-19 cases and deaths for a given geographical region. See
get_incident_data
for the format of the output data.days_from_beginning (list) – the
list
of days to create quad PNG images. Must be nonempty, and every element must be \(\ge 0\). Default is[ 0, ]
.dirname (str) – the directory into which to save the quad PNG images. The default is the current working directory.
- Returns:
the
list
of filenames of PNG quad images that this method creates, intodirname
. For example, in the method invocation shown in Fig. 4.11,days_from_beginning = [ 150, ]
, and the list this method returns is[ '<dirname>/covid19_nyc_LATEST.0143.png', ]
.- Return type:
- covid19_stats.engine.viz2.create_summary_cases_or_deaths_rate_movie_frombeginning(inc_data, type_disp='cases', dirname='/usr/WS2/islam5/covid19_stats/docsrc', save_imgfiles=False)
This method is similar to
create_summary_cases_or_deaths_movie_frombeginning
in theviz
module. This is the back-end method for movie cases deaths mode for covid19_region_summary_rate. This creates an MP4 movie file of seven-day averaged COVID-19 new cases/day or deaths/day, with identifying metadata, for a given geographical region. Table 4.4 shows the resulting MP4 movie files, of cumulative COVID-19 cases and deaths, for the NYC metro area (top row), and the state of Virginia (bottom row). NYC metro area, latest movie of COVID-19 new cases/day
NYC metro area, latest movie of COVID-19 new deaths/day
Virginia, latest movie of COVID-19 new cases/day
Virginia, latest movie of COVID-19 new deaths/day
Here are the arguments,
- Parameters:
inc_data (dict) – the data for incidence of COVID-19 cases and deaths for a given geographical region. See
get_incident_data
for the format of the output data.type_disp – if
cases
, then show cumulative COVID-19 cases. Ifdeaths
, then show cumulative COVID-19 deaths. Can only becases
ordeaths
.dirname (str) – the directory into which to save the MP4 movie file, and optionally a zip archive of the PNG image files used to create the MP4 movie. The default is the current working directory.
save_imgfiles (bool) – if
True
, then will create a zip archive of the PNG image files used to create the MP4 movie. Its full name is<dirname>/covid19_7day_<prefix>_<type_disp>_LATEST_imagefiles.zip
.<dirname>
is the directory to save the MP4 file,<prefix>
is the region name prefix (for examplenyc
for the NYC metro area) located ininc_data['prefix']
, and<type_disp>
is eithercases
ordeath
. The default isFalse
.
- Returns:
the base name of the MP4 movie file it creates. For example, if
inc_data['prefix']
isnyc
andtype_disp
iscases
, this method returnscovid19_7day_nyc_cases_LATEST.mp4
. This method also saves the MP4 file as<dirname>/covid19_7day_nyc_cases_LATEST.mp4
, where<dirname>
is the directory to save the MP4 file.- Return type:
- covid19_stats.engine.viz2.create_summary_rate_movie_frombeginning(inc_data, dirname='/usr/WS2/islam5/covid19_stats/docsrc', save_imgfiles=False)
This method is similar to
create_summary_rate_movie_frombeginning
in theviz
module. This is the back-end method for movie mode for covid19_region_summary_rate. This creates an MP4 quad movie file of both seven day averaged COVID-19 new cases/day and deaths/day for a geographical region, and optionally a zip archive of PNG images used to create the MP4 file. This usescreate_plots_rate_daysfrombeginning
in a multiprocessing fashion, to create sub-collections of PNG quad images, and then collate them into an MP4 file using FFmpeg. Table 4.5 shows the resulting MP4 movie files, of seven day averged COVID-19 new cases/day and deaths/day, for the NYC metro area and the state of Virginia. NYC metro area, latest quad movie of COVID-19 new cases/day and deaths/day
Virginia, latest quad movie of COVID-19 new cases/day and deaths/day
Here are the arguments,
- Parameters:
inc_data (dict) – the data for incidence of COVID-19 cases and deaths for a given geographical region. See
get_incident_data
for the format of the output data.dirname (str) – the directory into which to save the MP4 movie file, and optionally a zip archive of the PNG image files used to create the MP4 movie. The default is the current working directory.
save_imgfiles (bool) – if
True
, then will create a zip archive of the PNG image files used to create the MP4 movie. Its full name is<dirname>/covid19_7day_<prefix>_LATEST_imagefiles.zip
.<dirname>
is the directory to save the MP4 file, and<prefix>
is the region name prefix (for examplenyc
for the NYC metro area) located ininc_data['prefix']
. The default isFalse
.
- Returns:
the base name of the MP4 movie file it creates. For example, if
inc_data['prefix']
isnyc
, this method returnscovid19_7day_nyc_LATEST.mp4
. This method also saves the MP4 file as<dirname>/covid19_7day_nyc_LATEST.mp4
, where<dirname>
is the directory to save the MP4 file.- Return type:
- covid19_stats.engine.viz2.get_summary_demo_rate_data(inc_data, dirname='/usr/WS2/islam5/covid19_stats/docsrc', store_data=True)
This method is similar to
get_summary_demo_data
in theviz
module. This is the back-end method for show mode for covid19_region_summary_rate. This creates six or eight files for a given geographical region. Given an inputinc_data
dict
, it produces six files by default. Hereprefix
is the value ofinc_data['prefix']
(for examplenyc
for the NYC metro area).covid19_7day_<prefix>_cases_LATEST.pdf
andcovid19_7day_<prefix>_cases_LATEST.png
: a PDF and PNG plot of the latest seven day averaged COVID-19 new cases/day for the geographical region.covid19_7day_<prefix>_death_LATEST.pdf
andcovid19_7day_<prefix>_death_LATEST.png
: a PDF and PNG plot of the latest seven day averaged COVID-19 new deaths/day for the geographical region.covid19_7day_<prefix>_cds_LATEST.pdf
andcovid19_7day_<prefix>_cds_LATEST.png
: a PDF and PNG plot of the latest seven day averaged COVID-19 new cases/day and deaths/day trend lines for the geographical region.
Optionally, one can choose to dump out two serialized
Pandas DataFrames
of the new COVID-19 cases/day and deaths/day, total and per county.covid19_7day_<prefix>_LATEST.pkl.gz
is the seven day averaged serializedPandas DataFrame
for the region. This runs from the seventh day after first incident to the last day. An example for the NYC metro area iscovid19_7day_nyc_LATEST.pkl.gz
.covid19_7day_<prefix>_LATEST.pkl.gz
is the one day averaged serializedPandas DataFrame
for the region. This runs from the first day after the first incident to the last day. An example for the NYC metro area iscovid19_1day_nyc_LATEST.pkl.gz
.
Table 4.6 displays the latest output for the NYC metro area.
NYC metro area, plot of latest COVID-19 new cases/day
NYC metro area, plot of latest COVID-19 new deaths/day
NYC metro area, plot of latest trend lines of COVID-19 new cases/day and deaths/day
Here are the arguments.
- Parameters:
inc_data (dict) – the data for incidence of COVID-19 cases and deaths for a given geographical region. See
get_incident_data
for the format of the output data.dirname (str) – the directory into which to save the six or seven files. The default is the current working directory.
store_data (bool) – if
True
, then create two serializedPandas DataFrames
of the COVID-19 cases and deaths, total and per county, up to the latest incident. Default isTrue
.
- covid19_stats.engine.viz2.plot_cases_deaths_rate_region(inc_data, ax, days_from_beginning=7, doTitle=True, legend_text_scaling=1.0, aspect_ratio_mult=1.0)
This method is similar to
plot_cases_deaths_region
in theviz
module. Plots trend lines of seven day averaged COVID-19 new cases/day and new deaths/day for a region. It is easier to show rather than tell. Fig. 4.12 depicts trend lines of COVID-19 new cases/day and deaths/day for the NYC metro area, 150 days after this metro’s first COVID-19 incident.Here are the arguments.
- Parameters:
inc_data (dict) – the data for incidence of COVID-19 cases and deaths for a given geographical region. See
get_incident_data
for the format of the output data.ax – the
Axes
onto which to make this plot.days_from_beginning (int) – days after first incident of COVID-19 in this region. Must be \(\ge 7\) because of the seven day average.
doTitle (bool) – if
True
, then display the title over the plot. Default isTrue
.legend_text_scaling (float) – sometimes the legend text for the cumulative COVID-19 cases and deaths is too large. This is a multiplier on that text’s font size. Default is 1.0, but must be \(> 0\).
aspect_ratio_mult (float) – in the quad plots created in
create_plots_rate_daysfrombeginning
or increate_summary_rate_movie_frombeginning
, without modification theAxes
may look too squashed and inconsistent with the three otherAxes
orGeoAxes
. This acts as a multiplier on the aspect ratio so that thisAxes
does not look out of place. Default is 1.0, but must be \(> 0\).
- covid19_stats.engine.viz2.plot_cases_or_deaths_rate_bycounty(inc_data, fig, type_disp='cases', days_from_beginning=7, doTitle=True, plot_artists={}, poly_line_width=1.0, legend_text_scaling=1.0, doSmarter=False, rows=1, cols=1, num=1)
This method is similar to
plot_cases_or_deaths_bycounty
in theviz
module. This displays the status of seven-day averaged COVID-19 new cases/day or deaths/days given an incidident datadict
,inc_data
. It displays the status of seven-day averaged COVID-19 new cases/day or deaths/day, a specific number of days from the beginning, coloring the counties in that region according to the legend maximum, and places the resultingGeoAxes
at a specific location in aFigure
grid ofAxes
orGeoAxes
.Instead of returning a
GeoAxes
, this initializes adict
of matplotlib objects,plot_artists
. In this way, subsequent plots, e.g. for different days after the beginnning, do not have to perform the relatively costly operation of recreating theGeoAxes
and fully painting in thePolygon
patches; instead, thesePolygon
patches are re-colored and necessaryText
artists’ strings are changed.This
dict
,plot_artists
, has the following keys, identical to those inplot_cases_or_deaths_bycounty
,axes
: when initialized, theGeoAxes
that consists of all counties, with COVID-19 cases or deaths, to display.sm
: theScalarMappable
describing the coloration by value for each county.
Furthermore, it is easier to show rather than tell. Fig. 4.13 depicts both seven-day averaged COVID-19 new cases/day and deaths/day for the NYC metro area, 150 days after this metro’s first COVID-19 incident.
Fig. 4.14 depicts both seven day averaged COVID-19 new cases/day and deaths/day for the CONUS, 150 days after its first COVID-19 incident.
Here are the arguments.
- Parameters:
inc_data (dict) – the data for incidence of COVID-19 cases and deaths for a given geographical region. See
get_incident_data
for the format of the output data.fig – the
Figure
onto which to create aGeoAxes
(stored into theplot_artists
dict
) containing geographic features. Last three arguments –rows
,cols
, andnum
– describe the relative placement of the createdGeoAxes
. Seeadd_subplot
for those three arguments’ meanings.type_disp (str) – if
cases
, then show cumulative COVID-19 cases. Ifdeaths
, then show cumulative COVID-19 deaths. Can only becases
ordeaths
.days_from_beginning (int) – days after first incident of COVID-19 in this region. Must be \(\ge 7\), due to the seven-day rolling average.
doTitle (bool) – if
True
, then display the title over the plot. Default isTrue
.plot_artists (dict) – this contains the essential plotting objects for quicker re-display when plotting different days. Look at this description.
poly_line_width (float) – the line width of the counties to draw in the plot.
legend_text_scaling (float) – sometimes the text annotations showing the date, number of incident days, and cumulative deaths or cases is too large. This is a multiplier on that text’s font size. Default is 1.0, but must be \(> 0\).
doSmarter (bool) – if
False
, then make a plot tailored for small regions (relative to the size of the earth), such as states or MSAs. IfTrue
, then make a plot tailored for large regions such as the CONUS. Default isFalse
.rows (int) – the number of rows for axes in the
Figure
grid. Must be \(\ge 1\), and by default is 1.cols (int) – the number of columns for axes in the
Figure
grid. Must be \(\ge 1\), and by default is 1.num (int) – the plot number of the
GeoAxes
in thisFigure
grid. Must be \(\ge 1\) and \(\le\)rows
timescolumns
. Its default is 1. Look atadd_subplot
for its meaning.