Changeset b89f519 in sasmodels
- Timestamp:
- Mar 4, 2015 2:34:25 PM (10 years ago)
- Branches:
- master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- 3c56da87
- Parents:
- 12c810f
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
compare.py
r5134b2c rb89f519 81 81 return np.random.rand() 82 82 else: 83 # length, scale, background in [0,200]84 return 2 00*np.random.rand()83 # values from 0 to 2*x for all other parameters 84 return 2*np.random.rand()*(v if v != 0 else 1) 85 85 86 86 def randomize_model(name, pars, seed=None): … … 145 145 return value, average_time 146 146 147 def make_data(qmax, is2D, Nq=128 ):147 def make_data(qmax, is2D, Nq=128, view='log'): 148 148 if is2D: 149 149 from sasmodels.bumps_model import empty_data2D, set_beam_stop … … 153 153 else: 154 154 from sasmodels.bumps_model import empty_data1D 155 qmax = math.log10(qmax) 156 data = empty_data1D(np.logspace(qmax-3, qmax, Nq)) 155 if view == 'log': 156 qmax = math.log10(qmax) 157 q = np.logspace(qmax-3, qmax, Nq) 158 else: 159 q = np.linspace(0.001*qmax, qmax, Nq) 160 data = empty_data1D(q) 157 161 index = slice(None, None) 158 162 return data, index 159 163 160 164 def compare(name, pars, Ncpu, Nocl, opts, set_pars): 165 view = 'linear' if '-linear' in opts else 'log' if '-log' in opts else 'q4' if '-q4' in opts else 'log' 166 161 167 opt_values = dict(split 162 168 for s in opts for split in ((s.split('='),)) … … 166 172 Nq = int(opt_values.get('-Nq', '128')) 167 173 is2D = not "-1d" in opts 168 data, index = make_data(qmax, is2D, Nq )174 data, index = make_data(qmax, is2D, Nq, view=view) 169 175 170 176 … … 174 180 175 181 # randomize parameters 182 pars.update(set_pars) 176 183 if '-random' in opts or '-random' in opt_values: 177 184 seed = int(opt_values['-random']) if '-random' in opt_values else None 178 185 pars, seed = randomize_model(name, pars, seed=seed) 179 186 print "Randomize using -random=%i"%seed 180 pars.update(set_pars)181 187 182 188 # parameter selection … … 223 229 if Ncpu > 0: 224 230 if Nocl > 0: plt.subplot(131) 225 plot_data(data, cpu, scale='log')231 plot_data(data, cpu, view=view) 226 232 plt.title("%s t=%.1f ms"%(comp,cpu_time)) 227 233 cbar_title = "log I" 228 234 if Nocl > 0: 229 235 if Ncpu > 0: plt.subplot(132) 230 plot_data(data, ocl, scale='log')236 plot_data(data, ocl, view=view) 231 237 plt.title("opencl t=%.1f ms"%ocl_time) 232 238 cbar_title = "log I" … … 234 240 plt.subplot(133) 235 241 if '-abs' in opts: 236 err,errstr, scale= resid, "abs err", "linear"237 else: 238 err,errstr, scale= abs(relerr), "rel err", "log"242 err,errstr,errview = resid, "abs err", "linear" 243 else: 244 err,errstr,errview = abs(relerr), "rel err", "log" 239 245 #err,errstr = ocl/cpu,"ratio" 240 plot_data(data, err, scale=scale)246 plot_data(data, err, view=errview) 241 247 plt.title("max %s = %.3g"%(errstr, max(abs(err[index])))) 242 cbar_title = errstr if scale=="linear" else "log "+errstr248 cbar_title = errstr if errview=="linear" else "log "+errstr 243 249 if is2D: 244 250 h = plt.colorbar() … … 281 287 -pars/-nopars* prints the parameter set or not 282 288 -abs/-rel* plot relative or absolute error 289 -linear/-log/-q4 intensity scaling 283 290 -hist/-nohist* plot histogram of relative error 284 291 … … 301 308 'nopars','pars', 302 309 'rel','abs', 310 'linear', 'log', 'q4', 303 311 'hist','nohist', 304 312 ]) -
sasmodels/bumps_model.py
r1353f60 rb89f519 154 154 155 155 156 def plot_data(data, iq, vmin=None, vmax=None, scale='log'):156 def plot_data(data, iq, vmin=None, vmax=None, view='log'): 157 157 """ 158 158 Plot the target value for the data. This could be the data itself, … … 166 166 iq = iq + 0 167 167 valid = np.isfinite(iq) 168 if scale== 'log':168 if view == 'log': 169 169 valid[valid] = (iq[valid] > 0) 170 170 iq[valid] = np.log10(iq[valid]) 171 elif view == 'q4': 172 iq[valid] = iq*(data.qx_data[valid]**2+data.qy_data[valid]**2)**2 171 173 iq[~valid | data.mask] = 0 172 174 #plottable = iq … … 183 185 extent=[xmin, xmax, ymin, ymax], vmin=vmin, vmax=vmax) 184 186 else: # 1D data 185 if scale == 'linear': 187 if view == 'linear' or view == 'q4': 188 #idx = np.isfinite(iq) 189 scale = data.x**4 if view == 'q4' else 1.0 190 plt.plot(data.x, scale*iq) #, '.') 191 else: 192 # Find the values that are finite and positive 186 193 idx = np.isfinite(iq) 187 plt.plot(data.x[idx], iq[idx]) 188 else: 189 idx = np.isfinite(iq) 190 idx[idx] = (iq[idx] > 0) 191 plt.loglog(data.x[idx], iq[idx]) 194 idx[idx] = iq[idx]>0 195 iq[~idx] = np.nan 196 plt.loglog(data.x, iq) 192 197 193 198 … … 207 212 mresid = masked_array((theory - data.y) / data.dy, mdata.mask) 208 213 214 scale = data.x**4 if view == 'q4' else 1.0 209 215 plt.subplot(121) 210 plt.errorbar(data.x, mdata, yerr=data.dy)211 plt.plot(data.x, mtheory, '-', hold=True)212 plt.yscale( view)216 plt.errorbar(data.x, scale*mdata, yerr=data.dy) 217 plt.plot(data.x, scale*mtheory, '-', hold=True) 218 plt.yscale('linear' if view == 'q4' else view) 213 219 plt.subplot(122) 214 220 plt.plot(data.x, mresid, 'x') … … 234 240 resid = (theory - data.data) / data.err_data 235 241 plt.subplot(131) 236 plot_data(data, data.data, scale=view)242 plot_data(data, data.data, view=view) 237 243 plt.colorbar() 238 244 plt.subplot(132) 239 plot_data(data, theory, scale=view)245 plot_data(data, theory, view=view) 240 246 plt.colorbar() 241 247 plt.subplot(133) 242 plot_data(data, resid, scale='linear')248 plot_data(data, resid, view='linear') 243 249 plt.colorbar() 244 250
Note: See TracChangeset
for help on using the changeset viewer.