From bd5e0c94afc8e47ca22e698e71b7e1b4fbdad6f1 Mon Sep 17 00:00:00 2001 From: Tony Tung Date: Mon, 8 Apr 2019 11:22:35 -0700 Subject: [PATCH 1/5] Unbreak master 1. Normalize the run(..) method with the contract specified in SpotFinderAlgorithmBase. 2. Flag an error if someone tries to specify a blobs_image with LocalSearchBlobDetector. 3. Temporarily provide a `image_to_spots` method which the SpotFinderAlgorithmBase requires. Test plan: `make -j fast` --- .../_detector/local_search_blob_detector.py | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/starfish/spots/_detector/local_search_blob_detector.py b/starfish/spots/_detector/local_search_blob_detector.py index 9eaf4af86..85d3c20a1 100644 --- a/starfish/spots/_detector/local_search_blob_detector.py +++ b/starfish/spots/_detector/local_search_blob_detector.py @@ -21,7 +21,7 @@ from starfish.intensity_table.intensity_table import IntensityTable from starfish.intensity_table.intensity_table_coordinates import \ transfer_physical_coords_from_imagestack_to_intensity_table -from starfish.types import Axes, Features, Number +from starfish.types import Axes, Features, Number, SpotAttributes from starfish.util import click from ._base import SpotFinderAlgorithmBase @@ -32,7 +32,6 @@ class LocalSearchBlobDetector(SpotFinderAlgorithmBase): - def __init__( self, min_sigma: Union[Number, Tuple[Number, ...]], @@ -352,7 +351,13 @@ def _build_intensity_table( return intensity_table def run( - self, data: ImageStack, verbose: bool=False, n_processes: Optional[int]=None + self, + primary_image: ImageStack, + blobs_image: Optional[ImageStack] = None, + blobs_axes: Optional[Tuple[Axes, ...]] = None, + verbose: bool = False, + n_processes: Optional[int] = None, + *args, ) -> IntensityTable: """Find 1-hot coded spots in data. @@ -372,7 +377,15 @@ def run( Contains detected coded spots. """ - per_tile_spot_results = self._find_spots(data, verbose=verbose, n_processes=n_processes) + + if blobs_image is not None: + raise ValueError( + "blobs_image shouldn't be set for LocalSearchBlobDetector. This is likely an " + "usage error." + ) + + per_tile_spot_results = self._find_spots( + primary_image, verbose=verbose, n_processes=n_processes) per_round_spot_results = self._merge_spots_by_round(per_tile_spot_results) @@ -385,16 +398,23 @@ def run( intensity_table = self._build_intensity_table( per_round_spot_results, distances, indices, - rounds=data.xarray[Axes.ROUND.value].values, channels=data.xarray[Axes.CH.value].values, - search_radius=self.search_radius, anchor_round=self.anchor_round + rounds=primary_image.xarray[Axes.ROUND.value].values, + channels=primary_image.xarray[Axes.CH.value].values, + search_radius=self.search_radius, + anchor_round=self.anchor_round ) transfer_physical_coords_from_imagestack_to_intensity_table( - image_stack=data, intensity_table=intensity_table + image_stack=primary_image, intensity_table=intensity_table ) return intensity_table + def image_to_spots(self, data_image: Union[np.ndarray, xr.DataArray]) -> SpotAttributes: + # LocalSearchBlobDetector does not follow the same contract as the remaining spot detectors. + # TODO: (ambrosejcarr) Rationalize the spot detectors by contract and then remove this hack. + raise NotImplementedError() + @staticmethod @click.command("LocalSearchBlobDetector") @click.option( From 2fdd23c080b1da1d07797adfd71ed9366e13726e Mon Sep 17 00:00:00 2001 From: "Ambrose J. Carr" Date: Mon, 8 Apr 2019 14:28:05 -0400 Subject: [PATCH 2/5] Add note warning users not to pass blobs_image --- starfish/spots/_detector/local_search_blob_detector.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/starfish/spots/_detector/local_search_blob_detector.py b/starfish/spots/_detector/local_search_blob_detector.py index 85d3c20a1..707f1daeb 100644 --- a/starfish/spots/_detector/local_search_blob_detector.py +++ b/starfish/spots/_detector/local_search_blob_detector.py @@ -371,6 +371,11 @@ def run( Number of processes to devote to spot finding. If None, will use the number of available cpus (Default None). + Notes + ----- + Blobs image is an unused parameter that is included for testing purposes. It should not + be passed to this method. If it is passed, the method will trigger a ValueError. + Returns ------- IntensityTable From 8f5b5009196fd7bc978a374e2e96ce22b8cd4488 Mon Sep 17 00:00:00 2001 From: Tony Tung Date: Mon, 8 Apr 2019 11:30:16 -0700 Subject: [PATCH 3/5] Fix grammar. --- starfish/spots/_detector/local_search_blob_detector.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/starfish/spots/_detector/local_search_blob_detector.py b/starfish/spots/_detector/local_search_blob_detector.py index 707f1daeb..f030b14fc 100644 --- a/starfish/spots/_detector/local_search_blob_detector.py +++ b/starfish/spots/_detector/local_search_blob_detector.py @@ -385,8 +385,8 @@ def run( if blobs_image is not None: raise ValueError( - "blobs_image shouldn't be set for LocalSearchBlobDetector. This is likely an " - "usage error." + "blobs_image shouldn't be set for LocalSearchBlobDetector. This is likely a usage " + "error." ) per_tile_spot_results = self._find_spots( From 0a382760b5b8cf91b2c6e5fea65b008425887d47 Mon Sep 17 00:00:00 2001 From: Ambrose J Carr Date: Mon, 8 Apr 2019 11:31:19 -0700 Subject: [PATCH 4/5] Update starfish/spots/_detector/local_search_blob_detector.py --- starfish/spots/_detector/local_search_blob_detector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/starfish/spots/_detector/local_search_blob_detector.py b/starfish/spots/_detector/local_search_blob_detector.py index f030b14fc..61bcd9e5e 100644 --- a/starfish/spots/_detector/local_search_blob_detector.py +++ b/starfish/spots/_detector/local_search_blob_detector.py @@ -373,7 +373,7 @@ def run( Notes ----- - Blobs image is an unused parameter that is included for testing purposes. It should not + blobs_image is an unused parameter that is included for testing purposes. It should not be passed to this method. If it is passed, the method will trigger a ValueError. Returns From 317a0e4dadbf8030125d28d894ba5890d5fb7231 Mon Sep 17 00:00:00 2001 From: Tony Tung Date: Mon, 8 Apr 2019 11:41:36 -0700 Subject: [PATCH 5/5] remove trailing ws. --- starfish/spots/_detector/local_search_blob_detector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/starfish/spots/_detector/local_search_blob_detector.py b/starfish/spots/_detector/local_search_blob_detector.py index 61bcd9e5e..c3c65e208 100644 --- a/starfish/spots/_detector/local_search_blob_detector.py +++ b/starfish/spots/_detector/local_search_blob_detector.py @@ -374,7 +374,7 @@ def run( Notes ----- blobs_image is an unused parameter that is included for testing purposes. It should not - be passed to this method. If it is passed, the method will trigger a ValueError. + be passed to this method. If it is passed, the method will trigger a ValueError. Returns -------