Skip to content

plot_inset_chart_mean_compare

calculate_mean(dir_name)

Calculate the mean of the InsetChart.json files in the given directory.

Parameters:

Name Type Description Default
dir_name str

Directory with InsetChart.json files

required

Return

mean_cr: Mean ChannelReport object raw_data_list: List of raw data dictionaries from the InsetChart.json files

Source code in emodpy_malaria/plotting/plot_inset_chart_mean_compare.py
def calculate_mean(dir_name: str):
    """
    Calculate the mean of the InsetChart.json files in the given directory.

    Args:
        dir_name:
            Directory with InsetChart.json files

    Return:
        mean_cr: Mean ChannelReport object
        raw_data_list: List of raw data dictionaries from the InsetChart.json files
    """
    test_filenames = helpers.get_filenames(dir_or_filename=dir_name,
                                           file_prefix="InsetChart",
                                           file_extension="json")

    raw_data_list = []
    total_df = pd.DataFrame()
    for test_fn in test_filenames:
        with open(test_fn, "r") as test_file:
            test_json = json.loads(test_file.read())
            raw_data_list.append(test_json)
        df = ChannelReport.convert_to_df(test_json)
        total_df = pd.concat([total_df, df])

    mean_df = total_df.groupby("Time").mean().reset_index()
    mean_cr = ChannelReport(df=mean_df)
    mean_cr = mean_cr.convert_df_to_channel_report(df=mean_df)

    return mean_cr, raw_data_list

plot_mean(dir1, dir2, dir3, title=None, add_dir_names_to_title=True, show_raw_data=False, subplot_index_min=0, subplot_index_max=100, output=None)

Plot the mean of the InsetChart.json files in the given directories.

Parameters:

Name Type Description Default
dir1 str

Directory with InsetChart.json files

required
dir2 str

Directory with InsetChart.json files

required
dir3 str

Directory with InsetChart.json files

required
title str

Title of Plot

None
show_raw_data bool

If true, shows the raw/individual simulation data in a lighter color.

False
subplot_index_min int

The index of the first subplot to show based on the alphabetical order of the channels in the report.

0
subplot_index_min int

The index of the last subplot to show based on the alphabetical order of the channels in the report.

0
output str

If provided, a directory will be created and images saved to the folder. If not provided, it opens windows.

None

Return

None, if output is provided, an image will be saved to the output directory, else a window will be opened.

Source code in emodpy_malaria/plotting/plot_inset_chart_mean_compare.py
def plot_mean(dir1: str,
              dir2: str,
              dir3: str,
              title: str = None,
              add_dir_names_to_title: bool = True,
              show_raw_data: bool = False,
              subplot_index_min: int = 0,
              subplot_index_max: int = 100,
              output: str = None):
    """
    Plot the mean of the InsetChart.json files in the given directories.

    Args:
        dir1:
            Directory with InsetChart.json files

        dir2:
            Directory with InsetChart.json files

        dir3:
            Directory with InsetChart.json files

        title:
            Title of Plot

        show_raw_data:
            If true, shows the raw/individual simulation data in a lighter color.

        subplot_index_min:
            The index of the first subplot to show based on the alphabetical
            order of the channels in the report.

        subplot_index_min:
            The index of the last subplot to show based on the alphabetical
            order of the channels in the report.

        output:
            If provided, a directory will be created and images saved to the folder.  If not provided, it opens windows.

    Return:
        None, if output is provided, an image will be saved to the output directory, else a window will be opened.
    """
    dir_names = []
    mean_data = []
    raw_data_lists = []

    if dir1 is not None:
        dir_names.append(dir1)
        mean_cr_1, raw_data_list_1 = calculate_mean(dir1)
        mean_data.append(mean_cr_1)
        raw_data_lists.append(raw_data_list_1)

    if dir2 is not None:
        dir_names.append(dir2)
        mean_cr_2, raw_data_list_2 = calculate_mean(dir2)
        mean_data.append(mean_cr_2)
        raw_data_lists.append(raw_data_list_2)

    if dir3 is not None:
        dir_names.append(dir3)
        mean_cr_3, raw_data_list_3 = calculate_mean(dir3)
        mean_data.append(mean_cr_3)
        raw_data_lists.append(raw_data_list_3)

    plot_name = title
    if plot_name is None:
        plot_name = "InsetChart_Compare"

    tmp_title = ""
    if title is not None:
        tmp_title = title
        if add_dir_names_to_title:
            tmp_title = tmp_title + "\n" + pic.create_title_string(reference=None, data_filenames=dir_names)
    else:
        tmp_title = pic.create_title_string(reference=None, data_filenames=dir_names)

    if not show_raw_data:
        raw_data_lists = None

    pic.plot_data(title=tmp_title,
                  ref_data=None,
                  test_data=mean_data,
                  raw_data_list_of_lists=raw_data_lists,
                  test_filenames=dir_names,
                  subplot_index_min=subplot_index_min,
                  subplot_index_max=subplot_index_max,
                  img_dir=output,
                  plot_name=plot_name)