Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • swain-lab/aliby/aliby-mirror
  • swain-lab/aliby/alibylite
2 results
Show changes
Showing
with 520 additions and 726 deletions
This diff is collapsed.
This diff is collapsed.
...@@ -129,7 +129,7 @@ def nuc_est_conv( ...@@ -129,7 +129,7 @@ def nuc_est_conv(
def nuc_conv_3d(cell_mask, trap_image, pixel_size=0.23, spacing=0.6): def nuc_conv_3d(cell_mask, trap_image, pixel_size=0.23, spacing=0.6):
cell_mask = np.dstack([cell_mask] * trap_image.shape[-1]) cell_mask = np.stack([cell_mask] * trap_image.shape[0])
ratio = spacing / pixel_size ratio = spacing / pixel_size
cell_fluo = trap_image[cell_mask] cell_fluo = trap_image[cell_mask]
num_cell_fluo = len(np.nonzero(cell_fluo)[0]) num_cell_fluo = len(np.nonzero(cell_fluo)[0])
......
...@@ -13,7 +13,7 @@ def trap_apply(cell_fun, cell_masks, *args, **kwargs): ...@@ -13,7 +13,7 @@ def trap_apply(cell_fun, cell_masks, *args, **kwargs):
cell_fun: function cell_fun: function
Function to apply to the cell (from extraction/cell.py) Function to apply to the cell (from extraction/cell.py)
cell_masks: 3d array cell_masks: 3d array
Segmentation masks for the cells. Note that cells are the last dimension N (Y,X,N) Segmentation masks for the cells. Note that cells are in the first dimension (N, Y,X)
*args: tuple *args: tuple
Trap_image and any other arguments to pass if needed to custom functions. Trap_image and any other arguments to pass if needed to custom functions.
**kwargs: dict **kwargs: dict
...@@ -23,7 +23,7 @@ def trap_apply(cell_fun, cell_masks, *args, **kwargs): ...@@ -23,7 +23,7 @@ def trap_apply(cell_fun, cell_masks, *args, **kwargs):
return [cell_fun(mask, *args, **kwargs) for mask in cell_masks] return [cell_fun(mask, *args, **kwargs) for mask in cell_masks]
def reduce_z(trap_image: np.ndarray, fun: t.Callable): def reduce_z(trap_image: np.ndarray, fun: t.Callable, axis: int = 0):
""" """
Reduce the trap_image to 2d. Reduce the trap_image to 2d.
...@@ -33,15 +33,16 @@ def reduce_z(trap_image: np.ndarray, fun: t.Callable): ...@@ -33,15 +33,16 @@ def reduce_z(trap_image: np.ndarray, fun: t.Callable):
Images for all the channels associated with a trap Images for all the channels associated with a trap
fun: function fun: function
Function to execute the reduction Function to execute the reduction
axis: int (default 0)
Axis in which we apply the reduction operation.
""" """
# FUTURE replace with py3.10's match-case. # FUTURE replace with py3.10's match-case.
if ( if (
hasattr(fun, "__module__") and fun.__module__[:10] == "bottleneck" hasattr(fun, "__module__") and fun.__module__[:10] == "bottleneck"
): # Bottleneck type ): # Bottleneck type
return getattr(bn.reduce, fun.__name__)(trap_image, axis=2) return getattr(bn.reduce, fun.__name__)(trap_image, axis=axis)
elif isinstance(fun, np.ufunc): elif isinstance(fun, np.ufunc):
# optimise the reduction function if possible # optimise the reduction function if possible
return fun.reduce(trap_image, axis=2) return fun.reduce(trap_image, axis=axis)
else: # WARNING: Very slow, only use when no alternatives exist else: # WARNING: Very slow, only use when no alternatives exist
return np.apply_along_axis(fun, 2, trap_image) return np.apply_along_axis(fun, axis, trap_image)
This diff is collapsed.
...@@ -20,7 +20,6 @@ def div0(array, fill=0, axis=-1): ...@@ -20,7 +20,6 @@ def div0(array, fill=0, axis=-1):
slices_0, slices_1 = [[slice(None)] * len(array.shape)] * 2 slices_0, slices_1 = [[slice(None)] * len(array.shape)] * 2
slices_0[axis] = 0 slices_0[axis] = 0
slices_1[axis] = 1 slices_1[axis] = 1
with np.errstate(divide="ignore", invalid="ignore"): with np.errstate(divide="ignore", invalid="ignore"):
c = np.true_divide( c = np.true_divide(
array[tuple(slices_0)], array[tuple(slices_0)],
......
...@@ -5,14 +5,14 @@ import numpy as np ...@@ -5,14 +5,14 @@ import numpy as np
def imBackground(cell_masks, trap_image): def imBackground(cell_masks, trap_image):
""" """
Finds the median background (pixels not comprising cells) from trap_image Find the median background (pixels not comprising cells) from trap_image.
Parameters Parameters
---------- ----------
cell_masks: 3d array cell_masks: 3d array
Segmentation masks for cells Segmentation masks for cells
trap_image: trap_image:
The image (all channels) for the tile containing the cell The image (all channels) for the tile containing the cell.
""" """
if not len(cell_masks): if not len(cell_masks):
# create cell_masks if none are given # create cell_masks if none are given
...@@ -25,14 +25,14 @@ def imBackground(cell_masks, trap_image): ...@@ -25,14 +25,14 @@ def imBackground(cell_masks, trap_image):
def background_max5(cell_masks, trap_image): def background_max5(cell_masks, trap_image):
""" """
Finds the mean of the maximum five pixels of the background (pixels not comprising cells) from trap_image Finds the mean of the maximum five pixels of the background.
Parameters Parameters
---------- ----------
cell_masks: 3d array cell_masks: 3d array
Segmentation masks for cells Segmentation masks for cells.
trap_image: trap_image:
The image (all channels) for the tile containing the cell The image (all channels) for the tile containing the cell.
""" """
if not len(cell_masks): if not len(cell_masks):
# create cell_masks if none are given # create cell_masks if none are given
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -54,4 +54,6 @@ class detrend(PostProcessABC): ...@@ -54,4 +54,6 @@ class detrend(PostProcessABC):
).mean() ).mean()
# Detrend: subtract normalised time series by moving average # Detrend: subtract normalised time series by moving average
signal_detrend = signal.subtract(signal_movavg) signal_detrend = signal.subtract(signal_movavg)
return signal_detrend.dropna(axis=1) # Remove columns with NaNs # Rolling window operations create columns that are all NaNs at the left
# and right edges because of the maths. This line removes these columns.
return signal_detrend.dropna(axis=1, how="all")
This diff is collapsed.