Exemplo n.º 1
0
 def _sumForegroundInLambda(self, ws):
     """Sum the foreground region into a single histogram."""
     foreground = self._foregroundIndices(ws)
     sumIndices = [i for i in range(foreground[0], foreground[2] + 1)]
     beamPosIndex = foreground[1]
     foregroundWSName = self._names.withSuffix('foreground_grouped')
     foregroundWS = ExtractSingleSpectrum(
         InputWorkspace=ws,
         OutputWorkspace=foregroundWSName,
         WorkspaceIndex=beamPosIndex,
         EnableLogging=self._subalgLogging)
     maxIndex = ws.getNumberHistograms() - 1
     foregroundYs = foregroundWS.dataY(0)
     foregroundEs = foregroundWS.dataE(0)
     numpy.square(foregroundEs, out=foregroundEs)
     for i in sumIndices:
         if i == beamPosIndex:
             continue
         if i < 0 or i > maxIndex:
             self.log().warning('Foreground partially out of the workspace.')
         addeeWSName = self._names.withSuffix('foreground_addee')
         addeeWS = ExtractSingleSpectrum(
             InputWorkspace=ws,
             OutputWorkspace=addeeWSName,
             WorkspaceIndex=i,
             EnableLogging=self._subalgLogging)
         addeeWS = RebinToWorkspace(
             WorkspaceToRebin=addeeWS,
             WorkspaceToMatch=foregroundWS,
             OutputWorkspace=addeeWSName,
             EnableLogging=self._subalgLogging)
         ys = addeeWS.readY(0)
         foregroundYs += ys
         es = addeeWS.readE(0)
         foregroundEs += es**2
         self._cleanup.cleanup(addeeWS)
     self._cleanup.cleanup(ws)
     numpy.sqrt(foregroundEs, out=foregroundEs)
     return foregroundWS
Exemplo n.º 2
0
    def _sumForegroundInLambda(self, ws):
        """Sum the foreground region into a single histogram."""
        foreground = self._foregroundIndices(ws)
        sumIndices = [i for i in range(foreground[0], foreground[2] + 1)]
        beamPosIndex = foreground[1]
        foregroundWSName = self._names.withSuffix('grouped')
        foregroundWS = ExtractSingleSpectrum(InputWorkspace=ws,
                                             OutputWorkspace=foregroundWSName,
                                             WorkspaceIndex=beamPosIndex,
                                             EnableLogging=self._subalgLogging)
        maxIndex = ws.getNumberHistograms() - 1
        foregroundYs = foregroundWS.dataY(0)
        foregroundEs = foregroundWS.dataE(0)
        numpy.square(foregroundEs, out=foregroundEs)
        for i in sumIndices:
            if i == beamPosIndex:
                continue
            if i < 0 or i > maxIndex:
                self.log().warning(
                    'Foreground partially out of the workspace.')
            addeeWSName = self._names.withSuffix('addee')
            addeeWS = ExtractSingleSpectrum(InputWorkspace=ws,
                                            OutputWorkspace=addeeWSName,
                                            WorkspaceIndex=i,
                                            EnableLogging=self._subalgLogging)
            addeeWS = RebinToWorkspace(WorkspaceToRebin=addeeWS,
                                       WorkspaceToMatch=foregroundWS,
                                       OutputWorkspace=addeeWSName,
                                       EnableLogging=self._subalgLogging)
            ys = addeeWS.readY(0)
            foregroundYs += ys
            es = addeeWS.readE(0)
            foregroundEs += es**2
            self._cleanup.cleanup(addeeWS)
        self._cleanup.cleanup(ws)
        numpy.sqrt(foregroundEs, out=foregroundEs)
        # Move the detector to the fractional linePosition
        linePosition = ws.run().getProperty(
            common.SampleLogs.LINE_POSITION).value
        instr = common.instrumentName(ws)
        pixelSize = common.pixelSize(instr)
        dist = pixelSize * (linePosition - beamPosIndex)

        if dist != 0.:
            detPoint1 = ws.spectrumInfo().position(0)
            detPoint2 = ws.spectrumInfo().position(20)
            beta = numpy.math.atan2((detPoint2[0] - detPoint1[0]),
                                    (detPoint2[2] - detPoint1[2]))
            xvsy = numpy.math.sin(beta) * dist
            mz = numpy.math.cos(beta) * dist
            if instr == 'D17':
                mx = xvsy
                my = 0.0
                rotationAxis = [0, 1, 0]
            else:
                mx = 0.0
                my = xvsy
                rotationAxis = [-1, 0, 0]
            MoveInstrumentComponent(Workspace=foregroundWS,
                                    ComponentName='detector',
                                    X=mx,
                                    Y=my,
                                    Z=mz,
                                    RelativePosition=True)
            theta = foregroundWS.spectrumInfo().twoTheta(0) / 2.
            RotateInstrumentComponent(Workspace=foregroundWS,
                                      ComponentName='detector',
                                      X=rotationAxis[0],
                                      Y=rotationAxis[1],
                                      Z=rotationAxis[2],
                                      Angle=theta,
                                      RelativeRotation=True)
        return foregroundWS