Ejemplo n.º 1
0
def Fit(*args, **kwargs):
    """
    Fit defines the interface to the fitting framework within Mantid.
    It can work with arbitrary data sources and therefore some options
    are only available when the function & workspace type are known.
    
    This simple wrapper takes the Function (as a string) & the InputWorkspace
    as the first two arguments. The remaining arguments must be 
    specified by keyword.
    
    Example:
      Fit(Function='name=LinearBackground,A0=0.3', InputWorkspace=dataWS',
          StartX='0.05',EndX='1.0',Output="Z1")
    """
    Function, InputWorkspace = get_mandatory_args('Fit', ["Function", "InputWorkspace"], *args, **kwargs)
    # Check for behaviour consistent with old API
    if type(Function) == str and Function in mtd:
        raise ValueError("Fit API has changed. The function must now come first in the argument list and the workspace second.")
    
    # Create and execute
    algm = mtd.createAlgorithm('Fit')
    algm.setPropertyValue('Function', str(Function)) # Must be set first
    algm.setPropertyValue('InputWorkspace', str(InputWorkspace))
    try:
        del kwargs['Function']
        del kwargs['InputWorkspace']
    except KeyError:
        pass
    for key, value in kwargs.iteritems():
        try:
            algm.setPropertyValue(key, _makeString(value).lstrip('? '))
        except RuntimeError:
            mtd.sendWarningMessage("You've passed a property (%s) to Fit() that doesn't apply to this workspace type." % key)
    algm.execute()
    return algm
Ejemplo n.º 2
0
def Load(*args, **kwargs):
    """
    Load is a more flexible algorithm than other Mantid algorithms.
    It's aim is to discover the correct loading algorithm for a
    given file. This flexibility comes at the expense of knowing the
    properties out right before the file is specified.
    
    The argument list for the Load function has to be more flexible to
    allow this searching to occur. Two arguments must be specified:
    
      - Filename :: The name of the file,
      - OutputWorkspace :: The name of the workspace,
    
    either as the first two arguments in the list or as keywords. Any other
    properties that the Load algorithm has can be specified by keyword only.
    
    Some common keywords are:
     - SpectrumMin,
     - SpectrumMax,
     - SpectrumList,
     - EntryNumber
    
    Example:
      # Simple usage, ISIS NeXus file
      Load('INSTR00001000.nxs', 'run_ws')
      
      # ISIS NeXus with SpectrumMin and SpectrumMax = 1
      Load('INSTR00001000.nxs', 'run_ws', SpectrumMin=1,SpectrumMax=1)
      
      # SNS Event NeXus with precount on
      Load('INSTR_1000_event.nxs', 'event_ws', Precount=True)
      
      # A mix of keyword and non-keyword is also possible
      Load('event_ws', Filename='INSTR_1000_event.nxs',Precount=True)
    """
    filename, wkspace = get_mandatory_args('Load', ['Filename', 'OutputWorkspace'], *args, **kwargs)
    
    # Create and execute
    algm = mtd.createAlgorithm('Load')
    algm.setPropertyValue('Filename', filename) # Must be set first
    algm.setPropertyValue('OutputWorkspace', wkspace)
    # Remove them from the kwargs if they are there so they are not set twice
    try:
        del kwargs['Filename']
        del kwargs['OutputWorkspace']
    except KeyError:
        pass
    for key, value in kwargs.iteritems():
        try:
            algm.setPropertyValue(key, _makeString(value).lstrip('? '))
        except RuntimeError:
            mtd.sendWarningMessage("You've passed a property (%s) to Load() that doesn't apply to this filetype."% key)
    algm.execute()
    return algm
Ejemplo n.º 3
0
def Load(*args, **kwargs):
    """
    Load is a more flexible algorithm than other Mantid algorithms.
    It's aim is to discover the correct loading algorithm for a
    given file. This flexibility comes at the expense of knowing the
    properties out right before the file is specified.
    
    The argument list for the Load function has to be more flexible to
    allow this searching to occur. Two arguments must be specified:
    
      - Filename :: The name of the file,
      - OutputWorkspace :: The name of the workspace,
    
    either as the first two arguments in the list or as keywords. Any other
    properties that the Load algorithm has can be specified by keyword only.
    
    Some common keywords are:
     - SpectrumMin,
     - SpectrumMax,
     - SpectrumList,
     - EntryNumber
    
    Example:
      # Simple usage, ISIS NeXus file
      Load('INSTR00001000.nxs', 'run_ws')
      
      # ISIS NeXus with SpectrumMin and SpectrumMax = 1
      Load('INSTR00001000.nxs', 'run_ws', SpectrumMin=1,SpectrumMax=1)
      
      # SNS Event NeXus with precount on
      Load('INSTR_1000_event.nxs', 'event_ws', Precount=True)
      
      # A mix of keyword and non-keyword is also possible
      Load('event_ws', Filename='INSTR_1000_event.nxs',Precount=True)
    """
    # Small inner function to grab the mandatory arguments and translate possible
    # exceptions
    def get_argument_value(key, kwargs):
        try:
            value = kwargs[key]
            del kwargs[key]
            return value
        except KeyError:
            raise RuntimeError('%s argument not supplied to Load function' % str(key))
    
    if len(args) == 2:
        filename = args[0]
        wkspace = args[1]
    elif len(args) == 1:
        if 'Filename' in kwargs:
            wkspace = args[0]
            filename = get_argument_value('Filename', kwargs)
        elif 'OutputWorkspace' in kwargs:
            filename = args[0]
            wkspace = get_argument_value('OutputWorkspace', kwargs)
        else:
            raise RuntimeError('Cannot find "Filename" or "OutputWorkspace" in key word list. '
                               'Cannot use single positional argument.')
    elif len(args) == 0:
        filename = get_argument_value('Filename', kwargs)
        wkspace = get_argument_value('OutputWorkspace', kwargs)
    else:
        raise RuntimeError('Load() takes at most 2 positional arguments, %d found.' % len(args))
    
    # Create and execute
    algm = mtd.createAlgorithm('Load')
    algm.setPropertyValue('Filename', filename) # Must be set first
    algm.setPropertyValue('OutputWorkspace', wkspace)
    for key, value in kwargs.iteritems():
        algm.setPropertyValue(key, _makeString(value).lstrip('? '))
    algm.execute()
    return algm