Changes in / [ed82794:d07c883] in sasmodels


Ignore:
Location:
sasmodels
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/compare.py

    r190fc2b r190fc2b  
    604604def columnize(L, indent="", width=79): 
    605605    """ 
    606     Format a list of strings into columns for printing. 
     606    Format a list of strings into columns. 
     607 
     608    Returns a string with carriage returns ready for printing. 
    607609    """ 
    608610    column_width = max(len(w) for w in L) + 1 
  • sasmodels/core.py

    r190fc2b r190fc2b  
    3838    """ 
    3939    Load a model definition given the model name. 
     40 
     41    This returns a handle to the module defining the model.  This can be 
     42    used with functions in generate to build the docs or extract model info. 
    4043    """ 
    4144    __import__('sasmodels.models.'+model_name) 
  • sasmodels/data.py

    r69ec80f r299edd2  
    8787 
    8888class Data1D(object): 
     89    """ 
     90    1D data object. 
     91 
     92    Note that this definition matches the attributes from sasview, with 
     93    some generic 1D data vectors and some SAS specific definitions.  Some 
     94    refactoring to allow consistent naming conventions between 1D, 2D and 
     95    SESANS data would be helpful. 
     96 
     97    **Attributes** 
     98 
     99    *x*, *dx*: $q$ vector and gaussian resolution 
     100 
     101    *y*, *dy*: $I(q)$ vector and measurement uncertainty 
     102 
     103    *mask*: values to include in plotting/analysis 
     104 
     105    *dxl*: slit widths for slit smeared data, with *dx* ignored 
     106 
     107    *qmin*, *qmax*: range of $q$ values in *x* 
     108 
     109    *filename*: label for the data line 
     110 
     111    *_xaxis*, *_xunit*: label and units for the *x* axis 
     112 
     113    *_yaxis*, *_yunit*: label and units for the *y* axis 
     114    """ 
    89115    def __init__(self, x=None, y=None, dx=None, dy=None): 
    90116        self.x, self.y, self.dx, self.dy = x, y, dx, dy 
     
    93119        self.qmin = x.min() if x is not None else np.NaN 
    94120        self.qmax = x.max() if x is not None else np.NaN 
    95         self.mask = np.isnan(y) if y is not None else None 
     121        # TODO: why is 1D mask False and 2D mask True? 
     122        self.mask = (np.isnan(y) if y is not None 
     123                     else np.zeros_like(x,'b') if x is not None 
     124                     else None) 
    96125        self._xaxis, self._xunit = "x", "" 
    97126        self._yaxis, self._yunit = "y", "" 
     
    114143 
    115144class Data2D(object): 
     145    """ 
     146    2D data object. 
     147 
     148    Note that this definition matches the attributes from sasview. Some 
     149    refactoring to allow consistent naming conventions between 1D, 2D and 
     150    SESANS data would be helpful. 
     151 
     152    **Attributes** 
     153 
     154    *qx_data*, *dqx_data*: $q_x$ matrix and gaussian resolution 
     155 
     156    *qy_data*, *dqy_data*: $q_y$ matrix and gaussian resolution 
     157 
     158    *data*, *err_data*: $I(q)$ matrix and measurement uncertainty 
     159 
     160    *mask*: values to exclude from plotting/analysis 
     161 
     162    *qmin*, *qmax*: range of $q$ values in *x* 
     163 
     164    *filename*: label for the data line 
     165 
     166    *_xaxis*, *_xunit*: label and units for the *x* axis 
     167 
     168    *_yaxis*, *_yunit*: label and units for the *y* axis 
     169 
     170    *_zaxis*, *_zunit*: label and units for the *y* axis 
     171 
     172    *Q_unit*, *I_unit*: units for Q and intensity 
     173 
     174    *x_bins*, *y_bins*: grid steps in *x* and *y* directions 
     175    """ 
    116176    def __init__(self, x=None, y=None, z=None, dx=None, dy=None, dz=None): 
    117177        self.qx_data, self.dqx_data = x, dx 
    118178        self.qy_data, self.dqy_data = y, dy 
    119179        self.data, self.err_data = z, dz 
    120         self.mask = ~np.isnan(z) if z is not None else None 
     180        self.mask = (~np.isnan(z) if z is not None 
     181                     else np.ones_like(x) if x is not None 
     182                     else None) 
    121183        self.q_data = np.sqrt(x**2 + y**2) 
    122184        self.qmin = 1e-16 
     
    126188        self.Q_unit = "1/A" 
    127189        self.I_unit = "1/cm" 
    128         self.xaxis("Q_x", "A^{-1}") 
    129         self.yaxis("Q_y", "A^{-1}") 
    130         self.zaxis("Intensity", r"\text{cm}^{-1}") 
     190        self.xaxis("Q_x", "1/A") 
     191        self.yaxis("Q_y", "1/A") 
     192        self.zaxis("Intensity", "1/cm") 
    131193        self._xaxis, self._xunit = "x", "" 
    132194        self._yaxis, self._yunit = "y", "" 
     
    157219 
    158220class Vector(object): 
     221    """ 
     222    3-space vector of *x*, *y*, *z* 
     223    """ 
    159224    def __init__(self, x=None, y=None, z=None): 
    160225        self.x, self.y, self.z = x, y, z 
     
    235300    """ 
    236301    Plot data loaded by the sasview loader. 
     302 
     303    *data* is a sasview data object, either 1D, 2D or SESANS. 
     304 
     305    *view* is log or linear. 
     306 
     307    *limits* sets the intensity limits on the plot; if None then the limits 
     308    are inferred from the data. 
    237309    """ 
    238310    # Note: kind of weird using the plot result functions to plot just the 
     
    249321def plot_theory(data, theory, resid=None, view='log', 
    250322                use_data=True, limits=None): 
     323    """ 
     324    Plot theory calculation. 
     325 
     326    *data* is needed to define the graph properties such as labels and 
     327    units, and to define the data mask. 
     328 
     329    *theory* is a matrix of the same shape as the data. 
     330 
     331    *view* is log or linear 
     332 
     333    *use_data* is True if the data should be plotted as well as the theory. 
     334 
     335    *limits* sets the intensity limits on the plot; if None then the limits 
     336    are inferred from the data. 
     337    """ 
    251338    if hasattr(data, 'lam'): 
    252339        _plot_result_sesans(data, theory, resid, use_data=True, limits=limits) 
     
    258345 
    259346def protect(fn): 
     347    """ 
     348    Decorator to wrap calls in an exception trapper which prints the 
     349    exception and continues.  Keyboard interrupts are ignored. 
     350    """ 
    260351    def wrapper(*args, **kw): 
    261352        try: 
    262353            return fn(*args, **kw) 
     354        except KeyboardInterrupt: 
     355            raise 
    263356        except: 
    264357            traceback.print_exc() 
     
    332425@protect 
    333426def _plot_result_sesans(data, theory, resid, use_data, limits=None): 
     427    """ 
     428    Plot SESANS results. 
     429    """ 
    334430    import matplotlib.pyplot as plt 
    335431    use_data = use_data and data.y is not None 
     
    459555 
    460556def demo(): 
     557    """ 
     558    Load and plot a SAS dataset. 
     559    """ 
    461560    data = load_data('DEC07086.DAT') 
    462561    set_beam_stop(data, 0.004) 
Note: See TracChangeset for help on using the changeset viewer.