Пример #1
0
    def PyExec(self):
        """ Main execution body
        """
        inputws = self.getProperty("InputWorkspace").value
        epptable = self.getProperty("EPPTable").value
        outws_name = self.getPropertyValue("OutputWorkspace")

        run = inputws.getRun()
        tof1 = float(run.getLogData('TOF1').value)
        wavelength = float(run.getLogData('wavelength').value)
        velocity = sp.constants.h / (sp.constants.m_n * wavelength * 1e-10
                                     )  # m/s
        instrument = inputws.getInstrument()
        sample = instrument.getSample()
        t_fit = np.array(epptable.column('PeakCentre')) - tof1
        outws = CloneWorkspace(inputws, OutputWorkspace=outws_name)
        # mask detectors with EPP=0
        bad_data = np.where(t_fit <= 0)[0]
        if len(bad_data) > 0:
            self.log().warning("Detectors " + str(bad_data) +
                               " have EPP=0 and will be masked.")
            MaskDetectors(outws, DetectorList=bad_data)

        for idx in range(outws.getNumberHistograms()):
            # correct TOF only if fit of EPP was succesful
            if t_fit[idx] > 0:
                det = instrument.getDetector(
                    outws.getSpectrum(idx).getDetectorIDs()[0])
                sdd = det.getDistance(sample)
                t2_el = sdd * 1.0e+6 / velocity  # microseconds
                newX = inputws.readX(idx) + t2_el - t_fit[idx]
                outws.setX(idx, newX)

        self.setProperty("OutputWorkspace", outws)
Пример #2
0
    def _generateNormalization(self, WS, normType, normWS):
        if normType == 'None':
            return None
        elif normType == "Extracted from Data":
            window = self.getProperty("PeakClippingWindowSize").value

            smooth_range = self.getProperty("SmoothingRange").value

            peak_clip_WS = CloneWorkspace(InputWorkspace=WS,
                                          OutputWorkspace='peak_clip_WS')
            n_histo = peak_clip_WS.getNumberHistograms()

            x = peak_clip_WS.extractX()
            y = peak_clip_WS.extractY()
            e = peak_clip_WS.extractE()

            for h in range(n_histo):
                peak_clip_WS.setX(h, x[h])
                peak_clip_WS.setY(
                    h,
                    self.peak_clip(y[h],
                                   win=window,
                                   decrese=True,
                                   LLS=True,
                                   smooth_window=smooth_range))
                peak_clip_WS.setE(h, e[h])
            return 'peak_clip_WS'
        else:  # other values are already held in normWS
            return normWS
Пример #3
0
    def PyExec(self):
        """ Main execution body
        """
        inputws = self.getProperty("InputWorkspace").value
        epptable = self.getProperty("EPPTable").value
        outws_name = self.getPropertyValue("OutputWorkspace")

        run = inputws.getRun()
        tof1 = float(run.getLogData('TOF1').value)
        wavelength = float(run.getLogData('wavelength').value)
        velocity = sp.constants.h/(sp.constants.m_n*wavelength*1e-10)   # m/s
        instrument = inputws.getInstrument()
        sample = instrument.getSample()
        t_fit = np.array(epptable.column('PeakCentre') ) - tof1
        outws = CloneWorkspace(inputws, OutputWorkspace=outws_name)
        # mask detectors with EPP=0
        bad_data = np.where(t_fit <= 0)[0]
        if len(bad_data) > 0:
            self.log().warning("Detectors " + str(bad_data) + " have EPP=0 and will be masked.")
            MaskDetectors(outws, DetectorList=bad_data)

        for idx in range(outws.getNumberHistograms()):
            # correct TOF only if fit of EPP was succesful
            if t_fit[idx] > 0:
                det = instrument.getDetector(outws.getSpectrum(idx).getDetectorIDs()[0])
                sdd = det.getDistance(sample)
                t2_el = sdd*1.0e+6/velocity         # microseconds
                newX = inputws.readX(idx) + t2_el - t_fit[idx]
                outws.setX(idx, newX)

        self.setProperty("OutputWorkspace", outws)
