Changeset a839b22 in sasmodels
- Timestamp:
- Nov 29, 2017 10:18:30 AM (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:
- 2d81cfe
- Parents:
- fa79f5c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/data.py
rfa79f5c ra839b22 37 37 import numpy as np # type: ignore 38 38 39 # pylint: disable=unused-import 39 40 try: 40 41 from typing import Union, Dict, List, Optional … … 43 44 else: 44 45 Data = Union["Data1D", "Data2D", "SesansData"] 46 # pylint: enable=unused-import 45 47 46 48 def load_data(filename, index=0): … … 137 139 *_yaxis*, *_yunit*: label and units for the *y* axis 138 140 """ 139 def __init__(self, x=None, y=None, dx=None, dy=None): 140 # type: (Optional[np.ndarray], Optional[np.ndarray], Optional[np.ndarray], Optional[np.ndarray]) -> None 141 def __init__(self, 142 x=None, # type: Optional[np.ndarray] 143 y=None, # type: Optional[np.ndarray] 144 dx=None, # type: Optional[np.ndarray] 145 dy=None # type: Optional[np.ndarray] 146 ): 147 # type: (...) -> None 141 148 self.x, self.y, self.dx, self.dy = x, y, dx, dy 142 149 self.dxl = None … … 211 218 *x_bins*, *y_bins*: grid steps in *x* and *y* directions 212 219 """ 213 def __init__(self, x=None, y=None, z=None, dx=None, dy=None, dz=None): 214 # type: (Optional[np.ndarray], Optional[np.ndarray], Optional[np.ndarray], Optional[np.ndarray], Optional[np.ndarray], Optional[np.ndarray]) -> None 220 def __init__(self, 221 x=None, # type: Optional[np.ndarray] 222 y=None, # type: Optional[np.ndarray] 223 z=None, # type: Optional[np.ndarray] 224 dx=None, # type: Optional[np.ndarray] 225 dy=None, # type: Optional[np.ndarray] 226 dz=None # type: Optional[np.ndarray] 227 ): 228 # type: (...) -> None 215 229 self.qx_data, self.dqx_data = x, dx 216 230 self.qy_data, self.dqy_data = y, dy … … 369 383 370 384 371 def plot_theory(data, theory, resid=None, view='log', 372 use_data=True, limits=None, Iq_calc=None): 373 # type: (Data, Optional[np.ndarray], Optional[np.ndarray], str, bool, Optional[Tuple[float,float]], Optional[np.ndarray]) -> None 385 def plot_theory(data, # type: Data 386 theory, # type: Optional[np.ndarray] 387 resid=None, # type: Optional[np.ndarray] 388 view='log', # type: str 389 use_data=True, # type: bool 390 limits=None, # type: Optional[np.ndarray] 391 Iq_calc=None # type: Optional[np.ndarray] 392 ): 393 # type: (...) -> None 374 394 """ 375 395 Plot theory calculation. … … 417 437 418 438 @protect 419 def _plot_result1D(data, theory, resid, view, use_data, 420 limits=None, Iq_calc=None): 421 # type: (Data1D, Optional[np.ndarray], Optional[np.ndarray], str, bool, Optional[Tuple[float, float]], Optional[np.ndarray]) -> None 439 def _plot_result1D(data, # type: Data1D 440 theory, # type: Optional[np.ndarray] 441 resid, # type: Optional[np.ndarray] 442 view, # type: str 443 use_data, # type: bool 444 limits=None, # type: Optional[Tuple[float, float]] 445 Iq_calc=None # type: Optional[np.ndarray] 446 ): 447 # type: (...) -> None 422 448 """ 423 449 Plot the data and residuals for 1D data. … … 515 541 516 542 @protect 517 def _plot_result_sesans(data, theory, resid, use_data, limits=None): 518 # type: (SesansData, Optional[np.ndarray], Optional[np.ndarray], bool, Optional[Tuple[float, float]]) -> None 543 def _plot_result_sesans(data, # type: SesansData 544 theory, # type: Optional[np.ndarray] 545 resid, # type: Optional[np.ndarray] 546 use_data, # type: bool 547 limits=None # type: Optional[Tuple[float, float]] 548 ): 549 # type: (...) -> None 519 550 """ 520 551 Plot SESANS results. … … 560 591 561 592 @protect 562 def _plot_result2D(data, theory, resid, view, use_data, limits=None): 563 # type: (Data2D, Optional[np.ndarray], Optional[np.ndarray], str, bool, Optional[Tuple[float,float]]) -> None 593 def _plot_result2D(data, # type: Data2D 594 theory, # type: Optional[np.ndarray] 595 resid, # type: Optional[np.ndarray] 596 view, # type: str 597 use_data, # type: bool 598 limits=None # type: Optional[Tuple[float, float]] 599 ): 600 # type: (...) -> None 564 601 """ 565 602 Plot the data and residuals for 2D data. … … 596 633 _plot_2d_signal(data, target, view=view, vmin=vmin, vmax=vmax) 597 634 plt.title('data') 598 h = plt.colorbar()599 h .set_label('$I(q)$')635 handle = plt.colorbar() 636 handle.set_label('$I(q)$') 600 637 601 638 # plot theory … … 605 642 _plot_2d_signal(data, theory, view=view, vmin=vmin, vmax=vmax) 606 643 plt.title('theory') 607 h = plt.colorbar()608 h .set_label(r'$\log_{10}I(q)$' if view == 'log'609 else r'$q^4 I(q)$' if view == 'q4'610 else '$I(q)$')644 handle = plt.colorbar() 645 handle.set_label(r'$\log_{10}I(q)$' if view == 'log' 646 else r'$q^4 I(q)$' if view == 'q4' 647 else '$I(q)$') 611 648 612 649 # plot resid … … 616 653 _plot_2d_signal(data, resid, view='linear') 617 654 plt.title('residuals') 618 h = plt.colorbar()619 h .set_label(r'$\Delta I(q)$')655 handle = plt.colorbar() 656 handle.set_label(r'$\Delta I(q)$') 620 657 621 658 622 659 @protect 623 def _plot_2d_signal(data, signal, vmin=None, vmax=None, view='log'): 624 # type: (Data2D, np.ndarray, Optional[float], Optional[float], str) -> Tuple[float, float] 660 def _plot_2d_signal(data, # type: Data2D 661 signal, # type: np.ndarray 662 vmin=None, # type: Optional[float] 663 vmax=None, # type: Optional[float] 664 view='log' # type: str 665 ): 666 # type: (...) -> Tuple[float, float] 625 667 """ 626 668 Plot the target value for the data. This could be the data itself, … … 637 679 if view == 'log': 638 680 valid[valid] = (image[valid] > 0) 639 if vmin is None: vmin = image[valid & ~data.mask].min() 640 if vmax is None: vmax = image[valid & ~data.mask].max() 681 if vmin is None: 682 vmin = image[valid & ~data.mask].min() 683 if vmax is None: 684 vmax = image[valid & ~data.mask].max() 641 685 image[valid] = np.log10(image[valid]) 642 686 elif view == 'q4': 643 687 image[valid] *= (data.qx_data[valid]**2+data.qy_data[valid]**2)**2 644 if vmin is None: vmin = image[valid & ~data.mask].min() 645 if vmax is None: vmax = image[valid & ~data.mask].max() 688 if vmin is None: 689 vmin = image[valid & ~data.mask].min() 690 if vmax is None: 691 vmax = image[valid & ~data.mask].max() 646 692 else: 647 if vmin is None: vmin = image[valid & ~data.mask].min() 648 if vmax is None: vmax = image[valid & ~data.mask].max() 693 if vmin is None: 694 vmin = image[valid & ~data.mask].min() 695 if vmax is None: 696 vmax = image[valid & ~data.mask].max() 649 697 650 698 image[~valid | data.mask] = 0 … … 655 703 ymin, ymax = min(data.qy_data), max(data.qy_data) 656 704 if view == 'log': 657 vmin_scaled, vmax_scaled = np.log10(vmin), np.log10(vmax)705 vmin_scaled, vmax_scaled = np.log10(vmin), np.log10(vmax) 658 706 else: 659 707 vmin_scaled, vmax_scaled = vmin, vmax
Note: See TracChangeset
for help on using the changeset viewer.