def PyExec(self):

        # Get peaks in dSpacing from file, and check we have what we need, before doing anything
        expectedPeaksD = EnggUtils.read_in_expected_peaks(self.getPropertyValue("ExpectedPeaksFromFile"),
                                                          self.getProperty('ExpectedPeaks').value)

        if len(expectedPeaksD) < 1:
            raise ValueError("Cannot run this algorithm without any input expected peaks")

        inWS = self.getProperty('Workspace').value
        WSIndices = EnggUtils.getWsIndicesFromInProperties(inWS, self.getProperty('Bank').value,
                                                           self.getProperty(self.INDICES_PROP_NAME).value)

        vanWS = self.getProperty("VanadiumWorkspace").value
        vanIntegWS = self.getProperty('VanIntegrationWorkspace').value
        vanCurvesWS = self.getProperty('VanCurvesWorkspace').value
        # These corrections rely on ToF<->Dspacing conversions, so ideally they'd be done after the
        # calibration step, which creates a cycle / chicken-and-egg issue.
        EnggUtils.applyVanadiumCorrections(self, inWS, WSIndices, vanWS, vanIntegWS, vanCurvesWS)

        rebinnedWS = self._prepareWsForFitting(inWS)
        posTbl = self._calculateCalibPositionsTbl(rebinnedWS, WSIndices, expectedPeaksD)

        # Produce 2 results: 'output table' and 'apply calibration' + (optional) calibration file
        self.setProperty("OutDetPosTable", posTbl)
        self._applyCalibrationTable(inWS, posTbl)
        self._outputDetPosFile(self.getPropertyValue('OutDetPosFilename'), posTbl)
예제 #2
0
    def PyExec(self):

        import EnggUtils

        # Get peaks in dSpacing from file
        expectedPeaksD = EnggUtils.read_in_expected_peaks(
            self.getPropertyValue("ExpectedPeaksFromFile"), self.getProperty("ExpectedPeaks").value
        )

        prog = Progress(self, start=0, end=1, nreports=2)

        prog.report("Focusing the input workspace")
        focussed_ws = self._focus_run(
            self.getProperty("InputWorkspace").value,
            self.getProperty("VanadiumWorkspace").value,
            self.getProperty("Bank").value,
            self.getProperty(self.INDICES_PROP_NAME).value,
        )

        if len(expectedPeaksD) < 1:
            raise ValueError("Cannot run this algorithm without any input expected peaks")

        prog.report("Fitting parameters for the focused run")
        difc, zero, fitted_peaks = self._fit_params(focussed_ws, expectedPeaksD)

        self.log().information(
            "Fitted {0} peaks. Resulting difc: {1}, tzero: {2}".format(fitted_peaks.rowCount(), difc, zero)
        )
        self.log().information(
            "Peaks fitted: {0}, centers in ToF: {1}".format(fitted_peaks.column("dSpacing"), fitted_peaks.column("X0"))
        )

        self._produce_outputs(difc, zero, fitted_peaks)
예제 #3
0
    def PyExec(self):
        import EnggUtils

        max_reports = 20
        prog = Progress(self, start=0, end=1, nreports=max_reports)
        # Get peaks in dSpacing from file
        prog.report("Reading peaks")

        expected_peaks_dsp = EnggUtils.read_in_expected_peaks(filename=self.getPropertyValue("ExpectedPeaksFromFile"),
                                                              expected_peaks=self.getProperty('ExpectedPeaks').value)
        if len(expected_peaks_dsp) < 1:
            raise ValueError("Cannot run this algorithm without any input expected peaks")

        prog.report('Focusing the input workspace')
        focused_ws = self._focus_run(self.getProperty('InputWorkspace').value,
                                     self.getProperty("VanadiumWorkspace").value,
                                     self.getProperty('Bank').value,
                                     self.getProperty(self.INDICES_PROP_NAME).value,
                                     prog)

        prog.report('Fitting parameters for the focused run')
        difa, difc, zero, fitted_peaks = self._fit_params(focused_ws, expected_peaks_dsp, prog)

        self.log().information("Fitted {0} peaks. Resulting DIFA: {1}, DIFC: {2}, TZERO: {3}".
                               format(fitted_peaks.rowCount(), difa, difc, zero))
        self.log().information("Peaks fitted: {0}, centers in ToF: {1}".
                               format(fitted_peaks.column("dSpacing"),
                                      fitted_peaks.column("X0")))

        prog.report("Producing outputs")
        self._produce_outputs(difa, difc, zero, fitted_peaks)

        prog.report(max_reports, "Calibration complete")
