示例#1
0
 def createSampleWorkspace(self):
     """ Create a dummy workspace that looks like a sample run"""
     #create a dummy workspace
     function = "name=Lorentzian,Amplitude=1,PeakCentre=5,FWHM=1"
     ws = CreateSampleWorkspace("Histogram", Function="User Defined", UserDefinedFunction=function, XMin=0, XMax=10, BinWidth=0.01, XUnit="DeltaE")
     ws = ScaleX(ws, -5, "Add") #shift to center on 0
     ws = ScaleX(ws, 0.1) #scale to size
     LoadInstrument(ws, InstrumentName='IRIS', RewriteSpectraMap=True)
     return ws
示例#2
0
    def createSampleWorkspace(self):
        function = "name=Lorentzian,Amplitude=1,PeakCentre=5,FWHM=1"

        workspace = CreateSampleWorkspace(WorkspaceType="Histogram",
                                          Function="User Defined",
                                          UserDefinedFunction=function,
                                          XMin=0,
                                          XMax=10,
                                          BinWidth=0.01,
                                          XUnit="DeltaE")

        # Shift to center on 0 and then scale to size
        workspace = ScaleX(workspace, -5, "Add")
        workspace = ScaleX(workspace, 0.1)
        LoadInstrument(Workspace=workspace, InstrumentName='IRIS', RewriteSpectraMap=True)
        return workspace
示例#3
0
def _generate_big_sample_ws(ws_name, n_spec):
    sample_data_x = np.arange(0, 10, 0.01)
    sample_data_y = _rayleigh(sample_data_x, 1)

    data_x = np.empty(0)
    data_y = np.empty(0)
    v_axis = list()
    for idx in range(0, n_spec):
        data_x = np.append(data_x, sample_data_x)
        data_y = np.append(data_y, sample_data_y)
        v_axis.append(str(0.1 * idx))

    # Create the workspace and give it some units
    CreateWorkspace(OutputWorkspace=ws_name,
                    DataX=data_x,
                    DataY=data_y,
                    NSpec=n_spec,
                    UnitX='MomentumTransfer',
                    VerticalAxisUnit='QSquared',
                    VerticalAxisValues=','.join(v_axis))
    # Centre the peak over 0
    ScaleX(InputWorkspace=ws_name,
           Factor=-1,
           Operation="Add",
           OutputWorkspace=ws_name)

    return mtd[ws_name]
示例#4
0
def create_test_ws_and_group():
    myFunc = "name=Gaussian, PeakCentre=2, Height=100, Sigma=0.01;" + \
        "name=Gaussian, PeakCentre=1, Height=100, Sigma=0.01;" + \
        "name=Gaussian, PeakCentre=4, Height=100, Sigma=0.01"
    ws = CreateSampleWorkspace("Event",
                               "User Defined",
                               myFunc,
                               BankPixelWidth=1,
                               XUnit='dSpacing',
                               XMax=5,
                               BinWidth=0.001,
                               NumEvents=100000,
                               NumBanks=8)
    for n in range(1, 5):
        MoveInstrumentComponent(ws,
                                ComponentName=f'bank{n}',
                                X=1 + n / 10,
                                Y=0,
                                Z=1 + n / 10,
                                RelativePosition=False)
        MoveInstrumentComponent(ws,
                                ComponentName=f'bank{n+4}',
                                X=2 + n / 10,
                                Y=0,
                                Z=2 + n / 10,
                                RelativePosition=False)

    MaskDetectors(ws, WorkspaceIndexList=[3, 7])

    ws = ScaleX(ws, Factor=1.05, IndexMin=1, IndexMax=1)
    ws = ScaleX(ws, Factor=0.95, IndexMin=2, IndexMax=2)
    ws = ScaleX(ws, Factor=1.05, IndexMin=4, IndexMax=6)
    ws = ScaleX(ws, Factor=1.02, IndexMin=5, IndexMax=5)
    ws = ScaleX(ws, Factor=0.98, IndexMin=6, IndexMax=6)
    ws = Rebin(ws, '0,0.001,5')
    ws = ConvertUnits(ws, Target='TOF')

    groups, _, _ = CreateGroupingWorkspace(InputWorkspace=ws,
                                           ComponentName='basic_rect',
                                           CustomGroupingString='1-4,5-8')

    return ws, groups
示例#5
0
def _generate_sample_ws(ws_name):
    data_x = np.arange(0, 10, 0.01)
    data_y = _rayleigh(data_x, 1)

    # Create the workspace and give it some units
    CreateWorkspace(OutputWorkspace=ws_name, DataX=data_x, DataY=data_y, \
                    UnitX='MomentumTransfer', VerticalAxisUnit='QSquared', VerticalAxisValues='0.2')
    # Centre the peak over 0
    ScaleX(InputWorkspace=ws_name, Factor=-1, Operation="Add", OutputWorkspace=ws_name)

    return mtd[ws_name]
 def convertToWavenumber(self, ws):
     mev2cm = (constants.elementary_charge / 1000) / (constants.h * constants.c * 100)
     u0 = ws.getAxis(0).getUnit().unitID()
     u1 = ws.getAxis(1).getUnit().unitID()
     if u0 == 'DeltaE' or u1 == 'DeltaE':
         if u0 == 'MomentumTransfer':
             ws = Transpose(ws)
         ws.getAxis(0).setUnit('DeltaE_inWavenumber')
         ws = ScaleX(ws, mev2cm)
         ws = Scale(ws, 1/mev2cm)
         if u0 == 'MomentumTransfer':
             ws = Transpose(ws)
     return ws
示例#7
0
    def add_previous_pulse(w):
        """
        Duplicate the events but shift them by one pulse, then add to
        input workspace

        Parameters
        ----------
        w: Mantid.EventsWorkspace

        Returns
        -------
        Mantid.EventsWorkspace
        """
        pulse_width = 1.e6 / 60  # in micro-seconds
        _t_w = ScaleX(w, Factor=-pulse_width, Operation='Add')
        _t_w = Plus(w, _t_w, OutputWorkspace=w.name())
        return _t_w
示例#8
0
 def _shift_workspace(self, workspace, shift_factor):
     return ScaleX(InputWorkspace=workspace,
                   Factor=shift_factor,
                   OutputWorkspace="__shifted",
                   Operation="Add",
                   StoreInADS=False)