Skip to content
Snippets Groups Projects
Commit 8752c9ed authored by pswain's avatar pswain
Browse files

refactor(bud_to_bud_plot): changes for clarity

parent ef809724
No related branches found
No related tags found
No related merge requests found
...@@ -609,7 +609,7 @@ def bud_to_bud_plot( ...@@ -609,7 +609,7 @@ def bud_to_bud_plot(
dl, dl,
colour="b", colour="b",
group=None, group=None,
nbins=None, no_t_values=None,
no_future_buddings=1, no_future_buddings=1,
return_signal=False, return_signal=False,
df=None, df=None,
...@@ -637,9 +637,9 @@ def bud_to_bud_plot( ...@@ -637,9 +637,9 @@ def bud_to_bud_plot(
Colour of lines. Colour of lines.
group: str, optional group: str, optional
The name of the group to plot. The name of the group to plot.
nbins: int, optional no_t_values: int, optional
The number of time bins to partition the interval between the The number of time points into which to partition the interval between
first and the second budding event. budding events.
no_future_buddings: int, optional no_future_buddings: int, optional
The number of future budding events to include. Default is 1. The number of future budding events to include. Default is 1.
return_signal: boolean, optional return_signal: boolean, optional
...@@ -664,10 +664,10 @@ def bud_to_bud_plot( ...@@ -664,10 +664,10 @@ def bud_to_bud_plot(
>>> bud_to_bud_plot(4, "flavin", dl, group="fy4", filter_func=butterworth_filter) >>> bud_to_bud_plot(4, "flavin", dl, group="fy4", filter_func=butterworth_filter)
""" """
if df is None: if df is None:
t, signal_data = dl.get_time_series(signal, group=group) _, signal_data = dl.get_time_series(signal, group=group)
t, buddings = dl.get_time_series("buddings", group=group) t, buddings = dl.get_time_series("buddings", group=group)
else: else:
t, signal_data = dl.get_time_series(signal, group=group, df=df) _, signal_data = dl.get_time_series(signal, group=group, df=df)
t, buddings = dl.get_time_series("buddings", group=group, df=df) t, buddings = dl.get_time_series("buddings", group=group, df=df)
if filter_func is not None: if filter_func is not None:
signal_data = filter_func(signal_data) signal_data = filter_func(signal_data)
...@@ -684,11 +684,14 @@ def bud_to_bud_plot( ...@@ -684,11 +684,14 @@ def bud_to_bud_plot(
no_future_buddings_index=no_future_buddings - 1, no_future_buddings_index=no_future_buddings - 1,
) )
if local_times: if local_times:
# find bins for normalised time, between 0 and no_future_buddings # find values for normalised time between 0 and no_future_buddings
nbins = int(np.median([len(local_time) for local_time in local_times])) if no_t_values is None:
ntbins = np.linspace(0, no_future_buddings, nbins) no_t_values = int(
np.median([len(local_time) for local_time in local_times])
)
t_values = np.linspace(0, no_future_buddings, no_t_values)
# interpolate each local signal to make a new signal # interpolate each local signal to make a new signal
new_signal = np.nan * np.ones((len(local_signals), nbins)) new_signal = np.nan * np.ones((len(local_signals), no_t_values))
for i in range(len(local_signals)): for i in range(len(local_signals)):
s = local_signals[i] s = local_signals[i]
# normalise time between 0 and no_future_buddings # normalise time between 0 and no_future_buddings
...@@ -696,7 +699,7 @@ def bud_to_bud_plot( ...@@ -696,7 +699,7 @@ def bud_to_bud_plot(
nt = nt / nt[-1] * no_future_buddings nt = nt / nt[-1] * no_future_buddings
# interpolate into the bins # interpolate into the bins
new_signal[i, :] = np.interp( new_signal[i, :] = np.interp(
ntbins, t_values,
nt[~np.isnan(s)], nt[~np.isnan(s)],
s[~np.isnan(s)], s[~np.isnan(s)],
left=np.nan, left=np.nan,
...@@ -705,10 +708,10 @@ def bud_to_bud_plot( ...@@ -705,10 +708,10 @@ def bud_to_bud_plot(
# plot median and percentiles # plot median and percentiles
if show_figure: if show_figure:
plt.figure() plt.figure()
plt.plot(ntbins, np.nanmedian(new_signal, axis=0), f"{colour}.-") plt.plot(t_values, np.nanmedian(new_signal, axis=0), f"{colour}.-")
for lower, upper in zip([45, 40, 35], [55, 60, 65]): for lower, upper in zip([45, 40, 35], [55, 60, 65]):
plt.fill_between( plt.fill_between(
ntbins, t_values,
np.nanpercentile(new_signal, lower, axis=0), np.nanpercentile(new_signal, lower, axis=0),
np.nanpercentile(new_signal, upper, axis=0), np.nanpercentile(new_signal, upper, axis=0),
alpha=0.06, alpha=0.06,
......
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