From 04beb227573ced91d13d7e15f72153939962c210 Mon Sep 17 00:00:00 2001 From: Matt Einhorn Date: Mon, 12 Aug 2024 20:08:44 -0400 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Alessandro Felder --- cellfinder/core/detect/filters/plane/classical_filter.py | 2 +- cellfinder/core/detect/filters/plane/plane_filter.py | 2 +- cellfinder/core/tools/threading.py | 3 ++- tests/core/test_integration/test_detection.py | 5 +---- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/cellfinder/core/detect/filters/plane/classical_filter.py b/cellfinder/core/detect/filters/plane/classical_filter.py index eeeef4fe..3812c014 100644 --- a/cellfinder/core/detect/filters/plane/classical_filter.py +++ b/cellfinder/core/detect/filters/plane/classical_filter.py @@ -14,7 +14,7 @@ def normalize( ) -> None: """ Normalizes the 3d tensor so each z-plane is independently scaled to be - in the [0, clipping_value] range. + in the [0, clipping_value] range (if upscale is `True`) or in the [0,1] (if `upscale` is `False`). It is done to filtered_planes inplace. """ diff --git a/cellfinder/core/detect/filters/plane/plane_filter.py b/cellfinder/core/detect/filters/plane/plane_filter.py index e3c7df20..d7890434 100644 --- a/cellfinder/core/detect/filters/plane/plane_filter.py +++ b/cellfinder/core/detect/filters/plane/plane_filter.py @@ -148,7 +148,7 @@ def _threshold_planes( threshold_value: int, ) -> None: """ - Thresholds peaks to those above the mean/std. + Sets each plane (in-place) to threshold_value, where the corresponding enhanced_plane > mean + n_sds_above_mean_thresh*std. Each plane will be set to zero elsewhere. """ planes_1d = enhanced_planes.view(enhanced_planes.shape[0], -1) diff --git a/cellfinder/core/tools/threading.py b/cellfinder/core/tools/threading.py index 836890fc..4692ab41 100644 --- a/cellfinder/core/tools/threading.py +++ b/cellfinder/core/tools/threading.py @@ -1,6 +1,6 @@ """ Provides classes that can run a function in another thread or process and -allows passing data to and from them. It also passes on any exceptions that +allow passing data to and from the threads/processes. It also passes on any exceptions that occur in the secondary thread/sub-process in the main thread or when it exits. @@ -36,6 +36,7 @@ def worker(thread: ThreadWithException, power: float): # just send the id back thread.send_msg_to_mainthread(tensor_id) + # we can also handle errors here, which will be re-raised in the main process if tensor_id == 7: raise ValueError("I fell asleep") diff --git a/tests/core/test_integration/test_detection.py b/tests/core/test_integration/test_detection.py index e469e101..c0382ec1 100644 --- a/tests/core/test_integration/test_detection.py +++ b/tests/core/test_integration/test_detection.py @@ -282,10 +282,7 @@ def test_detection_cluster_splitting( def test_detection_cell_too_large(synthetic_spot_clusters, no_free_cpus): """ - Test cluster splitting for overlapping cells. - - Test filtering/detection on cpu and cuda. Because splitting is only on cpu - so make sure if detection is on cuda, splitting still works. + Test we detect one big artifact if the signal has a too large foreground structure. """ # max_cell_volume is volume of soma * spread sphere. For values below # radius is 7 pixels. So volume is ~1500 pixels