def setUp(self):
     input_ws = CreateSampleWorkspace(
         Function="User Defined",
         UserDefinedFunction="name=LinearBackground, " +
         "A0=0.3;name=Gaussian, PeakCentre=5, Height=10, Sigma=0.3",
         NumBanks=2,
         BankPixelWidth=1,
         XMin=0,
         XMax=10,
         BinWidth=0.1,
         BankDistanceFromSample=4.0)
     self._input_ws = input_ws
     self._table = FindEPP(input_ws, OutputWorkspace="table")
     AddSampleLog(self._input_ws,
                  LogName='wavelength',
                  LogText='4.0',
                  LogType='Number',
                  LogUnit='Angstrom')
     for i in range(input_ws.getNumberHistograms()):
         y = input_ws.dataY(i)
         y.fill(0.)
         y[51] = 100.
         e = input_ws.dataE(i)
         e.fill(0.)
         e[51] = 10.
    def _create_workspaces(self):
        cal=CreateSampleWorkspace(NumBanks=1,BinWidth=20000,PixelSpacing=0.1,BankPixelWidth=100)
        RotateInstrumentComponent(cal, ComponentName='bank1', X=1, Y=0.5, Z=2, Angle=35)
        MoveInstrumentComponent(cal, ComponentName='bank1', X=1, Y=1, Z=5)
        bkg=CloneWorkspace(cal)
        data=CloneWorkspace(cal)
        AddSampleLog(cal, LogName="gd_prtn_chrg", LogType='Number', NumberType='Double', LogText='200')
        AddSampleLog(bkg, LogName="gd_prtn_chrg", LogType='Number', NumberType='Double', LogText='50')
        AddSampleLog(data, LogName="gd_prtn_chrg", LogType='Number', NumberType='Double', LogText='100')
        AddSampleLog(cal, LogName="duration", LogType='Number', NumberType='Double', LogText='20')
        AddSampleLog(bkg, LogName="duration", LogType='Number', NumberType='Double', LogText='5')
        AddSampleLog(data, LogName="duration", LogType='Number', NumberType='Double', LogText='10')

        def get_cal_counts(n):
            if n < 5000:
                return 0.9
            else:
                return 1.0

        def get_bkg_counts(n):
            return 1.5*get_cal_counts(n)

        def get_data_counts(n,twoTheta):
            tt1=30
            tt2=45
            return get_bkg_counts(n)+10*np.exp(-(twoTheta-tt1)**2/1)+20*np.exp(-(twoTheta-tt2)**2/0.2)

        for i in range(cal.getNumberHistograms()):
            cal.setY(i, [get_cal_counts(i)*2.0])
            bkg.setY(i, [get_bkg_counts(i)/2.0])
            twoTheta=data.getInstrument().getDetector(i+10000).getTwoTheta(V3D(0,0,0),V3D(0,0,1))*180/np.pi
            data.setY(i, [get_data_counts(i,twoTheta)])

        return data, cal, bkg
