bucky.viz package¶
Submodules¶
bucky.viz.geoid module¶
-
bucky.viz.geoid.
read_geoid_from_graph
(graph_file=None)¶ Creates a dataframe relating geographic administration levels, e.g. admin2 values in a given admin1.
- Parameters
graph_file (string or None) – Location of graph file. If None, uses most recently created graph in data/input_graphs/
- Returns
df – Dataframe with names and values for admin0, admin1, and admin2 levels
- Return type
Pandas DataFrame
-
bucky.viz.geoid.
read_lookup
(geofile, country='US')¶ Creates a dataframe relating geographic administration levels e.g. admin2 values in a given admin1 based on a lookup table.
- Parameters
geofile (string) – Location of lookup table
country (string (default: 'US')) – Country name
- Returns
df – Dataframe with names and values for admin0, admin1, and admin2
- Return type
Pandas DataFrame
bucky.viz.map module¶
-
bucky.viz.map.
get_dates
(df, frequency='weekly')¶ Given a DataFrame of simulation data, this method returns dates based on the requested frequency.
- Parameters
df (Pandas DataFrame) – Dataframe of simulation data
frequency ({'daily', 'monthly', 'weekly' (default)}) – Frequency of selected dates
- Returns
date_list – List of dates
- Return type
list of strings
-
bucky.viz.map.
get_map_data
(data_dir, adm_level, use_mean=False)¶ Reads requested simulation data.
Maps are created using one level down from the requested map level. For example, a national map is created using state-level data.
- Parameters
data_dir (string) – Location of preprocessed simulation data
adm_level ({'adm0', adm1'}) – Admin level of requested map
use_mean (boolean) – If true, uses mean data. Otherwise, uses median quantile
- Returns
df – Requested preprocessed simulation data
- Return type
Pandas DataFrame
-
bucky.viz.map.
get_state_outline
(adm2_data, adm1_data)¶ Given admin2 shape data, finds matching admin1 shape data in order to get the admin1 outline.
- Parameters
adm2_data (Geopandas GeoDataFrame) – Admin2-level shape data
adm1_data (Geopandas GeoDataFrame) – Admin1-level shape data
- Returns
outline_df – Admin1-level shape data that match values in admin2
- Return type
Geopandas GeoDataFrame
-
bucky.viz.map.
make_adm1_maps
(adm2_shape_df, adm1_shape_df, df, lookup_df, dates, cols, adm1_list, output_dir, log_scale=True, colormap='Reds', add_outline=False)¶ Creates adm1 maps.
- Parameters
adm2_shape_df (Geopandas GeoDataFrame) – Shapefile information at the admin2 level
adm1_shape_df (Geopandas GeoDataFrame) – Shapefile information at the admin1 level
df (Pandas DataFrame) – Simulation data to plot
lookup_df (Pandas DataFrame) – Dataframe containing mapping between admin levels
dates (list of strings) – List of dates to make maps for
cols (list of strings) – List of columns to make maps for
adm1_list (list of strings or None) – List of explicit admin1 names to create names for. If None, a map is made for each unique admin1 in the lookup table
output_dir (string) – Directory to place created maps
log_scale (boolean (default: True)) – If true, uses log scaling
colormap (string, (default: 'Reds')) – Colormap to use; must be a valid Matplotlib colormap
add_outline (boolean (default: False)) – Add a thicker outline to the map
-
bucky.viz.map.
make_map
(shape_df, df, dates, adm_key, cols, output_dir, title_prefix=None, log_scale=True, colormap='Reds', outline_df=None)¶ Creates a map for each date and column.
- Parameters
shape_df (Geopandas GeoDataFrame) – Shapefile information at the required admin level
df (Pandas DataFrame) – Simulation data to plot
dates (list of strings) – List of dates to make maps for
cols (list of strings) – List of columns to make maps for
output_dir (string) – Directory to place created maps
title_prefix (string or None) – String to add to map prefix
log_scale (boolean) – If true, uses log scaling
colormap (string (default: 'Reds')) – Colormap to use; must be a valid Matplotlib colormap
outline_df (Geopandas GeoDataFrame or None) – Shapefile for outline
bucky.viz.plot module¶
Bucky Plotting Tools (bucky.viz.plot
)¶
TODO
-
bucky.viz.plot.
interval
(mean, sem, conf, N)¶
-
bucky.viz.plot.
make_plots
(adm_levels, input_dir, output_dir, lookup, plot_hist, plot_columns, quantiles, window_size, end_date, hist_file, min_hist_points, admin1=None, hist_start=None)¶ Wrapper function around plot. Creates plots, aggregating data if necessary.
- Parameters
adm_levels (list of strings) – List of ADM levels to make plots for
input_dir (string) – Location of simulation data
output_dir (string) – Parent directory to place created plots.
lookup (Pandas DataFrame) – Lookup table for geographic mapping information
plot_hist (boolean) – If true, will plot historical data
plot_columns (list of strings) – List of columns to plot from data
quantiles (list of floats (or None)) – List of quantiles to plot. If None, will plot all available quantiles in data.
window_size (int) – Size of window (in days) to apply to historical data
end_date (string, formatted as YYYY-MM-DD) – Plot data until this date. If None, uses last date in simulation
hist_file (string) – Path to historical data file. If None, uses either CSSE or Covid Tracking data depending on columns requested.
min_hist_points (int) – Minimum number of historical data points to plot.
admin1 (list of strings, or None) – List of admin1 values to make plots for. If None, a plot will be created for every unique admin1 values. Otherwise, plots are only made for those requested.
hist_start (string, formatted as YYYY-MM-DD) – Plot historical data from this point. If None, aligns with simulation start date
-
bucky.viz.plot.
plot
(output_dir, lookup_df, key, sim_data, hist_data, plot_columns, quantiles)¶ Given a dataframe and a key, creates plots with requested columns.
For example, a DataFrame with state-level data would create a plot for each unique state. Simulation data is plotted as a line with shaded confidence intervals. Historical data is added as scatter points if requested.
- Parameters
output_dir (string) – Location to place created plots.
lookup_df (Pandas DataFrame) – Dataframe containing information relating different geographic areas
key (string) – Key to use to relate simulation data and geographic areas. Must appear in lookup and simulation data (and historical data if applicable)
sim_data (Pandas DataFrame) – Simulation data to plot
hist_data (Pandas DataFrame) – Historical data to add to plot
plot_columns (list of strings) – Columns to plot
quantiles (list of floats (or None)) – List of quantiles to plot. If None, will plot all available quantiles in data.