예제 #4
0
    def PyExec(self):
        # Get peaks in dSpacing from file, and check we have what we need, before doing anything
        expected_peaks_d = EnggUtils.read_in_expected_peaks(self.getPropertyValue("ExpectedPeaksFromFile"),
                                                            self.getProperty('ExpectedPeaks').value)

        if len(expected_peaks_d) < 1:
            raise ValueError("Cannot run this algorithm without any input expected peaks")

        in_wks = self.getProperty('Workspace').value
        wks_indices = EnggUtils.get_ws_indices_from_input_properties(in_wks, self.getProperty('Bank').value,
                                                                     self.getProperty(self.INDICES_PROP_NAME).value)

        van_wks = self.getProperty("VanadiumWorkspace").value
        van_integ_wks = self.getProperty('VanIntegrationWorkspace').value
        van_curves_wks = self.getProperty('VanCurvesWorkspace').value
        # These corrections rely on ToF<->Dspacing conversions, so ideally they'd be done after the
        # calibration step, which creates a cycle / chicken-and-egg issue.
        EnggUtils.apply_vanadium_corrections(self, in_wks, wks_indices, van_wks, van_integ_wks, van_curves_wks)

        rebinned_ws = self._prepare_ws_for_fitting(in_wks, self.getProperty('RebinBinWidth').value)
        pos_tbl, peaks_tbl = self._calculate_calib_positions_tbl(rebinned_ws, wks_indices, expected_peaks_d)

        # Produce 2 results: 'output table' and 'apply calibration' + (optional) calibration file
        self.setProperty("OutDetPosTable", pos_tbl)
        self.setProperty("FittedPeaks", peaks_tbl)
        self._apply_calibration_table(in_wks, pos_tbl)
        self._output_det_pos_file(self.getPropertyValue('OutDetPosFilename'), pos_tbl)
예제 #5
0
    def PyExec(self):
        # Get peaks in dSpacing from file, and check we have what we need, before doing anything
        expected_peaks_d = EnggUtils.read_in_expected_peaks(self.getPropertyValue("ExpectedPeaksFromFile"),
                                                            self.getProperty('ExpectedPeaks').value)

        if len(expected_peaks_d) < 1:
            raise ValueError("Cannot run this algorithm without any input expected peaks")

        in_wks = self.getProperty('Workspace').value
        wks_indices = EnggUtils.get_ws_indices_from_input_properties(in_wks, self.getProperty('Bank').value,
                                                                     self.getProperty(self.INDICES_PROP_NAME).value)

        van_wks = self.getProperty("VanadiumWorkspace").value
        van_integ_wks = self.getProperty('VanIntegrationWorkspace').value
        van_curves_wks = self.getProperty('VanCurvesWorkspace').value
        # These corrections rely on ToF<->Dspacing conversions, so ideally they'd be done after the
        # calibration step, which creates a cycle / chicken-and-egg issue.
        EnggUtils.apply_vanadium_corrections(self, in_wks, wks_indices, van_wks, van_integ_wks, van_curves_wks)

        rebinned_ws = self._prepare_ws_for_fitting(in_wks, self.getProperty('RebinBinWidth').value)
        pos_tbl, peaks_tbl = self._calculate_calib_positions_tbl(rebinned_ws, wks_indices, expected_peaks_d)

        # Produce 2 results: 'output table' and 'apply calibration' + (optional) calibration file
        self.setProperty("OutDetPosTable", pos_tbl)
        self.setProperty("FittedPeaks", peaks_tbl)
        self._apply_calibration_table(in_wks, pos_tbl)
        self._output_det_pos_file(self.getPropertyValue('OutDetPosFilename'), pos_tbl)
