Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions cellfinder/core/classify/classify.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from cellfinder.core.train.train_yaml import depth_type, models


def main(

Check failure on line 22 in cellfinder/core/classify/classify.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 17 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=brainglobe_cellfinder&issues=AZ0C5v5u6BZSWFp2ZGo1&open=AZ0C5v5u6BZSWFp2ZGo1&pullRequest=606
points: List[Cell],
signal_array: types.array,
background_array: types.array,
Expand Down Expand Up @@ -90,9 +90,19 @@
A callback function that is called during classification. Called with
the batch number once that batch has been classified.
"""
if signal_array.ndim != 3:
raise IOError("Signal data must be 3D")
if background_array.ndim != 3:
if signal_array.ndim == 2:
if background_array.ndim != 2:
raise IOError("For 2D signal data, background must also be 2D")
if cube_depth != 1:
raise ValueError(
"For 2D data, cube_depth must be 1. "
"Train/use a 2D classifier or set skip_classification."
)
signal_array = signal_array[None, ...]
background_array = background_array[None, ...]
elif signal_array.ndim != 3:
raise IOError("Signal data must be 2D or 3D")
elif background_array.ndim != 3:
raise IOError("Background data must be 3D")

# Too many workers doesn't increase speed, and uses huge amounts of RAM
Expand All @@ -101,6 +111,8 @@

start_time = datetime.now()

if len(voxel_sizes) == 2:
voxel_sizes = (1.0, *voxel_sizes)
voxel_sizes = list(map(float, voxel_sizes))
logger.debug("Initialising cube generator")
dataset = CuboidArrayDataset(
Expand Down
22 changes: 20 additions & 2 deletions cellfinder/core/detect/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@


@inference_wrapper
def main(

Check failure on line 32 in cellfinder/core/detect/detect.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 19 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=brainglobe_cellfinder&issues=AZ0C5v476BZSWFp2ZGo0&open=AZ0C5v476BZSWFp2ZGo0&pullRequest=606
signal_array: types.array,
start_plane: int = 0,
end_plane: int = -1,
Expand Down Expand Up @@ -66,6 +66,7 @@
----------
signal_array : numpy.ndarray or dask array
3D array representing the signal data in z, y, x order.
2D arrays are also accepted and treated as a single z-plane.
start_plane : int
First plane index to process (inclusive, to process a subset of the
data).
Expand Down Expand Up @@ -176,8 +177,23 @@
f"{signal_array.dtype}"
)

if signal_array.ndim != 3:
raise ValueError("Input data must be 3D")
is_2d = False
if signal_array.ndim == 2:
is_2d = True
signal_array = signal_array[None, ...]
elif signal_array.ndim != 3:
raise ValueError("Input data must be 2D or 3D")

if is_2d:
if start_plane != 0:
raise ValueError("For 2D data, start_plane must be 0.")
if end_plane not in (-1, 1):
raise ValueError(
"For 2D data, end_plane must be 1 (or -1 for default)."
)
end_plane = 1
ball_z_size = 1
split_ball_z_size = 1

if end_plane < 0:
end_plane = len(signal_array)
Expand All @@ -192,6 +208,8 @@

batch_size = max(batch_size, 1)
# brainmapper can pass them in as str
if len(voxel_sizes) == 2:
voxel_sizes = (1.0, *voxel_sizes)
voxel_sizes = list(map(float, voxel_sizes))

settings = DetectionSettings(
Expand Down
17 changes: 17 additions & 0 deletions cellfinder/core/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from cellfinder.core.train.train_yaml import depth_type


def main(

Check failure on line 11 in cellfinder/core/main.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=brainglobe_cellfinder&issues=AZ0C5v9K6BZSWFp2ZGo2&open=AZ0C5v9K6BZSWFp2ZGo2&pullRequest=606
signal_array: types.array,
background_array: types.array,
voxel_sizes: Tuple[float, float, float],
Expand Down Expand Up @@ -55,10 +55,13 @@
----------
signal_array : numpy.ndarray or dask array
3D array representing the signal data in z, y, x order.
2D arrays are also accepted and treated as a single z-plane.
background_array : numpy.ndarray or dask array
3D array representing the signal data in z, y, x order.
2D arrays are also accepted and treated as a single z-plane.
voxel_sizes : 3-tuple of floats
Size of your voxels in the z, y, and x dimensions (microns).
For 2D inputs, you may pass a 2-tuple (y, x); z is assumed to be 1.0.
start_plane : int
First plane index to process (inclusive, to process a subset of the
data).
Expand Down Expand Up @@ -188,6 +191,20 @@
from cellfinder.core.detect import detect
from cellfinder.core.tools import prep

if signal_array.ndim == 2:
if background_array.ndim != 2:
raise ValueError(
"For 2D signal inputs, background_array must also be 2D."
)
if not skip_classification:
raise ValueError(
"2D classification is not supported in this pipeline yet. "
"Set skip_classification=True to run detection only, or "
"train a dedicated 2D classifier and wire it in."
)
if len(voxel_sizes) == 2:
voxel_sizes = (1.0, *voxel_sizes)

if not skip_detection:
logger.info("Detecting cell candidates")

Expand Down