Changeset 630156b in sasmodels


Ignore:
Timestamp:
Apr 20, 2017 1:52:02 PM (7 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
3a45c2c, 8ae8532, ba62072, 93d0ea7
Parents:
f2f5413
Message:

sascomp: improve data file handling; add -help as alias to -html; default to -mono

Location:
sasmodels
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/compare.py

    r650c6d2 r630156b  
    7373    -1d*/-2d computes 1d or 2d data 
    7474    -preset*/-random[=seed] preset or random parameters 
    75     -mono/-poly* force monodisperse/polydisperse 
     75    -mono*/-poly force monodisperse or allow polydisperse demo parameters 
    7676    -magnetic/-nonmagnetic* suppress magnetism 
    7777    -cutoff=1e-5* cutoff value for including a point in polydispersity 
     
    8484    -edit starts the parameter explorer 
    8585    -default/-demo* use demo vs default parameters 
    86     -html shows the model docs instead of running the model 
     86    -help/-html shows the model docs instead of running the model 
    8787    -title="note" adds note to the plot title, after the model name 
    8888    -data="path" uses q, dq from the data file 
     
    753753    comp = opts['engines'][1] if have_comp else None 
    754754    data = opts['data'] 
    755     use_data = have_base ^ have_comp 
     755    use_data = (opts['datafile'] is not None) and (have_base ^ have_comp) 
    756756 
    757757    # Plot if requested 
    758758    view = opts['view'] 
    759759    import matplotlib.pyplot as plt 
    760     if limits is None: 
     760    if limits is None and not use_data: 
    761761        vmin, vmax = np.Inf, -np.Inf 
    762762        if have_base: 
     
    836836    'linear', 'log', 'q4', 
    837837    'hist', 'nohist', 
    838     'edit', 'html', 
     838    'edit', 'html', 'help', 
    839839    'demo', 'default', 
    840840    ]) 
     
    947947        'cutoff'    : 0.0, 
    948948        'seed'      : -1,  # default to preset 
    949         'mono'      : False, 
     949        'mono'      : True, 
    950950        # Default to magnetic a magnetic moment is set on the command line 
    951951        'magnetic'  : False, 
     
    958958        'html'      : False, 
    959959        'title'     : None, 
    960         'data'      : None, 
     960        'datafile'  : None, 
    961961    } 
    962962    engines = [] 
     
    980980        elif arg.startswith('-random='):   opts['seed'] = int(arg[8:]) 
    981981        elif arg.startswith('-title='):    opts['title'] = arg[7:] 
    982         elif arg.startswith('-data='):     opts['data'] = arg[6:] 
     982        elif arg.startswith('-data='):     opts['datafile'] = arg[6:] 
    983983        elif arg == '-random':  opts['seed'] = np.random.randint(1000000) 
    984984        elif arg == '-preset':  opts['seed'] = -1 
     
    10051005        elif arg == '-default':    opts['use_demo'] = False 
    10061006        elif arg == '-html':    opts['html'] = True 
     1007        elif arg == '-help':    opts['html'] = True 
    10071008    # pylint: enable=bad-whitespace 
    10081009 
     
    11211122 
    11221123    # Create the computational engines 
    1123     if opts['data'] is not None: 
    1124         data = load_data(os.path.expanduser(opts['data'])) 
     1124    if opts['datafile'] is not None: 
     1125        data = load_data(os.path.expanduser(opts['datafile'])) 
    11251126    else: 
    11261127        data, _ = make_data(opts) 
  • sasmodels/data.py

    r09e9e13 r630156b  
    5151    from sas.sascalc.dataloader.loader import Loader  # type: ignore 
    5252    loader = Loader() 
    53     data = loader.load(filename) 
    54     if data is None: 
     53    # Allow for one part in multipart file 
     54    if '[' in filename: 
     55        filename, indexstr = filename[:-1].split('[') 
     56        index = int(indexstr) 
     57    else: 
     58        index = None 
     59    datasets = loader.load(filename) 
     60    if datasets is None: 
    5561        raise IOError("Data %r could not be loaded" % filename) 
     62    if not isinstance(datasets, list): 
     63        datasets = [datasets] 
     64    if index is None and len(datasets) > 1: 
     65        raise ValueError("Need to specify filename[index] for multipart data") 
     66    data = datasets[index if index is not None else 0] 
    5667    if hasattr(data, 'x'): 
    5768        data.qmin, data.qmax = data.x.min(), data.x.max() 
    5869        data.mask = (np.isnan(data.y) if data.y is not None 
    5970                     else np.zeros_like(data.x, dtype='bool')) 
     71    elif hasattr(data, 'qx_data'): 
     72        data.mask = ~data.mask 
    6073    return data 
    6174 
Note: See TracChangeset for help on using the changeset viewer.