Ejemplo n.º 1
0
    def _determine_single_crystal_diffraction(self):
        """
        All work related to the determination of the diffraction pattern
        """

        a, b, c = self.getProperty('LatticeSizes').value
        alpha, beta, gamma = self.getProperty('LatticeAngles').value

        u = self.getProperty('VectorU').value
        v = self.getProperty('VectorV').value

        uproj = self.getProperty('Uproj').value
        vproj = self.getProperty('Vproj').value
        wproj = self.getProperty('Wproj').value

        n_bins = self.getProperty('NBins').value
        self._n_bins = (n_bins, n_bins, 1)

        axis0 = '{},0,1,0,1'.format(self.getProperty('PsiAngleLog').value)
        axis1 = '{},0,1,0,1'.format(self.getProperty('PsiOffset').value)

        # Options for SetUB independent of run
        ub_args = dict(a=a,
                       b=b,
                       c=c,
                       alpha=alpha,
                       beta=beta,
                       gamma=gamma,
                       u=u,
                       v=v)
        min_values = None
        # Options for algorithm ConvertToMD independent of run
        convert_to_md_kwargs = dict(QDimensions='Q3D',
                                    dEAnalysisMode='Elastic',
                                    Q3DFrames='HKL',
                                    QConversionScales='HKL',
                                    Uproj=uproj,
                                    Vproj=vproj,
                                    Wproj=wproj)
        md_norm_scd_kwargs = None  # Options for algorithm MDNormSCD

        # Find solid angle and flux
        if self._vanadium_files:
            kwargs = dict(Filename='+'.join(self._vanadium_files),
                          MaskFile=self.getProperty("MaskFile").value,
                          MomentumMin=self._momentum_range[0],
                          MomentumMax=self._momentum_range[1])
            _t_solid_angle, _t_int_flux = \
                MDNormSCDPreprocessIncoherent(**kwargs)
        else:
            _t_solid_angle = self.nominal_solid_angle('_t_solid_angle')
            _t_int_flux = self.nominal_integrated_flux('_t_int_flux')

        # Process a sample at a time
        run_numbers = self._getRuns(self.getProperty("RunNumbers").value,
                                    doIndiv=True)
        run_numbers = list(itertools.chain.from_iterable(run_numbers))
        diffraction_reporter = Progress(self,
                                        start=0.0,
                                        end=1.0,
                                        nreports=len(run_numbers))
        for i_run, run in enumerate(run_numbers):
            _t_sample = self._mask_t0_crop(run, '_t_sample')

            # Set Goniometer and UB matrix
            SetGoniometer(_t_sample, Axis0=axis0, Axis1=axis1)
            SetUB(_t_sample, **ub_args)
            if self._bkg:
                self._bkg.run().getGoniometer().\
                    setR(_t_sample.run().getGoniometer().getR())
                SetUB(self._bkg, **ub_args)
            # Determine limits for momentum transfer in HKL space. Needs to be
            # done only once. We use the first run.
            if min_values is None:
                kwargs = dict(QDimensions='Q3D',
                              dEAnalysisMode='Elastic',
                              Q3DFrames='HKL')
                min_values, max_values = ConvertToMDMinMaxGlobal(
                    _t_sample, **kwargs)
                convert_to_md_kwargs.update({
                    'MinValues': min_values,
                    'MaxValues': max_values
                })

            # Convert to MD
            _t_md = ConvertToMD(_t_sample,
                                OutputWorkspace='_t_md',
                                **convert_to_md_kwargs)
            if self._bkg:
                _t_bkg_md = ConvertToMD(self._bkg,
                                        OutputWorkspace='_t_bkg_md',
                                        **convert_to_md_kwargs)

            # Determine aligned dimensions. Need to be done only once
            if md_norm_scd_kwargs is None:
                aligned = list()
                for i_dim in range(3):
                    kwargs = {
                        'name': _t_md.getDimension(i_dim).name,
                        'min': min_values[i_dim],
                        'max': max_values[i_dim],
                        'n_bins': self._n_bins[i_dim]
                    }
                    aligned.append(
                        '{name},{min},{max},{n_bins}'.format(**kwargs))
                md_norm_scd_kwargs = dict(AlignedDim0=aligned[0],
                                          AlignedDim1=aligned[1],
                                          AlignedDim2=aligned[2],
                                          FluxWorkspace=_t_int_flux,
                                          SolidAngleWorkspace=_t_solid_angle,
                                          SkipSafetyCheck=True)

            # Normalize sample by solid angle and integrated flux;
            # Accumulate runs into the temporary workspaces
            MDNormSCD(_t_md,
                      OutputWorkspace='_t_data',
                      OutputNormalizationWorkspace='_t_norm',
                      TemporaryDataWorkspace='_t_data'
                      if mtd.doesExist('_t_data') else None,
                      TemporaryNormalizationWorkspace='_t_norm'
                      if mtd.doesExist('_t_norm') else None,
                      **md_norm_scd_kwargs)
            if self._bkg:
                MDNormSCD(_t_bkg_md,
                          OutputWorkspace='_t_bkg_data',
                          OutputNormalizationWorkspace='_t_bkg_norm',
                          TemporaryDataWorkspace='_t_bkg_data'
                          if mtd.doesExist('_t_bkg_data') else None,
                          TemporaryNormalizationWorkspace='_t_bkg_norm'
                          if mtd.doesExist('_t_bkg_norm') else None,
                          **md_norm_scd_kwargs)
            message = 'Processing sample {} of {}'.\
                format(i_run+1, len(run_numbers))
            diffraction_reporter.report(message)
        self._temps.workspaces.append('PreprocessedDetectorsWS')  # to remove
        # Iteration over the sample runs is done.

        # Division by vanadium, subtract background, and rename workspaces
        name = self.getPropertyValue("OutputWorkspace")
        _t_data = DivideMD(LHSWorkspace='_t_data', RHSWorkspace='_t_norm')
        if self._bkg:
            _t_bkg_data = DivideMD(LHSWorkspace='_t_bkg_data',
                                   RHSWorkspace='_t_bkg_norm')
            _t_scale = CreateSingleValuedWorkspace(DataValue=self._bkg_scale)
            _t_bkg_data = MultiplyMD(_t_bkg_data, _t_scale)
            ws = MinusMD(_t_data, _t_bkg_data)
            RenameWorkspace(_t_data, OutputWorkspace=name + '_dat')
            RenameWorkspace(_t_bkg_data, OutputWorkspace=name + '_bkg')
        else:
            ws = _t_data
        RenameWorkspace(ws, OutputWorkspace=name)
        self.setProperty("OutputWorkspace", ws)
        diffraction_reporter.report(len(run_numbers), 'Done')
