Holiday syncing :)

This commit is contained in:
j-hartling
2026-04-02 16:00:56 +02:00
parent 298969a067
commit 0b9264b1e1
14 changed files with 627 additions and 667 deletions

View File

@@ -1,9 +1,20 @@
import numpy as np
from scipy.stats import gaussian_kde
def shorten_species(name):
genus, species = name.split('_')
return genus[0] + '. ' + species
def unsort_unique(array):
values, inds = np.unique(array, return_index=True)
return values[np.argsort(inds)]
def get_kde(data, sigma, axis=None, n=1000, pad=10):
if axis is None:
axis = np.linspace(data.min() - pad * sigma, data.max() + pad * sigma, n)
pdf = gaussian_kde(data, sigma)(axis)
return pdf, axis
def get_saturation(sigmoid, low=0.05, high=0.95, first=True, last=True,
condense=None):
if condense == 'norm' and sigmoid.ndim == 2:
@@ -16,17 +27,17 @@ def get_saturation(sigmoid, low=0.05, high=0.95, first=True, last=True,
low_value = min_value + low * span
high_value = min_value + high * span
low_mask = sigmoid >= low_value
high_mask = sigmoid >= high_value
low_mask = sigmoid <= low_value
high_mask = sigmoid <= high_value
if sigmoid.ndim == 1:
low_ind = np.nonzero(low_mask)[0][0]
high_ind = np.nonzero(high_mask)[0][0]
low_ind = np.nonzero(low_mask)[0][-1]
high_ind = np.nonzero(high_mask)[0][-1]
elif condense == 'all':
low_ind = np.nonzero(low_mask.all(axis=1))[0][0]
high_ind = np.nonzero(high_mask.all(axis=1))[0][0]
low_ind = np.nonzero(low_mask.all(axis=1))[0][-1]
high_ind = np.nonzero(high_mask.all(axis=1))[0][-1]
else:
low_ind, high_ind = [], []
for i in range(sigmoid.shape[1]):
low_ind.append(np.nonzero(low_mask[:, i])[0][0])
high_ind.append(np.nonzero(high_mask[:, i])[0][0])
return low_ind, high_ind
low_ind.append(np.nonzero(low_mask[:, i])[0][-1])
high_ind.append(np.nonzero(high_mask[:, i])[0][-1])
return low_ind, high_ind