コード例 #1
0
ファイル: __init__.py プロジェクト: luzpaz/mantid
def dynamicsusceptibility(workspace, temperature, outputName=None, zeroEnergyEpsilon=1e-6):
    """Convert :math:`S(Q,E)` to susceptibility :math:`\chi''(Q,E)`.

    #. If the X units are not in DeltaE, the workspace is transposed
    #. The Y data in *workspace* is multiplied by :math:`1 - e^{\Delta E / (kT)}`
    #. Y data in the bin closest to 0 meV and within -*zeroEnergyEpsilon* < :math:`\Delta E` < *zeroEnergyEpsilon* is set to 0
    #. If the input was transposed, transpose the output as well

    :param workspace: a :math:`S(Q,E)` workspace to convert
    :type workspace: :class:`mantid.api.MatrixWorkspace`
    :param temperature: temperature in Kelvin
    :type temperature: float
    :param outputName: name of the output workspace. If :class:`None`, the output will be given some generated name.
    :type outputName: str or None
    :param zeroEnergyEpsilon: if a bin center is within this value from 0, the bin's value is set to zero.
    :type zeroEnergyEpsilon: float
    :returns: a :class:`mantid.api.MatrixWorkspace` containing :math:`\chi''(Q,E)`
    """
    workspace = _normws(workspace)
    horAxis = workspace.getAxis(0)
    horUnit = horAxis.getUnit().unitID()
    doTranspose = horUnit != 'DeltaE'
    if outputName is None:
        outputName = 'CHIofQW_{}'.format(str(workspace))
    if doTranspose:
        workspace = Transpose(workspace, OutputWorkspace='__transposed_SofQW_', EnableLogging=False)
    c = 1e-3 * constants.e / constants.k / temperature
    outWS = OneMinusExponentialCor(workspace, OutputWorkspace=outputName, C=c, Operation='Multiply', EnableLogging=False)
    _removesingularity(outWS, zeroEnergyEpsilon)
    if doTranspose:
        outWS = Transpose(outWS, OutputWorkspace=outputName, EnableLogging=False)
        DeleteWorkspace('__transposed_SofQW_', EnableLogging=False)
    outWS.setYUnit("Dynamic susceptibility")
    return outWS
コード例 #2
0
ファイル: __init__.py プロジェクト: samueljackson92/mantid
def dynamicsusceptibility(workspace, temperature, outputName=None, zeroEnergyEpsilon=1e-6):
    """Convert :math:`S(Q,E)` to susceptibility :math:`\chi''(Q,E)`.

    #. If the X units are not in DeltaE, the workspace is transposed
    #. The Y data in *workspace* is multiplied by :math:`1 - e^{\Delta E / (kT)}`
    #. Y data in the bin closest to 0 meV and within -*zeroEnergyEpsilon* < :math:`\Delta E` < *zeroEnergyEpsilon* is set to 0
    #. If the input was transposed, transpose the output as well

    :param workspace: a :math:`S(Q,E)` workspace to convert
    :type workspace: :class:`mantid.api.MatrixWorkspace`
    :param temperature: temperature in Kelvin
    :type temperature: float
    :param outputName: name of the output workspace. If :class:`None`, the output will be given some generated name.
    :type outputName: str or None
    :param zeroEnergyEpsilon: if a bin center is within this value from 0, the bin's value is set to zero.
    :type zeroEnergyEpsilon: float
    :returns: a :class:`mantid.api.MatrixWorkspace` containing :math:`\chi''(Q,E)`
    """
    workspace = _normws(workspace)
    horAxis = workspace.getAxis(0)
    horUnit = horAxis.getUnit().unitID()
    doTranspose = horUnit != 'DeltaE'
    if outputName is None:
        outputName = 'CHIofQW_{}'.format(str(workspace))
    if doTranspose:
        workspace = Transpose(workspace, OutputWorkspace='__transposed_SofQW_', EnableLogging=False)
    c = 1e-3 * constants.e / constants.k / temperature
    outWS = OneMinusExponentialCor(workspace, OutputWorkspace=outputName, C=c, Operation='Multiply', EnableLogging=False)
    _removesingularity(outWS, zeroEnergyEpsilon)
    if doTranspose:
        outWS = Transpose(outWS, OutputWorkspace=outputName, EnableLogging=False)
        DeleteWorkspace('__transposed_SofQW_', EnableLogging=False)
    outWS.setYUnit('Dynamic susceptibility')
    return outWS
コード例 #3
0
def process_monitor_efficiency(workspace_name):
    """
    Process monitor efficiency for a given workspace.

    @param workspace_name Name of workspace to process monitor for
    """
    from mantid.simpleapi import OneMinusExponentialCor

    monitor_workspace_name = workspace_name + '_mon'
    instrument = mtd[workspace_name].getInstrument()

    try:
        area = instrument.getNumberParameter('Workflow.Monitor1-Area')[0]
        thickness = instrument.getNumberParameter(
            'Workflow.Monitor1-Thickness')[0]
        attenuation = instrument.getNumberParameter(
            'Workflow.Monitor1-Attenuation')[0]
    except IndexError:
        raise ValueError('Cannot get monitor details form parameter file')

    if area == -1 or thickness == -1 or attenuation == -1:
        logger.information('For workspace %s, skipping monitor efficiency' %
                           workspace_name)
        return

    OneMinusExponentialCor(InputWorkspace=monitor_workspace_name,
                           OutputWorkspace=monitor_workspace_name,
                           C=attenuation * thickness,
                           C1=area)
