Example #1
0
def do_load(file_specifier, output_ws_name, ipf_filename, load_logs,
            load_opts):
    """
    Loads the files, passing the given file specifier in the load command.

    :param file_specifier:  The file specifier (single file, range or sum)
    :param output_ws_name:  The name of the output workspace to create
    :param ipf_filename:    The instrument parameter file to load with
    :param load_opts:       Additional loading options
    :param load_logs:       If True, load logs
    """
    from mantid.simpleapi import LoadVesuvio, LoadParameterFile

    if 'VESUVIO' in ipf_filename:
        # Load all spectra. They are cropped later
        LoadVesuvio(Filename=str(file_specifier),
                    OutputWorkspace=output_ws_name,
                    SpectrumList='1-198',
                    **load_opts)
    else:
        Load(Filename=file_specifier,
             OutputWorkspace=output_ws_name,
             LoadLogFiles=load_logs,
             **load_opts)

    # Load the instrument parameters
    LoadParameterFile(Workspace=output_ws_name, Filename=ipf_filename)
Example #2
0
    def test_get_set_matrix_workspace(self):
        ws = LoadEmptyInstrument(InstrumentName='ENGIN-X', OutputWorkspace='ws')
        LoadParameterFile(Workspace=ws, Filename='ENGIN-X_Parameters.xml')
        axis = ws.getAxis(0)
        unit = axis.getUnit()
        axis.setUnit("TOF")

        func = FunctionFactory.Instance().createPeakFunction("BackToBackExponential")
        func.setParameter(3, 24000)  # set centre
        func.setMatrixWorkspace(ws, 800, 0.0, 0.0)  # calculate A,B,S
        self.assertTrue(func.isExplicitlySet(1))
Example #3
0
def _load_indirect_instrument(instr, parameters):
    from mantid.simpleapi import LoadEmptyInstrument, \
        LoadParameterFile, AddSampleLog, config
    # Create a workspace from an indirect instrument
    out = LoadEmptyInstrument(InstrumentName=instr)
    if instr in parameters:
        LoadParameterFile(out,
                          Filename=os.path.join(
                              config.getInstrumentDirectory(),
                              parameters[instr]))
    if not out.run().hasProperty('EMode'):
        # EMode would usually get attached via data loading
        # We skip that so have to apply manually
        AddSampleLog(out,
                     LogName='EMode',
                     LogText='Indirect',
                     LogType='String')
    return out
def load_files(data_files, ipf_filename, spec_min, spec_max, sum_files=False, load_logs=True, load_opts=None):
    """
    Loads a set of files and extracts just the spectra we care about (i.e. detector range and monitor).

    @param data_files List of data file names
    @param ipf_filename File path/name for the instrument parameter file to load
    @param spec_min Minimum spectra ID to load
    @param spec_max Maximum spectra ID to load
    @param sum_files Sum loaded files
    @param load_logs Load log files when loading runs
    @param load_opts Additional options to be passed to load algorithm

    @return List of loaded workspace names and flag indicating chopped data
    """
    from mantid.simpleapi import (Load, LoadVesuvio, LoadParameterFile,
                                  ChopData, ExtractSingleSpectrum,
                                  CropWorkspace)

    if load_opts is None:
        load_opts = {}

    workspace_names = []

    for filename in data_files:
        # The filename without path and extension will be the workspace name
        ws_name = os.path.splitext(os.path.basename(str(filename)))[0]
        logger.debug('Loading file %s as workspace %s' % (filename, ws_name))

        if 'VESUVIO' in ipf_filename:
            # Load all spectra. They are cropped later
            LoadVesuvio(Filename=str(filename),
                        OutputWorkspace=ws_name,
                        SpectrumList='1-198',
                        **load_opts)
        else:
            Load(Filename=filename,
                 OutputWorkspace=ws_name,
                 LoadLogFiles=load_logs,
                 **load_opts)

        # Load the instrument parameters
        LoadParameterFile(Workspace=ws_name,
                          Filename=ipf_filename)

        # Add the workspace to the list of workspaces
        workspace_names.append(ws_name)

        # Get the spectrum number for the monitor
        instrument = mtd[ws_name].getInstrument()
        monitor_index = int(instrument.getNumberParameter('Workflow.Monitor1-SpectrumNumber')[0])
        logger.debug('Workspace %s monitor 1 spectrum number :%d' % (ws_name, monitor_index))

        # Chop data if required
        try:
            chop_threshold = mtd[ws_name].getInstrument().getNumberParameter('Workflow.ChopDataIfGreaterThan')[0]
            x_max = mtd[ws_name].readX(0)[-1]
            chopped_data = x_max > chop_threshold
        except IndexError:
            chopped_data = False
        logger.information('Workspace {0} need data chop: {1}'.format(ws_name, str(chopped_data)))

        workspaces = [ws_name]
        if chopped_data:
            ChopData(InputWorkspace=ws_name,
                     OutputWorkspace=ws_name,
                     MonitorWorkspaceIndex=monitor_index,
                     IntegrationRangeLower=5000.0,
                     IntegrationRangeUpper=10000.0,
                     NChops=5)
            workspaces = mtd[ws_name].getNames()

        for chop_ws_name in workspaces:
            # Get the monitor spectrum
            monitor_ws_name = chop_ws_name + '_mon'
            ExtractSingleSpectrum(InputWorkspace=chop_ws_name,
                                  OutputWorkspace=monitor_ws_name,
                                  WorkspaceIndex=monitor_index)

            # Crop to the detectors required
            chop_ws = mtd[chop_ws_name]
            CropWorkspace(InputWorkspace=chop_ws_name,
                          OutputWorkspace=chop_ws_name,
                          StartWorkspaceIndex=chop_ws.getIndexFromSpectrumNumber(int(spec_min)),
                          EndWorkspaceIndex=chop_ws.getIndexFromSpectrumNumber(int(spec_max)))

    logger.information('Loaded workspace names: %s' % (str(workspace_names)))
    logger.information('Chopped data: %s' % (str(chopped_data)))

    # Sum files if needed
    if sum_files and len(data_files) > 1:
        if chopped_data:
            workspace_names = sum_chopped_runs(workspace_names)
        else:
            workspace_names = sum_regular_runs(workspace_names)

    logger.information('Summed workspace names: %s' % (str(workspace_names)))

    return workspace_names, chopped_data