コード例 #1
0
    def PyExec(self):

    	import EnginXUtils

    	ws = self._loadCalibrationRun()

    	ws = self._prepareWsForFitting(ws)

    	positionTable = self._createPositionsTable()

    	indices = EnginXUtils.getWsIndicesForBank(self.getProperty('Bank').value, ws)

    	prog = Progress(self, 0, 1, len(indices))

    	for i in indices:

    		_, difc = self._fitPeaks(ws, i)

    		det = ws.getDetector(i)

    		newPos = self._getCalibratedDetPos(difc, det, ws)

    		positionTable.addRow([det.getID(), newPos])

    		prog.report()

    	self.setProperty("DetectorPositions", positionTable)
コード例 #2
0
    def PyExec(self):

    	import EnginXUtils

    	ws = self._loadCalibrationRun()

    	ws = self._prepareWsForFitting(ws)

    	positionTable = self._createPositionsTable()

    	indices = EnginXUtils.getWsIndicesForBank(self.getProperty('Bank').value, ws)

    	prog = Progress(self, 0, 1, len(indices))

    	for i in indices:

    		_, difc = self._fitPeaks(ws, i)

    		det = ws.getDetector(i)

    		newPos = self._getCalibratedDetPos(difc, det, ws)

    		positionTable.addRow([det.getID(), newPos])

    		prog.report()

    	self.setProperty("DetectorPositions", positionTable)
コード例 #3
0
    def PyExec(self):

        import EnginXUtils

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

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

        # Get expected peaks in TOF for the detector
        inWS = self.getProperty("InputWorkspace").value
        dimType = inWS.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))

        wsIndex = 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.
        expectedPeaksToF = sorted(self._expectedPeaksInTOF(expectedPeaksD, inWS, wsIndex))

        foundPeaks = self._peaksFromFindPeaks(inWS, expectedPeaksToF, wsIndex)
        if foundPeaks.rowCount() < len(expectedPeaksToF):
            txt = "Peaks effectively found: " + str(foundPeaks)[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)

        peaksTableName = self.getPropertyValue("OutFittedPeaksTable")
        difc, zero = self._fitAllPeaks(inWS, wsIndex, (foundPeaks, expectedPeaksD), peaksTableName)
        self._produceOutputs(difc, zero)
コード例 #4
0
    def PyExec(self):
        import EnginXUtils

        # Get the run workspace
        ws = self.getProperty('InputWorkspace').value

        indices = EnginXUtils.getWsIndicesFromInProperties(ws, self.getProperty('Bank').value,
                                                           self.getProperty(self.INDICES_PROP_NAME).value)

    	# Leave the data for the bank we are interested in only
        ws = self._cropData(ws, indices)

    	# Apply calibration
        self._applyCalibration(ws)

    	# Convert to dSpacing
        ws = self._convertToDSpacing(ws)

    	# Sum the values
        ws = self._sumSpectra(ws)

    	# Convert back to time of flight
        ws = self._convertToTOF(ws)

    	# OpenGenie displays distributions instead of pure counts (this is done implicitly when
    	# converting units), so I guess that's what users will expect
        self._convertToDistr(ws)

        self.setProperty("OutputWorkspace", ws)
コード例 #5
0
    def _produceOutputs(self, difc, zero):
        """
        Just fills in the output properties as requested

        @param difc :: the difc GSAS parameter as fitted here
        @param zero :: the zero GSAS parameter as fitted here
        """

        import EnginXUtils

        self.setProperty('Difc', difc)
        self.setProperty('Zero', zero)

        # make output table if requested
        tblName = self.getPropertyValue("OutputParametersTableName")
        if '' != tblName:
            EnginXUtils.generateOutputParTable(tblName, difc, zero)
            self.log().information("Output parameters added into a table workspace: %s" % tblName)
コード例 #6
0
    def PyExec(self):

        # Get peaks in dSpacing from file, and check we have what we need, before doing anything
        expectedPeaksD = EnginXUtils.readInExpectedPeaks(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 = EnginXUtils.getWsIndicesFromInProperties(inWS, self.getProperty('Bank').value,
                                                             self.getProperty(self.INDICES_PROP_NAME).value)

        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)
コード例 #7
0
    def PyExec(self):

        import EnginXUtils

        focussed_ws = self._focusRun(self.getProperty('InputWorkspace').value,
                                     self.getProperty('Bank').value,
                                     self.getProperty(self.INDICES_PROP_NAME).value)

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

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

        difc, zero = self._fitParams(focussed_ws, expectedPeaksD)

        self._produceOutputs(difc, zero)
コード例 #8
0
    def _cropData(self, ws):
        """ Crops the workspace so that only data for the specified bank is left.

		    NB: This assumes spectra for a bank are consequent.
		"""

        import EnginXUtils

        indices = EnginXUtils.getWsIndicesForBank(self.getProperty("Bank").value, ws)

        # Leave only spectra between min and max
        alg = self.createChildAlgorithm("CropWorkspace")
        alg.setProperty("InputWorkspace", ws)
        alg.setProperty("StartWorkspaceIndex", min(indices))
        alg.setProperty("EndWorkspaceIndex", max(indices))
        alg.execute()

        return alg.getProperty("OutputWorkspace").value
コード例 #9
0
    def _cropData(self, ws):
    	""" Crops the workspace so that only data for the specified bank is left.

    	    NB: This assumes spectra for a bank are consequent.
    	"""

    	import EnginXUtils

    	indices = EnginXUtils.getWsIndicesForBank(self.getProperty('Bank').value, ws)

    	# Leave only spectra between min and max
    	alg = self.createChildAlgorithm('CropWorkspace')
    	alg.setProperty('InputWorkspace', ws)
    	alg.setProperty('StartWorkspaceIndex', min(indices))
    	alg.setProperty('EndWorkspaceIndex', max(indices))
    	alg.execute()

    	return alg.getProperty('OutputWorkspace').value