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 test_fore_back_region(self): # calculation of foreground and background regions is done correctly centres = np.array([100., 90.]) sd = np.array([5., 11.5]) lopx, hipx, background_pixels = fore_back_region(centres, sd) assert_(len(lopx) == 2) assert_(len(hipx) == 2) assert_(len(background_pixels) == 2) assert_(isinstance(lopx[0], numbers.Integral)) assert_(isinstance(hipx[0], numbers.Integral)) calc_lower = np.floor(centres - sd * EXTENT_MULT) assert_equal(lopx, calc_lower) calc_higher = np.ceil(centres + sd * EXTENT_MULT) assert_equal(hipx, calc_higher) y1 = np.atleast_1d(np.round(lopx - PIXEL_OFFSET).astype('int')) y0 = np.atleast_1d( np.round(lopx - PIXEL_OFFSET - EXTENT_MULT * sd).astype('int')) y2 = np.atleast_1d(np.round(hipx + PIXEL_OFFSET).astype('int')) y3 = np.atleast_1d( np.round(hipx + PIXEL_OFFSET + EXTENT_MULT * sd).astype('int')) bp = np.r_[np.arange(y0[0], y1[0] + 1), np.arange(y2[0], y3[0] + 1)] assert_equal(bp, background_pixels[0])
def test_fore_back_region(self): # calculation of foreground and background regions is done correctly centres = np.array([100., 90.]) sd = np.array([5., 11.5]) lopx, hipx, background_pixels = fore_back_region(centres, sd) assert_(len(lopx) == 2) assert_(len(hipx) == 2) assert_(len(background_pixels) == 2) assert_(isinstance(lopx[0], numbers.Integral)) assert_(isinstance(hipx[0], numbers.Integral)) calc_lower = np.floor(centres - sd * EXTENT_MULT) assert_equal(lopx, calc_lower) calc_higher = np.ceil(centres + sd * EXTENT_MULT) assert_equal(hipx, calc_higher) y1 = np.atleast_1d( np.round(lopx - PIXEL_OFFSET).astype('int')) y0 = np.atleast_1d( np.round(lopx - PIXEL_OFFSET - EXTENT_MULT * sd).astype('int')) y2 = np.atleast_1d( np.round(hipx + PIXEL_OFFSET).astype('int')) y3 = np.atleast_1d( np.round(hipx + PIXEL_OFFSET + EXTENT_MULT * sd).astype('int')) bp = np.r_[np.arange(y0[0], y1[0] + 1), np.arange(y2[0], y3[0] + 1)] assert_equal(bp, background_pixels[0])
def on_true_fwhm_valueChanged(self, val): self._true_sd = val / 2.3548 regions = fore_back_region(self._true_centre, self._true_sd) self._low_px, self._high_px, bp = regions self._low_bkg = np.min(bp[0]) self._high_bkg = np.max(bp[0]) self.redraw_cross_section_regions()
def on_true_centre_valueChanged(self, val): self._true_centre = val regions = fore_back_region(self._true_centre, self._true_sd) self._low_px, self._high_px, bp = regions # perhaps fore_back_region returned regions that weren't on the # detector self._low_px = np.clip(self._low_px, 0, np.size(self.detector, 1)) self._high_px = np.clip(self._high_px, 0, np.size(self.detector, 1)) # perhaps fore_back_region returned no background pixels if len(bp[0]) > 0: self._low_bkg = np.min(bp[0]) self._high_bkg = np.max(bp[0]) self.redraw_cross_section_regions()