Example #1
0
    def isel(self, indexers: Mapping[Axes, Union[int, tuple]]):
        """Given a dictionary mapping the index name to either a value or a range represented as a
        tuple, return an Imagestack with each dimension indexed by position accordingly

        Parameters
        ----------
        indexers : Dict[Axes, (int/tuple)]
            A dictionary of dim:index where index is the value or range to index the dimension

        Examples
        --------

        Create an Imagestack using the ``synthetic_stack`` method
            >>> from starfish import ImageStack
            >>> from starfish.types import Axes
            >>> stack = ImageStack.synthetic_stack(5, 5, 15, 200, 200)
            >>> stack
            <starfish.ImageStack (r: 5, c: 5, z: 15, y: 200, x: 200)>
            >>> stack.isel({Axes.ROUND: (1, None), Axes.CH: 0, Axes.ZPLANE: 0})
            <starfish.ImageStack (r: 4, c: 1, z: 1, y: 200, x: 200)>
            >>> stack.isel({Axes.ROUND: 0, Axes.CH: 0, Axes.ZPLANE: 1,
            ...Axes.Y: 100, Axes.X: (None, 100)})
            <starfish.ImageStack (r: 1, c: 1, z: 1, y: 1, x: 100)>
            and the imagestack's physical coordinates
            xarray also indexed and recalculated according to the x,y slicing.

        Returns
        -------
        ImageStack :
            a new image stack indexed by given value or range.
        """
        stack = deepcopy(self)
        selector = indexing_utils.convert_to_selector(indexers)
        stack._data._data = indexing_utils.index_keep_dimensions(self.xarray, selector, by_pos=True)
        return stack
Example #2
0
    def get_partial(self, indexers: Mapping[Axes, Union[int, slice, Sequence]]):
        """
        Slice the codebook data according to the provided indexing parameters. Used in a composite
        codebook scenario.

        Parameters
        ----------
        indexers : Mapping[Axes, Union[int, Sequence]]
            A dictionary of dim:index where index is the value, values or range to index the
            dimension
        """
        selector = indexing_utils.convert_to_selector(indexers)
        return indexing_utils.index_keep_dimensions(self, indexers=selector)
Example #3
0
    def sel(self, indexers: Mapping[Axes, Union[int, slice, Sequence]]):
        """Given a dictionary mapping the index name to either a value or a range represented as a
        tuple, return an Imagestack with each dimension indexed accordingly

        Parameters
        ----------
        indexers : Mapping[Axes, Union[int, Union[int, Sequence]]
            A dictionary of dim:index where index is the value, values, or range to index the
            dimension

        Examples
        --------

        Create an Imagestack :py:func:`~starfish.imagestack.imagestack.ImageStack.synthetic_stack`
            >>> from starfish import ImageStack
            >>> from starfish.core.imagestack.test.factories import synthetic_stack
            >>> from starfish.types import Axes
            >>> stack = synthetic_stack(5, 5, 15, 200, 200)
            >>> stack
            <starfish.ImageStack (r: 5, c: 5, z: 15, y: 200, x: 200)>
            >>> stack.sel({Axes.ROUND: (1, None), Axes.CH: 0, Axes.ZPLANE: 0})
            <starfish.ImageStack (r: 4, c: 1, z: 1, y: 200, x: 200)>
            >>> stack.sel({Axes.ROUND: 0, Axes.CH: 0, Axes.ZPLANE: 1,
            ...Axes.Y: 100, Axes.X: (None, 100)})
            <starfish.ImageStack (r: 1, c: 1, z: 1, y: 1, x: 100)>
            and the imagestack's physical coordinates
            xarray also indexed and recalculated according to the x,y slicing.

        Returns
        -------
        ImageStack :
            a new image stack indexed by given value or range.
        """
        self._ensure_data_loaded()
        stack = deepcopy(self)
        selector = indexing_utils.convert_to_selector(indexers)
        stack._data = indexing_utils.index_keep_dimensions(
            self.xarray, selector)
        return stack
Example #4
0
def process_fov(fov_num: int, round_num: int, experiment_str: str):
    """Process a single field of view of ISS data
    Parameters
    ----------
    fov_num : int
        The field of view to process
    experiment_str : int
        path of experiment json file
    round_num : int
        The round number within the given fov to process

    Returns
    -------
    DecodedSpots :
        tabular object containing the locations of detected spots.
    """

    fov_str: str = f"fov_{int(fov_num):03d}"

    # load experiment
    experiment = starfish.Experiment.from_json(experiment_str)

    fov = experiment[fov_str]
    img = fov.get_images(starfish.FieldOfView.PRIMARY_IMAGES,
                         rounds=[round_num])

    codebook = indexing_utils.index_keep_dimensions(experiment.codebook,
                                                    {Axes.ROUND: round_num})

    # filter
    clip1 = starfish.image.Filter.Clip(p_min=50, p_max=100)
    clip1.run(img)

    bandpass = starfish.image.Filter.Bandpass(lshort=.5,
                                              llong=7,
                                              threshold=0.0)
    bandpass.run(img)

    glp = starfish.image.Filter.GaussianLowPass(sigma=(1, 0, 0),
                                                is_volume=True)
    glp.run(img)

    clip2 = starfish.image.Filter.Clip(p_min=99, p_max=100, is_volume=True)
    clip2.run(img)

    # find spots
    tlmpf = starfish.spots.DetectSpots.TrackpyLocalMaxPeakFinder(
        spot_diameter=5,  # must be odd integer
        min_mass=0.02,
        max_size=2,  # this is max radius
        separation=7,
        noise_size=0.65,  # this is not used because preprocess is False
        preprocess=False,
        percentile=
        10,  # this is irrelevant when min_mass, spot_diameter, and max_size are set properly
        verbose=True,
        is_volume=True,
    )

    intensities = tlmpf.run(img)

    # decode
    decoded = codebook.decode_per_round_max(intensities)

    # save results
    df = decoded.to_decoded_spots()
    return df