Exemplo n.º 1
0
    def _locate_global_xlimit(self):
        """Find the global bin from all spectrum"""
        input_workspaces = self.getProperty("InputWorkspace").value
        mask = self.getProperty("MaskWorkspace").value
        maks_angle = self.getProperty("MaskAngle").value
        target = self.getProperty("Target").value
        e_fixed = self.getProperty("EFixed").value

        # NOTE:
        # Due to range difference among incoming spectra, a common bin para is needed
        # such that all data can be binned exactly the same way.
        _xMin, _xMax = 1e16, -1e16

        # BEGIN_FOR: located_global_xMin&xMax
        for n, _wsn in enumerate(input_workspaces):
            _ws = AnalysisDataService.retrieve(_wsn)
            _mskn = f"__mask_{n}"
            self.temp_workspace_list.append(_mskn)

            ExtractMask(_ws, OutputWorkspace=_mskn, EnableLogging=False)
            if maks_angle != Property.EMPTY_DBL:
                MaskAngle(
                    Workspace=_mskn,
                    MinAngle=maks_angle,
                    Angle="Phi",
                    EnableLogging=False,
                )
            if mask is not None:
                BinaryOperateMasks(
                    InputWorkspace1=_mskn,
                    InputWorkspace2=mask,
                    OperationType="OR",
                    OutputWorkspace=_mskn,
                    EnableLogging=False,
                )

            _ws_tmp = ExtractUnmaskedSpectra(
                InputWorkspace=_ws, MaskWorkspace=_mskn, EnableLogging=False
            )
            if isinstance(mtd["_ws_tmp"], IEventWorkspace):
                _ws_tmp = Integration(InputWorkspace=_ws_tmp, EnableLogging=False)
            _ws_tmp = ConvertSpectrumAxis(
                InputWorkspace=_ws_tmp,
                Target=target,
                EFixed=e_fixed,
                EnableLogging=False,
            )
            _ws_tmp = Transpose(
                InputWorkspace=_ws_tmp, OutputWorkspace=f"__ws_{n}", EnableLogging=False
            )

            _xMin = min(_xMin, _ws_tmp.readX(0).min())
            _xMax = max(_xMax, _ws_tmp.readX(0).max())
        # END_FOR: located_global_xMin&xMax

        return _xMin, _xMax
Exemplo n.º 2
0
    def _convert_data(self, input_workspaces):
        mask = self.getProperty("MaskWorkspace").value
        mask_angle = self.getProperty("MaskAngle").value
        outname = self.getProperty("OutputWorkspace").valueAsStr

        # NOTE:
        # Due to range difference among incoming spectra, a common bin para is needed
        # such that all data can be binned exactly the same way.

        # BEGIN_FOR: located_global_xMin&xMax
        output_workspaces = [
            f"{outname}{n+1}" for n in range(len(input_workspaces))
        ]
        mask_workspaces = []
        for n, (_wksp_in, _wksp_out) in enumerate(
                zip(input_workspaces, output_workspaces)):
            _wksp_in = str(_wksp_in)
            _mask_n = f"__mask_{n}"  # mask for n-th
            self.temp_workspace_list.append(_mask_n)  # cleanup later

            ExtractMask(InputWorkspace=_wksp_in,
                        OutputWorkspace=_mask_n,
                        EnableLogging=False)
            if mask_angle != Property.EMPTY_DBL:
                MaskAngle(
                    Workspace=_mask_n,
                    MinAngle=mask_angle,
                    Angle="Phi",
                    EnableLogging=False,
                )
            if mask is not None:
                # might be a bug if the mask angle isn't set
                BinaryOperateMasks(
                    InputWorkspace1=_mask_n,
                    InputWorkspace2=mask,
                    OperationType="OR",
                    OutputWorkspace=_mask_n,
                    EnableLogging=False,
                )

            self._to_spectrum_axis(_wksp_in, _wksp_out, _mask_n)

            # append to the list of processed workspaces
            mask_workspaces.append(_mask_n)

        return output_workspaces, mask_workspaces
