Пример #1
0
    def test_centroid(self):
        y = np.ones(10)
        centroid, sd = peak_utils.centroid(y)
        assert_equal(centroid, 4.5)

        y = np.ones(3)
        x = np.array([0, 1.0, 9.])
        centroid, sd = peak_utils.centroid(y, x=x)
        assert_equal(centroid, 4.5)

        y = np.ones(2)
        centroid, sd = peak_utils.centroid(y, dx=9.)
        assert_equal(centroid, 4.5)
Пример #2
0
    def test_centroid(self):
        y = np.ones(10)
        centroid, sd = peak_utils.centroid(y)
        assert_equal(centroid, 4.5)

        y = np.ones(3)
        x = np.array([0, 1.0, 9.0])
        centroid, sd = peak_utils.centroid(y, x=x)
        assert_equal(centroid, 4.5)

        y = np.ones(2)
        centroid, sd = peak_utils.centroid(y, dx=9.0)
        assert_equal(centroid, 4.5)
Пример #3
0
    def __call__(self, detector, detector_err):
        """
        Start the manual beam find

        Parameters
        ----------
        detector : np.ndarray
            detector image. Shape `(N, T, Y)` or `(T, Y)`. If N > 1 then only
            the first image is processed
        detector_err: np.ndarray
            uncertainties (sd) associated with detector image

        Returns
        -------
        beam_centre, beam_sd, lopx, hipx, background_pixels :
            np.ndarray, np.ndarray, np.ndarray, np.ndarray, list of np.ndarray

            Beam centre, standard deviation, lowest pixel in foreground region,
            highest pixel in foreground region, each of the entries in
            `background_pixels` is an array specifying pixels that are in the
            background region.
        """
        # assume that the ndim is 2 or 3.
        # only process the first detector image (N = 0).
        self.detector = detector
        self.detector_err = detector_err
        n_images = 1

        if detector.ndim > 2:
            self.detector = detector[0]
            self.detector_err = detector_err[0]
            n_images = np.size(detector, 0)

        # guess peak centre from centroid.
        xs = np.sum(self.detector, axis=0)
        self._integrate_position, _ = centroid(xs)
        self.integrate_position.setValue(self._integrate_position)
        self.integrate_width.setValue(self._integrate_width)

        self.recalculate_graphs()

        self.dialog.exec_()

        y1 = int(round(self._low_px - PIXEL_OFFSET))
        y2 = int(round(self._high_px + PIXEL_OFFSET))
        background_pixels = np.r_[np.arange(self._low_bkg, y1 + 1),
                                  np.arange(y2, self._high_bkg + 1)]

        return (np.ones((n_images, )) * self._true_centre, np.ones(
            (n_images, )) * self._true_sd, np.ones(
                (n_images, )) * self._low_px, np.ones(
                    (n_images, )) * self._high_px,
                [background_pixels for i in range(n_images)])
Пример #4
0
    def __call__(self, detector, detector_err, name):
        """
        Start the manual beam find

        Parameters
        ----------
        detector : np.ndarray
            detector image. Shape `(N, T, Y)` or `(T, Y)`. If N > 1 then only
            the first image is processed
        detector_err: np.ndarray
            uncertainties (sd) associated with detector image
        name: str
            Name of the dataset

        Returns
        -------
        beam_centre, beam_sd, lopx, hipx, background_pixels :
            np.ndarray, np.ndarray, np.ndarray, np.ndarray, list of np.ndarray

            Beam centre, standard deviation, lowest pixel in foreground region,
            highest pixel in foreground region, each of the entries in
            `background_pixels` is an array specifying pixels that are in the
            background region.
        """
        # assume that the ndim is 2 or 3.
        # only process the first detector image (N = 0).
        self.detector = detector
        self.detector_err = detector_err
        n_images = 1

        if detector.ndim > 2:
            self.detector = detector[0]
            self.detector_err = detector_err[0]
            n_images = np.size(detector, 0)

        # set min/max values for the detector image GUI. Crashes result
        # otherwise
        self.integrate_position.setMaximum(np.size(self.detector, -1) - 1)
        self.integrate_width.setMaximum(np.size(self.detector, -1) - 1)
        self.pixels_to_include.setMaximum(np.size(self.detector, 0))
        self.true_centre.setMaximum(np.size(self.detector, -1))

        # guess peak centre from centroid.
        xs = np.sum(self.detector, axis=0)
        self._integrate_position, _ = centroid(xs)
        self.integrate_position.setValue(self._integrate_position)
        self.integrate_width.setValue(self._integrate_width)

        self.recalculate_graphs()
        # set the title of the window to give context about what dataset is
        # being processed.
        self.setWindowTitle("Manual beam finder")
        if name is not None:
            self.setWindowTitle("Manual beam finder: " + name)

        self.dialog.exec_()

        y1 = int(round(self._low_px - PIXEL_OFFSET))
        y2 = int(round(self._high_px + PIXEL_OFFSET))
        background_pixels = np.r_[np.arange(self._low_bkg, y1 + 1),
                                  np.arange(y2, self._high_bkg + 1)]

        return (
            np.ones((n_images, )) * self._true_centre,
            np.ones((n_images, )) * self._true_sd,
            np.ones((n_images, )) * self._low_px,
            np.ones((n_images, )) * self._high_px,
            [background_pixels for i in range(n_images)],
        )