Changes in sasmodels/compare.py [1fbadb2:65fbf7c] in sasmodels


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/compare.py

    r1fbadb2 r65fbf7c  
    645645 
    646646def make_data(opts): 
    647     # type: (Dict[str, Any]) -> Tuple[Data, np.ndarray] 
     647    # type: (Dict[str, Any], float) -> Tuple[Data, np.ndarray] 
    648648    """ 
    649649    Generate an empty dataset, used with the model to set Q points 
     
    667667        if opts['zero']: 
    668668            q = np.hstack((0, q)) 
    669         data = empty_data1D(q, resolution=res) 
     669        # TODO: provide command line control of lambda and Delta lambda/lambda 
     670        #L, dLoL = 5, 0.14/np.sqrt(6)  # wavelength and 14% triangular FWHM 
     671        L, dLoL = 0, 0 
     672        data = empty_data1D(q, resolution=res, L=L, dL=L*dLoL) 
    670673        index = slice(None, None) 
    671674    return data, index 
     
    786789    base_n, comp_n = opts['count'] 
    787790    base_pars, comp_pars = opts['pars'] 
    788     data = opts['data'] 
     791    base_data, comp_data = opts['data'] 
    789792 
    790793    comparison = comp is not None 
     
    800803            print("%s t=%.2f ms, intensity=%.0f" 
    801804                  % (base.engine, base_time, base_value.sum())) 
    802         _show_invalid(data, base_value) 
     805        _show_invalid(base_data, base_value) 
    803806    except ImportError: 
    804807        traceback.print_exc() 
     
    812815                print("%s t=%.2f ms, intensity=%.0f" 
    813816                      % (comp.engine, comp_time, comp_value.sum())) 
    814             _show_invalid(data, comp_value) 
     817            _show_invalid(base_data, comp_value) 
    815818        except ImportError: 
    816819            traceback.print_exc() 
     
    866869    have_base, have_comp = (base_value is not None), (comp_value is not None) 
    867870    base, comp = opts['engines'] 
    868     data = opts['data'] 
     871    base_data, comp_data = opts['data'] 
    869872    use_data = (opts['datafile'] is not None) and (have_base ^ have_comp) 
    870873 
    871874    # Plot if requested 
    872875    view = opts['view'] 
     876    #view = 'log' 
    873877    if limits is None: 
    874878        vmin, vmax = np.inf, -np.inf 
     
    884888        if have_comp: 
    885889            plt.subplot(131) 
    886         plot_theory(data, base_value, view=view, use_data=use_data, limits=limits) 
     890        plot_theory(base_data, base_value, view=view, use_data=use_data, limits=limits) 
    887891        plt.title("%s t=%.2f ms"%(base.engine, base_time)) 
    888892        #cbar_title = "log I" 
     
    891895            plt.subplot(132) 
    892896        if not opts['is2d'] and have_base: 
    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) 
     897            plot_theory(comp_data, base_value, view=view, use_data=use_data, limits=limits) 
     898        plot_theory(comp_data, comp_value, view=view, use_data=use_data, limits=limits) 
    895899        plt.title("%s t=%.2f ms"%(comp.engine, comp_time)) 
    896900        #cbar_title = "log I" 
     
    908912            err[err > cutoff] = cutoff 
    909913        #err,errstr = base/comp,"ratio" 
    910         plot_theory(data, None, resid=err, view=errview, use_data=use_data) 
     914        # Note: base_data only since base and comp have same q values (though 
     915        # perhaps different resolution), and we are plotting the difference 
     916        # at each q 
     917        plot_theory(base_data, None, resid=err, view=errview, use_data=use_data) 
    911918        plt.xscale('log' if view == 'log' and not opts['is2d'] else 'linear') 
    912919        plt.legend(['P%d'%(k+1) for k in range(setnum+1)], loc='best') 
     
    10751082        'qmax'      : 0.05, 
    10761083        'nq'        : 128, 
    1077         'res'       : 0.0, 
     1084        'res'       : '0.0', 
    10781085        'noise'     : 0.0, 
    10791086        'accuracy'  : 'Low', 
     
    11151122        elif arg.startswith('-q='): 
    11161123            opts['qmin'], opts['qmax'] = [float(v) for v in arg[3:].split(':')] 
    1117         elif arg.startswith('-res='):      opts['res'] = float(arg[5:]) 
     1124        elif arg.startswith('-res='):      opts['res'] = arg[5:] 
    11181125        elif arg.startswith('-noise='):    opts['noise'] = float(arg[7:]) 
    11191126        elif arg.startswith('-sets='):     opts['sets'] = int(arg[6:]) 
     
    11731180    if opts['qmin'] is None: 
    11741181        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) 
    11791182 
    11801183    comparison = any(PAR_SPLIT in v for v in values) 
     
    12161219        opts['cutoff'] = [float(opts['cutoff'])]*2 
    12171220 
    1218     base = make_engine(model_info[0], data, opts['engine'][0], 
     1221    if PAR_SPLIT in opts['res']: 
     1222        opts['res'] = [float(k) for k in opts['res'].split(PAR_SPLIT, 2)] 
     1223        comparison = True 
     1224    else: 
     1225        opts['res'] = [float(opts['res'])]*2 
     1226 
     1227    if opts['datafile'] is not None: 
     1228        data = load_data(os.path.expanduser(opts['datafile'])) 
     1229    else: 
     1230        # Hack around the fact that make_data doesn't take a pair of resolutions 
     1231        res = opts['res'] 
     1232        opts['res'] = res[0] 
     1233        data0, _ = make_data(opts) 
     1234        if res[0] != res[1]: 
     1235            opts['res'] = res[1] 
     1236            data1, _ = make_data(opts) 
     1237        else: 
     1238            data1 = data0 
     1239        opts['res'] = res 
     1240        data = data0, data1 
     1241 
     1242    base = make_engine(model_info[0], data[0], opts['engine'][0], 
    12191243                       opts['cutoff'][0], opts['ngauss'][0]) 
    12201244    if comparison: 
    1221         comp = make_engine(model_info[1], data, opts['engine'][1], 
     1245        comp = make_engine(model_info[1], data[1], opts['engine'][1], 
    12221246                           opts['cutoff'][1], opts['ngauss'][1]) 
    12231247    else: 
Note: See TracChangeset for help on using the changeset viewer.