Ejemplo n.º 2
0
    def _determine_single_crystal_diffraction(self):
        """
        All work related to the determination of the diffraction pattern
        """

        a, b, c = self.getProperty('LatticeSizes').value
        alpha, beta, gamma = self.getProperty('LatticeAngles').value

        u = self.getProperty('VectorU').value
        v = self.getProperty('VectorV').value

        uproj = self.getProperty('Uproj').value
        vproj = self.getProperty('Vproj').value
        wproj = self.getProperty('Wproj').value

        n_bins = self.getProperty('NBins').value
        self._n_bins = (n_bins, n_bins, 1)

        axis0 = '{},0,1,0,1'.format(self.getProperty('PsiAngleLog').value)
        axis1 = '{},0,1,0,1'.format(self.getProperty('PsiOffset').value)

        # Options for SetUB independent of run
        ub_args = dict(a=a, b=b, c=c,
                       alpha=alpha, beta=beta, gamma=gamma,
                       u=u, v=v)
        min_values = None
        # Options for algorithm ConvertToMD independent of run
        cmd_args = dict(QDimensions='Q3D', dEAnalysisMode='Elastic',
                        Q3DFrames='HKL', QConversionScales='HKL',
                        Uproj=uproj, Vproj=vproj, Wproj=wproj)
        mdn_args = None  # Options for algorithm MDNormSCD

        # Find solid angle and flux
        if self._vanadium_files:
            kwargs = dict(Filename='+'.join(self._vanadium_files),
                          MaskFile=self.getProperty("MaskFile").value,
                          MomentumMin=self._momentum_range[0],
                          MomentumMax=self._momentum_range[1])
            _t_solid_angle, _t_int_flux = \
                MDNormSCDPreprocessIncoherent(**kwargs)
        else:
            _t_solid_angle = self.nominal_solid_angle('_t_solid_angle')
            _t_int_flux = self.nominal_integrated_flux('_t_int_flux')

        # Process a sample at a time
        run_numbers = self._getRuns(self.getProperty("RunNumbers").value,
                                    doIndiv=True)
        run_numbers = list(itertools.chain.from_iterable(run_numbers))
        diffraction_reporter = Progress(self, start=0.0, end=1.0,
                                        nreports=len(run_numbers))
        for i_run, run in enumerate(run_numbers):
            _t_sample = self._mask_t0_crop(run, '_t_sample')

            # Set Goniometer and UB matrix
            SetGoniometer(_t_sample, Axis0=axis0, Axis1=axis1)
            SetUB(_t_sample, **ub_args)
            if self._bkg:
                self._bkg.run().getGoniometer().\
                    setR(_t_sample.run().getGoniometer().getR())
                SetUB(self._bkg, **ub_args)
            # Determine limits for momentum transfer in HKL space. Needs to be
            # done only once. We use the first run.
            if min_values is None:
                kwargs = dict(QDimensions='Q3D',
                              dEAnalysisMode='Elastic',
                              Q3DFrames='HKL')
                min_values, max_values = ConvertToMDMinMaxGlobal(_t_sample, **kwargs)
                cmd_args.update({'MinValues': min_values,
                                 'MaxValues': max_values})

            # Convert to MD
            _t_md = ConvertToMD(_t_sample, OutputWorkspace='_t_md',
                                **cmd_args)
            if self._bkg:
                _t_bkg_md = ConvertToMD(self._bkg, OutputWorkspace='_t_bkg_md',
                                        **cmd_args)

            # Determine aligned dimensions. Need to be done only once
            if mdn_args is None:
                aligned = list()
                for i_dim in range(3):
                    kwargs = {'name': _t_md.getDimension(i_dim).name,
                              'min': min_values[i_dim],
                              'max': max_values[i_dim],
                              'n_bins': self._n_bins[i_dim]}
                    aligned.append(
                        '{name},{min},{max},{n_bins}'.format(**kwargs))
                mdn_args = dict(AlignedDim0=aligned[0],
                                AlignedDim1=aligned[1],
                                AlignedDim2=aligned[2],
                                FluxWorkspace=_t_int_flux,
                                SolidAngleWorkspace=_t_solid_angle,
                                SkipSafetyCheck=True)

            # Normalize sample by solid angle and integrated flux;
            # Accumulate runs into the temporary workspaces
            MDNormSCD(_t_md,
                      OutputWorkspace='_t_data',
                      OutputNormalizationWorkspace='_t_norm',
                      TemporaryDataWorkspace='_t_data' if
                      mtd.doesExist('_t_data') else None,
                      TemporaryNormalizationWorkspace='_t_norm' if
                      mtd.doesExist('_t_norm') else None,
                      **mdn_args)
            if self._bkg:
                MDNormSCD(_t_bkg_md,
                          OutputWorkspace='_t_bkg_data',
                          OutputNormalizationWorkspace='_t_bkg_norm',
                          TemporaryDataWorkspace='_t_bkg_data' if
                          mtd.doesExist('_t_bkg_data') else None,
                          TemporaryNormalizationWorkspace='_t_bkg_norm'
                          if mtd.doesExist('_t_bkg_norm') else None,
                          **mdn_args)
            message = 'Processing sample {} of {}'.\
                format(i_run+1, len(run_numbers))
            diffraction_reporter.report(message)
        self._temps.workspaces.append('PreprocessedDetectorsWS')  # to remove
        # Iteration over the sample runs is done.

        # Division by vanadium, subtract background, and rename workspaces
        name = self.getPropertyValue("OutputWorkspace")
        _t_data = DivideMD(LHSWorkspace='_t_data', RHSWorkspace='_t_norm')
        if self._bkg:
            _t_bkg_data = DivideMD(LHSWorkspace='_t_bkg_data',
                                   RHSWorkspace='_t_bkg_norm')
            _t_scale = CreateSingleValuedWorkspace(DataValue=self._bkg_scale)
            _t_bkg_data = MultiplyMD(_t_bkg_data, _t_scale)
            ws = MinusMD(_t_data, _t_bkg_data)
            RenameWorkspace(_t_data, OutputWorkspace=name + '_dat')
            RenameWorkspace(_t_bkg_data, OutputWorkspace=name + '_bkg')
        else:
            ws = _t_data
        RenameWorkspace(ws, OutputWorkspace=name)
        self.setProperty("OutputWorkspace", ws)
        diffraction_reporter.report(len(run_numbers), 'Done')
