Changeset b151003 in sasmodels for sasmodels/compare.py


Ignore:
Timestamp:
Apr 14, 2016 8:57:32 AM (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:
391ea92, dd7fc12
Parents:
0ce5710 (diff), 7abcc59 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge remote-tracking branch 'origin/master' into polydisp

Conflicts:

sasmodels/model_test.py

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/compare.py

    r7ae2b7f rb151003  
    5757    -lowq*/-midq/-highq/-exq use q values up to 0.05, 0.2, 1.0, 10.0 
    5858    -nq=128 sets the number of Q points in the data set 
     59    -zero indicates that q=0 should be included 
    5960    -1d*/-2d computes 1d or 2d data 
    6061    -preset*/-random[=seed] preset or random parameters 
     
    482483        index = ~data.mask 
    483484    else: 
    484         if opts['view'] == 'log': 
     485        if opts['view'] == 'log' and not opts['zero']: 
    485486            qmax = math.log10(qmax) 
    486487            q = np.logspace(qmax-3, qmax, nq) 
    487488        else: 
    488489            q = np.linspace(0.001*qmax, qmax, nq) 
     490        if opts['zero']: 
     491            q = np.hstack((0, q)) 
    489492        data = empty_data1D(q, resolution=res) 
    490493        index = slice(None, None) 
     
    505508        return eval_opencl(model_info, data, dtype=dtype, cutoff=cutoff) 
    506509 
     510def _show_invalid(data, theory): 
     511    if not theory.mask.any(): 
     512        return 
     513 
     514    if hasattr(data, 'x'): 
     515        bad = zip(data.x[theory.mask], theory[theory.mask]) 
     516        print("   *** ", ", ".join("I(%g)=%g"%(x, y) for x,y in bad)) 
     517 
     518 
    507519def compare(opts, limits=None): 
    508520    """ 
     
    525537        try: 
    526538            base_value, base_time = time_calculation(base, pars, Nbase) 
     539            base_value = np.ma.masked_invalid(base_value) 
    527540            print("%s t=%.2f ms, intensity=%.0f" 
    528                   % (base.engine, base_time, sum(base_value))) 
     541                  % (base.engine, base_time, base_value.sum())) 
     542            _show_invalid(data, base_value) 
    529543        except ImportError: 
    530544            traceback.print_exc() 
     
    536550        try: 
    537551            comp_value, comp_time = time_calculation(comp, pars, Ncomp) 
     552            comp_value = np.ma.masked_invalid(comp_value) 
    538553            print("%s t=%.2f ms, intensity=%.0f" 
    539                   % (comp.engine, comp_time, sum(comp_value))) 
     554                  % (comp.engine, comp_time, comp_value.sum())) 
     555            _show_invalid(data, comp_value) 
    540556        except ImportError: 
    541557            traceback.print_exc() 
     
    560576        vmin, vmax = np.Inf, -np.Inf 
    561577        if Nbase > 0: 
    562             vmin = min(vmin, min(base_value)) 
    563             vmax = max(vmax, max(base_value)) 
     578            vmin = min(vmin, base_value.min()) 
     579            vmax = max(vmax, base_value.max()) 
    564580        if Ncomp > 0: 
    565             vmin = min(vmin, min(comp_value)) 
    566             vmax = max(vmax, max(comp_value)) 
     581            vmin = min(vmin, comp_value.min()) 
     582            vmax = max(vmax, comp_value.max()) 
    567583        limits = vmin, vmax 
    568584 
     
    587603        if view == 'linear': 
    588604            plt.xscale('linear') 
    589         plt.title("max %s = %.3g"%(errstr, max(abs(err)))) 
     605        plt.title("max %s = %.3g"%(errstr, abs(err).max())) 
    590606        #cbar_title = errstr if errview=="linear" else "log "+errstr 
    591607    #if is2D: 
     
    609625 
    610626def _print_stats(label, err): 
    611     sorted_err = np.sort(abs(err)) 
     627    sorted_err = np.sort(abs(err.compressed())) 
    612628    p50 = int((len(err)-1)*0.50) 
    613629    p98 = int((len(err)-1)*0.98) 
     
    629645    'half', 'fast', 'single', 'double', 
    630646    'single!', 'double!', 'quad!', 'sasview', 
    631     'lowq', 'midq', 'highq', 'exq', 
     647    'lowq', 'midq', 'highq', 'exq', 'zero', 
    632648    '2d', '1d', 
    633649    'preset', 'random', 
     
    755771        elif arg == '-midq':    opts['qmax'] = 0.2 
    756772        elif arg == '-lowq':    opts['qmax'] = 0.05 
     773        elif arg == '-zero':    opts['zero'] = True 
    757774        elif arg.startswith('-nq='):       opts['nq'] = int(arg[4:]) 
    758775        elif arg.startswith('-res='):      opts['res'] = float(arg[5:]) 
Note: See TracChangeset for help on using the changeset viewer.