diff --git a/src/agora/io/signal.py b/src/agora/io/signal.py index 6d63f6a..70e94c5 100644 --- a/src/agora/io/signal.py +++ b/src/agora/io/signal.py @@ -6,7 +6,7 @@ from functools import cached_property, lru_cache from pathlib import Path -import bottleneck as bn +import numpy as np import h5py import numpy as np import pandas as pd @@ -109,7 +109,7 @@ def get_retained(df, cutoff): Cells must be present for at least cutoff fraction of the total number of time points. """ - return df.loc[bn.nansum(df.notna(), axis=1) > df.shape[1] * cutoff] + return df.loc[np.nansum(df.notna(), axis=1) > df.shape[1] * cutoff] @property def channels(self) -> t.Collection[str]: diff --git a/src/agora/utils/kymograph.py b/src/agora/utils/kymograph.py index 7570f99..dfd145c 100644 --- a/src/agora/utils/kymograph.py +++ b/src/agora/utils/kymograph.py @@ -143,12 +143,12 @@ def filt_cluster( def cluster_kymograph(kymograph: pd.DataFrame, n: int = 2): - import bottleneck as bn + import numpy as np from sklearn.cluster import KMeans # Normalise according to mean value of signal X = ( - kymograph.divide(bn.nanmean(kymograph, axis=1), axis=0) + kymograph.divide(np.nanmean(kymograph, axis=1), axis=0) .dropna(axis=1) .values ) diff --git a/src/extraction/core/extractor.py b/src/extraction/core/extractor.py index 44bdb52..3146c4d 100644 --- a/src/extraction/core/extractor.py +++ b/src/extraction/core/extractor.py @@ -5,7 +5,6 @@ from pathlib import Path import aliby.global_settings as global_settings -import bottleneck as bn import h5py import numpy as np import pandas as pd @@ -613,7 +612,7 @@ def get_imgs_background_subtract(self, tree, tiles, bgs): # move Z to last column to allow subtraction lambda img, bgs: np.moveaxis(img, 0, -1) # median of background over all pixels for each Z section - - bn.median(img[:, bgs], axis=1), + - np.median(img[:, bgs], axis=1), img[ch], bgs, ) diff --git a/src/extraction/core/functions/cell.py b/src/extraction/core/functions/cell.py index d0df543..cb26684 100644 --- a/src/extraction/core/functions/cell.py +++ b/src/extraction/core/functions/cell.py @@ -15,7 +15,6 @@ import math import typing as t -import bottleneck as bn import numpy as np from scipy import ndimage @@ -98,7 +97,7 @@ def median(cell_mask, trap_image) -> int: Segmentation mask for the cell. trap_image: 2d array """ - return bn.median(trap_image[cell_mask]) + return np.median(trap_image[cell_mask]) def max2p5pc(cell_mask, trap_image) -> float: @@ -116,7 +115,7 @@ def max2p5pc(cell_mask, trap_image) -> float: n_top = int(np.ceil(npixels * 0.025)) # sort pixels in cell and find highest 2.5% pixels = trap_image[cell_mask] - top_values = bn.partition(pixels, len(pixels) - n_top)[-n_top:] + top_values = np.partition(pixels, len(pixels) - n_top)[-n_top:] # find mean of these highest pixels return np.mean(top_values) @@ -137,7 +136,7 @@ def max5px_median(cell_mask, trap_image) -> float: # sort pixels in cell pixels = trap_image[cell_mask] if len(pixels) > 5: - top_values = bn.partition(pixels, len(pixels) - 5)[-5:] + top_values = np.partition(pixels, len(pixels) - 5)[-5:] # find mean of five brightest pixels max5px = np.mean(top_values) med = np.median(pixels) diff --git a/src/extraction/core/functions/distributors.py b/src/extraction/core/functions/distributors.py index bcf5c5b..7ab1f2d 100644 --- a/src/extraction/core/functions/distributors.py +++ b/src/extraction/core/functions/distributors.py @@ -1,6 +1,5 @@ import typing as t -import bottleneck as bn import numpy as np @@ -40,7 +39,7 @@ def reduce_z(trap_image: np.ndarray, fun: t.Callable, axis: int = 0): if ( hasattr(fun, "__module__") and fun.__module__[:10] == "bottleneck" ): # Bottleneck type - return getattr(bn.reduce, fun.__name__)(trap_image, axis=axis) + return getattr(np.reduce, fun.__name__)(trap_image, axis=axis) elif isinstance(fun, np.ufunc): # optimise the reduction function if possible return fun.reduce(trap_image, axis=axis) diff --git a/src/extraction/core/functions/loaders.py b/src/extraction/core/functions/loaders.py index 1f0b6c8..023cf2c 100644 --- a/src/extraction/core/functions/loaders.py +++ b/src/extraction/core/functions/loaders.py @@ -5,7 +5,6 @@ import numpy as np from cp_measure.bulk import get_all_measurements from skimage.measure import regionprops_table -import bottleneck as bn from extraction.core.functions import cell, trap from extraction.core.functions.custom import localisation @@ -152,11 +151,11 @@ def load_redfuns( Functions to perform the reduction. """ RED_FUNS = { - "max": bn.nanmax, - "mean": bn.nanmean, - "median": bn.nanmedian, + "max": np.nanmax, + "mean": np.nanmean, + "median": np.nanmedian, "div0": div0, - "add": bn.nansum, + "add": np.nansum, "None": None, } if additional_reducers is not None: