Skip to content
Snippets Groups Projects
Commit 8178f935 authored by pswain's avatar pswain
Browse files

added sorting2

parent 68d4b0ee
No related branches found
No related tags found
No related merge requests found
import numpy as np
def sort_by_budding(buddings, bud_number=0):
"""Return indices for each cell when a particular budding occurs."""
bud_indices = np.transpose(np.nonzero(buddings))
sort_order = []
for cell_i in range(buddings.shape[0]):
cell_buds = bud_indices[bud_indices[:, 0] == cell_i, :]
if bud_number < cell_buds.shape[0]:
sort_order.append(cell_buds[bud_number][1])
else:
sort_order.append(np.nan)
sort_order = np.array(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))
else:
sorted_indices = np.nanargmax(sdata, axis=1)
sort_order[not_all_nan(data)] = sorted_indices
return sort_order
def not_all_nan(data):
"""Find rows that are not all NaN."""
indices = ~np.all(np.isnan(data), axis=1)
return indices
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