Exemple #1
0
    def recalculate_graphs(self):
        """
        After the ROI for the beam find has been changed redraw the detector
        cross section and recalculate the beam centre and widths.
        """
        x, xs, xs_err = get_cross_section(self.detector, self.detector_err,
                                          self._pixels_to_include,
                                          self._integrate_position,
                                          self._integrate_width)

        # peak finder returns (centroid, gaussian coefs)
        beam_centre, beam_sd = peak_finder(xs, x=x)[1]

        self._true_centre = beam_centre
        self._true_sd = beam_sd

        regions = fore_back_region(beam_centre, beam_sd)
        self._low_px, self._high_px, bp = regions
        self._low_bkg = np.min(bp[0])
        self._high_bkg = np.max(bp[0])

        self.detector_image.display_image(self.detector, beam_centre,
                                          self._low_px, self._high_px,
                                          self._low_bkg, self._high_bkg,
                                          self._pixels_to_include,
                                          self._integrate_width,
                                          self._integrate_position)
        self.cross_section.display_cross_section(x, xs, beam_centre,
                                                 self._low_px, self._high_px,
                                                 self._low_bkg, self._high_bkg)

        self.true_centre.setValue(self._true_centre)
        self.true_fwhm.setValue(self._true_sd * 2.3548)
Exemple #2
0
 def test_peak_finder(self):
     mean = 10.1234
     sd = 5.55
     x = np.linspace(-100, 100.5, 101)
     y = peak_utils.gauss(x, 0, 10, mean, sd)
     res = peak_utils.peak_finder(y, x=x)
     assert_almost_equal(res[1][0], mean)
     assert_almost_equal(res[1][1], sd)
Exemple #3
0
 def test_peak_finder(self):
     mean = 10.1234
     sd = 5.55
     x = np.linspace(-100, 100.5, 101)
     y = peak_utils.gauss(x, 0, 10, mean, sd)
     res = peak_utils.peak_finder(y, x=x)
     assert_almost_equal(res[1][0], mean)
     assert_almost_equal(res[1][1], sd)
