Changeset d15a908 in sasmodels for sasmodels/compare.py


Ignore:
Timestamp:
Jan 27, 2016 5:35:15 PM (8 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
fdc538a
Parents:
37a7252
Message:

doc and delint

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/compare.py

    r608e31e rd15a908  
    7272# doc string so that we can display it at run time if there is an error. 
    7373# lin 
    74 __doc__ = __doc__ + """ 
     74__doc__ = (__doc__  # pylint: disable=redefined-builtin 
     75           + """ 
    7576Program description 
    7677------------------- 
    7778 
    78 """ + USAGE 
     79""" 
     80           + USAGE) 
    7981 
    8082 
     
    281283            theory = lambda: smearer.get_value() 
    282284        else: 
    283             theory = lambda: model.evalDistribution([data.qx_data[index], data.qy_data[index]]) 
     285            theory = lambda: model.evalDistribution([data.qx_data[index], 
     286                                                     data.qy_data[index]]) 
    284287    elif smearer is not None: 
    285288        theory = lambda: smearer(model.evalDistribution(data.x)) 
     
    416419        try: 
    417420            base_value, base_time = time_calculation(base, pars, Nbase) 
    418             print("%s t=%.1f ms, intensity=%.0f"%(base.engine, base_time, sum(base_value))) 
     421            print("%s t=%.1f ms, intensity=%.0f" 
     422                  % (base.engine, base_time, sum(base_value))) 
    419423        except ImportError: 
    420424            traceback.print_exc() 
     
    426430        try: 
    427431            comp_value, comp_time = time_calculation(comp, pars, Ncomp) 
    428             print("%s t=%.1f ms, intensity=%.0f"%(comp.engine, comp_time, sum(comp_value))) 
     432            print("%s t=%.1f ms, intensity=%.0f" 
     433                  % (comp.engine, comp_time, sum(comp_value))) 
    429434        except ImportError: 
    430435            traceback.print_exc() 
     
    433438    # Compare, but only if computing both forms 
    434439    if Nbase > 0 and Ncomp > 0: 
    435         #print("speedup %.2g"%(comp_time/base_time)) 
    436         #print("max |base/comp|", max(abs(base_value/comp_value)), "%.15g"%max(abs(base_value)), "%.15g"%max(abs(comp_value))) 
    437         #comp *= max(base_value/comp_value) 
    438440        resid = (base_value - comp_value) 
    439441        relerr = resid/comp_value 
    440         _print_stats("|%s-%s|"%(base.engine, comp.engine) + (" "*(3+len(comp.engine))), 
     442        _print_stats("|%s-%s|" 
     443                     % (base.engine, comp.engine) + (" "*(3+len(comp.engine))), 
    441444                     resid) 
    442         _print_stats("|(%s-%s)/%s|"%(base.engine, comp.engine, comp.engine), 
     445        _print_stats("|(%s-%s)/%s|" 
     446                     % (base.engine, comp.engine, comp.engine), 
    443447                     relerr) 
    444448 
     
    591595    invalid = [o[1:] for o in flags 
    592596               if o[1:] not in NAME_OPTIONS 
    593                    and not any(o.startswith('-%s='%t) for t in VALUE_OPTIONS)] 
     597               and not any(o.startswith('-%s='%t) for t in VALUE_OPTIONS)] 
    594598    if invalid: 
    595599        print("Invalid options: %s"%(", ".join(invalid))) 
     
    597601 
    598602 
     603    # pylint: disable=bad-whitespace 
    599604    # Interpret the flags 
    600605    opts = { 
     
    651656        elif arg == '-sasview': engines.append(arg[1:]) 
    652657        elif arg == '-edit':    opts['explore'] = True 
     658    # pylint: enable=bad-whitespace 
    653659 
    654660    if len(engines) == 0: 
     
    675681    presets = {} 
    676682    for arg in values: 
    677         k,v = arg.split('=',1) 
     683        k, v = arg.split('=', 1) 
    678684        if k not in pars: 
    679685            # extract base name without polydispersity info 
    680686            s = set(p.split('_pd')[0] for p in pars) 
    681             print("%r invalid; parameters are: %s"%(k,", ".join(sorted(s)))) 
     687            print("%r invalid; parameters are: %s"%(k, ", ".join(sorted(s)))) 
    682688            sys.exit(1) 
    683689        presets[k] = float(v) if not k.endswith('type') else v 
     
    697703 
    698704    # Create the computational engines 
    699     data, _index = make_data(opts) 
     705    data, _ = make_data(opts) 
    700706    if n1: 
    701707        base = make_engine(model_definition, data, engines[0], opts['cutoff']) 
     
    707713        comp = None 
    708714 
     715    # pylint: disable=bad-whitespace 
    709716    # Remember it all 
    710717    opts.update({ 
     
    718725        'engines'   : [base, comp], 
    719726    }) 
     727    # pylint: enable=bad-whitespace 
    720728 
    721729    return opts 
    722730 
    723 def main(): 
    724     opts = parse_opts() 
    725     if opts['explore']: 
    726         explore(opts) 
    727     else: 
    728         compare(opts) 
    729  
    730731def explore(opts): 
     732    """ 
     733    Explore the model using the Bumps GUI. 
     734    """ 
    731735    import wx 
    732736    from bumps.names import FitProblem 
     
    734738 
    735739    problem = FitProblem(Explore(opts)) 
    736     isMac = "cocoa" in wx.version() 
     740    is_mac = "cocoa" in wx.version() 
    737741    app = wx.App() 
    738742    frame = AppFrame(parent=None, title="explore") 
    739     if not isMac: frame.Show() 
     743    if not is_mac: frame.Show() 
    740744    frame.panel.set_model(model=problem) 
    741745    frame.panel.Layout() 
    742746    frame.panel.aui.Split(0, wx.TOP) 
    743     if isMac: frame.Show() 
     747    if is_mac: frame.Show() 
    744748    app.MainLoop() 
    745749 
    746750class Explore(object): 
    747751    """ 
    748     Return a bumps wrapper for a SAS model comparison. 
     752    Bumps wrapper for a SAS model comparison. 
     753 
     754    The resulting object can be used as a Bumps fit problem so that 
     755    parameters can be adjusted in the GUI, with plots updated on the fly. 
    749756    """ 
    750757    def __init__(self, opts): 
     
    787794        Return cost. 
    788795        """ 
     796        # pylint: disable=no-self-use 
    789797        return 0.  # No nllf 
    790798 
     
    804812 
    805813 
     814def main(): 
     815    """ 
     816    Main program. 
     817    """ 
     818    opts = parse_opts() 
     819    if opts['explore']: 
     820        explore(opts) 
     821    else: 
     822        compare(opts) 
     823 
    806824if __name__ == "__main__": 
    807825    main() 
Note: See TracChangeset for help on using the changeset viewer.