Changeset 0b040de in sasmodels


Ignore:
Timestamp:
Oct 17, 2016 8:06:32 PM (7 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
b6f10d8
Parents:
73e08ae
Message:

nicer formatting for magnetic parameters in parameter summary table

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/compare.py

    r248561a r0b040de  
    7373    -preset*/-random[=seed] preset or random parameters 
    7474    -mono/-poly* force monodisperse/polydisperse 
     75    -magnetic/-nonmagnetic* suppress magnetism 
    7576    -cutoff=1e-5* cutoff value for including a point in polydispersity 
    7677    -pars/-nopars* prints the parameter set or not 
     
    349350    lines = [] 
    350351    parameters = model_info.parameters 
     352    magnetic = False 
    351353    for p in parameters.user_parameters(pars, is2d): 
     354        if any(p.id.startswith(x) for x in ('M0:', 'mtheta:', 'mphi:')): 
     355            continue 
     356        if p.id.startswith('up:') and not magnetic: 
     357            continue 
    352358        fields = dict( 
    353359            value=pars.get(p.id, p.default), 
     
    357363            pdtype=pars.get(p.id+"_pd_type", 'gaussian'), 
    358364            relative_pd=p.relative_pd, 
     365            M0=pars.get('M0:'+p.id, 0.), 
     366            mphi=pars.get('mphi:'+p.id, 0.), 
     367            mtheta=pars.get('mtheta:'+p.id, 0.), 
    359368        ) 
    360369        lines.append(_format_par(p.name, **fields)) 
     370        magnetic = magnetic or fields['M0'] != 0. 
    361371    return "\n".join(lines) 
    362372 
     
    364374 
    365375def _format_par(name, value=0., pd=0., n=0, nsigma=3., pdtype='gaussian', 
    366                 relative_pd=False): 
     376                relative_pd=False, M0=0., mphi=0., mtheta=0.): 
    367377    # type: (str, float, float, int, float, str) -> str 
    368378    line = "%s: %g"%(name, value) 
     
    372382        line += " +/- %g  (%d points in [-%g,%g] sigma %s)"\ 
    373383                % (pd, n, nsigma, nsigma, pdtype) 
     384    if M0 != 0.: 
     385        line += "  M0:%.3f  mphi:%.1f  mtheta:%.1f" % (M0, mphi, mtheta) 
    374386    return line 
    375387 
     
    385397    for p in pars: 
    386398        if p.endswith("_pd_n"): pars[p] = 0 
     399    return pars 
     400 
     401def suppress_magnetism(pars): 
     402    # type: (ParameterSet) -> ParameterSet 
     403    """ 
     404    Suppress theta_pd for now until the normalization is resolved. 
     405 
     406    May also suppress complete polydispersity of the model to test 
     407    models more quickly. 
     408    """ 
     409    pars = pars.copy() 
     410    for p in pars: 
     411        if p.startswith("M0:"): pars[p] = 0 
    387412    return pars 
    388413 
     
    687712        #cbar_title = "log I" 
    688713    if n_comp > 0 and n_base > 0: 
     714        if not opts['is2d']: 
     715            plot_theory(data, base_value, view=view, use_data=False, limits=limits) 
    689716        plt.subplot(133) 
    690717        if not opts['rel_err']: 
     
    750777    'preset', 'random', 
    751778    'poly', 'mono', 
     779    'magnetic', 'nonmagnetic', 
    752780    'nopars', 'pars', 
    753781    'rel', 'abs', 
     
    857885        'seed'      : -1,  # default to preset 
    858886        'mono'      : False, 
     887        # Default to magnetic a magnetic moment is set on the command line 
     888        'magnetic'  : any(v.startswith('M0:') for v in values), 
    859889        'show_pars' : False, 
    860890        'show_hist' : False, 
     
    890920        elif arg == '-mono':    opts['mono'] = True 
    891921        elif arg == '-poly':    opts['mono'] = False 
     922        elif arg == '-magnetic':       opts['magnetic'] = True 
     923        elif arg == '-nonmagnetic':    opts['magnetic'] = False 
    892924        elif arg == '-pars':    opts['show_pars'] = True 
    893925        elif arg == '-nopars':  opts['show_pars'] = False 
     
    9751007    constrain_pars(model_info, pars) 
    9761008    constrain_pars(model_info2, pars2) 
     1009    if not opts['magnetic']: 
     1010        pars = suppress_magnetism(pars) 
     1011        pars2 = suppress_magnetism(pars2) 
    9771012 
    9781013    same_model = name == name2 and pars == pars 
Note: See TracChangeset for help on using the changeset viewer.