示例#1
0
    def _generate_tof_fit_workspace(difa, difc, tzero, bank):
        bank_ws = Ads.retrieve(CalibrationModel._generate_table_workspace_name(bank))

        x_val = []
        y_val = []
        y2_val = []

        difa_to_plot = difa
        difc_to_plot = difc
        tzero_to_plot = tzero

        for irow in range(0, bank_ws.rowCount()):
            x_val.append(bank_ws.cell(irow, 0))
            y_val.append(bank_ws.cell(irow, 5))
            y2_val.append(pow(x_val[irow], 2) * difa_to_plot + x_val[irow] * difc_to_plot + tzero_to_plot)

        ws1 = CreateWorkspace(DataX=x_val,
                              DataY=y_val,
                              UnitX="Expected Peaks Centre (dSpacing A)",
                              YUnitLabel="Fitted Peaks Centre(TOF, us)")
        ws2 = CreateWorkspace(DataX=x_val, DataY=y2_val)

        output_ws = "engggui_tof_peaks_bank_" + str(bank)
        if Ads.doesExist(output_ws):
            DeleteWorkspace(output_ws)

        AppendSpectra(ws1, ws2, OutputWorkspace=output_ws)
        DeleteWorkspace(ws1)
        DeleteWorkspace(ws2)
示例#2
0
def conjoin_workspaces(*workspaces):
    from mantid.simpleapi import AppendSpectra

    conjoined = workspaces[0]
    for workspace in workspaces[1:]:
        conjoined = AppendSpectra(conjoined, workspace, StoreInADS=False)
    return conjoined
示例#3
0
def append_spectrum(single, composite):
    """
    Append a single spectrum to a matrix workspace.
    Caveat to solve: single and composite have different number of bins
    :param single: workspace containing the single new spectrum
    :param composite: workspace matrix containing the processed spectra
    """
    # Find binning triad for the single and composite workspaces
    qs = single.dataX(0)
    qsm, dqs, qsM = qs[0], (qs[-1] - qs[0]) / (len(qs) - 1), qs[-1]
    qc = composite.dataX(0)
    qcm, dqc, qcM = qc[0], (qc[-1] - qc[0]) / (len(qc) - 1), qc[-1]
    # Find the biggest range and finer binning
    qmin = qsm if qsm < qcm else qcm
    dq = dqs if dqs < dqc else dqc
    qmax = qsM if qsM < qcM else qcM
    # Rebin when necessary
    delete_single = False
    if [qsm, dqs, qsM] != [qmin, dq, qmax]:
        delete_single = True
        single = Rebin(single, [qmin, dq, qmax])
    if [qcm, dqc, qcM] != [qmin, dq, qmax]:
        composite = Rebin(composite, [qmin, dq, qmax],
                          OutputWorkspace=composite.name())
    composite = AppendSpectra(composite,
                              single,
                              OutputWorkspace=composite.name())
    if delete_single:
        DeleteWorkspace(single)
    return composite
示例#4
0
    def _plot_difc_zero(difc, tzero):
        for i in range(1, 3):
            bank_ws = Ads.retrieve(
                CalibrationModel._generate_table_workspace_name(i - 1))

            x_val = []
            y_val = []
            y2_val = []

            difc_to_plot = difc[0]
            tzero_to_plot = tzero[0]

            for irow in range(0, bank_ws.rowCount()):
                x_val.append(bank_ws.cell(irow, 0))
                y_val.append(bank_ws.cell(irow, 5))
                y2_val.append(x_val[irow] * difc_to_plot + tzero_to_plot)

            ws1 = CreateWorkspace(DataX=x_val,
                                  DataY=y_val,
                                  UnitX="Expected Peaks Centre (dSpacing A)",
                                  YUnitLabel="Fitted Peaks Centre(TOF, us)")
            ws2 = CreateWorkspace(DataX=x_val, DataY=y2_val)

            output_ws = "engggui_difc_zero_peaks_bank_" + str(i)
            if Ads.doesExist(output_ws):
                DeleteWorkspace(output_ws)

            AppendSpectra(ws1, ws2, OutputWorkspace=output_ws)
            DeleteWorkspace(ws1)
            DeleteWorkspace(ws2)

            difc_zero_ws = Ads.retrieve(output_ws)
            # Create plot
            difc_zero_plot = plot([difc_zero_ws], [0, 1],
                                  plot_kwargs={
                                      "linestyle": "--",
                                      "marker": "o",
                                      "markersize": "3"
                                  })
            difc_zero_plot.gca().set_title("Engg Gui Difc Zero Peaks Bank " +
                                           str(i))
            difc_zero_plot.gca().legend(
                ("Peaks Fitted", "DifC/TZero Fitted Straight Line"))
            difc_zero_plot.gca().set_xlabel(
                "Expected Peaks Centre(dSpacing, A)")
示例#5
0
def _append(workspace1, workspace2):
    return AppendSpectra(InputWorkspace1=workspace1,
                         InputWorkspace2=workspace2,
                         OutputWorkspace="__appended",
                         StoreInADS=False,
                         EnableLogging=False)
示例#6
0
def conjoin_workspaces(*workspaces):
    conjoined = workspaces[0]
    for workspace in workspaces[1:]:
        conjoined = AppendSpectra(conjoined, workspace, StoreInADS=False)
    return conjoined
示例#7
0
    def PyExec(self):
        self._setup()

        # Fit line to each of the spectra
        function = 'name=LinearBackground, A0=0, A1=0'
        input_params = [
            self._input_ws + ',i%d' % i
            for i in range(self._spec_range[0], self._spec_range[1] + 1)
        ]
        input_params = ';'.join(input_params)
        PlotPeakByLogValue(Input=input_params,
                           OutputWorkspace=self._output_msd_ws,
                           Function=function,
                           StartX=self._x_range[0],
                           EndX=self._x_range[1],
                           FitType='Sequential',
                           CreateOutput=True)

        delete_alg = self.createChildAlgorithm("DeleteWorkspace",
                                               enableLogging=False)
        delete_alg.setProperty(
            "Workspace", self._output_msd_ws + '_NormalisedCovarianceMatrices')
        delete_alg.execute()
        delete_alg.setProperty("Workspace",
                               self._output_msd_ws + '_Parameters')
        delete_alg.execute()
        rename_alg = self.createChildAlgorithm("RenameWorkspace",
                                               enableLogging=False)
        rename_alg.setProperty("InputWorkspace", self._output_msd_ws)
        rename_alg.setProperty("OutputWorkspace", self._output_param_ws)
        rename_alg.execute()

        params_table = mtd[self._output_param_ws]

        # MSD value should be positive, but the fit output is negative
        msd = params_table.column('A1')
        for i, value in enumerate(msd):
            params_table.setCell('A1', i, value * -1)

        # Create workspaces for each of the parameters
        parameter_ws_group = []

        # A0 workspace
        ws_name = self._output_msd_ws + '_A0'
        parameter_ws_group.append(ws_name)
        ConvertTableToMatrixWorkspace(self._output_param_ws,
                                      OutputWorkspace=ws_name,
                                      ColumnX='axis-1',
                                      ColumnY='A0',
                                      ColumnE='A0_Err',
                                      EnableLogging=False)
        xunit = mtd[ws_name].getAxis(0).setUnit('Label')
        xunit.setLabel('Temperature', 'K')
        SortXAxis(InputWorkspace=ws_name,
                  OutputWorkspace=ws_name,
                  EnableLogging=False)

        # A1 workspace
        ws_name = self._output_msd_ws + '_A1'
        parameter_ws_group.append(ws_name)
        ConvertTableToMatrixWorkspace(self._output_param_ws,
                                      OutputWorkspace=ws_name,
                                      ColumnX='axis-1',
                                      ColumnY='A1',
                                      ColumnE='A1_Err',
                                      EnableLogging=False)
        xunit = mtd[ws_name].getAxis(0).setUnit('Label')
        xunit.setLabel('Temperature', 'K')
        SortXAxis(InputWorkspace=ws_name,
                  OutputWorkspace=ws_name,
                  EnableLogging=False)

        AppendSpectra(InputWorkspace1=self._output_msd_ws + '_A0',
                      InputWorkspace2=self._output_msd_ws + '_A1',
                      ValidateInputs=False,
                      OutputWorkspace=self._output_msd_ws,
                      EnableLogging=False)
        delete_alg.setProperty("Workspace", self._output_msd_ws + '_A0')
        delete_alg.execute()
        delete_alg.setProperty("Workspace", self._output_msd_ws + '_A1')
        delete_alg.execute()
        # Create a new vertical axis for the Q and Q**2 workspaces
        y_axis = NumericAxis.create(2)
        for idx in range(1):
            y_axis.setValue(idx, idx)
        mtd[self._output_msd_ws].replaceAxis(1, y_axis)

        # Rename fit workspace group
        original_fit_ws_name = self._output_msd_ws + '_Workspaces'
        if original_fit_ws_name != self._output_fit_ws:
            rename_alg.setProperty("InputWorkspace",
                                   self._output_msd_ws + '_Workspaces')
            rename_alg.setProperty("OutputWorkspace", self._output_fit_ws)
            rename_alg.execute()

        # Add sample logs to output workspace
        copy_alg = self.createChildAlgorithm("CopyLogs", enableLogging=False)
        copy_alg.setProperty("InputWorkspace", self._input_ws)
        copy_alg.setProperty("OutputWorkspace", self._output_msd_ws)
        copy_alg.execute()
        copy_alg.setProperty("InputWorkspace", self._input_ws)
        copy_alg.setProperty("OutputWorkspace", self._output_fit_ws)
        copy_alg.execute()

        self.setProperty('OutputWorkspace', self._output_msd_ws)
        self.setProperty('ParameterWorkspace', self._output_param_ws)
        self.setProperty('FitWorkspaces', self._output_fit_ws)