Changeset 248561a in sasmodels for sasmodels/compare.py


Ignore:
Timestamp:
Oct 17, 2016 11:09:44 AM (8 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:
52e9a45
Parents:
7fcdc9f
Message:

allow math functions such as sqrt and atan in parameter expressions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/compare.py

    rff1fff5 r248561a  
    110110 
    111111kerneldll.ALLOW_SINGLE_PRECISION_DLLS = True 
     112 
     113# list of math functions for use in evaluating parameters 
     114MATH = dict((k,getattr(math, k)) for k in dir(math) if not k.startswith('_')) 
    112115 
    113116# CRUFT python 2.6 
     
    923926    pars = get_pars(model_info, opts['use_demo']) 
    924927    pars2 = get_pars(model_info2, opts['use_demo']) 
     928    pars2.update((k, v) for k, v in pars.items() if k in pars2) 
    925929    # randomize parameters 
    926930    #pars.update(set_pars)  # set value before random to control range 
     
    953957 
    954958    # Evaluate preset parameter expressions 
    955     context = pars.copy() 
     959    context = MATH.copy() 
     960    context.update(pars) 
    956961    context.update((k,v) for k,v in presets.items() if isinstance(v, float)) 
    957962    for k, v in presets.items(): 
    958963        if not isinstance(v, float) and not k.endswith('_type'): 
    959964            presets[k] = eval(v, context) 
    960     context = pars.copy() 
    961965    context.update(presets) 
    962966    context.update((k,v) for k,v in presets2.items() if isinstance(v, float)) 
     
    995999 
    9961000    if opts['show_pars']: 
    997         print(str(parlist(model_info, pars, opts['is2d']))) 
     1001        if not same_model: 
     1002            print("==== %s ====="%model_info.name) 
     1003            print(str(parlist(model_info, pars, opts['is2d']))) 
     1004            print("==== %s ====="%model_info2.name) 
     1005            print(str(parlist(model_info2, pars2, opts['is2d']))) 
     1006        else: 
     1007            print(str(parlist(model_info, pars, opts['is2d']))) 
    9981008 
    9991009    # Create the computational engines 
Note: See TracChangeset for help on using the changeset viewer.