Changes in sasmodels/compare.py [af7a97c:5770493] in sasmodels
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/compare.py
raf7a97c r5770493 107 107 -title="note" adds note to the plot title, after the model name 108 108 -weights shows weights plots for the polydisperse parameters 109 -profile shows the sld profile if the model has a plottable sld profile110 109 111 110 === output options === 112 111 -edit starts the parameter explorer 113 112 -help/-html shows the model docs instead of running the model 114 115 === environment variables ===116 -DSAS_MODELPATH=path sets directory containing custom models117 -DSAS_OPENCL=vendor:device|none sets the target OpenCL device118 -DXDG_CACHE_HOME=~/.cache sets the pyopencl cache root (linux only)119 -DSAS_COMPILER=tinycc|msvc|mingw|unix sets the DLL compiler120 -DSAS_OPENMP=1 turns on OpenMP for the DLLs121 -DSAS_DLL_PATH=path sets the path to the compiled modules122 113 123 114 The interpretation of quad precision depends on architecture, and may … … 654 645 655 646 def make_data(opts): 656 # type: (Dict[str, Any] , float) -> Tuple[Data, np.ndarray]647 # type: (Dict[str, Any]) -> Tuple[Data, np.ndarray] 657 648 """ 658 649 Generate an empty dataset, used with the model to set Q points … … 676 667 if opts['zero']: 677 668 q = np.hstack((0, q)) 678 # TODO: provide command line control of lambda and Delta lambda/lambda 679 #L, dLoL = 5, 0.14/np.sqrt(6) # wavelength and 14% triangular FWHM 680 L, dLoL = 0, 0 681 data = empty_data1D(q, resolution=res, L=L, dL=L*dLoL) 669 data = empty_data1D(q, resolution=res) 682 670 index = slice(None, None) 683 671 return data, index … … 784 772 dim = base._kernel.dim 785 773 plot_weights(model_info, get_mesh(model_info, base_pars, dim=dim)) 786 if opts['show_profile']:787 import pylab788 base, comp = opts['engines']789 base_pars, comp_pars = opts['pars']790 have_base = base._kernel.info.profile is not None791 have_comp = (792 comp is not None793 and comp._kernel.info.profile is not None794 and base_pars != comp_pars795 )796 if have_base or have_comp:797 pylab.figure()798 if have_base:799 plot_profile(base._kernel.info, **base_pars)800 if have_comp:801 plot_profile(comp._kernel.info, label='comp', **comp_pars)802 pylab.legend()803 774 if opts['plot']: 804 775 import matplotlib.pyplot as plt … … 806 777 return limits 807 778 808 def plot_profile(model_info, label='base', **args):809 # type: (ModelInfo, List[Tuple[float, np.ndarray, np.ndarray]]) -> None810 """811 Plot the profile returned by the model profile method.812 813 *model_info* defines model parameters, etc.814 815 *mesh* is a list of tuples containing (*value*, *dispersity*, *weights*)816 for each parameter, where (*dispersity*, *weights*) pairs are the817 distributions to be plotted.818 """819 import pylab820 821 args = dict((k, v) for k, v in args.items()822 if "_pd" not in k823 and ":" not in k824 and k not in ("background", "scale", "theta", "phi", "psi"))825 args = args.copy()826 827 args.pop('scale', 1.)828 args.pop('background', 0.)829 z, rho = model_info.profile(**args)830 #pylab.interactive(True)831 pylab.plot(z, rho, '-', label=label)832 pylab.grid(True)833 #pylab.show()834 835 836 837 779 def run_models(opts, verbose=False): 838 780 # type: (Dict[str, Any]) -> Dict[str, Any] … … 844 786 base_n, comp_n = opts['count'] 845 787 base_pars, comp_pars = opts['pars'] 846 base_data, comp_data = opts['data']788 data = opts['data'] 847 789 848 790 comparison = comp is not None … … 858 800 print("%s t=%.2f ms, intensity=%.0f" 859 801 % (base.engine, base_time, base_value.sum())) 860 _show_invalid( base_data, base_value)802 _show_invalid(data, base_value) 861 803 except ImportError: 862 804 traceback.print_exc() … … 870 812 print("%s t=%.2f ms, intensity=%.0f" 871 813 % (comp.engine, comp_time, comp_value.sum())) 872 _show_invalid( base_data, comp_value)814 _show_invalid(data, comp_value) 873 815 except ImportError: 874 816 traceback.print_exc() … … 924 866 have_base, have_comp = (base_value is not None), (comp_value is not None) 925 867 base, comp = opts['engines'] 926 base_data, comp_data = opts['data']868 data = opts['data'] 927 869 use_data = (opts['datafile'] is not None) and (have_base ^ have_comp) 928 870 929 871 # Plot if requested 930 872 view = opts['view'] 931 #view = 'log'932 873 if limits is None: 933 874 vmin, vmax = np.inf, -np.inf … … 943 884 if have_comp: 944 885 plt.subplot(131) 945 plot_theory( base_data, base_value, view=view, use_data=use_data, limits=limits)886 plot_theory(data, base_value, view=view, use_data=use_data, limits=limits) 946 887 plt.title("%s t=%.2f ms"%(base.engine, base_time)) 947 888 #cbar_title = "log I" … … 950 891 plt.subplot(132) 951 892 if not opts['is2d'] and have_base: 952 plot_theory( comp_data, base_value, view=view, use_data=use_data, limits=limits)953 plot_theory( comp_data, comp_value, view=view, use_data=use_data, limits=limits)893 plot_theory(data, base_value, view=view, use_data=use_data, limits=limits) 894 plot_theory(data, comp_value, view=view, use_data=use_data, limits=limits) 954 895 plt.title("%s t=%.2f ms"%(comp.engine, comp_time)) 955 896 #cbar_title = "log I" … … 967 908 err[err > cutoff] = cutoff 968 909 #err,errstr = base/comp,"ratio" 969 # Note: base_data only since base and comp have same q values (though 970 # perhaps different resolution), and we are plotting the difference 971 # at each q 972 plot_theory(base_data, None, resid=err, view=errview, use_data=use_data) 910 plot_theory(data, None, resid=err, view=errview, use_data=use_data) 973 911 plt.xscale('log' if view == 'log' and not opts['is2d'] else 'linear') 974 912 plt.legend(['P%d'%(k+1) for k in range(setnum+1)], loc='best') … … 1004 942 OPTIONS = [ 1005 943 # Plotting 1006 'plot', 'noplot', 1007 'weights', 'profile', 944 'plot', 'noplot', 'weights', 1008 945 'linear', 'log', 'q4', 1009 946 'rel', 'abs', … … 1121 1058 1122 1059 invalid = [o[1:] for o in flags 1123 if not (o[1:] in NAME_OPTIONS 1124 or any(o.startswith('-%s='%t) for t in VALUE_OPTIONS) 1125 or o.startswith('-D'))] 1060 if o[1:] not in NAME_OPTIONS 1061 and not any(o.startswith('-%s='%t) for t in VALUE_OPTIONS)] 1126 1062 if invalid: 1127 1063 print("Invalid options: %s"%(", ".join(invalid))) … … 1139 1075 'qmax' : 0.05, 1140 1076 'nq' : 128, 1141 'res' : '0.0',1077 'res' : 0.0, 1142 1078 'noise' : 0.0, 1143 1079 'accuracy' : 'Low', … … 1160 1096 'count' : '1', 1161 1097 'show_weights' : False, 1162 'show_profile' : False,1163 1098 'sphere' : 0, 1164 1099 'ngauss' : '0', … … 1180 1115 elif arg.startswith('-q='): 1181 1116 opts['qmin'], opts['qmax'] = [float(v) for v in arg[3:].split(':')] 1182 elif arg.startswith('-res='): opts['res'] = arg[5:]1117 elif arg.startswith('-res='): opts['res'] = float(arg[5:]) 1183 1118 elif arg.startswith('-noise='): opts['noise'] = float(arg[7:]) 1184 1119 elif arg.startswith('-sets='): opts['sets'] = int(arg[6:]) … … 1221 1156 elif arg == '-default': opts['use_demo'] = False 1222 1157 elif arg == '-weights': opts['show_weights'] = True 1223 elif arg == '-profile': opts['show_profile'] = True1224 1158 elif arg == '-html': opts['html'] = True 1225 1159 elif arg == '-help': opts['html'] = True 1226 elif arg.startswith('-D'):1227 var, val = arg[2:].split('=')1228 os.environ[var] = val1229 1160 # pylint: enable=bad-whitespace,C0321 1230 1161 … … 1242 1173 if opts['qmin'] is None: 1243 1174 opts['qmin'] = 0.001*opts['qmax'] 1175 if opts['datafile'] is not None: 1176 data = load_data(os.path.expanduser(opts['datafile'])) 1177 else: 1178 data, _ = make_data(opts) 1244 1179 1245 1180 comparison = any(PAR_SPLIT in v for v in values) … … 1281 1216 opts['cutoff'] = [float(opts['cutoff'])]*2 1282 1217 1283 if PAR_SPLIT in opts['res']: 1284 opts['res'] = [float(k) for k in opts['res'].split(PAR_SPLIT, 2)] 1285 comparison = True 1286 else: 1287 opts['res'] = [float(opts['res'])]*2 1288 1289 if opts['datafile'] is not None: 1290 data = load_data(os.path.expanduser(opts['datafile'])) 1291 else: 1292 # Hack around the fact that make_data doesn't take a pair of resolutions 1293 res = opts['res'] 1294 opts['res'] = res[0] 1295 data0, _ = make_data(opts) 1296 if res[0] != res[1]: 1297 opts['res'] = res[1] 1298 data1, _ = make_data(opts) 1299 else: 1300 data1 = data0 1301 opts['res'] = res 1302 data = data0, data1 1303 1304 base = make_engine(model_info[0], data[0], opts['engine'][0], 1218 base = make_engine(model_info[0], data, opts['engine'][0], 1305 1219 opts['cutoff'][0], opts['ngauss'][0]) 1306 1220 if comparison: 1307 comp = make_engine(model_info[1], data [1], opts['engine'][1],1221 comp = make_engine(model_info[1], data, opts['engine'][1], 1308 1222 opts['cutoff'][1], opts['ngauss'][1]) 1309 1223 else: … … 1462 1376 path = os.path.dirname(info.filename) 1463 1377 url = "file://" + path.replace("\\", "/")[2:] + "/" 1464 rst2html.view_html_ wxapp(html, url)1378 rst2html.view_html_qtapp(html, url) 1465 1379 1466 1380 def explore(opts):
Note: See TracChangeset
for help on using the changeset viewer.