def test_window_validation(self):
     # test too small a window
     with self.assertRaises(RuntimeError):
         EnggEstimateFocussedBackground(InputWorkspace='ws', OutputWorkspace='ws_bg', NIterations=20, XWindow=0.1)
     # test too large a window
     with self.assertRaises(RuntimeError):
         EnggEstimateFocussedBackground(InputWorkspace='ws', OutputWorkspace='ws_bg', NIterations=20, XWindow=200)
    def test_subtraction(self):

        # get bg and subtract
        ws_bg = EnggEstimateFocussedBackground(InputWorkspace='ws', NIterations=20, XWindow=3)
        ws_diff = self.ws - ws_bg

        # test residuals to ensure background is well approximated
        self.assertAlmostEqual(np.mean(ws_diff.readY(0)[self.mask]), 0, delta=0.01)
        self.assertAlmostEqual(np.median(ws_diff.readY(0)[self.mask]), 0, delta=0.01)
Пример #3
0
 def estimate_background(self, ws_name, niter, xwindow, doSGfilter):
     try:
         ws_bg = EnggEstimateFocussedBackground(InputWorkspace=ws_name, OutputWorkspace=ws_name + "_bg",
                                                NIterations=niter, XWindow=xwindow, ApplyFilterSG=doSGfilter)
     except (ValueError, RuntimeError) as e:
         # ValueError when Niter not positive integer, RuntimeError when Window too small
         logger.error("Error on arguments supplied to EnggEstimateFocusedBackground: " + str(e))
         ws_bg = SetUncertainties(InputWorkspace=ws_name)  # copy data and zero errors
         ws_bg = Minus(LHSWorkspace=ws_bg, RHSWorkspace=ws_bg)  # workspace of zeros with same num spectra
     return ws_bg
Пример #4
0
 def _get_van_curves_for_roi(region: str, van_processed_inst_ws,
                             grouping_ws):  # -> Workspace
     """
     Retrieve vanadium curves for this roi from the ADS if they exist, create them if not
     :param region: String describing region of interest
     :param van_processed_inst_ws: Processed instrument workspace of this vanadium run
     :param grouping_ws: Grouping workspace for DiffractionFoucussing
     :return: Curves workspace for this roi
     """
     curves_roi_name = CURVES_PREFIX + region
     # check if van curves for roi in ADS (should exist if not first run in session)
     if Ads.doesExist(curves_roi_name):
         return Ads.retrieve(curves_roi_name)
     else:
         # focus processed instrument ws over specified region of interest, iot produce vanadium curves for roi
         focused_curves = DiffractionFocussing(
             InputWorkspace=van_processed_inst_ws,
             OutputWorkspace=curves_roi_name,
             GroupingWorkspace=grouping_ws)
         EnggEstimateFocussedBackground(InputWorkspace=focused_curves,
                                        OutputWorkspace=focused_curves,
                                        NIterations='15',
                                        XWindow=0.03)
         return focused_curves
Пример #5
0
 def estimate_background(self, ws_name, niter, xwindow, doSGfilter):
     ws_bg = EnggEstimateFocussedBackground(InputWorkspace=ws_name, OutputWorkspace=ws_name + "_bg",
                                            NIterations=niter, XWindow=xwindow, ApplyFilterSG=doSGfilter)
     self._background_workspaces[ws_name] = ws_bg
     return ws_bg