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 the viz 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.

../_images/covid19_7day_nyc_LATEST.0143.png

Fig. 4.11 Quad plot of seven day averaged COVID-19 new cases/day and deaths/day for the NYC metro area, 150 days after its first incident. The name of the file is covid19_nyc_LATEST.0143.png (150 days minus 7 days), so that FFmpeg can easily create movies; frames must start from all zeros in the file name, so day 7 would be 0000.

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, into dirname. 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:

list

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 the viz 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).

Table 4.4 Latest seven-day averaged COVID-19 new cases/day, and deaths/day, for the NYC metro area and Virginia

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. If deaths, then show cumulative COVID-19 deaths. Can only be cases or deaths.

  • 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 example nyc for the NYC metro area) located in inc_data['prefix'], and <type_disp> is either cases or death. The default is False.

Returns:

the base name of the MP4 movie file it creates. For example, if inc_data['prefix'] is nyc and type_disp is cases, this method returns covid19_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:

str

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 the viz 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 uses create_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.

Table 4.5 Latest quad movies of COVID-19 for the NYC metro area and 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 example nyc for the NYC metro area) located in inc_data['prefix']. The default is False.

Returns:

the base name of the MP4 movie file it creates. For example, if inc_data['prefix'] is nyc, this method returns covid19_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:

str

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 the viz 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 input inc_data dict, it produces six files by default. Here prefix is the value of inc_data['prefix'] (for example nyc for the NYC metro area).

  • covid19_7day_<prefix>_cases_LATEST.pdf and covid19_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 and covid19_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 and covid19_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 serialized Pandas DataFrame for the region. This runs from the seventh day after first incident to the last day. An example for the NYC metro area is covid19_7day_nyc_LATEST.pkl.gz.

  • covid19_7day_<prefix>_LATEST.pkl.gz is the one day averaged serialized Pandas 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 is covid19_1day_nyc_LATEST.pkl.gz.

Table 4.6 displays the latest output for the NYC metro area.

Table 4.6 Latest plots of cumulative COVID-19 cases, deaths, and trend lines for the NYC metro area

covid19_7day_nyc_cases_latest

covid19_7day_nyc_death_latest

covid19_7day_nyc_cds_latest

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 serialized Pandas DataFrames of the COVID-19 cases and deaths, total and per county, up to the latest incident. Default is True.

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 the viz 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.

../_images/viz2_plot_cases_deaths_rate_region_nyc.png

Fig. 4.12 Plot of seven day averaged COVID-19 new cases/day and deaths/day for the NYC metro area, 150 days after its first incident. Plot scaling is logarithmic, and dots accentuate the state of the new cases/day and deaths/day 150 days after first incident. We have chosen to display the title. The lower-alpha and more jagged lines depict the one-day averaged 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.

  • 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 is True.

  • 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 in create_summary_rate_movie_frombeginning, without modification the Axes may look too squashed and inconsistent with the three other Axes or GeoAxes. This acts as a multiplier on the aspect ratio so that this Axes 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 the viz module. This displays the status of seven-day averaged COVID-19 new cases/day or deaths/days given an incidident data dict, 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 resulting GeoAxes at a specific location in a Figure grid of Axes or GeoAxes.

Instead of returning a GeoAxes, this initializes a dict 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 the GeoAxes and fully painting in the Polygon patches; instead, these Polygon patches are re-colored and necessary Text artists’ strings are changed.

This dict, plot_artists, has the following keys, identical to those in plot_cases_or_deaths_bycounty,

  • axes: when initialized, the GeoAxes that consists of all counties, with COVID-19 cases or deaths, to display.

  • sm: the ScalarMappable 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.

../_images/viz2_plot_cases_or_deaths_rate_bycounty_nyc.png

Fig. 4.13 On the left, is the seven-day averaged COVID-19 new cases/day, and on the right, is the COVID-19 new deaths/day, for the NYC metro area, 150 days after its first COVID-19 incident. The color limits for cases (left) is \(10^4\) cases/day, while the color limits for death (right) is \(1.7\times 10^3\) deaths/day. We have chosen to display the titles over both plots. Color scaling is logarithmic.

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.

../_images/viz2_plot_cases_or_deaths_rate_bycounty_conus.png

Fig. 4.14 On the left, is the seven-day averaged COVID-19 new cases/day, and on the right, is the COVID-19 new deaths/day, for the CONUS, 150 days after its first COVID-19 incident. The color limits for cases (left) is \(3.2\times 10^4\) cases/day, while the color limits for death (right) is \(1.7\times 10^3\) deaths/day. We have chosen to display the titles over both plots. Color scaling is logarithmic.

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 a GeoAxes (stored into the plot_artists dict) containing geographic features. Last three arguments – rows, cols, and num – describe the relative placement of the created GeoAxes. See add_subplot for those three arguments’ meanings.

  • type_disp (str) – if cases, then show cumulative COVID-19 cases. If deaths, then show cumulative COVID-19 deaths. Can only be cases or deaths.

  • 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 is True.

  • 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. If True, then make a plot tailored for large regions such as the CONUS. Default is False.

  • 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 this Figure grid. Must be \(\ge 1\) and \(\le\)rows times columns. Its default is 1. Look at add_subplot for its meaning.