Changeset 1e7b202a in sasmodels for sasmodels/compare.py


Ignore:
Timestamp:
Jun 28, 2018 12:31:19 PM (6 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
b1a0f3e, 707cbdb, c11d09f
Parents:
5c36bf1
Message:

add profile plot to sascomp

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/compare.py

    r65fbf7c r1e7b202a  
    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 
    109110 
    110111    === output options === 
     
    775776            dim = base._kernel.dim 
    776777            plot_weights(model_info, get_mesh(model_info, base_pars, dim=dim)) 
     778        if opts['show_profile']: 
     779            import pylab 
     780            base, comp = opts['engines'] 
     781            base_pars, comp_pars = opts['pars'] 
     782            have_base = base._kernel.info.profile is not None 
     783            have_comp = ( 
     784                comp is not None 
     785                and comp._kernel.info.profile is not None 
     786                and base_pars != comp_pars 
     787            ) 
     788            if have_base or have_comp: 
     789                pylab.figure() 
     790            if have_base: 
     791                plot_profile(base._kernel.info, **base_pars) 
     792            if have_comp: 
     793                plot_profile(comp._kernel.info, label='comp', **comp_pars) 
     794                pylab.legend() 
    777795    if opts['plot']: 
    778796        import matplotlib.pyplot as plt 
    779797        plt.show() 
    780798    return limits 
     799 
     800def plot_profile(model_info, label='base', **args): 
     801    # type: (ModelInfo, List[Tuple[float, np.ndarray, np.ndarray]]) -> None 
     802    """ 
     803    Plot the profile returned by the model profile method. 
     804 
     805    *model_info* defines model parameters, etc. 
     806 
     807    *mesh* is a list of tuples containing (*value*, *dispersity*, *weights*) 
     808    for each parameter, where (*dispersity*, *weights*) pairs are the 
     809    distributions to be plotted. 
     810    """ 
     811    import pylab 
     812 
     813    args = dict((k, v) for k, v in args.items() 
     814                if "_pd" not in k 
     815                   and ":" not in k 
     816                   and k not in ("background", "scale", "theta", "phi", "psi")) 
     817    args = args.copy() 
     818 
     819    args.pop('scale', 1.) 
     820    args.pop('background', 0.) 
     821    z, rho = model_info.profile(**args) 
     822    #pylab.interactive(True) 
     823    pylab.plot(z, rho, '-', label=label) 
     824    pylab.grid(True) 
     825    #pylab.show() 
     826 
     827 
    781828 
    782829def run_models(opts, verbose=False): 
     
    949996OPTIONS = [ 
    950997    # Plotting 
    951     'plot', 'noplot', 'weights', 
     998    'plot', 'noplot', 
     999    'weights', 'profile', 
    9521000    'linear', 'log', 'q4', 
    9531001    'rel', 'abs', 
     
    11031151        'count'     : '1', 
    11041152        'show_weights' : False, 
     1153        'show_profile' : False, 
    11051154        'sphere'    : 0, 
    11061155        'ngauss'    : '0', 
     
    11631212        elif arg == '-default': opts['use_demo'] = False 
    11641213        elif arg == '-weights': opts['show_weights'] = True 
     1214        elif arg == '-profile': opts['show_profile'] = True 
    11651215        elif arg == '-html':    opts['html'] = True 
    11661216        elif arg == '-help':    opts['html'] = True 
Note: See TracChangeset for help on using the changeset viewer.