예제 #6
0
    def PyExec(self):

        import EnggUtils

        # Get peaks in dSpacing from file
        expected_peaks_dsp = EnggUtils.read_in_expected_peaks(
            self.getPropertyValue("ExpectedPeaksFromFile"),
            self.getProperty('ExpectedPeaks').value)

        if len(expected_peaks_dsp) < 1:
            raise ValueError(
                "Cannot run this algorithm without any input expected peaks")

        prog = Progress(self, start=0, end=1, nreports=2)

        prog.report('Focusing the input workspace')
        focussed_ws = self._focus_run(
            self.getProperty('InputWorkspace').value,
            self.getProperty("VanadiumWorkspace").value,
            self.getProperty('Bank').value,
            self.getProperty(self.INDICES_PROP_NAME).value)

        prog.report('Fitting parameters for the focused run')
        difa, difc, zero, fitted_peaks = self._fit_params(
            focussed_ws, expected_peaks_dsp)

        self.log().information(
            "Fitted {0} peaks. Resulting DIFA: {1}, DIFC: {2}, TZERO: {3}".
            format(fitted_peaks.rowCount(), difa, difc, zero))
        self.log().information("Peaks fitted: {0}, centers in ToF: {1}".format(
            fitted_peaks.column("dSpacing"), fitted_peaks.column("X0")))

        self._produce_outputs(difa, difc, zero, fitted_peaks)
예제 #7
0
    def PyExec(self):

        import EnggUtils

        # Get peaks in dSpacing from file
        expected_peaks_dsp = EnggUtils.read_in_expected_peaks(self.getPropertyValue("ExpectedPeaksFromFile"),
                                                              self.getProperty('ExpectedPeaks').value)

        if len(expected_peaks_dsp) < 1:
            raise ValueError("Cannot run this algorithm without any input expected peaks")

        # Get expected peaks in TOF for the detector
        in_wks = self.getProperty("InputWorkspace").value
        dimType = in_wks.getXDimension().getName()
        if self.EXPECTED_DIM_TYPE != dimType:
            raise ValueError("This algorithm expects a workspace with %s X dimension, but "
                             "the X dimension of the input workspace is: '%s'" % (self.EXPECTED_DIM_TYPE, dimType))

        wks_index = self.getProperty("WorkspaceIndex").value

        # FindPeaks will return a list of peaks sorted by the centre found. Sort the peaks as well,
        # so we can match them with fitted centres later.
        expected_peaks_ToF = sorted(self._expected_peaks_in_ToF(expected_peaks_dsp, in_wks, wks_index))

        found_peaks = self._peaks_from_find_peaks(in_wks, expected_peaks_ToF, wks_index)
        if found_peaks.rowCount() < len(expected_peaks_ToF):
            txt = "Peaks effectively found: " + str(found_peaks)[1:-1]
            self.log().warning("Some peaks from the list of expected peaks were not found by the algorithm "
                               "FindPeaks which this algorithm uses to check that the data has the the "
                               "expected peaks. " + txt)

        peaks_table_name = self.getPropertyValue("OutFittedPeaksTable")
        difc, zero, fitted_peaks = self._fit_all_peaks(in_wks, wks_index,
                                                       (found_peaks, expected_peaks_dsp), peaks_table_name)
        self._produce_outputs(difc, zero, fitted_peaks)
