Changeset 8696a87 in sasmodels for sasmodels/data.py
- Timestamp:
- Feb 1, 2016 4:38:33 AM (8 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:
- f12357f, 577912b
- Parents:
- 504abee (diff), 5c962df (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/data.py
r69ec80f r5c962df 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): 352 """ 353 Trap and print errors from function. 354 """ 261 355 try: 262 356 return fn(*args, **kw) 357 except KeyboardInterrupt: 358 raise 263 359 except: 264 360 traceback.print_exc() … … 332 428 @protect 333 429 def _plot_result_sesans(data, theory, resid, use_data, limits=None): 430 """ 431 Plot SESANS results. 432 """ 334 433 import matplotlib.pyplot as plt 335 434 use_data = use_data and data.y is not None … … 459 558 460 559 def demo(): 560 """ 561 Load and plot a SAS dataset. 562 """ 461 563 data = load_data('DEC07086.DAT') 462 564 set_beam_stop(data, 0.004)
Note: See TracChangeset
for help on using the changeset viewer.