Пример #4
0
    def _generateNormalization(self, WS, normType, normWS):
        if normType == 'None':
            return None
        elif normType == "Extracted from Data":
            window = self.getProperty("PeakClippingWindowSize").value

            smooth_range = self.getProperty("SmoothingRange").value

            peak_clip_WS = str(WS).replace('_red', '_normalizer')
            peak_clip_WS = CloneWorkspace(InputWorkspace=WS, OutputWorkspace=peak_clip_WS)
            n_histo = peak_clip_WS.getNumberHistograms()

            for h in range(n_histo):
                peak_clip_WS.setY(h, self.peak_clip(peak_clip_WS.readY(h), win=window, decrese=True,
                                                    LLS=True, smooth_window=smooth_range))
            return str(peak_clip_WS)
        else:  # other values are already held in normWS
            return normWS
Пример #5
0
    def _generateNormalization(self, WS, normType, normWS):
        if normType == 'None':
            return None
        elif normType == "Extracted from Data":
            window = self.getProperty("PeakClippingWindowSize").value

            smooth_range = self.getProperty("SmoothingRange").value

            peak_clip_WS = str(WS).replace('_red', '_normalizer')
            peak_clip_WS = CloneWorkspace(InputWorkspace=WS, OutputWorkspace=peak_clip_WS)
            n_histo = peak_clip_WS.getNumberHistograms()

            for h in range(n_histo):
                peak_clip_WS.setY(h, self.peak_clip(peak_clip_WS.readY(h), win=window, decrese=True,
                                                    LLS=True, smooth_window=smooth_range))
            return str(peak_clip_WS)
        else:  # other values are already held in normWS
            return normWS
Пример #6
0
def convert_to_2theta(ws_name, num_bins=1000):
    """
    """
    # duplicate for vanadium
    vanadium = CloneWorkspace(InputWorkspace=ws_name,
                              OutputWorkspace='vanadium')

    # transfer to 2theta for data
    ConvertSpectrumAxis(InputWorkspace=ws_name,
                        OutputWorkspace=ws_name,
                        Target='Theta')
    Transpose(InputWorkspace=ws_name, OutputWorkspace=ws_name)
    ResampleX(InputWorkspace=ws_name,
              OutputWorkspace=ws_name,
              NumberBins=num_bins,
              PreserveEvents=False)

    # vanadium: set to 1 for now
    time_van_start = time.time()
    for iws in range(vanadium.getNumberHistograms()):
        vanadium.dataY(iws)[0] = 1.
    time_van_stop = time.time()
    ConvertSpectrumAxis(InputWorkspace='vanadium',
                        OutputWorkspace='vanadium',
                        Target='Theta')
    Transpose(InputWorkspace='vanadium', OutputWorkspace='vanadium')
    ResampleX(InputWorkspace='vanadium',
              OutputWorkspace='vanadium',
              NumberBins=num_bins,
              PreserveEvents=False)

    norm_ws_name = ws_name + '_normalized'
    Divide(LHSWorkspace=ws_name,
           RHSWorkspace='vanadium',
           OutputWorkspace=norm_ws_name)

    print('Create vanadium workspace : {} seconds'.format(time_van_stop -
                                                          time_van_start))

    return norm_ws_name
Пример #7
0
    def _generateNormalization(self, WS, normType, normWS):
        if normType == 'None':
            return None
        elif normType == "Extracted from Data":
            window = self.getProperty("PeakClippingWindowSize").value

            smooth_range = self.getProperty("SmoothingRange").value

            peak_clip_WS = CloneWorkspace(WS)
            n_histo = peak_clip_WS.getNumberHistograms()

            x = peak_clip_WS.extractX()
            y = peak_clip_WS.extractY()
            e = peak_clip_WS.extractE()

            for h in range(n_histo):
                peak_clip_WS.setX(h, x[h])
                peak_clip_WS.setY(h, self.peak_clip(y[h], win=window, decrese=True,
                                                    LLS=True, smooth_window=smooth_range))
                peak_clip_WS.setE(h, e[h])
            return peak_clip_WS
        else: # other values are already held in normWS
            return normWS