From b6575f2507caed1ccb1881308288a84b367ad7f1 Mon Sep 17 00:00:00 2001 From: Arin Wongprommoon <arin.wongprommoon@ed.ac.uk> Date: Fri, 17 Jun 2022 10:33:27 +0100 Subject: [PATCH] [routines] Unit scaling argument Specifying a sampling period via the sampling_period argument duplicated multiplying the horizontal axes by a scaling factor. This is because recent changes to postprocessor (see last paragraph of commit) makes the columns of DataFrames show absolute time units (e.g. [0, 5, 10, 15...] if the images were taken every 5 minutes). Previously, columns showed time points (e.g. [0, 1, 2, 3...]). All routines relied on column labels to define the horizontal axis. This issue would have been addressed more timely if the commit in question had a more informative description; 'add tiniterval property' tells me nothing and does not inform me that it affects the column labels. These recent changes mean that the sampling_period argument is no longer necessary. However, instead of deleting this argument, I've decided to repurpose it for unit scaling, e.g. from minutes to hours. Operationally, nothing has changed, but the meaning of the argument has changed, and I've updated the docstrings accordingly. This commit may affect horizontal axes of plots affected; users should inspect the axes carefully, especially if the source data relies on postprocessor.grouper. This bug was likely caused by 17e13b596828f88bcd973eb34824eea1dd319425 on 2022-06-16 14:21. It is unclear from the commit message, but I suspect that this commit attempted to incorporate the image sampling interval into defining the DataFrame columns produced by postprocessor. This commit addresses issue #20. --- routines/mean_plot.py | 14 +++++++------- routines/median_plot.py | 14 +++++++------- routines/plottingabc.py | 4 ++-- routines/single_birth_plot.py | 14 +++++++------- routines/single_plot.py | 14 +++++++------- 5 files changed, 30 insertions(+), 30 deletions(-) diff --git a/routines/mean_plot.py b/routines/mean_plot.py index a3af66d6..e2594483 100644 --- a/routines/mean_plot.py +++ b/routines/mean_plot.py @@ -13,7 +13,7 @@ class _MeanPlotter(BasePlotter): self, trace_df, trace_name, - sampling_period, + unit_scaling, label, mean_color, error_color, @@ -22,7 +22,7 @@ class _MeanPlotter(BasePlotter): ylabel, plot_title, ): - super().__init__(trace_name, sampling_period, xlabel, plot_title) + super().__init__(trace_name, unit_scaling, xlabel, plot_title) # Define attributes from arguments self.trace_df = trace_df self.label = label @@ -35,7 +35,7 @@ class _MeanPlotter(BasePlotter): self.ylabel = ylabel # Mean and standard error - self.trace_time = np.array(self.trace_df.columns) * self.sampling_period + self.trace_time = np.array(self.trace_df.columns) * self.unit_scaling self.mean_ts = self.trace_df.mean(axis=0) self.stderr = self.trace_df.std(axis=0) / np.sqrt(len(self.trace_df)) @@ -64,7 +64,7 @@ class _MeanPlotter(BasePlotter): def mean_plot( trace_df, trace_name="flavin", - sampling_period=5, + unit_scaling=1, label="wild type", mean_color="b", error_color="lightblue", @@ -82,8 +82,8 @@ def mean_plot( Time series of traces (rows = cells, columns = time points). trace_name : string Name of trace being plotted, e.g. 'flavin'. - sampling_period : int or float - Sampling period, in unit time. + unit_scaling : int or float + Unit scaling factor, e.g. 1/60 to convert minutes to hours. label : string Name of group being plotted, e.g. a strain name. mean_color : string @@ -109,7 +109,7 @@ def mean_plot( plotter = _MeanPlotter( trace_df, trace_name, - sampling_period, + unit_scaling, label, mean_color, error_color, diff --git a/routines/median_plot.py b/routines/median_plot.py index 4b3205c5..573263b3 100644 --- a/routines/median_plot.py +++ b/routines/median_plot.py @@ -13,7 +13,7 @@ class _MedianPlotter(BasePlotter): self, trace_df, trace_name, - sampling_period, + unit_scaling, label, median_color, error_color, @@ -22,7 +22,7 @@ class _MedianPlotter(BasePlotter): ylabel, plot_title, ): - super().__init__(trace_name, sampling_period, xlabel, plot_title) + super().__init__(trace_name, unit_scaling, xlabel, plot_title) # Define attributes from arguments self.trace_df = trace_df self.label = label @@ -35,7 +35,7 @@ class _MedianPlotter(BasePlotter): self.ylabel = ylabel # Median and interquartile range - self.trace_time = np.array(self.trace_df.columns) * self.sampling_period + self.trace_time = np.array(self.trace_df.columns) * self.unit_scaling self.median_ts = self.trace_df.median(axis=0) self.quartile1_ts = self.trace_df.quantile(0.25) self.quartile3_ts = self.trace_df.quantile(0.75) @@ -65,7 +65,7 @@ class _MedianPlotter(BasePlotter): def median_plot( trace_df, trace_name="flavin", - sampling_period=5, + unit_scaling=1, label="wild type", median_color="b", error_color="lightblue", @@ -83,8 +83,8 @@ def median_plot( Time series of traces (rows = cells, columns = time points). trace_name : string Name of trace being plotted, e.g. 'flavin'. - sampling_period : int or float - Sampling period, in unit time. + unit_scaling : int or float + Unit scaling factor, e.g. 1/60 to convert minutes to hours. label : string Name of group being plotted, e.g. a strain name. median_color : string @@ -110,7 +110,7 @@ def median_plot( plotter = _MedianPlotter( trace_df, trace_name, - sampling_period, + unit_scaling, label, median_color, error_color, diff --git a/routines/plottingabc.py b/routines/plottingabc.py index 1990df9f..97b89aa7 100644 --- a/routines/plottingabc.py +++ b/routines/plottingabc.py @@ -6,10 +6,10 @@ from abc import ABC class BasePlotter(ABC): """Base class for plotting handler classes""" - def __init__(self, trace_name, sampling_period, xlabel, plot_title): + def __init__(self, trace_name, unit_scaling, xlabel, plot_title): """Common attributes""" self.trace_name = trace_name - self.sampling_period = sampling_period + self.unit_scaling = unit_scaling self.xlabel = xlabel self.ylabel = None diff --git a/routines/single_birth_plot.py b/routines/single_birth_plot.py index 6d1a405c..671cfec0 100644 --- a/routines/single_birth_plot.py +++ b/routines/single_birth_plot.py @@ -14,7 +14,7 @@ class _SingleBirthPlotter(_SinglePlotter): trace_values, trace_name, birth_mask, - sampling_period, + unit_scaling, trace_color, birth_color, trace_linestyle, @@ -27,7 +27,7 @@ class _SingleBirthPlotter(_SinglePlotter): trace_timepoints, trace_values, trace_name, - sampling_period, + unit_scaling, trace_color, trace_linestyle, xlabel, @@ -40,7 +40,7 @@ class _SingleBirthPlotter(_SinglePlotter): def plot(self, ax): """Draw the line plots on the provided Axes.""" - trace_time = self.trace_timepoints * self.sampling_period + trace_time = self.trace_timepoints * self.unit_scaling super().plot(ax) birth_mask_bool = self.birth_mask.astype(bool) for occurence, birth_time in enumerate(trace_time[birth_mask_bool]): @@ -62,7 +62,7 @@ def single_birth_plot( trace_values, trace_name="flavin", birth_mask=None, - sampling_period=5, + unit_scaling=1, trace_color="b", birth_color="k", trace_linestyle="-", @@ -84,8 +84,8 @@ def single_birth_plot( birth_mask : array_like Mask to indicate where births are. Expect values of '0' and '1' or 'False' and 'True' in the elements. - sampling_period : int or float - Sampling period, in unit time. + unit_scaling : int or float + Unit scaling factor, e.g. 1/60 to convert minutes to hours. trace_color : string matplotlib colour string for the trace birth_color : string @@ -116,7 +116,7 @@ def single_birth_plot( trace_values, trace_name, birth_mask, - sampling_period, + unit_scaling, trace_color, birth_color, trace_linestyle, diff --git a/routines/single_plot.py b/routines/single_plot.py index 11ee9406..68e7d760 100644 --- a/routines/single_plot.py +++ b/routines/single_plot.py @@ -13,13 +13,13 @@ class _SinglePlotter(BasePlotter): trace_timepoints, trace_values, trace_name, - sampling_period, + unit_scaling, trace_color, trace_linestyle, xlabel, plot_title, ): - super().__init__(trace_name, sampling_period, xlabel, plot_title) + super().__init__(trace_name, unit_scaling, xlabel, plot_title) # Define attributes from arguments self.trace_timepoints = trace_timepoints self.trace_values = trace_values @@ -33,7 +33,7 @@ class _SinglePlotter(BasePlotter): """Draw the line plot on the provided Axes.""" super().plot(ax) ax.plot( - self.trace_timepoints * self.sampling_period, + self.trace_timepoints * self.unit_scaling, self.trace_values, color=self.trace_color, linestyle=self.trace_linestyle, @@ -45,7 +45,7 @@ def single_plot( trace_timepoints, trace_values, trace_name="flavin", - sampling_period=5, + unit_scaling=1, trace_color="b", trace_linestyle="-", xlabel="Time (min)", @@ -62,8 +62,8 @@ def single_plot( Trace to plot. trace_name : string Name of trace being plotted, e.g. 'flavin'. - sampling_period : int or float - Sampling period, in unit time. + unit_scaling : int or float + Unit scaling factor, e.g. 1/60 to convert minutes to hours. trace_color : string matplotlib colour string, specifies colour of line plot. trace_linestyle : string @@ -89,7 +89,7 @@ def single_plot( trace_timepoints, trace_values, trace_name, - sampling_period, + unit_scaling, trace_color, trace_linestyle, xlabel, -- GitLab