Skip to content
Snippets Groups Projects
Commit 977ffc4c authored by pswain's avatar pswain
Browse files

fix(kymograph): error in using sort_order

parent 8178f935
No related branches found
No related tags found
No related merge requests found
......@@ -105,7 +105,7 @@ def kymograph(
dt = np.min(np.diff(np.sort(df.time.unique())))
data = wdf.to_numpy()
if sort_order is not None:
data = data[np.argsort(sort_order), :]
data = data[sort_order, :]
if filterfunc is not None:
data = filterfunc(data)
if standardscale:
......@@ -146,7 +146,7 @@ def kymograph(
if buddings:
buddings = df.pivot(index=y, columns=x, values="buddings").to_numpy()
if sort_order is not None:
buddings = buddings[np.argsort(sort_order), :]
buddings = buddings[sort_order, :]
bud_mask = np.ma.masked_where(buddings == 0, buddings)
ax.imshow(bud_mask, interpolation="none")
ax.figure.colorbar(
......
......@@ -11,20 +11,21 @@ def sort_by_budding(buddings, bud_number=0):
sort_order.append(cell_buds[bud_number][1])
else:
sort_order.append(np.nan)
sort_order = np.array(sort_order)
sort_order = np.argsort(sort_order)
return sort_order
def sort_by_maximum(data, byfunction=None):
"""Return indices of cells sorted by largest value."""
sort_order = np.nan * np.ones(data.shape[0])
sdata = data[not_all_nan(data), :]
if byfunction is not None:
sorted_indices = np.argsort(byfunction(sdata, axis=1))
def sort_by_maximum(data, byfunction, reverse=False):
"""
Return indices of cells sorted by largest value.
Any cells that have all NaN values are placed last.
"""
sort_order = np.argsort(byfunction(data, axis=1))
if reverse:
return sort_order[::-1]
else:
sorted_indices = np.nanargmax(sdata, axis=1)
sort_order[not_all_nan(data)] = sorted_indices
return sort_order
return sort_order
def not_all_nan(data):
......
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