Ejemplo n.º 1
0
    def _measure_spot_intensities(
            self, stack: ImageStack,
            spot_attributes: pd.DataFrame) -> IntensityTable:

        n_ch = stack.shape[Indices.CH]
        n_hyb = stack.shape[Indices.HYB]
        spot_attribute_index = dataframe_to_multiindex(spot_attributes)
        intensity_table = IntensityTable.empty_intensity_table(
            spot_attribute_index, n_ch, n_hyb)

        indices = product(range(n_ch), range(n_hyb))
        for c, h in indices:
            image, _ = stack.get_slice({Indices.CH: c, Indices.HYB: h})
            blob_intensities: pd.Series = self._measure_blob_intensity(
                image, spot_attributes, self.measurement_function)
            intensity_table[:, c, h] = blob_intensities

        return intensity_table
Ejemplo n.º 2
0
    def register(self, image: ImageStack):
        # TODO: (ambrosejcarr) is this the appropriate way of dealing with Z in registration?
        mp = image.max_proj(Indices.CH, Indices.Z)
        reference_image = self.reference_stack.max_proj(
            Indices.HYB, Indices.CH, Indices.Z)

        for h in range(image.num_hybs):
            # compute shift between maximum projection (across channels) and dots, for each hyb round
            # TODO: make the max projection array ignorant of axes ordering.
            shift, error = compute_shift(mp[h, :, :], reference_image,
                                         self.upsampling)
            print("For hyb: {}, Shift: {}, Error: {}".format(h, shift, error))

            for c in range(image.num_chs):
                for z in range(image.num_zlayers):
                    # apply shift to all zlayers, channels, and hyb rounds
                    indices = {Indices.HYB: h, Indices.CH: c, Indices.Z: z}
                    data, axes = image.get_slice(indices=indices)
                    assert len(axes) == 0
                    result = shift_im(data, shift)
                    image.set_slice(indices=indices, data=result)

        return image