def test_ia_util_9():
    """
    Test runningIfHasNeighbors() function.
    """
    # Test 4 of 5 with new neighbors, one in error state.
    c_x = numpy.array([1.0, 2.0, 3.0, 4.0, 5.0])
    c_y = numpy.array([1.0, 1.0, 1.0, 1.0, 1.0])
    n_x = numpy.array([1.1, 2.1, 3.1, 4.1])
    n_y = numpy.array([1.1, 1.1, 1.1, 1.1])
    status = numpy.array([0, 1, 2, 1, 1], dtype=numpy.int32)

    new_status = iaUtilsC.runningIfHasNeighbors(status, c_x, c_y, n_x, n_y,
                                                0.5)
    correct = [0, 0, 2, 0, 1]
    for i in range(new_status.size):
        assert (new_status[i] == correct[i])

    # Test 2 of 5 with new neighbors, one in error state.
    n_x = numpy.array([1.9, 2.1])
    n_y = numpy.array([1.1, 1.1])
    status = numpy.array([0, 1, 2, 1, 1], dtype=numpy.int32)

    new_status = iaUtilsC.runningIfHasNeighbors(status, c_x, c_y, n_x, n_y,
                                                0.5)
    correct = [0, 0, 2, 1, 1]
    for i in range(new_status.size):
        assert (new_status[i] == correct[i])

    # Test 1 of 2 with new neighbors, but both with radius of each other.
    c_x = numpy.array([2.0, 3.0])
    c_y = numpy.array([2.0, 2.0])
    n_x = numpy.array([1.0])
    n_y = numpy.array([2.0])
    status = numpy.array([1, 1], dtype=numpy.int32)

    new_status = iaUtilsC.runningIfHasNeighbors(status, c_x, c_y, n_x, n_y,
                                                1.5)
    correct = [0, 1]
    for i in range(new_status.size):
        assert (new_status[i] == correct[i])
Beispiel #2
0
    def fitPeaks(self, new_peaks, peaks_type):
        """
        Performs a single iteration of peak fitting.
        
        new_peaks - A dictionary containing numpy arrays specifying peak x/y location, etc.
                    to add to the fit.
        peaks_type - The type of the peaks, e.g. 'finder' if they were identified by the 
                     peak finder, or '??' if they were provided by the user.
    
        returns the current fit peaks image.
        """
        # Check if we need to do anything.
        if (new_peaks["x"].size > 0):

            # Update status of current peaks (if any) that are near
            # to the new peaks that are being added.
            #
            if (self.mfitter.getNFit() > 0):
                c_x = self.mfitter.getPeakProperty("x")
                c_y = self.mfitter.getPeakProperty("y")
                status = self.mfitter.getPeakProperty("status")
                new_status = iaUtilsC.runningIfHasNeighbors(
                    status, c_x, c_y, new_peaks["x"], new_peaks["y"],
                    self.neighborhood)
                self.mfitter.setPeakStatus(new_status)

            # Add new peaks.
            self.mfitter.newPeaks(new_peaks, peaks_type)

            # Iterate fitting and remove any error peaks.
            #
            # The assumption is that because error peaks are longer in the
            # fit image we don't have to do additional iterations on the
            # remaining peaks after the error peaks have been removed.
            #
            if not self.no_fitting:
                self.mfitter.doFit()
                self.mfitter.removeErrorPeaks()

            # Remove peaks that are too close to each other and/or that
            # have a low significance score.
            #
            status = self.mfitter.getPeakProperty("status")

            # Identify peaks that are to close based on the somewhat
            # arbitrary criteria of being within 1 sigma.
            #
            # markDimmerPeaks() will update the status array, in particular
            # it will mark the dimmer of two peaks that are too close as ERROR.
            #
            px = self.mfitter.getPeakProperty("x")
            py = self.mfitter.getPeakProperty("y")
            n_proximity = iaUtilsC.markDimmerPeaks(
                px, py, self.mfitter.getPeakProperty("height"), status,
                self.sigma, self.neighborhood)

            # Identify peaks that have a low significance score.
            #
            # markLowSignificancePeaks() will update the status array, in particular
            # it will mark low significance peaks as ERROR.
            #
            n_significance = iaUtilsC.markLowSignificancePeaks(
                px, py, self.mfitter.getPeakProperty("significance"), status,
                self.minimum_significance, self.neighborhood)

            # This does the actual peak removal. We update the peak status in
            # mfitter, then tell mfitter to remove all the ERROR peaks.
            #
            if ((n_proximity + n_significance) > 0):
                self.mfitter.setPeakStatus(status)
                self.mfitter.removeErrorPeaks()
                self.mfitter.incProximityCounter(n_proximity)
                self.mfitter.incSignificanceCounter(n_significance)

            # If we have unconverged peaks, iterate some more.
            if (self.mfitter.getUnconverged() > 0) and (not self.no_fitting):
                self.mfitter.doFit()
                self.mfitter.removeErrorPeaks()

        # Return the current fit image.
        return self.mfitter.getFitImage()