예제 #8
0
    def PyExec(self):

        import EnggUtils

        # Get peaks in dSpacing from file
        expected_peaks = EnggUtils.read_in_expected_peaks(
            self.getPropertyValue("ExpectedPeaksFromFile"),
            self.getProperty('ExpectedPeaks').value)

        if len(expected_peaks) < 1:
            raise ValueError(
                "Cannot run this algorithm without any input expected peaks")

        # Get expected peaks in TOF for the detector
        in_wks = self.getProperty("InputWorkspace").value
        dim_type = in_wks.getXDimension().name
        if self.EXPECTED_DIM_TYPE != dim_type:
            raise ValueError(
                "This algorithm expects a workspace with %s X dimension, but "
                "the X dimension of the input workspace is: '%s'" %
                (self.EXPECTED_DIM_TYPE, dim_type))

        wks_index = self.getProperty("WorkspaceIndex").value

        if self._any_expected_peaks_in_ws_range(in_wks, expected_peaks):
            expected_peaks_tof = sorted(expected_peaks)
        else:
            expected_peaks_tof = sorted(
                self._expected_peaks_in_tof(expected_peaks, in_wks, wks_index))
            self._expected_peaks_are_in_tof = False
            if not self._any_expected_peaks_in_ws_range(
                    in_wks, expected_peaks_tof):
                raise ValueError(
                    "Expected peak centres lie outside the limits of the workspace x axis"
                )

        found_peaks = self._peaks_from_find_peaks(in_wks, expected_peaks_tof,
                                                  wks_index)
        if found_peaks.rowCount() < len(expected_peaks_tof):
            txt = "Peaks effectively found: " + str(found_peaks)[1:-1]
            self.log().warning(
                "Some peaks from the list of expected peaks were not found by the algorithm "
                "FindPeaks which this algorithm uses to check that the data has the the "
                "expected peaks. " + txt)

        peaks_table_name = self.getPropertyValue("OutFittedPeaksTable")
        fitted_peaks = self._fit_all_peaks(in_wks, wks_index,
                                           (found_peaks, expected_peaks),
                                           peaks_table_name)

        # mandatory output
        self.setProperty('FittedPeaks', fitted_peaks)
예제 #9
0
    def PyExec(self):

        import EnggUtils

        # Get peaks in dSpacing from file
        expected_peaks_dsp = EnggUtils.read_in_expected_peaks(
            self.getPropertyValue("ExpectedPeaksFromFile"),
            self.getProperty('ExpectedPeaks').value)

        if len(expected_peaks_dsp) < 1:
            raise ValueError(
                "Cannot run this algorithm without any input expected peaks")

        # Get expected peaks in TOF for the detector
        in_wks = self.getProperty("InputWorkspace").value
        dimType = in_wks.getXDimension().getName()
        if self.EXPECTED_DIM_TYPE != dimType:
            raise ValueError(
                "This algorithm expects a workspace with %s X dimension, but "
                "the X dimension of the input workspace is: '%s'" %
                (self.EXPECTED_DIM_TYPE, dimType))

        wks_index = self.getProperty("WorkspaceIndex").value

        # FindPeaks will return a list of peaks sorted by the centre found. Sort the peaks as well,
        # so we can match them with fitted centres later.
        expected_peaks_ToF = sorted(
            self._expected_peaks_in_ToF(expected_peaks_dsp, in_wks, wks_index))

        found_peaks = self._peaks_from_find_peaks(in_wks, expected_peaks_ToF,
                                                  wks_index)
        if found_peaks.rowCount() < len(expected_peaks_ToF):
            txt = "Peaks effectively found: " + str(found_peaks)[1:-1]
            self.log().warning(
                "Some peaks from the list of expected peaks were not found by the algorithm "
                "FindPeaks which this algorithm uses to check that the data has the the "
                "expected peaks. " + txt)

        peaks_table_name = self.getPropertyValue("OutFittedPeaksTable")
        fitted_peaks = self._fit_all_peaks(in_wks, wks_index,
                                           (found_peaks, expected_peaks_dsp),
                                           peaks_table_name)

        # mandatory output
        self.setProperty('FittedPeaks', fitted_peaks)