Ejemplo n.º 3
0
    def _create_workspaces(self):
        cal=CreateSampleWorkspace(NumBanks=1,BinWidth=20000,PixelSpacing=0.1,BankPixelWidth=100)
        RotateInstrumentComponent(cal, ComponentName='bank1', X=1, Y=0.5, Z=2, Angle=35)
        MoveInstrumentComponent(cal, ComponentName='bank1', X=1, Y=1, Z=5)
        bkg=CloneWorkspace(cal)
        data=CloneWorkspace(cal)
        AddSampleLog(cal, LogName="gd_prtn_chrg", LogType='Number', NumberType='Double', LogText='200')
        AddSampleLog(bkg, LogName="gd_prtn_chrg", LogType='Number', NumberType='Double', LogText='50')
        AddSampleLog(data, LogName="gd_prtn_chrg", LogType='Number', NumberType='Double', LogText='100')
        AddSampleLog(cal, LogName="duration", LogType='Number', NumberType='Double', LogText='20')
        AddSampleLog(bkg, LogName="duration", LogType='Number', NumberType='Double', LogText='5')
        AddSampleLog(data, LogName="duration", LogType='Number', NumberType='Double', LogText='10')

        def get_cal_counts(n):
            if n < 5000:
                return 0.9
            else:
                return 1.0

        def get_bkg_counts(n):
            return 1.5*get_cal_counts(n)

        def get_data_counts(n,twoTheta):
            tt1=30
            tt2=45
            return get_bkg_counts(n)+10*np.exp(-(twoTheta-tt1)**2/1)+20*np.exp(-(twoTheta-tt2)**2/0.2)

        for i in range(cal.getNumberHistograms()):
            cal.setY(i, [get_cal_counts(i)*2.0])
            bkg.setY(i, [get_bkg_counts(i)/2.0])
            twoTheta=data.getInstrument().getDetector(i+10000).getTwoTheta(V3D(0,0,0),V3D(0,0,1))*180/np.pi
            data.setY(i, [get_data_counts(i,twoTheta)])

        return data, cal, bkg
 def createPhononWS(self, T, en, e_units):
     fn = 'name=Gaussian, PeakCentre='+str(en)+', Height=1, Sigma=0.5;'
     fn +='name=Gaussian, PeakCentre=-'+str(en)+', Height='+str(np.exp(-en*11.6/T))+', Sigma=0.5;'
     ws = CreateSampleWorkspace(binWidth = 0.1, XMin = -25, XMax = 25, XUnit = e_units, Function = 'User Defined', UserDefinedFunction=fn)
     LoadInstrument(ws, InstrumentName='MARI', RewriteSpectraMap = True)
     with self.assertRaises(RuntimeError):
         ws_DOS = ComputeIncoherentDOS(ws)
     ws = SofQW3(ws, [0, 0.05, 8], 'Direct', 25)
     qq = np.arange(0, 8, 0.05)+0.025
     for i in range(ws.getNumberHistograms()):
         ws.setY(i, ws.readY(i)*qq[i]**2)
         ws.setE(i, ws.readE(i)*qq[i]**2)
     return ws
Ejemplo n.º 5
0
 def createPhononWS(self, T, en, e_units):
     fn = 'name=Gaussian, PeakCentre='+str(en)+', Height=1, Sigma=0.5;'
     fn +='name=Gaussian, PeakCentre=-'+str(en)+', Height='+str(np.exp(-en*11.6/T))+', Sigma=0.5;'
     ws = CreateSampleWorkspace(binWidth = 0.1, XMin = -25, XMax = 25, XUnit = e_units, Function = 'User Defined', UserDefinedFunction=fn)
     LoadInstrument(ws, InstrumentName='MARI', RewriteSpectraMap = True)
     with self.assertRaises(RuntimeError):
         ws_DOS = ComputeIncoherentDOS(ws)
     ws = SofQW3(ws, [0, 0.05, 8], 'Direct', 25)
     qq = np.arange(0, 8, 0.05)+0.025
     for i in range(ws.getNumberHistograms()):
         ws.setY(i, ws.readY(i)*qq[i]**2)
         ws.setE(i, ws.readE(i)*qq[i]**2)
     return ws
Ejemplo n.º 6
0
 def create_workspace(self, name):
     workspace = CreateSampleWorkspace(OutputWorkspace=name, NumBanks=1, BankPixelWidth=5, XMin=0.1,
                                       XMax=3.1, BinWidth=0.1, XUnit='DeltaE')
     AddSampleLog(Workspace=workspace, LogName='Ei', LogText='3.', LogType='Number')
     sim_scattering_data = np.arange(0, 1.5, 0.002).reshape(30, 25).transpose()
     for i in range(workspace.getNumberHistograms()):
         workspace.setY(i, sim_scattering_data[i])
     workspace = wrap_workspace(workspace, name)
     workspace.is_PSD = False
     workspace.limits['MomentumTransfer'] = [0.1, 3.1, 0.1]
     workspace.limits['|Q|'] = [0.1, 3.1, 0.1]
     workspace.limits['DeltaE'] = [-10, 15, 1]
     workspace.e_fixed = 10
     return workspace