Exemple #4
0
    def on_cross_drag_release(self, event):
        """
        A listener for press->drag->release events on the cross section plot.
        This is where the user is graphically editing foreground/background
        regions
        """
        low_bkg = self.cross_section._low_bkg
        high_bkg = self.cross_section._high_bkg
        lopx = self.cross_section._low_px
        hipx = self.cross_section._high_px

        dragged_attr, dragged_line = self.cross_section._press[0]
        if (lopx >= hipx) or (low_bkg >= high_bkg):
            # set it back to what it was
            setattr(self.cross_section, dragged_attr,
                    getattr(self, dragged_attr))
            # and redraw the line
            dragged_line.set_xdata(getattr(self, dragged_attr))
            self.cross_section.draw()
            return
        else:
            # drag was legal, update the attribute in here
            setattr(self, dragged_attr,
                    getattr(self.cross_section, dragged_attr))

        # recalculate beam_centre, beam_sd based off cross section
        x, xs, xs_err = get_cross_section(self.detector, self.detector_err,
                                          self._pixels_to_include,
                                          self._integrate_position,
                                          self._integrate_width)
        # trim to foreground region
        in_foreground = np.logical_and(x >= lopx, x <= hipx)
        x = x[in_foreground]
        xs = xs[in_foreground]

        # calculate peak centre
        self._true_centre, self._true_sd = peak_finder(xs, x=x)[1]

        # redraw beam centre on detector image and cross section
        self.cross_section.l_bc.set_xdata(self._true_centre)
        self.cross_section.draw()

        self.detector_image.l_lbkg.set_ydata(self._low_bkg - 0.5)
        self.detector_image.l_hbkg.set_ydata(self._high_bkg + 0.5)
        self.detector_image.l_lfore.set_ydata(self._low_px - 0.5)
        self.detector_image.l_hfore.set_ydata(self._high_px + 0.5)
        self.detector_image.l_bc.set_ydata(self._true_centre)

        self.detector_image.draw()

        # update the spinboxes, but without triggering its slot
        self.true_centre.valueChanged.disconnect()
        self.true_centre.setValue(self._true_centre)
        self.true_centre.valueChanged.connect(self.on_true_centre_valueChanged)

        self.true_fwhm.valueChanged.disconnect()
        self.true_fwhm.setValue(self._true_sd * 2.3548)
        self.true_fwhm.valueChanged.connect(self.on_true_fwhm_valueChanged)
    def recalculate_graphs(self):
        """
        After the ROI for the beam find has been changed redraw the detector
        cross section and recalculate the beam centre and widths.
        """
        x, xs, xs_err = get_cross_section(self.detector, self.detector_err,
                                          self._pixels_to_include,
                                          self._integrate_position,
                                          self._integrate_width)

        # peak finder returns (centroid, gaussian coefs)
        beam_centre, beam_sd = peak_finder(xs, x=x)[1]

        self._true_centre = beam_centre
        self._true_sd = beam_sd

        regions = fore_back_region(beam_centre, beam_sd)
        self._low_px, self._high_px, bp = regions
        self._low_bkg = np.min(bp[0])
        self._high_bkg = np.max(bp[0])

        self.detector_image.display_image(self.detector, beam_centre,
                                          self._low_px,
                                          self._high_px,
                                          self._low_bkg,
                                          self._high_bkg,
                                          self._pixels_to_include,
                                          self._integrate_width,
                                          self._integrate_position)
        self.cross_section.display_cross_section(x, xs, beam_centre,
                                                 self._low_px,
                                                 self._high_px,
                                                 self._low_bkg,
                                                 self._high_bkg)

        self.true_centre.setValue(self._true_centre)
        self.true_fwhm.setValue(self._true_sd * 2.3548)
    def on_cross_drag_release(self, event):
        """
        A listener for press->drag->release events on the cross section plot.
        This is where the user is graphically editing foreground/background
        regions
        """
        low_bkg = self.cross_section._low_bkg
        high_bkg = self.cross_section._high_bkg
        lopx = self.cross_section._low_px
        hipx = self.cross_section._high_px

        dragged_attr, dragged_line = self.cross_section._press[0]
        if (lopx >= hipx) or (low_bkg >= high_bkg):
            # set it back to what it was
            setattr(self.cross_section,
                    dragged_attr,
                    getattr(self, dragged_attr))
            # and redraw the line
            dragged_line.set_xdata(getattr(self, dragged_attr))
            self.cross_section.draw()
            return
        else:
            # drag was legal, update the attribute in here
            setattr(self,
                    dragged_attr,
                    getattr(self.cross_section, dragged_attr))

        # recalculate beam_centre, beam_sd based off cross section
        x, xs, xs_err = get_cross_section(self.detector,
                                          self.detector_err,
                                          self._pixels_to_include,
                                          self._integrate_position,
                                          self._integrate_width)
        # trim to foreground region
        in_foreground = np.logical_and(x >= lopx, x <= hipx)
        x = x[in_foreground]
        xs = xs[in_foreground]

        # calculate peak centre
        self._true_centre, self._true_sd = peak_finder(xs, x=x)[1]

        # redraw beam centre on detector image and cross section
        self.cross_section.l_bc.set_xdata(self._true_centre)
        self.cross_section.draw()

        self.detector_image.l_lbkg.set_ydata(self._low_bkg - 0.5)
        self.detector_image.l_hbkg.set_ydata(self._high_bkg + 0.5)
        self.detector_image.l_lfore.set_ydata(self._low_px - 0.5)
        self.detector_image.l_hfore.set_ydata(self._high_px + 0.5)
        self.detector_image.l_bc.set_ydata(self._true_centre)

        self.detector_image.draw()

        # update the spinboxes, but without triggering its slot
        self.true_centre.valueChanged.disconnect()
        self.true_centre.setValue(self._true_centre)
        self.true_centre.valueChanged.connect(self.on_true_centre_valueChanged)

        self.true_fwhm.valueChanged.disconnect()
        self.true_fwhm.setValue(self._true_sd * 2.3548)
        self.true_fwhm.valueChanged.connect(self.on_true_fwhm_valueChanged)