Exemplo n.º 3
0
    def PyExec(self):
        data = self.getProperty("InputWorkspace").value
        cal = self.getProperty("CalibrationWorkspace").value
        bkg = self.getProperty("BackgroundWorkspace").value
        mask = self.getProperty("MaskWorkspace").value
        target = self.getProperty("Target").value
        eFixed = self.getProperty("EFixed").value
        xMin = self.getProperty("XMin").value
        xMax = self.getProperty("XMax").value
        numberBins = self.getProperty("NumberBins").value
        normaliseBy = self.getProperty("NormaliseBy").value
        maskAngle = self.getProperty("MaskAngle").value
        outWS = self.getPropertyValue("OutputWorkspace")

        data_scale = 1
        cal_scale = 1
        bkg_scale = 1

        if normaliseBy == "Monitor":
            data_scale = data.run().getProtonCharge()
        elif normaliseBy == "Time":
            data_scale = data.run().getLogData('duration').value

        ExtractMask(data, OutputWorkspace='__mask_tmp', EnableLogging=False)

        if maskAngle != Property.EMPTY_DBL:
            MaskAngle(Workspace='__mask_tmp',
                      MinAngle=maskAngle,
                      Angle='Phi',
                      EnableLogging=False)

        if mask is not None:
            BinaryOperateMasks(InputWorkspace1='__mask_tmp',
                               InputWorkspace2=mask,
                               OperationType='OR',
                               OutputWorkspace='__mask_tmp',
                               EnableLogging=False)

        ExtractUnmaskedSpectra(InputWorkspace=data,
                               MaskWorkspace='__mask_tmp',
                               OutputWorkspace='__data_tmp',
                               EnableLogging=False)
        if isinstance(mtd['__data_tmp'], IEventWorkspace):
            Integration(InputWorkspace='__data_tmp',
                        OutputWorkspace='__data_tmp',
                        EnableLogging=False)
        ConvertSpectrumAxis(InputWorkspace='__data_tmp',
                            Target=target,
                            EFixed=eFixed,
                            OutputWorkspace=outWS,
                            EnableLogging=False)
        Transpose(InputWorkspace=outWS,
                  OutputWorkspace=outWS,
                  EnableLogging=False)
        ResampleX(InputWorkspace=outWS,
                  OutputWorkspace=outWS,
                  XMin=xMin,
                  XMax=xMax,
                  NumberBins=numberBins,
                  EnableLogging=False)

        if cal is not None:
            ExtractUnmaskedSpectra(InputWorkspace=cal,
                                   MaskWorkspace='__mask_tmp',
                                   OutputWorkspace='__cal_tmp',
                                   EnableLogging=False)
            if isinstance(mtd['__cal_tmp'], IEventWorkspace):
                Integration(InputWorkspace='__cal_tmp',
                            OutputWorkspace='__cal_tmp',
                            EnableLogging=False)
            CopyInstrumentParameters(data, '__cal_tmp', EnableLogging=False)
            ConvertSpectrumAxis(InputWorkspace='__cal_tmp',
                                Target=target,
                                EFixed=eFixed,
                                OutputWorkspace='__cal_tmp',
                                EnableLogging=False)
            Transpose(InputWorkspace='__cal_tmp',
                      OutputWorkspace='__cal_tmp',
                      EnableLogging=False)
            ResampleX(InputWorkspace='__cal_tmp',
                      OutputWorkspace='__cal_tmp',
                      XMin=xMin,
                      XMax=xMax,
                      NumberBins=numberBins,
                      EnableLogging=False)
            Divide(LHSWorkspace=outWS,
                   RHSWorkspace='__cal_tmp',
                   OutputWorkspace=outWS,
                   EnableLogging=False)
            if normaliseBy == "Monitor":
                cal_scale = cal.run().getProtonCharge()
            elif normaliseBy == "Time":
                cal_scale = cal.run().getLogData('duration').value

        Scale(InputWorkspace=outWS,
              OutputWorkspace=outWS,
              Factor=cal_scale / data_scale,
              EnableLogging=False)

        if bkg is not None:
            ExtractUnmaskedSpectra(InputWorkspace=bkg,
                                   MaskWorkspace='__mask_tmp',
                                   OutputWorkspace='__bkg_tmp',
                                   EnableLogging=False)
            if isinstance(mtd['__bkg_tmp'], IEventWorkspace):
                Integration(InputWorkspace='__bkg_tmp',
                            OutputWorkspace='__bkg_tmp',
                            EnableLogging=False)
            CopyInstrumentParameters(data, '__bkg_tmp', EnableLogging=False)
            ConvertSpectrumAxis(InputWorkspace='__bkg_tmp',
                                Target=target,
                                EFixed=eFixed,
                                OutputWorkspace='__bkg_tmp',
                                EnableLogging=False)
            Transpose(InputWorkspace='__bkg_tmp',
                      OutputWorkspace='__bkg_tmp',
                      EnableLogging=False)
            ResampleX(InputWorkspace='__bkg_tmp',
                      OutputWorkspace='__bkg_tmp',
                      XMin=xMin,
                      XMax=xMax,
                      NumberBins=numberBins,
                      EnableLogging=False)
            if cal is not None:
                Divide(LHSWorkspace='__bkg_tmp',
                       RHSWorkspace='__cal_tmp',
                       OutputWorkspace='__bkg_tmp',
                       EnableLogging=False)
            if normaliseBy == "Monitor":
                bkg_scale = bkg.run().getProtonCharge()
            elif normaliseBy == "Time":
                bkg_scale = bkg.run().getLogData('duration').value
            Scale(InputWorkspace='__bkg_tmp',
                  OutputWorkspace='__bkg_tmp',
                  Factor=cal_scale / bkg_scale,
                  EnableLogging=False)
            Scale(InputWorkspace='__bkg_tmp',
                  OutputWorkspace='__bkg_tmp',
                  Factor=self.getProperty('BackgroundScale').value,
                  EnableLogging=False)
            Minus(LHSWorkspace=outWS,
                  RHSWorkspace='__bkg_tmp',
                  OutputWorkspace=outWS,
                  EnableLogging=False)

        self.setProperty("OutputWorkspace", outWS)

        # remove temp workspaces
        [
            DeleteWorkspace(ws, EnableLogging=False)
            for ws in self.temp_workspace_list if mtd.doesExist(ws)
        ]
Exemplo n.º 4
0
pcm = ax.pcolormesh(iq_output.qx,
                    iq_output.qy,
                    iq_output.intensity.T,
                    cmap='jet')
ax.set_title("Wing")
ax.set_xlabel("$Q_x (\AA^{-1})$")
ax.set_ylabel("$Q_y (\AA^{-1})$")
fig.colorbar(pcm, ax=ax)

filename = os.path.join(output_dir, '2D', f'{outputFilename}_2D_wing.png')
fig.savefig(filename)

# 1D|Q|
from mantid.simpleapi import MaskAngle

MaskAngle(processed_data_wing, MinAngle=57)
MaskAngle(processed_data_main, MaxAngle=0.165)

q_data_main = sans.convert_to_q(processed_data_main, mode='scalar')
q_min_main = q_data_main.mod_q.min()
q_max_main = q_data_main.mod_q.max()
q_min_main = 0.003
q_max_main = 0.045
print('Qmin1d', q_min_main)
q_data_wing = sans.convert_to_q(processed_data_wing, mode='scalar')
q_min_wing = q_data_wing.mod_q.min()
q_max_wing = q_data_wing.mod_q.max()
q_min_wing = 0.035
q_max_wing = 0.850

if bin1d_type == 'scalar':