Exemplo n.º 1
0
 def PyExec(self):
     input_ws = self.getProperty("InputWorkspace").value
     eff_ws = self.getProperty("DetectorEfficiencyWorkspace").value
     transposed = Transpose(InputWorkspace=eff_ws, StoreInADS=False)
     efficiencies = transposed.extractY().flatten()
     errors = transposed.extractE().flatten()
     n_hist = input_ws.getNumberHistograms()
     if n_hist % efficiencies.size != 0:
         raise ValueError(
             'Number of histograms in input workspace is not a multiple of number of entries in detector efficiency '
             'workspace.')
     n_time_indexes = n_hist / efficiencies.size
     to_multiply = CreateWorkspace(DataY=np.repeat(efficiencies,
                                                   n_time_indexes),
                                   DataE=np.repeat(errors, n_time_indexes),
                                   DataX=np.zeros(n_hist),
                                   NSpec=n_hist,
                                   StoreInADS=False)
     output = Multiply(
         LHSWorkspace=input_ws,
         RHSWorkspace=to_multiply,
         OutputWorkspace=self.getPropertyValue("OutputWorkspace"))
     # In the output we should mask the detectors where calibration constant is masked
     det_IDs = ''
     n_pixels_per_tube = eff_ws.getNumberHistograms()
     for spectrum in range(n_pixels_per_tube):
         if eff_ws.hasMaskedBins(spectrum):
             masked = eff_ws.maskedBinsIndices(spectrum)
             for bin in masked:
                 det_IDs += str(bin * n_pixels_per_tube + spectrum +
                                1) + ','
     if det_IDs:
         MaskDetectors(Workspace=output, DetectorList=det_IDs[:-1])
     self.setProperty("OutputWorkspace", output)
 def PyExec(self):
     input_ws = self.getProperty("InputWorkspace").value
     eff_ws = self.getProperty("DetectorEfficiencyWorkspace").value
     transposed = Transpose(InputWorkspace=eff_ws, StoreInADS=False)
     efficiencies = transposed.extractY().flatten()
     errors = transposed.extractE().flatten()
     n_hist = input_ws.getNumberHistograms()
     if n_hist % efficiencies.size != 0:
         raise ValueError('Number of histograms in input workspace is not a multiple of number of entries in detector efficiency '
                          'workspace.')
     n_time_indexes = n_hist / efficiencies.size
     to_multiply = CreateWorkspace(DataY=np.repeat(efficiencies, n_time_indexes), DataE=np.repeat(errors, n_time_indexes),
                                   DataX=np.zeros(n_hist), NSpec=n_hist, StoreInADS=False)
     output = Multiply(LHSWorkspace=input_ws, RHSWorkspace=to_multiply, OutputWorkspace=self.getPropertyValue("OutputWorkspace"))
     # In the output we should mask the detectors where calibration constant is masked
     det_IDs = ''
     n_pixels_per_tube = eff_ws.getNumberHistograms()
     for spectrum in range(n_pixels_per_tube):
         if eff_ws.hasMaskedBins(spectrum):
             masked = eff_ws.maskedBinsIndices(spectrum)
             for bin in masked:
                 det_IDs += str(bin * n_pixels_per_tube + spectrum + 1) + ','
     if det_IDs:
         MaskDetectors(Workspace=output, DetectorList=det_IDs[:-1])
     self.setProperty("OutputWorkspace", output)
    def test_2d_scanning_workspace(self):
        input_ws = CreateSampleWorkspace(NumMonitors=0,
                                         NumBanks=3,
                                         BankPixelWidth=2,
                                         XMin=0,
                                         XMax=5,
                                         BinWidth=1,
                                         NumScanPoints=7)

        calibration_x = np.array([0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2])
        calibration_y = np.arange(12)
        calibration_ws = CreateWorkspace(DataX=calibration_x,
                                         DataY=calibration_y,
                                         Nspec=4)
        calibrated_ws = ApplyDetectorScanEffCorr(input_ws, calibration_ws)

        tmp = Transpose(calibration_ws)
        tmp = tmp.extractY().flatten()
        to_multiply = np.repeat(tmp, 5 * 7)
        to_multiply = np.reshape(to_multiply, [7 * 12, 5])

        for det in range(7 * 12):
            for bin in range(5):
                self.assertEquals(
                    calibrated_ws.readY(det)[bin],
                    input_ws.readY(det)[bin] * to_multiply[det][bin])
 def PyExec(self):
     input_ws = self.getProperty("InputWorkspace").value
     eff_ws = self.getProperty("DetectorEfficiencyWorkspace").value
     transposed = Transpose(InputWorkspace=eff_ws, StoreInADS=False)
     efficiencies = transposed.extractY().flatten()
     errors = transposed.extractE().flatten()
     n_hist = input_ws.getNumberHistograms()
     if n_hist % efficiencies.size != 0:
         raise ValueError('Number of histograms in input workspace is not a multiple of number of entries in detector efficiency '
                          'workspace.')
     n_time_indexes = n_hist / efficiencies.size
     to_multiply = CreateWorkspace(DataY=np.repeat(efficiencies, n_time_indexes),DataE=np.repeat(errors, n_time_indexes),
                                   DataX=np.zeros(n_hist), NSpec=n_hist, StoreInADS=False)
     output = Multiply(LHSWorkspace=input_ws, RHSWorkspace=to_multiply, OutputWorkspace=self.getPropertyValue("OutputWorkspace"))
     self.setProperty("OutputWorkspace", output)
    def test_2d_scanning_workspace(self):
        input_ws = CreateSampleWorkspace(NumMonitors=0, NumBanks=3, BankPixelWidth=2, XMin=0, XMax=5, BinWidth=1, NumScanPoints=7)

        calibration_x = np.array([0,1,2,0,1,2,0,1,2,0,1,2])
        calibration_y = np.arange(12)
        calibration_ws = CreateWorkspace(DataX=calibration_x, DataY=calibration_y, Nspec=4)
        calibrated_ws = ApplyDetectorScanEffCorr(input_ws, calibration_ws)

        tmp = Transpose(calibration_ws)
        tmp = tmp.extractY().flatten()
        to_multiply = np.repeat(tmp, 5*7)
        to_multiply = np.reshape(to_multiply, [7*12,5])

        for det in range(7*12):
            for bin in range(5):
                self.assertEquals(calibrated_ws.readY(det)[bin], input_ws.readY(det)[bin] * to_multiply[det][bin])
Exemplo n.º 6
0
 def PyExec(self):
     input_ws = self.getProperty("InputWorkspace").value
     eff_ws = self.getProperty("DetectorEfficiencyWorkspace").value
     transposed = Transpose(InputWorkspace=eff_ws, StoreInADS=False)
     efficiencies = transposed.extractY().flatten()
     errors = transposed.extractE().flatten()
     n_hist = input_ws.getNumberHistograms()
     if n_hist % efficiencies.size != 0:
         raise ValueError(
             'Number of histograms in input workspace is not a multiple of number of entries in detector efficiency '
             'workspace.')
     n_time_indexes = n_hist / efficiencies.size
     to_multiply = CreateWorkspace(DataY=np.repeat(efficiencies,
                                                   n_time_indexes),
                                   DataE=np.repeat(errors, n_time_indexes),
                                   DataX=np.zeros(n_hist),
                                   NSpec=n_hist,
                                   StoreInADS=False)
     output = Multiply(
         LHSWorkspace=input_ws,
         RHSWorkspace=to_multiply,
         OutputWorkspace=self.getPropertyValue("OutputWorkspace"))
     self.setProperty("OutputWorkspace", output)