コード例 #4
0
    def _monitor_normalization(self, w, target):
        """
        Divide data by integrated monitor intensity

        Parameters
        ----------
        w: Mantid.EventsWorkspace
            Input workspace
        target: str
            Specify the entity the workspace refers to. Valid options are
            'sample', 'background', and 'vanadium'

        Returns
        -------
        Mantid.EventWorkspace
        """
        _t_mon = self._load_monitors(target)
        _t_mon = ConvertUnits(_t_mon, Target='Wavelength', Emode='Elastic')
        _t_mon = CropWorkspace(_t_mon,
                               XMin=self._wavelength_band[0],
                               XMax=self._wavelength_band[1])
        _t_mon = OneMinusExponentialCor(_t_mon,
                                        C='0.20749999999999999',
                                        C1='0.001276')
        _t_mon = Scale(_t_mon, Factor='1e-06', Operation='Multiply')
        _t_mon = Integration(_t_mon)  # total monitor count
        _t_w = Divide(w, _t_mon, OutputWorkspace=w.name())
        return _t_w
コード例 #5
0
    def _calculate_wavelength_band(self):
        """
        Calculate the wavelength band using the monitors from the sample runs

        Consider wavelenghts with an associated intensity above a certain
        fraction of the maximum observed intensity.
        """
        _t_w = self._load_monitors('sample')
        _t_w = ConvertUnits(_t_w, Target='Wavelength', Emode='Elastic')
        l_min, l_max = 0.0, 20.0
        _t_w = CropWorkspace(_t_w, XMin=l_min, XMax=l_max)
        _t_w = OneMinusExponentialCor(_t_w,
                                      C='0.20749999999999999',
                                      C1='0.001276')
        _t_w = Scale(_t_w, Factor='1e-06', Operation='Multiply')
        _t_w = Rebin(_t_w,
                     Params=[l_min, self._wavelength_dl, l_max],
                     PreserveEvents=False)
        y = _t_w.readY(0)
        k = np.argmax(y)  # y[k] is the maximum observed intensity
        factor = 0.8  # 80% of the maximum intensity
        i_s = k - 1
        while y[i_s] > factor * y[k]:
            i_s -= 1
        i_e = k + 1
        while y[i_e] > factor * y[k]:
            i_e += 1
        x = _t_w.readX(0)
        self._wavelength_band = [x[i_s], x[i_e]]
コード例 #6
0
    def _flux_normalization(self, w, target):
        """
        Divide data by integrated flux intensity

        Parameters
        ----------
        w: Mantid.EventsWorkspace
            Input workspace
        target: str
            Specify the entity the workspace refers to. Valid options are
            'sample', 'background', and 'vanadium'

        Returns
        -------
        Mantid.EventWorkspace
        """
        valid_targets = ('sample', 'background', 'vanadium')
        if target not in valid_targets:
            raise KeyError('Target must be one of ' + ', '.join(valid_targets))
        w_nor = None
        if self._flux_normalization_type == 'Monitor':
            _t_flux = None
            _t_flux_name = tws('monitor_aggregate')
            target_to_runs = dict(sample='RunNumbers',
                                  background='BackgroundRuns',
                                  vanadium='VanadiumRuns')
            rl = self._run_list(self.getProperty(target_to_runs[target]).value)

            _t_w_name = tws('monitor')
            for run in rl:
                run_name = '{0}_{1}'.format(self._short_inst, str(run))
                _t_w = LoadNexusMonitors(run_name, OutputWorkspace=_t_w_name)
                if _t_flux is None:
                    _t_flux = CloneWorkspace(_t_w,
                                             OutputWorkspace=_t_flux_name)
                else:
                    _t_flux = Plus(_t_flux, _t_w, OutputWorkspace=_t_flux_name)

            _t_flux = ConvertUnits(_t_flux,
                                   Target='Wavelength',
                                   Emode='Elastic',
                                   OutputWorkspace=_t_flux_name)
            _t_flux = CropWorkspace(_t_flux,
                                    XMin=self._wavelength_band[0],
                                    XMax=self._wavelength_band[1],
                                    OutputWorkspace=_t_flux_name)
            _t_flux = OneMinusExponentialCor(_t_flux,
                                             C='0.20749999999999999',
                                             C1='0.001276',
                                             OutputWorkspace=_t_flux_name)
            _t_flux = Scale(_t_flux,
                            Factor='1e-06',
                            Operation='Multiply',
                            OutputWorkspace=_t_flux_name)
            _t_flux = Integration(_t_flux,
                                  RangeLower=self._wavelength_band[0],
                                  RangeUpper=self._wavelength_band[1],
                                  OutputWorkspace=_t_flux_name)
            w_nor = Divide(w, _t_flux, OutputWorkspace=w.name())
        else:
            aggregate_flux = None
            if self._flux_normalization_type == 'Proton Charge':
                aggregate_flux = w.getRun().getProtonCharge()
            elif self._flux_normalization_type == 'Duration':
                aggregate_flux = w.getRun().getProperty('duration').value
            w_nor = Scale(w,
                          Operation='Multiply',
                          Factor=1.0 / aggregate_flux,
                          OutputWorkspace=w.name())
        return w_nor