Ejemplo n.º 3
0
 if have_van:
     MaskDetectors(event_ws, MaskedWorkspace=sa)
     XMin = sa.getXDimension().getMinimum()
     XMax = sa.getXDimension().getMaximum()
 event_ws = CropWorkspace(InputWorkspace=event_ws, XMin=XMin, XMax=XMax)
 event_ws = Rebin(event_ws,
                  Params="{},{},{}".format(XMin, XMax - XMin, XMax),
                  PreserveEvents=True)
 mde = ConvertToMD(InputWorkspace=event_ws,
                   QDimensions='Q3D',
                   dEAnalysisMode='Elastic',
                   Q3DFrames='HKL',
                   QConversionScales='HKL')
 for plot_param in plot_params:
     AxisNames = {'H': '[H,0,0]', 'K': '[0,K,0]', 'L': '[0,0,L]'}
     xaxis = mde.getDimension(
         mde.getDimensionIndexByName(AxisNames[plot_param['axis1']]))
     try:
         plot_xmin = float(plot_param['xmin'])
     except ValueError:
         plot_xmin = xaxis.getMinimum()
     try:
         plot_xmax = float(plot_param['xmax'])
     except ValueError:
         plot_xmax = xaxis.getMaximum()
     try:
         plot_xbins = int(plot_param['xsteps'])
     except ValueError:
         plot_xbins = 400
     AlignedDim0 = '{},{},{},{}'.format(AxisNames[plot_param['axis1']],
                                        plot_xmin, plot_xmax, plot_xbins)
     yaxis = mde.getDimension(