Ejemplo n.º 7
0
    def _get_sample_monitor_data(self, value):
        name = "test_monitor_workspace"
        monitor_workspace = CreateSampleWorkspace(OutputWorkspace=name,
                                                  NumBanks=0,
                                                  NumMonitors=8,
                                                  XMin=self.test_tof_min,
                                                  XMax=self.test_tof_max,
                                                  BinWidth=self.test_tof_width,
                                                  StoreInADS=False)

        for hist in range(monitor_workspace.getNumberHistograms()):
            data_y = monitor_workspace.dataY(hist)
            for index in range(len(data_y)):
                data_y[index] = value
            # This will be the background bin
            data_y[0] = 0.1
        return monitor_workspace
    def test_execute_single_with_solid_angle(self):
        alg = AlgorithmManager.create("DetectorFloodWeighting")
        alg.setChild(True)
        alg.initialize()
        alg.setProperty("SolidAngleCorrection", True)
        signal_value = 2
        in_ws = CreateSampleWorkspace(NumBanks=1, XUnit="Wavelength")
        alg.setProperty("InputWorkspace", in_ws)
        bands = [1,10]
        alg.setProperty("Bands", bands) # One band
        alg.setPropertyValue("OutputWorkspace", "dummy")
        alg.execute()

        out_ws = alg.getProperty("OutputWorkspace").value
        self.assertEqual(1, out_ws.blocksize())
        self.assertEqual("Wavelength", out_ws.getAxis(0).getUnit().unitID())
        self.assertEqual(in_ws.getNumberHistograms(), out_ws.getNumberHistograms(), msg="Number of histograms should be unchanged.")
Ejemplo n.º 9
0
    def test_execute_single_with_solid_angle(self):
        alg = AlgorithmManager.create("DetectorFloodWeighting")
        alg.setChild(True)
        alg.initialize()
        alg.setProperty("SolidAngleCorrection", True)
        signal_value = 2
        in_ws = CreateSampleWorkspace(NumBanks=1, XUnit="Wavelength")
        alg.setProperty("InputWorkspace", in_ws)
        bands = [1,10]
        alg.setProperty("Bands", bands) # One band
        alg.setPropertyValue("OutputWorkspace", "dummy")
        alg.execute()

        out_ws = alg.getProperty("OutputWorkspace").value
        self.assertEqual(1, out_ws.blocksize())
        self.assertEqual("Wavelength", out_ws.getAxis(0).getUnit().unitID())
        self.assertEqual(in_ws.getNumberHistograms(), out_ws.getNumberHistograms(), msg="Number of histograms should be unchanged.")
 def setUp(self):
     input_ws = CreateSampleWorkspace(
         Function="User Defined",
         UserDefinedFunction="name=LinearBackground, " +
         "A0=0.3;name=Gaussian, PeakCentre=5, Height=10, Sigma=0.3",
         NumBanks=2, BankPixelWidth=1, XMin=0, XMax=10, BinWidth=0.1,
         BankDistanceFromSample=4.0)
     self._input_ws = input_ws
     self._table = FindEPP(input_ws, OutputWorkspace="table")
     AddSampleLog(self._input_ws, LogName='wavelength', LogText='4.0',
                  LogType='Number', LogUnit='Angstrom')
     for i in range(input_ws.getNumberHistograms()):
         y = input_ws.dataY(i)
         y.fill(0.)
         y[51] = 100.
         e = input_ws.dataE(i)
         e.fill(0.)
         e[51] = 10.
Ejemplo n.º 11
0
 def _create_workspace(self, ws_2D=True, sample=True, xAx=True, yAxSpec=True,
                       yAxMt=True, instrument=True):
     """ create Workspace
     :param ws_2D: should workspace be 2D?
     :param sample: should workspace have sample logs?
     :param xAx: should x axis be DeltaE?
     :param yAxMt: should y axis be MomentumTransfer?
     :param yAxSpec: should y axis be SpectrumAxis?
     :param instrument: should workspace have a instrument?
     """
     # Event Workspace
     if not ws_2D:
         ws = CreateSampleWorkspace("Event", "One Peak", XUnit="DeltaE")
         return ws
     if not xAx:
         ws = CreateWorkspace(DataX=self.data_x, DataY=self.data_y, DataE=np.sqrt(self.data_y), NSpec=1, UnitX="TOF")
         return ws
     if not instrument:
         ws = CreateWorkspace(DataX=self.data_x, DataY=self.data_y, DataE=np.sqrt(self.data_y), NSpec=1, UnitX="DeltaE")
         return ws
     if not yAxMt and not yAxSpec:
         ws = CreateWorkspace(DataX=self.data_x, DataY=self.data_y, DataE=np.sqrt(self.data_y), NSpec=1, UnitX="DeltaE")
         LoadInstrument(ws, True, InstrumentName="TOFTOF")
         ConvertSpectrumAxis(InputWorkspace=ws, OutputWorkspace=ws, Target="theta", EMode="Direct")
         return ws
     if not yAxSpec and yAxMt:
         ws = CreateWorkspace(DataX=self.data_x, DataY=self.data_y, DataE=np.sqrt(self.data_y), NSpec=1, UnitX="DeltaE")
         LoadInstrument(ws, True, InstrumentName="TOFTOF")
         self._add_all_sample_logs(ws)
         ConvertSpectrumAxis(InputWorkspace=ws, OutputWorkspace="ws2", Target ="ElasticQ", EMode="Direct")
         ws2 = mtd["ws2"]
         return ws2
     if not sample:
         ws = CreateWorkspace(DataX=self.data_x, DataY=self.data_y, DataE=np.sqrt(self.data_y), NSpec=1, UnitX="DeltaE")
         LoadInstrument(ws, False, InstrumentName="TOFTOF")
         for i in range(ws.getNumberHistograms()):
             ws.getSpectrum(i).setDetectorID(i+1)
         return ws
     else:
         ws = CreateWorkspace(DataX=self.data_x, DataY=self.data_y, DataE=np.sqrt(self.data_y), NSpec=1, UnitX="DeltaE")
         LoadInstrument(ws, True, InstrumentName="TOFTOF")
         self._add_all_sample_logs(ws)
         return ws