예제 #10
0
    def PyExec(self):

        import EnggUtils

        # Get peaks in dSpacing from file
        expected_peaks = EnggUtils.read_in_expected_peaks(self.getPropertyValue("ExpectedPeaksFromFile"),
                                                          self.getProperty('ExpectedPeaks').value)

        if len(expected_peaks) < 1:
            raise ValueError("Cannot run this algorithm without any input expected peaks")

        # Get expected peaks in TOF for the detector
        in_wks = self.getProperty("InputWorkspace").value
        dim_type = in_wks.getXDimension().name
        if self.EXPECTED_DIM_TYPE != dim_type:
            raise ValueError("This algorithm expects a workspace with %s X dimension, but "
                             "the X dimension of the input workspace is: '%s'" % (self.EXPECTED_DIM_TYPE, dim_type))

        wks_index = self.getProperty("WorkspaceIndex").value

        if self._any_expected_peaks_in_ws_range(in_wks, expected_peaks):
            expected_peaks_tof = sorted(expected_peaks)
        else:
            expected_peaks_tof = sorted(self._expected_peaks_in_tof(expected_peaks, in_wks, wks_index))
            self._expected_peaks_are_in_tof = False
            if not self._any_expected_peaks_in_ws_range(in_wks, expected_peaks_tof):
                raise ValueError("Expected peak centres lie outside the limits of the workspace x axis")

        found_peaks = self._peaks_from_find_peaks(in_wks, expected_peaks_tof, wks_index)
        if found_peaks.rowCount() < len(expected_peaks_tof):
            txt = "Peaks effectively found: " + str(found_peaks)[1:-1]
            self.log().warning("Some peaks from the list of expected peaks were not found by the algorithm "
                               "FindPeaks which this algorithm uses to check that the data has the the "
                               "expected peaks. " + txt)

        peaks_table_name = self.getPropertyValue("OutFittedPeaksTable")
        fitted_peaks = self._fit_all_peaks(in_wks, wks_index,
                                           (found_peaks, expected_peaks), peaks_table_name)

        # mandatory output
        self.setProperty('FittedPeaks', fitted_peaks)
예제 #11
0
    def PyExec(self):
        mantid.logger.warning(
            "EnggCalibrate is deprecated as of May 2021. Please use PDCalibration instead."
        )
        import EnggUtils

        max_reports = 20
        prog = Progress(self, start=0, end=1, nreports=max_reports)
        # Get peaks in dSpacing from file
        prog.report("Reading peaks")

        expected_peaks_dsp = EnggUtils.read_in_expected_peaks(
            filename=self.getPropertyValue("ExpectedPeaksFromFile"),
            expected_peaks=self.getProperty('ExpectedPeaks').value)
        if len(expected_peaks_dsp) < 1:
            raise ValueError(
                "Cannot run this algorithm without any input expected peaks")

        prog.report('Focusing the input workspace')
        focused_ws = self._focus_run(
            self.getProperty('InputWorkspace').value,
            self.getProperty("VanadiumWorkspace").value,
            self.getProperty('Bank').value,
            self.getProperty(self.INDICES_PROP_NAME).value, prog)

        prog.report('Fitting parameters for the focused run')
        difa, difc, zero, fitted_peaks = self._fit_params(
            focused_ws, expected_peaks_dsp, prog)

        self.log().information(
            "Fitted {0} peaks. Resulting DIFA: {1}, DIFC: {2}, TZERO: {3}".
            format(fitted_peaks.rowCount(), difa, difc, zero))
        self.log().information("Peaks fitted: {0}, centers in ToF: {1}".format(
            fitted_peaks.column("dSpacing"), fitted_peaks.column("X0")))

        prog.report("Producing outputs")
        self._produce_outputs(difa, difc, zero, fitted_peaks)

        prog.report(max_reports, "Calibration complete")