Exemple #1
0
    def algorithm_wrapper(*args, **kwargs):
        """
            Note that if the Version parameter is passed, we will create
            the proper version of the algorithm without failing.
        """
        _version = version
        if "Version" in kwargs:
            _version = kwargs["Version"]
            del kwargs["Version"]
        algm = _create_algorithm_object(algorithm, _version)
        _set_logging_option(algm, kwargs)

        # Temporary removal of unneeded parameter from user's python scripts
        if "CoordinatesToUse" in kwargs and algorithm in __MDCOORD_FUNCTIONS__:
            del kwargs["CoordinatesToUse"]
 
        try:
            frame = kwargs["__LHS_FRAME_OBJECT__"]
            del kwargs["__LHS_FRAME_OBJECT__"]
        except KeyError:
            frame = None
            
        lhs = _funcreturns.lhs_info(frame=frame)
        lhs_args = _get_args_from_lhs(lhs, algm)
        final_keywords = _merge_keywords_with_lhs(kwargs, lhs_args)

        _set_properties(algm, *args, **final_keywords)
        algm.execute()
        return _gather_returns(algorithm, lhs, algm)
Exemple #2
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)
    # Remove from keywords so it is not set twice
    if "Function" in kwargs:
        del kwargs['Function']
    if "InputWorkspace" in kwargs:
        del kwargs['InputWorkspace']

    # Check for behaviour consistent with old API
    if type(Function) == str and Function in _ads:
        raise ValueError("Fit API has changed. The function must now come first in the argument list and the workspace second.")
    # Create and execute
    algm = _create_algorithm_object('Fit')
    _set_logging_option(algm, kwargs)
    algm.setProperty('Function', Function) # Must be set first
    algm.setProperty('InputWorkspace', InputWorkspace)

    # Set all workspace properties before others
    for key in kwargs.keys():
        if key.startswith('InputWorkspace_'):
            algm.setProperty(key, kwargs[key])
            del kwargs[key]
    
    lhs = _funcreturns.lhs_info()
    # Check for any properties that aren't known and warn they will not be used
    for key in kwargs.keys():
        if key not in algm:
            logger.warning("You've passed a property (%s) to Fit() that doesn't apply to any of the input workspaces." % key)
            del kwargs[key]
    _set_properties(algm, **kwargs)
    algm.execute()
    
    return _gather_returns('Fit', lhs, algm)
Exemple #3
0
 def algorithm_wrapper(*args, **kwargs):
     """
         Note that if the Version parameter is passed, we will create
         the proper version of the algorithm without failing.
     """
     _version = version
     if "Version" in kwargs:
         _version = kwargs["Version"]
         del kwargs["Version"]
     algm = _framework.createAlgorithm(algorithm, _version)
     _set_logging_option(algm, kwargs)
     lhs = _funcreturns.lhs_info()
     lhs_args = get_args_from_lhs(lhs, algm)
     final_keywords = merge_keywords_with_lhs(kwargs, lhs_args)
     _set_properties(algm, *args, **final_keywords)
     algm.execute()
     return gather_returns(algorithm, lhs, algm)
Exemple #4
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
      run_ws = Load('INSTR00001000.nxs')
      
      # Histogram NeXus with SpectrumMin and SpectrumMax = 1
      run_ws = Load('INSTR00001000.nxs', SpectrumMin=1,SpectrumMax=1)
      
      # Event NeXus with precount on
      event_ws = Load('INSTR_1000_event.nxs', Precount=True)
      
      # The output workspace name is picked up from the LHS unless overridden
      Load('INSTR00001000.nxs',OutputWorkspace='run_ws')
    """
    filename, = _get_mandatory_args('Load', ["Filename"], *args, **kwargs)
    
    # Create and execute
    algm = _create_algorithm_object('Load')
    _set_logging_option(algm, kwargs)
    algm.setProperty('Filename', filename) # Must be set first
    # Remove from keywords so it is not set twice
    try:
        del kwargs['Filename']
    except KeyError:
        pass
    lhs = _funcreturns.lhs_info()
    # If the output has not been assigned to anything, i.e. lhs[0] = 0 and kwargs does not have OutputWorkspace
    # then raise a more helpful error than what we would get from an algorithm
    if lhs[0] == 0 and 'OutputWorkspace' not in kwargs:
        raise RuntimeError("Unable to set output workspace name. Please either assign the output of "
                           "Load to a variable or use the OutputWorkspace keyword.") 
    
    lhs_args = _get_args_from_lhs(lhs, algm)
    final_keywords = _merge_keywords_with_lhs(kwargs, lhs_args)
    # Check for any properties that aren't known and warn they will not be used
    for key in final_keywords.keys():
        if key not in algm:
            logger.warning("You've passed a property (%s) to Load() that doesn't apply to this file type." % key)
            del final_keywords[key]
    _set_properties(algm, **final_keywords)
    algm.execute()
        
    # If a WorkspaceGroup was loaded then there will be a set of properties that have an underscore in the name
    # and users will simply expect the groups to be returned NOT the groups + workspaces.
    return _gather_returns('Load', lhs, algm, ignore_regex=['LoaderName','LoaderVersion','.*_.*'])