Ejemplo n.º 12
0
 def _create_workspace(self,
                       ws_2D=True,
                       sample=True,
                       xAx=True,
                       yAxSpec=True,
                       yAxMt=True,
                       instrument=True):
     """ create Workspace
     :param ws_2D: should workspace be 2D?
     :param sample: should workspace have sample logs?
     :param xAx: should x axis be DeltaE?
     :param yAxMt: should y axis be MomentumTransfer?
     :param yAxSpec: should y axis be SpectrumAxis?
     :param instrument: should workspace have a instrument?
     """
     # Event Workspace
     if not ws_2D:
         ws = CreateSampleWorkspace("Event", "One Peak", XUnit="DeltaE")
         return ws
     if not xAx:
         ws = CreateWorkspace(DataX=self.data_x,
                              DataY=self.data_y,
                              DataE=np.sqrt(self.data_y),
                              NSpec=1,
                              UnitX="TOF")
         return ws
     if not instrument:
         ws = CreateWorkspace(DataX=self.data_x,
                              DataY=self.data_y,
                              DataE=np.sqrt(self.data_y),
                              NSpec=1,
                              UnitX="DeltaE")
         return ws
     if not yAxMt and not yAxSpec:
         ws = CreateWorkspace(DataX=self.data_x,
                              DataY=self.data_y,
                              DataE=np.sqrt(self.data_y),
                              NSpec=1,
                              UnitX="DeltaE")
         LoadInstrument(ws, True, InstrumentName="TOFTOF")
         ConvertSpectrumAxis(InputWorkspace=ws,
                             OutputWorkspace=ws,
                             Target="theta",
                             EMode="Direct")
         return ws
     if not yAxSpec and yAxMt:
         ws = CreateWorkspace(DataX=self.data_x,
                              DataY=self.data_y,
                              DataE=np.sqrt(self.data_y),
                              NSpec=1,
                              UnitX="DeltaE")
         LoadInstrument(ws, True, InstrumentName="TOFTOF")
         self._add_all_sample_logs(ws)
         ConvertSpectrumAxis(InputWorkspace=ws,
                             OutputWorkspace="ws2",
                             Target="ElasticQ",
                             EMode="Direct")
         ws2 = mtd["ws2"]
         return ws2
     if not sample:
         ws = CreateWorkspace(DataX=self.data_x,
                              DataY=self.data_y,
                              DataE=np.sqrt(self.data_y),
                              NSpec=1,
                              UnitX="DeltaE")
         LoadInstrument(ws, False, InstrumentName="TOFTOF")
         for i in range(ws.getNumberHistograms()):
             ws.getSpectrum(i).setDetectorID(i + 1)
         return ws
     else:
         ws = CreateWorkspace(DataX=self.data_x,
                              DataY=self.data_y,
                              DataE=np.sqrt(self.data_y),
                              NSpec=1,
                              UnitX="DeltaE")
         LoadInstrument(ws, True, InstrumentName="TOFTOF")
         self._add_all_sample_logs(ws)
         return ws