Changeset 97d89af in sasmodels
- Timestamp:
- Aug 6, 2017 5:43:01 PM (7 years ago)
- Branches:
- master, core_shell_microgels, costrafo411, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- 0f6c41c
- Parents:
- bb39b4a
- Location:
- sasmodels
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/compare.py
rbb39b4a r97d89af 493 493 parameters = model_info.parameters 494 494 magnetic = False 495 magnetic_pars = [] 495 496 for p in parameters.user_parameters(pars, is2d): 496 497 if any(p.id.startswith(x) for x in ('M0:', 'mtheta:', 'mphi:')): 497 498 continue 498 if p.id.startswith('up:') and not magnetic: 499 if p.id.startswith('up:'): 500 magnetic_pars.append("%s=%s"%(p.id, pars.get(p.id, p.default))) 499 501 continue 500 502 fields = dict( … … 511 513 lines.append(_format_par(p.name, **fields)) 512 514 magnetic = magnetic or fields['M0'] != 0. 515 if magnetic and magnetic_pars: 516 lines.append(" ".join(magnetic_pars)) 513 517 return "\n".join(lines) 514 518 … … 528 532 return line 529 533 530 def suppress_pd(pars ):534 def suppress_pd(pars, suppress=True): 531 535 # type: (ParameterSet) -> ParameterSet 532 536 """ 533 Suppress theta_pd for now until the normalization is resolved. 534 535 May also suppress complete polydispersity of the model to test 536 models more quickly. 537 If suppress is True complete eliminate polydispersity of the model to test 538 models more quickly. If suppress is False, make sure at least one 539 parameter is polydisperse, setting the first polydispersity parameter to 540 15% if no polydispersity is given (with no explicit demo parameters given 541 in the model, there will be no default polydispersity). 537 542 """ 538 543 pars = pars.copy() 539 for p in pars: 540 if p.endswith("_pd_n"): 541 pars[p] = 0 544 if suppress: 545 for p in pars: 546 if p.endswith("_pd_n"): 547 pars[p] = 0 548 else: 549 any_pd = False 550 first_pd = None 551 for p in pars: 552 if p.endswith("_pd_n"): 553 any_pd |= (pars[p] != 0 and pars[p[:-2]] != 0.) 554 if first_pd is None: 555 first_pd = p 556 if not any_pd and first_pd is not None: 557 if pars[first_pd] == 0: 558 pars[first_pd] = 35 559 if pars[first_pd[:-2]] == 0: 560 pars[first_pd[:-2]] = 0.15 542 561 return pars 543 562 544 def suppress_magnetism(pars ):563 def suppress_magnetism(pars, suppress=True): 545 564 # type: (ParameterSet) -> ParameterSet 546 565 """ 547 Suppress theta_pd for now until the normalization is resolved. 548 549 May also suppress complete polydispersity of the model to test 550 models more quickly. 566 If suppress is True complete eliminate magnetism of the model to test 567 models more quickly. If suppress is False, make sure at least one sld 568 parameter is magnetic, setting the first parameter to have a strong 569 magnetic sld (8/A^2) at 60 degrees (with no explicit demo parameters given 570 in the model, there will be no default magnetism). 551 571 """ 552 572 pars = pars.copy() 553 for p in pars: 554 if p.startswith("M0:"): pars[p] = 0 573 if suppress: 574 for p in pars: 575 if p.startswith("M0:"): 576 pars[p] = 0 577 else: 578 any_mag = False 579 first_mag = None 580 for p in pars: 581 if p.startswith("M0:"): 582 any_mag |= (pars[p] != 0) 583 if first_mag is None: 584 first_mag = p 585 if not any_mag and first_mag is not None: 586 pars[first_mag] = 8. 555 587 return pars 556 588 … … 876 908 def plot_models(opts, result, limits=(np.Inf, -np.Inf), setnum=0): 877 909 # type: (Dict[str, Any], Dict[str, Any], Optional[Tuple[float, float]]) -> Tuple[float, float] 878 base_value, comp_value = result['base_value'], result['comp_value']910 base_value, comp_value = result['base_value'], result['comp_value'] 879 911 base_time, comp_time = result['base_time'], result['comp_time'] 880 912 resid, relerr = result['resid'], result['relerr'] … … 1153 1185 elif arg == '-edit': opts['explore'] = True 1154 1186 elif arg == '-demo': opts['use_demo'] = True 1155 elif arg == '-default': 1187 elif arg == '-default': opts['use_demo'] = False 1156 1188 elif arg == '-html': opts['html'] = True 1157 1189 elif arg == '-help': opts['html'] = True 1158 1190 # pylint: enable=bad-whitespace 1191 1192 # Magnetism forces 2D for now 1193 if opts['magnetic']: 1194 opts['is2d'] = True 1159 1195 1160 1196 # Force random if more than one set … … 1241 1277 constrain_pars(model_info, pars) 1242 1278 constrain_pars(model_info2, pars2) 1243 if opts['mono']: 1244 pars = suppress_pd(pars) 1245 pars2 = suppress_pd(pars2) 1246 if not opts['magnetic']: 1247 pars = suppress_magnetism(pars) 1248 pars2 = suppress_magnetism(pars2) 1279 pars = suppress_pd(pars, opts['mono']) 1280 pars2 = suppress_pd(pars2, opts['mono']) 1281 pars = suppress_magnetism(pars, not opts['magnetic']) 1282 pars2 = suppress_magnetism(pars2, not opts['magnetic']) 1249 1283 1250 1284 # Fill in parameters given on the command line -
sasmodels/models/sphere.py
r31df0c9 r97d89af 84 84 return radius 85 85 86 # VR defaults to 1.0 87 86 88 def random(): 87 89 import numpy as np … … 91 93 ) 92 94 return pars 93 94 # VR defaults to 1.095 96 demo = dict(scale=1, background=0,97 sld=6, sld_solvent=1,98 radius=120,99 radius_pd=.2, radius_pd_n=45)100 95 101 96 tests = [
Note: See TracChangeset
for help on using the changeset viewer.