Changeset e3571cb in sasmodels
- Timestamp:
- Oct 21, 2017 10:57:43 PM (7 years ago)
- Branches:
- master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- 2bccb5a
- Parents:
- 6773b02
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/compare.py
r3c24ccd re3571cb 83 83 -pars/-nopars* prints the parameter set or not 84 84 -default/-demo* use demo vs default parameters 85 -sphere[=150] set up spherical integration over theta/phi using n points 85 86 86 87 === calculation options === 87 -mono*/-poly force monodisperse or allow polydisperse demoparameters88 -mono*/-poly force monodisperse or allow polydisperse random parameters 88 89 -cutoff=1e-5* cutoff value for including a point in polydispersity 89 90 -magnetic/-nonmagnetic* suppress magnetism … … 279 280 # orientation in [-180,180], orientation pd in [0,45] 280 281 if p.endswith('_pd'): 281 return 0., 45.282 return 0., 180. 282 283 else: 283 284 return -180., 180. … … 434 435 435 436 437 def limit_dimensions(model_info, pars, maxdim): 438 # type: (ModelInfo, ParameterSet, float) -> None 439 """ 440 Limit parameters of units of Ang to maxdim. 441 """ 442 for p in model_info.parameters.call_parameters: 443 value = pars[p.name] 444 if p.units == 'Ang' and value > maxdim: 445 pars[p.name] = maxdim*10**np.random.uniform(-3,0) 446 436 447 def constrain_pars(model_info, pars): 437 448 # type: (ModelInfo, ParameterSet) -> None … … 496 507 Format the parameter list for printing. 497 508 """ 509 is2d = True 498 510 lines = [] 499 511 parameters = model_info.parameters … … 817 829 818 830 819 def compare(opts, limits=None ):831 def compare(opts, limits=None, maxdim=np.inf): 820 832 # type: (Dict[str, Any], Optional[Tuple[float, float]]) -> Tuple[float, float] 821 833 """ … … 828 840 as the values are adjusted, making it easier to see the effects of the 829 841 parameters. 842 843 *maxdim* is the maximum value for any parameter with units of Angstrom. 830 844 """ 831 845 for k in range(opts['sets']): 832 opts['pars'] = parse_pars(opts) 846 if k > 1: 847 # print a separate seed for each dataset for better reproducibility 848 new_seed = np.random.randint(1000000) 849 print("Set %d uses -random=%i"%(k+1,new_seed)) 850 np.random.seed(new_seed) 851 opts['pars'] = parse_pars(opts, maxdim=maxdim) 833 852 if opts['pars'] is None: 834 853 return … … 971 990 #err,errstr = base/comp,"ratio" 972 991 plot_theory(data, None, resid=err, view=errview, use_data=use_data) 973 if view == 'linear':974 plt.xscale('linear')992 plt.xscale('log' if view == 'log' else linear) 993 plt.legend(['P%d'%(k+1) for k in range(setnum+1)], loc='best') 975 994 plt.title("max %s = %.3g"%(errstr, abs(err).max())) 976 995 #cbar_title = errstr if errview=="linear" else "log "+errstr … … 1019 1038 'demo', 'default', # TODO: remove demo/default 1020 1039 'nopars', 'pars', 1040 'sphere', 'sphere=', # integrate over a sphere in 2d with n points 1021 1041 1022 1042 # Calculation options … … 1153 1173 'sets' : 0, 1154 1174 'engine' : 'default', 1155 ' evals' : '1',1175 'count' : '1', 1156 1176 'show_weights' : False, 1177 'sphere' : 0, 1157 1178 } 1158 1179 for arg in flags: … … 1179 1200 elif arg.startswith('-data='): opts['datafile'] = arg[6:] 1180 1201 elif arg.startswith('-engine='): opts['engine'] = arg[8:] 1181 elif arg.startswith('-neval='): opts['evals'] = arg[7:] 1202 elif arg.startswith('-neval='): opts['count'] = arg[7:] 1203 elif arg.startswith('-sphere'): 1204 opts['sphere'] = int(arg[8:]) if len(arg) > 7 else 150 1205 opts['is2d'] = True 1182 1206 elif arg == '-random': opts['seed'] = np.random.randint(1000000) 1183 1207 elif arg == '-preset': opts['seed'] = -1 … … 1238 1262 1239 1263 if PAR_SPLIT in opts['engine']: 1240 engine_types= opts['engine'].split(PAR_SPLIT, 2)1264 opts['engine'] = opts['engine'].split(PAR_SPLIT, 2) 1241 1265 comparison = True 1242 1266 else: 1243 engine_types= [opts['engine']]*21244 1245 if PAR_SPLIT in opts[' evals']:1246 evals = [int(k) for k in opts['evals'].split(PAR_SPLIT, 2)]1267 opts['engine'] = [opts['engine']]*2 1268 1269 if PAR_SPLIT in opts['count']: 1270 opts['count'] = [int(k) for k in opts['count'].split(PAR_SPLIT, 2)] 1247 1271 comparison = True 1248 1272 else: 1249 evals = [int(opts['evals'])]*21273 opts['count'] = [int(opts['count'])]*2 1250 1274 1251 1275 if PAR_SPLIT in opts['cutoff']: 1252 cutoff= [float(k) for k in opts['cutoff'].split(PAR_SPLIT, 2)]1276 opts['cutoff'] = [float(k) for k in opts['cutoff'].split(PAR_SPLIT, 2)] 1253 1277 comparison = True 1254 1278 else: 1255 cutoff= [float(opts['cutoff'])]*21256 1257 base = make_engine(model_info[0], data, engine_types[0], cutoff[0])1279 opts['cutoff'] = [float(opts['cutoff'])]*2 1280 1281 base = make_engine(model_info[0], data, opts['engine'][0], opts['cutoff'][0]) 1258 1282 if comparison: 1259 comp = make_engine(model_info[1], data, engine_types[1], cutoff[1])1283 comp = make_engine(model_info[1], data, opts['engine'][1], opts['cutoff'][1]) 1260 1284 else: 1261 1285 comp = None … … 1266 1290 'data' : data, 1267 1291 'name' : names, 1268 'def' : model_info, 1269 'count' : evals, 1292 'info' : model_info, 1270 1293 'engines' : [base, comp], 1271 1294 'values' : values, … … 1273 1296 # pylint: enable=bad-whitespace 1274 1297 1298 # Set the integration parameters to the half sphere 1299 if opts['sphere'] > 0: 1300 set_spherical_integration_parameters(opts, opts['sphere']) 1301 1275 1302 return opts 1276 1303 1277 def parse_pars(opts): 1278 model_info, model_info2 = opts['def'] 1304 def set_spherical_integration_parameters(opts, steps): 1305 """ 1306 Set integration parameters for spherical integration over the entire 1307 surface in theta-phi coordinates. 1308 """ 1309 # Set the integration parameters to the half sphere 1310 opts['values'].extend([ 1311 'theta=90', 1312 'theta_pd=%g'%(90/np.sqrt(3)), 1313 'theta_pd_n=%d'%steps, 1314 'theta_pd_type=rectangle', 1315 'phi=0', 1316 'phi_pd=%g'%(180/np.sqrt(3)), 1317 'phi_pd_n=%d'%(2*steps), 1318 'phi_pd_type=rectangle', 1319 #'background=0', 1320 ]) 1321 if 'psi' in opts['info'][0].parameters: 1322 opts['values'].append('psi=0') 1323 1324 def parse_pars(opts, maxdim=np.inf): 1325 model_info, model_info2 = opts['info'] 1279 1326 1280 1327 # Get demo parameters from model definition, or use default parameters … … 1287 1334 if opts['seed'] > -1: 1288 1335 pars = randomize_pars(model_info, pars) 1336 limit_dimensions(model_info, pars, maxdim) 1289 1337 if model_info != model_info2: 1290 1338 pars2 = randomize_pars(model_info2, pars2) 1339 limit_dimensions(model_info, pars2, maxdim) 1291 1340 # Share values for parameters with the same name 1292 1341 for k, v in pars.items(): … … 1365 1414 from . import rst2html 1366 1415 1367 info = opts[' def'][0]1416 info = opts['info'][0] 1368 1417 html = make_html(info) 1369 1418 path = os.path.dirname(info.filename) … … 1416 1465 opts['pars'] = list(opts['pars']) 1417 1466 p1, p2 = opts['pars'] 1418 m1, m2 = opts[' def']1467 m1, m2 = opts['info'] 1419 1468 self.fix_p2 = m1 != m2 or p1 != p2 1420 1469 model_info = m1 -
sasmodels/data.py
rfbb9397 re3571cb 363 363 if hasattr(data, 'isSesans') and data.isSesans: 364 364 _plot_result_sesans(data, None, None, use_data=True, limits=limits) 365 elif hasattr(data, 'qx_data') :365 elif hasattr(data, 'qx_data') and not getattr(data, 'radial', False): 366 366 _plot_result2D(data, None, None, view, use_data=True, limits=limits) 367 367 else: … … 391 391 if hasattr(data, 'isSesans') and data.isSesans: 392 392 _plot_result_sesans(data, theory, resid, use_data=True, limits=limits) 393 elif hasattr(data, 'qx_data') :393 elif hasattr(data, 'qx_data') and not getattr(data, 'radial', False): 394 394 _plot_result2D(data, theory, resid, view, use_data, limits=limits) 395 395 else: … … 425 425 import matplotlib.pyplot as plt # type: ignore 426 426 from numpy.ma import masked_array, masked # type: ignore 427 428 if getattr(data, 'radial', False): 429 radial_data.x = radial_data.q_data 430 radial_data.y = radial_data.data 427 431 428 432 use_data = use_data and data.y is not None -
sasmodels/modelinfo.py
r8698a0d re3571cb 502 502 raise KeyError("unknown parameter %r"%key) 503 503 return par 504 505 def __contains__(self, key): 506 for par in self.call_parameters: 507 if par.name == key: 508 return True 509 else: 510 return False 504 511 505 512 def _set_vector_lengths(self):
Note: See TracChangeset
for help on using the changeset viewer.