Skip to content
Snippets Groups Projects
Commit b6575f25 authored by Arin Wongprommoon's avatar Arin Wongprommoon
Browse files

[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 17e13b59
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.
parent 8e16964d
No related branches found
No related tags found
No related merge requests found
......@@ -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,
......
......@@ -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,
......
......@@ -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
......
......@@ -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,
......
......@@ -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,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment