예제 #1
0
def FitDialog(*args, **kwargs):
    """Popup a dialog for the Load algorithm. More help on the Load function
    is available via help(Load).

    Additional arguments available here (as keyword only) are:
      - Enable :: A CSV list of properties to keep enabled in the dialog
      - Disable :: A CSV list of properties to keep enabled in the dialog
      - Message :: An optional message string
    """
    arguments = {}
    try:
        function, inputworkspace = get_mandatory_args('FitDialog', ['Function', 'InputWorkspace'], *args, **kwargs)
        arguments['Function'] = function
        arguments['InputWorkspace'] = inputworkspace
    except RuntimeError:
        pass
    arguments.update(kwargs)
    if 'Enable' not in arguments: arguments['Enable']=''
    if 'Disable' not in arguments: arguments['Disable']=''
    if 'Message' not in arguments: arguments['Message']=''
    
    algm = _framework.createAlgorithm('Fit')
    _set_properties_dialog(algm,**arguments)
    algm.execute()
    return algm
예제 #2
0
def LoadDialog(*args, **kwargs):
    """Popup a dialog for the Load algorithm. More help on the Load function
    is available via help(Load).

    Additional arguments available here (as keyword only) are:
      - Enable :: A CSV list of properties to keep enabled in the dialog
      - Disable :: A CSV list of properties to keep enabled in the dialog
      - Message :: An optional message string
    """
    arguments = {}
    filename = None
    wkspace = None
    if len(args) == 2:
        filename = args[0]
        wkspace = args[1]
    elif len(args) == 1:
        if 'Filename' in kwargs:
            filename = kwargs['Filename']
            wkspace = args[0]
        elif 'OutputWorkspace' in kwargs:
            wkspace = kwargs['OutputWorkspace']
            filename = args[0]
    arguments['Filename'] = filename
    arguments['OutputWorkspace'] = wkspace
    arguments.update(kwargs)
    if 'Enable' not in arguments: arguments['Enable']=''
    if 'Disable' not in arguments: arguments['Disable']=''
    if 'Message' not in arguments: arguments['Message']=''
    
    algm = _framework.createAlgorithm('Load')
    _set_properties_dialog(algm,**arguments)
    algm.execute()
    return algm
예제 #3
0
 def algorithm_wrapper(*args, **kwargs):
     _version = version
     if "Version" in kwargs:
         _version = kwargs["Version"]
         del kwargs["Version"]
     for item in ["Message", "Enable", "Disable"]:
         if item not in kwargs:
             kwargs[item] = ""
         
     algm = _framework.createAlgorithm(algorithm, _version)
     _set_properties_dialog(algm, *args, **kwargs)
     algm.execute()
     return algm
예제 #4
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)
예제 #5
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 _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 = _framework.createAlgorithm('Fit')
    _set_logging_option(algm, kwargs)
    algm.setProperty('Function', Function) # Must be set first
    algm.setProperty('InputWorkspace', InputWorkspace)
    # Remove from keywords so it is not set twice
    try:
        del kwargs['Function']
        del kwargs['InputWorkspace']
    except KeyError:
        pass
    
    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 this file type." % key)
            del kwargs[key]
    _set_properties(algm, **kwargs)
    algm.execute()
    
    return gather_returns('Fit', lhs, algm)
예제 #6
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')
      
      # Historgram 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 = _framework.createAlgorithm('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','.*_.*'])