Changes in / [ed82794:d07c883] in sasmodels
- Location:
- sasmodels
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/compare.py
r190fc2b r190fc2b 604 604 def columnize(L, indent="", width=79): 605 605 """ 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. 607 609 """ 608 610 column_width = max(len(w) for w in L) + 1 -
sasmodels/core.py
r190fc2b r190fc2b 38 38 """ 39 39 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. 40 43 """ 41 44 __import__('sasmodels.models.'+model_name) -
sasmodels/data.py
r69ec80f r299edd2 87 87 88 88 class 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 """ 89 115 def __init__(self, x=None, y=None, dx=None, dy=None): 90 116 self.x, self.y, self.dx, self.dy = x, y, dx, dy … … 93 119 self.qmin = x.min() if x is not None else np.NaN 94 120 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) 96 125 self._xaxis, self._xunit = "x", "" 97 126 self._yaxis, self._yunit = "y", "" … … 114 143 115 144 class 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 """ 116 176 def __init__(self, x=None, y=None, z=None, dx=None, dy=None, dz=None): 117 177 self.qx_data, self.dqx_data = x, dx 118 178 self.qy_data, self.dqy_data = y, dy 119 179 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) 121 183 self.q_data = np.sqrt(x**2 + y**2) 122 184 self.qmin = 1e-16 … … 126 188 self.Q_unit = "1/A" 127 189 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") 131 193 self._xaxis, self._xunit = "x", "" 132 194 self._yaxis, self._yunit = "y", "" … … 157 219 158 220 class Vector(object): 221 """ 222 3-space vector of *x*, *y*, *z* 223 """ 159 224 def __init__(self, x=None, y=None, z=None): 160 225 self.x, self.y, self.z = x, y, z … … 235 300 """ 236 301 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. 237 309 """ 238 310 # Note: kind of weird using the plot result functions to plot just the … … 249 321 def plot_theory(data, theory, resid=None, view='log', 250 322 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 """ 251 338 if hasattr(data, 'lam'): 252 339 _plot_result_sesans(data, theory, resid, use_data=True, limits=limits) … … 258 345 259 346 def protect(fn): 347 """ 348 Decorator to wrap calls in an exception trapper which prints the 349 exception and continues. Keyboard interrupts are ignored. 350 """ 260 351 def wrapper(*args, **kw): 261 352 try: 262 353 return fn(*args, **kw) 354 except KeyboardInterrupt: 355 raise 263 356 except: 264 357 traceback.print_exc() … … 332 425 @protect 333 426 def _plot_result_sesans(data, theory, resid, use_data, limits=None): 427 """ 428 Plot SESANS results. 429 """ 334 430 import matplotlib.pyplot as plt 335 431 use_data = use_data and data.y is not None … … 459 555 460 556 def demo(): 557 """ 558 Load and plot a SAS dataset. 559 """ 461 560 data = load_data('DEC07086.DAT') 462 561 set_beam_stop(data, 0.004)
Note: See TracChangeset
for help on using the changeset viewer.