From 7cf000eb7134bdd59d44f025ba38cc03a44cce26 Mon Sep 17 00:00:00 2001 From: Dina Mistry Date: Fri, 26 Feb 2021 11:34:20 -0800 Subject: [PATCH 1/5] updating requirements --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 42b6e16b..bb92e327 100644 --- a/setup.py +++ b/setup.py @@ -45,7 +45,8 @@ include_package_data=True, install_requires=[ "sciris>=1.0.0", - "matplotlib>=3.3.0", + "covasim>=2.0.0", + "matplotlib>=3.3.0, <=3.3.4", "numpy", "scipy", "pandas", From 83127a9434d742b07b0c658d3b9b21e551776a6f Mon Sep 17 00:00:00 2001 From: Dina Mistry Date: Fri, 26 Feb 2021 14:41:37 -0800 Subject: [PATCH 2/5] fixing docstrings --- synthpops/plotting.py | 66 ++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 39 deletions(-) diff --git a/synthpops/plotting.py b/synthpops/plotting.py index 272cd5b8..08f911cc 100644 --- a/synthpops/plotting.py +++ b/synthpops/plotting.py @@ -508,21 +508,18 @@ def plot_array(expected, fig=None, ax=None, **kwargs): expected (array) : Array of expected values fig (matplotlib.figure) : Matplotlib.figure object ax (matplotlib.axis) : Matplotlib.axes object - - Other Parameters: - **kwargs: - generated (array) : Array of values generated using a model - names (list or dict) : names to display on x-axis, default is set to the indexes of data - figname (str) : name to save figure to disk - figdir (str) : directory to save the plot if provided - prefix (str) : used to prefix the title of the plot - fontsize (float) : default fontsize - color_1 (str) : color for expected data - color_2 (str) : color for generated data - expect_label (str) : Label to show in the plot, default to "expected" - value_text (bool) : If True, display the values on top of the bar if specified - rotation (float) : rotation angle for xticklabels - binned (bool) : If True, data are binned. Else, if False, plot a simple histogram for expected data. + **generated (array) : Array of values generated using a model + **names (list or dict) : names to display on x-axis, default is set to the indexes of data + **figname (str) : name to save figure to disk + **figdir (str) : directory to save the plot if provided + **prefix (str) : used to prefix the title of the plot + **fontsize (float) : default fontsize + **color_1 (str) : color for expected data + **color_2 (str) : color for generated data + **expect_label (str) : Label to show in the plot, default to "expected" + **value_text (bool) : If True, display the values on top of the bar if specified + **rotation (float) : rotation angle for xticklabels + **binned (bool) : If True, data are binned. Else, if False, plot a simple histogram for expected data. Returns: Matplotlib figure and axes. @@ -587,14 +584,11 @@ def autolabel(ax, rects, h_offset=0, v_offset=0.3, **kwargs): Attach a text label above each bar in *rects*, displaying its height. Args: - ax : Matplotlib.axes object - rects : Matplotlib.container.BarContainer - h_offset (float) : The position x to place the text at. - v_offset (float) : The position y to place the text at. - - Other Parameters: - **kwargs: - fontsize (float) : Default fontsize + ax : Matplotlib.axes object + rects : Matplotlib.container.BarContainer + h_offset (float) : The position x to place the text at. + v_offset (float) : The position y to place the text at. + **fontsize (float) : Default fontsize Returns: None. @@ -619,13 +613,7 @@ def plot_ages(pop, *args, **kwargs): Plot a comparison of the expected and generated age distribution. Args: - pop (pop object): population, either synthpops.pop.Pop, covasim.people.People, or dict - - Returns: - Matplotlib figure and axes. - - Other Parameters: - **kwargs: + pop (pop object) : population, either synthpops.pop.Pop, covasim.people.People, or dict left (float) : Matplotlib.figure.subplot.left right (float) : Matplotlib.figure.subplot.right top (float) : Matplotlib.figure.subplot.top @@ -636,6 +624,9 @@ def plot_ages(pop, *args, **kwargs): figname (str) : name to save figure to disk comparison (bool) : If True, plot comparison to the generated population + Returns: + Matplotlib figure and axes. + Note: If using pop with type covasim.people.Pop or dict, args must be supplied for the location parameters to get the expected distribution. @@ -723,15 +714,9 @@ def plot_school_sizes(pop, *args, **kwargs): each type of school expected. Args: - pop (pop object): population, either synthpops.pop.Pop, or dict - args (list): list of arguments to pass to data methods and plotting (see below) - kwargs (dict) : keyword arguments to pass to data methods and plotting (see below). - - Returns: - Matplotlib figure and axes. - - Other Parameters: - **kwargs: + pop (pop object) : population, either synthpops.pop.Pop, or dict + args (list) : list of arguments to pass to data methods and plotting (see below) + kwargs (dict) : keyword arguments to pass to data methods and plotting (see below). with_school_types (type) : If True, plot school size distributions by type, else plot overall school size distributions keys_to_exclude (str or list) : school types to exclude left (float) : Matplotlib.figure.subplot.left @@ -749,6 +734,9 @@ def plot_school_sizes(pop, *args, **kwargs): figname (str) : name to save figure to disk comparison (bool) : If True, plot comparison to the generated population + Returns: + Matplotlib figure and axes. + Note: If using pop with type covasim.people.Pop or dict, args must be supplied for the location parameters to get the expected distribution. From 35248c48f47c093987b7f9ec5e973758a3ac37b8 Mon Sep 17 00:00:00 2001 From: Dina Mistry Date: Fri, 26 Feb 2021 15:37:46 -0800 Subject: [PATCH 3/5] more doc fixing --- synthpops/plotting.py | 112 ++++++++++++++++++++---------------------- 1 file changed, 52 insertions(+), 60 deletions(-) diff --git a/synthpops/plotting.py b/synthpops/plotting.py index 08f911cc..e96e5e0a 100644 --- a/synthpops/plotting.py +++ b/synthpops/plotting.py @@ -279,20 +279,17 @@ def plot_contact_matrix(matrix, age_count, aggregate_age_count, age_brackets, ag aggregate_age_count (dict) : dictionary with the count of individuals in the population in each age bracket age_brackets (dict) : dictionary mapping age bracket keys to age bracket range age_by_brackets_dic (dict) : dictionary mapping age to the age bracket range it falls in - - Other Parameters: - **kwargs: - layer (str) : name of the physial contact layer: H for households, S for schools, W for workplaces, C for community, etc. - density_or_frequency (str) : Default value is 'density', see notes for more details. - logcolors_flag (bool) : If True, plot heatmap in logscale - aggregate_flag (bool) : If True, plot the contact matrix for aggregate age brackets, else single year age contact matrix. - cmap(str or matplotlib colormap) : colormap - fontsize (int) : base font size - rotation (int) : rotation for x axis labels - title_prefix(str) : optional title prefix for the figure - fig (Figure) : if supplied, use this figure instead of generating one - ax (Axes) : if supplied, use these axes instead of generating one - titles (dict) : dictionary of titles to be used for different layers + **layer (str) : name of the physial contact layer: H for households, S for schools, W for workplaces, C for community, etc. + **density_or_frequency (str) : Default value is 'density', see notes for more details. + **logcolors_flag (bool) : If True, plot heatmap in logscale + **aggregate_flag (bool) : If True, plot the contact matrix for aggregate age brackets, else single year age contact matrix. + **cmap(str or matplotlib colormap) : colormap + **fontsize (int) : base font size + **rotation (int) : rotation for x axis labels + **title_prefix(str) : optional title prefix for the figure + **fig (Figure) : if supplied, use this figure instead of generating one + **ax (Axes) : if supplied, use these axes instead of generating one + **titles (dict) : dictionary of titles to be used for different layers Returns: Matplotlib figure and axes. @@ -433,23 +430,20 @@ def plot_contacts(pop, **kwargs): Args: pop (pop object): population, either synthpops.pop.Pop or dict - - Other Parameters: - **kwargs: - layer (str) : name of the physial contact layer: H for households, S for schools, W for workplaces, C for community or other - aggregate_flag (bool) : If True, plot the contact matrix for aggregate age brackets, else single year age contact matrix. - logcolors_flag (bool) : If True, plot heatmap in logscale - density_or_frequency (str) : If 'density', then each contact counts for 1/(group size -1) of a person's contact in a group, elif 'frequency' then count each contact. This means that more people in a group leads to higher rates of contact/exposure. - state_location (string) : name of the state the location is in - country_location (string) : name of the country the location is in - cmap (str or matplotlib cmap) : colormap - fontsize (int) : base font size - rotation (int) : rotation for x axis labels - title_prefix(str) : optional title prefix for the figure - fig (matplotlib.figure) : If supplied, use this figure instead of generating one - ax (matplotlib.axes) : If supplied, use these axes instead of generating one - do_show (bool) : If True, show the plot - do_save (bool) : If True, save the plot to disk + **layer (str) : name of the physial contact layer: H for households, S for schools, W for workplaces, C for community or other + **aggregate_flag (bool) : If True, plot the contact matrix for aggregate age brackets, else single year age contact matrix. + **logcolors_flag (bool) : If True, plot heatmap in logscale + **density_or_frequency (str) : If 'density', then each contact counts for 1/(group size -1) of a person's contact in a group, elif 'frequency' then count each contact. This means that more people in a group leads to higher rates of contact/exposure. + **state_location (string) : name of the state the location is in + **country_location (string) : name of the country the location is in + **cmap (str or matplotlib cmap) : colormap + **fontsize (int) : base font size + **rotation (int) : rotation for x axis labels + **title_prefix(str) : optional title prefix for the figure + **fig (matplotlib.figure) : If supplied, use this figure instead of generating one + **ax (matplotlib.axes) : If supplied, use these axes instead of generating one + **do_show (bool) : If True, show the plot + **do_save (bool) : If True, save the plot to disk Returns: Matplotlib figure. @@ -608,21 +602,21 @@ def autolabel(ax, rects, h_offset=0, v_offset=0.3, **kwargs): text.set_fontsize(kwargs.fontsize) -def plot_ages(pop, *args, **kwargs): +def plot_ages(pop, **kwargs): """ Plot a comparison of the expected and generated age distribution. Args: pop (pop object) : population, either synthpops.pop.Pop, covasim.people.People, or dict - left (float) : Matplotlib.figure.subplot.left - right (float) : Matplotlib.figure.subplot.right - top (float) : Matplotlib.figure.subplot.top - bottom (float) : Matplotlib.figure.subplot.bottom - color_1 (str) : color for expected data - color_2 (str) : color for data from generated population - fontsize (float) : Matplotlib.figure.fontsize - figname (str) : name to save figure to disk - comparison (bool) : If True, plot comparison to the generated population + **left (float) : Matplotlib.figure.subplot.left + **right (float) : Matplotlib.figure.subplot.right + **top (float) : Matplotlib.figure.subplot.top + **bottom (float) : Matplotlib.figure.subplot.bottom + **color_1 (str) : color for expected data + **color_2 (str) : color for data from generated population + **fontsize (float) : Matplotlib.figure.fontsize + **figname (str) : name to save figure to disk + **comparison (bool) : If True, plot comparison to the generated population Returns: Matplotlib figure and axes. @@ -708,31 +702,29 @@ def plot_ages(pop, *args, **kwargs): return fig, ax -def plot_school_sizes(pop, *args, **kwargs): +def plot_school_sizes(pop, **kwargs): """ Plot a comparison of the expected and generated school size distribution for each type of school expected. Args: pop (pop object) : population, either synthpops.pop.Pop, or dict - args (list) : list of arguments to pass to data methods and plotting (see below) - kwargs (dict) : keyword arguments to pass to data methods and plotting (see below). - with_school_types (type) : If True, plot school size distributions by type, else plot overall school size distributions - keys_to_exclude (str or list) : school types to exclude - left (float) : Matplotlib.figure.subplot.left - right (float) : Matplotlib.figure.subplot.right - top (float) : Matplotlib.figure.subplot.top - bottom (float) : Matplotlib.figure.subplot.bottom - hspace (float) : Matplotlib.figure.subplot.hspace - subplot_height (float) : height of subplot in inches - subplot_width (float) : width of subplot in inches - screen_height_factor (float) : fraction of the screen height to use for display - location_text_y (float) : height to add location text to figure - fontsize (float) : Matplotlib.figure.fontsize - rotation (float) : rotation angle for xticklabels - cmap (str) : colormap - figname (str) : name to save figure to disk - comparison (bool) : If True, plot comparison to the generated population + **with_school_types (type) : If True, plot school size distributions by type, else plot overall school size distributions + **keys_to_exclude (str or list) : school types to exclude + **left (float) : Matplotlib.figure.subplot.left + **right (float) : Matplotlib.figure.subplot.right + **top (float) : Matplotlib.figure.subplot.top + **bottom (float) : Matplotlib.figure.subplot.bottom + **hspace (float) : Matplotlib.figure.subplot.hspace + **subplot_height (float) : height of subplot in inches + **subplot_width (float) : width of subplot in inches + **screen_height_factor (float) : fraction of the screen height to use for display + **location_text_y (float) : height to add location text to figure + **fontsize (float) : Matplotlib.figure.fontsize + **rotation (float) : rotation angle for xticklabels + **cmap (str) : colormap + **figname (str) : name to save figure to disk + **comparison (bool) : If True, plot comparison to the generated population Returns: Matplotlib figure and axes. From 727bc56b2a6295a546ba2018049c8f12863b82f9 Mon Sep 17 00:00:00 2001 From: Dina Mistry Date: Fri, 26 Feb 2021 16:05:20 -0800 Subject: [PATCH 4/5] one last simple attempt for docs with kwargs --- synthpops/plotting.py | 16 ++++++++-------- synthpops/schools.py | 11 ++++------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/synthpops/plotting.py b/synthpops/plotting.py index e96e5e0a..35af53e6 100644 --- a/synthpops/plotting.py +++ b/synthpops/plotting.py @@ -274,11 +274,11 @@ def plot_contact_matrix(matrix, age_count, aggregate_age_count, age_brackets, ag for aggregated age brackets. Args: - matrix (np.array) : symmetric contact matrix, element ij is the contact for an average individual in age group i with all of their contacts in age group j - age_count (dict) : dictionary with the count of individuals in the population for each age - aggregate_age_count (dict) : dictionary with the count of individuals in the population in each age bracket - age_brackets (dict) : dictionary mapping age bracket keys to age bracket range - age_by_brackets_dic (dict) : dictionary mapping age to the age bracket range it falls in + matrix (np.array) : symmetric contact matrix, element ij is the contact for an average individual in age group i with all of their contacts in age group j + age_count (dict) : dictionary with the count of individuals in the population for each age + aggregate_age_count (dict) : dictionary with the count of individuals in the population in each age bracket + age_brackets (dict) : dictionary mapping age bracket keys to age bracket range + age_by_brackets_dic (dict) : dictionary mapping age to the age bracket range it falls in **layer (str) : name of the physial contact layer: H for households, S for schools, W for workplaces, C for community, etc. **density_or_frequency (str) : Default value is 'density', see notes for more details. **logcolors_flag (bool) : If True, plot heatmap in logscale @@ -429,7 +429,7 @@ def plot_contacts(pop, **kwargs): Plot the age mixing matrix for a specific contact layer. Args: - pop (pop object): population, either synthpops.pop.Pop or dict + pop (pop object) : population, either synthpops.pop.Pop or dict **layer (str) : name of the physial contact layer: H for households, S for schools, W for workplaces, C for community or other **aggregate_flag (bool) : If True, plot the contact matrix for aggregate age brackets, else single year age contact matrix. **logcolors_flag (bool) : If True, plot heatmap in logscale @@ -607,7 +607,7 @@ def plot_ages(pop, **kwargs): Plot a comparison of the expected and generated age distribution. Args: - pop (pop object) : population, either synthpops.pop.Pop, covasim.people.People, or dict + pop (pop object) : population, either synthpops.pop.Pop, covasim.people.People, or dict **left (float) : Matplotlib.figure.subplot.left **right (float) : Matplotlib.figure.subplot.right **top (float) : Matplotlib.figure.subplot.top @@ -708,7 +708,7 @@ def plot_school_sizes(pop, **kwargs): each type of school expected. Args: - pop (pop object) : population, either synthpops.pop.Pop, or dict + pop (pop object) : population, either synthpops.pop.Pop, or dict **with_school_types (type) : If True, plot school size distributions by type, else plot overall school size distributions **keys_to_exclude (str or list) : school types to exclude **left (float) : Matplotlib.figure.subplot.left diff --git a/synthpops/schools.py b/synthpops/schools.py index 4376abab..3b81e872 100644 --- a/synthpops/schools.py +++ b/synthpops/schools.py @@ -1236,17 +1236,14 @@ def send_students_to_school(school_sizes, uids_in_school, uids_in_school_by_age, return syn_schools, syn_school_uids, syn_school_types -def get_enrollment_by_school_type(popdict, *args, **kwargs): +def get_enrollment_by_school_type(popdict, **kwargs): """ Get enrollment sizes by school types in popdict. Args: - popdict (dict): population dictionary - - Other Parameters: - **kwargs: - with_school_types (bool) : If True, return enrollment by school types as defined in the popdict. Otherwise, combine all enrollment sizes for a school type of None. - keys_to_exclude (list) : school types to exclude + popdict (dict) : population dictionary + **with_school_types (bool) : If True, return enrollment by school types as defined in the popdict. Otherwise, combine all enrollment sizes for a school type of None. + **keys_to_exclude (list) : school types to exclude Returns: dict: Dictionary of generated enrollment sizes by school type. From 06d73f6b03568724cb644bb617ae9f39c040dac4 Mon Sep 17 00:00:00 2001 From: Dina Mistry Date: Fri, 26 Feb 2021 16:32:42 -0800 Subject: [PATCH 5/5] minor version update --- synthpops/version.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/synthpops/version.py b/synthpops/version.py index bea13ea2..f614b61d 100644 --- a/synthpops/version.py +++ b/synthpops/version.py @@ -1,2 +1,2 @@ -__version__ = '1.5.0' -__versiondate__ = '2021-02-13' +__version__ = '1.5.1' +__versiondate__ = '2021-02-26'