Exemplo n.º 1
0
    def newBackground(self, background):
        """
        background - a list of background estimates of length n_channels.
        """
        if (len(background) != self.n_channels):
            raise daoFitC.MultiFitterException("Number of images does not match number of channels.")
        
        for i in range(self.n_channels):
            if (background[i].shape[0] != self.im_shape[0]) or (background[i].shape[1] != self.im_shape[1]):
                raise daoFitC.MultiFitterException("Background image shape and the original image shape are not the same.")

            self.clib.mFitNewBackground(self.mfit.contents.fit_data[i],
                                        numpy.ascontiguousarray(background[i], dtype = numpy.float64))
Exemplo n.º 2
0
    def newImage(self, image):
        """
        image - a list of images of length n_channels.
        """
        if (len(image) != self.n_channels):
            raise daoFitC.MultiFitterException("Number of images does not match number of channels.")
        
        for i in range(self.n_channels):
            if (image[i].shape[0] != self.im_shape[0]) or (image[i].shape[1] != self.im_shape[1]):
                raise daoFitC.MultiFitterException("Current image shape and the original image shape are not the same.")

            self.clib.mFitNewImage(self.mfit.contents.fit_data[i],
                                   numpy.ascontiguousarray(image[i], dtype = numpy.float64),
                                   0)
Exemplo n.º 3
0
    def initializeChannel(self, rqe, variance, channel):
        """
        Initializes the C fitter for a single image channel.

        This will also initialize the C multi-fitter if this hasn't been done. The
        C multi-fitter basically just coordinates the individual C fitters for each
        channel. Without the C fitters for each channel it cannot do anything.
        """
        if self.mfit is None:
            self.initializeC(variance)
            
        if (rqe.shape[0] != self.im_shape[0]) or (rqe.shape[1] != self.im_shape[1]):
            raise daoFitC.MultiFitterException("Current RQE shape and the original variance shape are not the same.")

        if (variance.shape[0] != self.im_shape[0]) or (variance.shape[1] != self.im_shape[1]):
            raise daoFitC.MultiFitterException("Current variance shape and the original variance shape are not the same.")
Exemplo n.º 4
0
    def newImage(self, image, channel):
        if (image.shape[0] != self.im_shape[0]) or (image.shape[1] !=
                                                    self.im_shape[1]):
            raise daoFitC.MultiFitterException(
                "Current image shape and the original image shape are not the same."
            )

        self.clib.mpNewImage(self.mfit, image, channel)
Exemplo n.º 5
0
    def setVariance(self, variance, channel):
        #
        # This is a little difference than the 3D-DAOSTORM, sCMOS and Spliner
        # because this is the first thing that will be called with an array
        # that is expected to have the same size of the images. So we initialize
        # the C library now, rather than in newImage().
        #
        if self.mfit is None:
            self.initializeC(variance)
        else:
            if (variance.shape[0] != self.im_shape[0]) or (variance.shape[1] !=
                                                           self.im_shape[1]):
                raise daoFitC.MultiFitterException(
                    "Current variance shape and the original variance shape are not the same."
                )

        self.clib.mpInitializeChannel(self.mfit, self.c_splines[channel],
                                      variance, channel)
Exemplo n.º 6
0
    def getPeakProperty(self, p_name, channel=0):
        """
        Return a numpy array containing the requested property.
        """
        if not p_name in self.peak_properties:
            raise daoFitC.MultiFitterException("No such property '" + p_name +
                                               "'")

        # Properties that are calculated from other properties.
        if (self.peak_properties[p_name] == "compound"):

            # Return 0 length array if there are no localizations.
            if (self.getNFit() == 0):
                return numpy.zeros(0, dtype=numpy.float64)

            # Peak significance calculation, calculated from the values for
            # all of the individual peaks.
            if (p_name == "significance"):
                bg_sum = numpy.zeros(self.getNFit(), dtype=numpy.float64)
                fg_sum = numpy.zeros(self.getNFit(), dtype=numpy.float64)
                for i in range(self.n_channels):
                    bg_sum += self.getPeakProperty("bg_sum", channel=i)
                    fg_sum += self.getPeakProperty("fg_sum", channel=i)
                return fg_sum / numpy.sqrt(bg_sum)

        # Floating point properties.
        elif (self.peak_properties[p_name] == "float"):
            values = numpy.ascontiguousarray(
                numpy.zeros(self.getNFit(), dtype=numpy.float64))
            self.clib.mFitGetPeakPropertyDouble(
                self.mfit.contents.fit_data[channel], values,
                ctypes.c_char_p(p_name.encode()))
            return values

        # Integer properties.
        elif (self.peak_properties[p_name] == "int"):
            values = numpy.ascontiguousarray(
                numpy.zeros(self.getNFit(), dtype=numpy.int32))
            self.clib.mFitGetPeakPropertyInt(
                self.mfit.contents.fit_data[channel], values,
                ctypes.c_char_p(p_name.encode()))
            return values
Exemplo n.º 7
0
    def initializeC(self, image):
        """
        This initializes the C fitting library. You can call this directly, but
        the idea is that it will get called automatically the first time that you
        provide a new image for fitting.
        """
        if self.scmos_cal is None:
            self.scmos_cal = numpy.ascontiguousarray(numpy.zeros(image.shape))
        else:
            self.scmos_cal = numpy.ascontiguousarray(self.scmos_cal)

        if (image.shape[0] != self.scmos_cal.shape[0]) or (
                image.shape[1] != self.scmos_cal.shape[1]):
            raise daoFitC.MultiFitterException(
                "Image shape and sCMOS calibration shape do not match.")

        self.im_shape = self.scmos_cal.shape
        self.mfit = self.clib.cfInitialize(self.c_spline, self.scmos_cal,
                                           numpy.ascontiguousarray(self.clamp),
                                           self.default_tol,
                                           self.scmos_cal.shape[1],
                                           self.scmos_cal.shape[0])
Exemplo n.º 8
0
 def setVariance(self, variance, channel):
     if self.mfit is None:
         self.initializeC(variance)
     else:
         if (variance.shape[0] != self.im_shape[0]) or (variance.shape[1] != self.im_shape[1]):
             raise daoFitC.MultiFitterException("Current variance shape and the original variance shape are not the same.")