Changes in sasmodels/compare.py [af7a97c:5770493] in sasmodels


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/compare.py

    raf7a97c r5770493  
    107107    -title="note" adds note to the plot title, after the model name 
    108108    -weights shows weights plots for the polydisperse parameters 
    109     -profile shows the sld profile if the model has a plottable sld profile 
    110109 
    111110    === output options === 
    112111    -edit starts the parameter explorer 
    113112    -help/-html shows the model docs instead of running the model 
    114  
    115     === environment variables === 
    116     -DSAS_MODELPATH=path sets directory containing custom models 
    117     -DSAS_OPENCL=vendor:device|none sets the target OpenCL device 
    118     -DXDG_CACHE_HOME=~/.cache sets the pyopencl cache root (linux only) 
    119     -DSAS_COMPILER=tinycc|msvc|mingw|unix sets the DLL compiler 
    120     -DSAS_OPENMP=1 turns on OpenMP for the DLLs 
    121     -DSAS_DLL_PATH=path sets the path to the compiled modules 
    122113 
    123114The interpretation of quad precision depends on architecture, and may 
     
    654645 
    655646def make_data(opts): 
    656     # type: (Dict[str, Any], float) -> Tuple[Data, np.ndarray] 
     647    # type: (Dict[str, Any]) -> Tuple[Data, np.ndarray] 
    657648    """ 
    658649    Generate an empty dataset, used with the model to set Q points 
     
    676667        if opts['zero']: 
    677668            q = np.hstack((0, q)) 
    678         # TODO: provide command line control of lambda and Delta lambda/lambda 
    679         #L, dLoL = 5, 0.14/np.sqrt(6)  # wavelength and 14% triangular FWHM 
    680         L, dLoL = 0, 0 
    681         data = empty_data1D(q, resolution=res, L=L, dL=L*dLoL) 
     669        data = empty_data1D(q, resolution=res) 
    682670        index = slice(None, None) 
    683671    return data, index 
     
    784772            dim = base._kernel.dim 
    785773            plot_weights(model_info, get_mesh(model_info, base_pars, dim=dim)) 
    786         if opts['show_profile']: 
    787             import pylab 
    788             base, comp = opts['engines'] 
    789             base_pars, comp_pars = opts['pars'] 
    790             have_base = base._kernel.info.profile is not None 
    791             have_comp = ( 
    792                 comp is not None 
    793                 and comp._kernel.info.profile is not None 
    794                 and base_pars != comp_pars 
    795             ) 
    796             if have_base or have_comp: 
    797                 pylab.figure() 
    798             if have_base: 
    799                 plot_profile(base._kernel.info, **base_pars) 
    800             if have_comp: 
    801                 plot_profile(comp._kernel.info, label='comp', **comp_pars) 
    802                 pylab.legend() 
    803774    if opts['plot']: 
    804775        import matplotlib.pyplot as plt 
     
    806777    return limits 
    807778 
    808 def plot_profile(model_info, label='base', **args): 
    809     # type: (ModelInfo, List[Tuple[float, np.ndarray, np.ndarray]]) -> None 
    810     """ 
    811     Plot the profile returned by the model profile method. 
    812  
    813     *model_info* defines model parameters, etc. 
    814  
    815     *mesh* is a list of tuples containing (*value*, *dispersity*, *weights*) 
    816     for each parameter, where (*dispersity*, *weights*) pairs are the 
    817     distributions to be plotted. 
    818     """ 
    819     import pylab 
    820  
    821     args = dict((k, v) for k, v in args.items() 
    822                 if "_pd" not in k 
    823                    and ":" not in k 
    824                    and k not in ("background", "scale", "theta", "phi", "psi")) 
    825     args = args.copy() 
    826  
    827     args.pop('scale', 1.) 
    828     args.pop('background', 0.) 
    829     z, rho = model_info.profile(**args) 
    830     #pylab.interactive(True) 
    831     pylab.plot(z, rho, '-', label=label) 
    832     pylab.grid(True) 
    833     #pylab.show() 
    834  
    835  
    836  
    837779def run_models(opts, verbose=False): 
    838780    # type: (Dict[str, Any]) -> Dict[str, Any] 
     
    844786    base_n, comp_n = opts['count'] 
    845787    base_pars, comp_pars = opts['pars'] 
    846     base_data, comp_data = opts['data'] 
     788    data = opts['data'] 
    847789 
    848790    comparison = comp is not None 
     
    858800            print("%s t=%.2f ms, intensity=%.0f" 
    859801                  % (base.engine, base_time, base_value.sum())) 
    860         _show_invalid(base_data, base_value) 
     802        _show_invalid(data, base_value) 
    861803    except ImportError: 
    862804        traceback.print_exc() 
     
    870812                print("%s t=%.2f ms, intensity=%.0f" 
    871813                      % (comp.engine, comp_time, comp_value.sum())) 
    872             _show_invalid(base_data, comp_value) 
     814            _show_invalid(data, comp_value) 
    873815        except ImportError: 
    874816            traceback.print_exc() 
     
    924866    have_base, have_comp = (base_value is not None), (comp_value is not None) 
    925867    base, comp = opts['engines'] 
    926     base_data, comp_data = opts['data'] 
     868    data = opts['data'] 
    927869    use_data = (opts['datafile'] is not None) and (have_base ^ have_comp) 
    928870 
    929871    # Plot if requested 
    930872    view = opts['view'] 
    931     #view = 'log' 
    932873    if limits is None: 
    933874        vmin, vmax = np.inf, -np.inf 
     
    943884        if have_comp: 
    944885            plt.subplot(131) 
    945         plot_theory(base_data, base_value, view=view, use_data=use_data, limits=limits) 
     886        plot_theory(data, base_value, view=view, use_data=use_data, limits=limits) 
    946887        plt.title("%s t=%.2f ms"%(base.engine, base_time)) 
    947888        #cbar_title = "log I" 
     
    950891            plt.subplot(132) 
    951892        if not opts['is2d'] and have_base: 
    952             plot_theory(comp_data, base_value, view=view, use_data=use_data, limits=limits) 
    953         plot_theory(comp_data, comp_value, view=view, use_data=use_data, limits=limits) 
     893            plot_theory(data, base_value, view=view, use_data=use_data, limits=limits) 
     894        plot_theory(data, comp_value, view=view, use_data=use_data, limits=limits) 
    954895        plt.title("%s t=%.2f ms"%(comp.engine, comp_time)) 
    955896        #cbar_title = "log I" 
     
    967908            err[err > cutoff] = cutoff 
    968909        #err,errstr = base/comp,"ratio" 
    969         # Note: base_data only since base and comp have same q values (though 
    970         # perhaps different resolution), and we are plotting the difference 
    971         # at each q 
    972         plot_theory(base_data, None, resid=err, view=errview, use_data=use_data) 
     910        plot_theory(data, None, resid=err, view=errview, use_data=use_data) 
    973911        plt.xscale('log' if view == 'log' and not opts['is2d'] else 'linear') 
    974912        plt.legend(['P%d'%(k+1) for k in range(setnum+1)], loc='best') 
     
    1004942OPTIONS = [ 
    1005943    # Plotting 
    1006     'plot', 'noplot', 
    1007     'weights', 'profile', 
     944    'plot', 'noplot', 'weights', 
    1008945    'linear', 'log', 'q4', 
    1009946    'rel', 'abs', 
     
    11211058 
    11221059    invalid = [o[1:] for o in flags 
    1123                if not (o[1:] in NAME_OPTIONS 
    1124                        or any(o.startswith('-%s='%t) for t in VALUE_OPTIONS) 
    1125                        or o.startswith('-D'))] 
     1060               if o[1:] not in NAME_OPTIONS 
     1061               and not any(o.startswith('-%s='%t) for t in VALUE_OPTIONS)] 
    11261062    if invalid: 
    11271063        print("Invalid options: %s"%(", ".join(invalid))) 
     
    11391075        'qmax'      : 0.05, 
    11401076        'nq'        : 128, 
    1141         'res'       : '0.0', 
     1077        'res'       : 0.0, 
    11421078        'noise'     : 0.0, 
    11431079        'accuracy'  : 'Low', 
     
    11601096        'count'     : '1', 
    11611097        'show_weights' : False, 
    1162         'show_profile' : False, 
    11631098        'sphere'    : 0, 
    11641099        'ngauss'    : '0', 
     
    11801115        elif arg.startswith('-q='): 
    11811116            opts['qmin'], opts['qmax'] = [float(v) for v in arg[3:].split(':')] 
    1182         elif arg.startswith('-res='):      opts['res'] = arg[5:] 
     1117        elif arg.startswith('-res='):      opts['res'] = float(arg[5:]) 
    11831118        elif arg.startswith('-noise='):    opts['noise'] = float(arg[7:]) 
    11841119        elif arg.startswith('-sets='):     opts['sets'] = int(arg[6:]) 
     
    12211156        elif arg == '-default': opts['use_demo'] = False 
    12221157        elif arg == '-weights': opts['show_weights'] = True 
    1223         elif arg == '-profile': opts['show_profile'] = True 
    12241158        elif arg == '-html':    opts['html'] = True 
    12251159        elif arg == '-help':    opts['html'] = True 
    1226         elif arg.startswith('-D'): 
    1227             var, val = arg[2:].split('=') 
    1228             os.environ[var] = val 
    12291160    # pylint: enable=bad-whitespace,C0321 
    12301161 
     
    12421173    if opts['qmin'] is None: 
    12431174        opts['qmin'] = 0.001*opts['qmax'] 
     1175    if opts['datafile'] is not None: 
     1176        data = load_data(os.path.expanduser(opts['datafile'])) 
     1177    else: 
     1178        data, _ = make_data(opts) 
    12441179 
    12451180    comparison = any(PAR_SPLIT in v for v in values) 
     
    12811216        opts['cutoff'] = [float(opts['cutoff'])]*2 
    12821217 
    1283     if PAR_SPLIT in opts['res']: 
    1284         opts['res'] = [float(k) for k in opts['res'].split(PAR_SPLIT, 2)] 
    1285         comparison = True 
    1286     else: 
    1287         opts['res'] = [float(opts['res'])]*2 
    1288  
    1289     if opts['datafile'] is not None: 
    1290         data = load_data(os.path.expanduser(opts['datafile'])) 
    1291     else: 
    1292         # Hack around the fact that make_data doesn't take a pair of resolutions 
    1293         res = opts['res'] 
    1294         opts['res'] = res[0] 
    1295         data0, _ = make_data(opts) 
    1296         if res[0] != res[1]: 
    1297             opts['res'] = res[1] 
    1298             data1, _ = make_data(opts) 
    1299         else: 
    1300             data1 = data0 
    1301         opts['res'] = res 
    1302         data = data0, data1 
    1303  
    1304     base = make_engine(model_info[0], data[0], opts['engine'][0], 
     1218    base = make_engine(model_info[0], data, opts['engine'][0], 
    13051219                       opts['cutoff'][0], opts['ngauss'][0]) 
    13061220    if comparison: 
    1307         comp = make_engine(model_info[1], data[1], opts['engine'][1], 
     1221        comp = make_engine(model_info[1], data, opts['engine'][1], 
    13081222                           opts['cutoff'][1], opts['ngauss'][1]) 
    13091223    else: 
     
    14621376    path = os.path.dirname(info.filename) 
    14631377    url = "file://" + path.replace("\\", "/")[2:] + "/" 
    1464     rst2html.view_html_wxapp(html, url) 
     1378    rst2html.view_html_qtapp(html, url) 
    14651379 
    14661380def explore(opts): 
Note: See TracChangeset for help on using the changeset viewer.