Changeset 013adb7 in sasmodels
- Timestamp:
- Dec 23, 2015 5:00:04 PM (9 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:
- 8b25ee1
- Parents:
- e21cc31
- Location:
- sasmodels
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/compare.py
re21cc31 r013adb7 253 253 cutoff=cutoff) 254 254 255 def compare(opts ):255 def compare(opts, limits=None): 256 256 Nbase, Ncomp = opts['N1'], opts['N2'] 257 257 pars = opts['pars'] … … 292 292 view = opts['view'] 293 293 import matplotlib.pyplot as plt 294 if limits is None: 295 vmin, vmax = np.Inf, -np.Inf 296 if Nbase > 0: 297 vmin = min(vmin, min(base_value)) 298 vmax = max(vmax, max(base_value)) 299 if Ncomp > 0: 300 vmin = min(vmin, min(comp_value)) 301 vmax = max(vmax, max(comp_value)) 302 limits = vmin, vmax 303 294 304 if Nbase > 0: 295 305 if Ncomp > 0: plt.subplot(131) 296 plot_theory(data, base_value, view=view, plot_data=False )306 plot_theory(data, base_value, view=view, plot_data=False, limits=limits) 297 307 plt.title("%s t=%.1f ms"%(base.engine, base_time)) 298 308 #cbar_title = "log I" 299 309 if Ncomp > 0: 300 310 if Nbase > 0: plt.subplot(132) 301 plot_theory(data, comp_value, view=view, plot_data=False )311 plot_theory(data, comp_value, view=view, plot_data=False, limits=limits) 302 312 plt.title("%s t=%.1f ms"%(comp.engine,comp_time)) 303 313 #cbar_title = "log I" … … 327 337 if not opts['explore']: 328 338 plt.show() 339 340 return limits 329 341 330 342 def _print_stats(label, err): … … 626 638 v.range(*parameter_range(k, v.value)) 627 639 else: 628 for k, v in self.pars.items():640 for k, v in pars.items(): 629 641 v.range(*parameter_range(k, v.value)) 630 642 631 643 self.pars = pars 632 644 self.pd_types = pd_types 645 self.limits = None 633 646 634 647 def numpoints(self): … … 654 667 pars.update(self.pd_types) 655 668 self.opts['pars'] = pars 656 compare(self.opts) 669 limits = compare(self.opts, limits=self.limits) 670 if self.limits is None: 671 vmin, vmax = limits 672 vmax = 1.3*vmax 673 vmin = vmax*1e-7 674 self.limits = vmin, vmax 657 675 658 676 -
sasmodels/data.py
rce166d3 r013adb7 220 220 221 221 222 def plot_data(data, view='log' ):222 def plot_data(data, view='log', limits=None): 223 223 """ 224 224 Plot data loaded by the sasview loader. … … 228 228 # do not repeat. 229 229 if hasattr(data, 'lam'): 230 _plot_result_sesans(data, None, None, plot_data=True )230 _plot_result_sesans(data, None, None, plot_data=True, limits=limits) 231 231 elif hasattr(data, 'qx_data'): 232 _plot_result2D(data, None, None, view, plot_data=True) 233 else: 234 _plot_result1D(data, None, None, view, plot_data=True) 235 236 237 def plot_theory(data, theory, resid=None, view='log', plot_data=True): 232 _plot_result2D(data, None, None, view, plot_data=True, limits=limits) 233 else: 234 _plot_result1D(data, None, None, view, plot_data=True, limits=limits) 235 236 237 def plot_theory(data, theory, resid=None, view='log', 238 plot_data=True, limits=None): 238 239 if hasattr(data, 'lam'): 239 _plot_result_sesans(data, theory, resid, plot_data=True )240 _plot_result_sesans(data, theory, resid, plot_data=True, limits=limits) 240 241 elif hasattr(data, 'qx_data'): 241 _plot_result2D(data, theory, resid, view, plot_data )242 else: 243 _plot_result1D(data, theory, resid, view, plot_data )242 _plot_result2D(data, theory, resid, view, plot_data, limits=limits) 243 else: 244 _plot_result1D(data, theory, resid, view, plot_data, limits=limits) 244 245 245 246 … … 256 257 257 258 @protect 258 def _plot_result1D(data, theory, resid, view, plot_data ):259 def _plot_result1D(data, theory, resid, view, plot_data, limits=None): 259 260 """ 260 261 Plot the data and residuals for 1D data. … … 296 297 some_present = some_present or (mtheory.count() > 0) 297 298 299 if limits is not None: 300 plt.ylim(*limits) 298 301 plt.xscale('linear' if not some_present else view) 299 302 plt.yscale('linear' … … 317 320 318 321 @protect 319 def _plot_result_sesans(data, theory, resid, plot_data ):322 def _plot_result_sesans(data, theory, resid, plot_data, limits=None): 320 323 import matplotlib.pyplot as plt 321 324 if data.y is None: … … 331 334 if theory is not None: 332 335 plt.plot(data.x, theory, '-', hold=True) 336 if limits is not None: 337 plt.ylim(*limits) 333 338 plt.xlabel('spin echo length (nm)') 334 339 plt.ylabel('polarization (P/P0)') … … 344 349 345 350 @protect 346 def _plot_result2D(data, theory, resid, view, plot_data ):351 def _plot_result2D(data, theory, resid, view, plot_data, limits=None): 347 352 """ 348 353 Plot the data and residuals for 2D data. … … 355 360 356 361 # Put theory and data on a common colormap scale 357 vmin, vmax = np.inf, -np.inf 358 if plot_data: 359 target = data.data[~data.mask] 360 datamin = target[target>0].min() if view == 'log' else target.min() 361 datamax = target.max() 362 vmin = min(vmin, datamin) 363 vmax = max(vmax, datamax) 364 if plot_theory: 365 theorymin = theory[theory>0].min() if view == 'log' else theory.min() 366 theorymax = theory.max() 367 vmin = min(vmin, theorymin) 368 vmax = max(vmax, theorymax) 362 if limits is None: 363 vmin, vmax = np.inf, -np.inf 364 if plot_data: 365 target = data.data[~data.mask] 366 datamin = target[target>0].min() if view == 'log' else target.min() 367 datamax = target.max() 368 vmin = min(vmin, datamin) 369 vmax = max(vmax, datamax) 370 if plot_theory: 371 theorymin = theory[theory>0].min() if view=='log' else theory.min() 372 theorymax = theory.max() 373 vmin = min(vmin, theorymin) 374 vmax = max(vmax, theorymax) 375 else: 376 vmin, vmax = limits 369 377 370 378 if plot_data: … … 388 396 plt.title('theory') 389 397 h = plt.colorbar() 390 h.set_label('$I(q)$') 398 h.set_label(r'$\log_{10}I(q)$' if view=='log' 399 else r'$q^4 I(q)$' if view == 'q4' 400 else '$I(q)$') 391 401 392 402 #if plot_data or plot_theory: … … 420 430 if view == 'log': 421 431 valid[valid] = (image[valid] > 0) 432 if vmin is None: vmin = image[valid & ~data.mask].min() 433 if vmax is None: vmax = image[valid & ~data.mask].max() 422 434 image[valid] = np.log10(image[valid]) 423 435 elif view == 'q4': 424 436 image[valid] *= (data.qx_data[valid]**2+data.qy_data[valid]**2)**2 437 if vmin is None: vmin = image[valid & ~data.mask].min() 438 if vmax is None: vmax = image[valid & ~data.mask].max() 439 else: 440 if vmin is None: vmin = image[valid & ~data.mask].min() 441 if vmax is None: vmax = image[valid & ~data.mask].max() 442 425 443 image[~valid | data.mask] = 0 426 444 #plottable = Iq … … 428 446 xmin, xmax = min(data.qx_data)/10, max(data.qx_data)/10 429 447 ymin, ymax = min(data.qy_data)/10, max(data.qy_data)/10 430 # TODO: fix vmin, vmax so it is shared for theory/resid 431 vmin = vmax = None 432 try: 433 if vmin is None: vmin = image[valid & ~data.mask].min() 434 if vmax is None: vmax = image[valid & ~data.mask].max() 435 except: 436 vmin, vmax = 0, 1 448 if view == 'log': 449 vmin, vmax = np.log10(vmin), np.log10(vmax) 437 450 plt.imshow(plottable.reshape(len(data.x_bins), len(data.y_bins)), 438 451 interpolation='nearest', aspect=1, origin='upper', … … 440 453 plt.xlabel("$q_x$/nm$^{-1}$") 441 454 plt.ylabel("$q_y$/nm$^{-1}$") 442 455 return vmin, vmax 443 456 444 457 def demo():
Note: See TracChangeset
for help on using the changeset viewer.