8. Data layout and plotting routines

sasmodels.data

SAS data representations.

Plotting functions for data sets:

plot_data() plots the data file.

plot_theory() plots a calculated result from the model.

Wrappers for the sasview data loader and data manipulations:

load_data() loads a sasview data file.

set_beam_stop() masks the beam stop from the data.

set_half() selects the right or left half of the data, which can be useful for shear measurements which have not been properly corrected for path length and reflections.

set_top() cuts the top part off the data.

Empty data sets for evaluating models without data:

empty_data1D() creates an empty dataset, which is useful for plotting a theory function before the data is measured.

empty_data2D() creates an empty 2D dataset.

Note that the empty datasets use a minimal representation of the SasView objects so that models can be run without SasView on the path. You could also use these for your own data loader.

class sasmodels.data.Data1D(x: Optional[numpy.ndarray] = None, y: Optional[numpy.ndarray] = None, dx: Optional[numpy.ndarray] = None, dy: Optional[numpy.ndarray] = None)

Bases: object

1D data object.

Note that this definition matches the attributes from sasview, with some generic 1D data vectors and some SAS specific definitions. Some refactoring to allow consistent naming conventions between 1D, 2D and SESANS data would be helpful.

Attributes

x, dx: \(q\) vector and gaussian resolution

y, dy: \(I(q)\) vector and measurement uncertainty

mask: values to include in plotting/analysis

dxl: slit widths for slit smeared data, with dx ignored

qmin, qmax: range of \(q\) values in x

filename: label for the data line

_xaxis, _xunit: label and units for the x axis

_yaxis, _yunit: label and units for the y axis

xaxis(label: str, unit: str) → None

set the x axis label and unit

yaxis(label: str, unit: str) → None

set the y axis label and unit

class sasmodels.data.Data2D(x: Optional[numpy.ndarray] = None, y: Optional[numpy.ndarray] = None, z: Optional[numpy.ndarray] = None, dx: Optional[numpy.ndarray] = None, dy: Optional[numpy.ndarray] = None, dz: Optional[numpy.ndarray] = None)

Bases: object

2D data object.

Note that this definition matches the attributes from sasview. Some refactoring to allow consistent naming conventions between 1D, 2D and SESANS data would be helpful.

Attributes

qx_data, dqx_data: \(q_x\) matrix and gaussian resolution

qy_data, dqy_data: \(q_y\) matrix and gaussian resolution

data, err_data: \(I(q)\) matrix and measurement uncertainty

mask: values to exclude from plotting/analysis

qmin, qmax: range of \(q\) values in x

filename: label for the data line

_xaxis, _xunit: label and units for the x axis

_yaxis, _yunit: label and units for the y axis

_zaxis, _zunit: label and units for the y axis

Q_unit, I_unit: units for Q and intensity

x_bins, y_bins: grid steps in x and y directions

xaxis(label: str, unit: str) → None

set the x axis label and unit

yaxis(label: str, unit: str) → None

set the y axis label and unit

zaxis(label: str, unit: str) → None

set the y axis label and unit

class sasmodels.data.Detector(pixel_size: Tuple[float, float] = (None, None), distance: float = None)

Bases: object

Detector attributes.

class sasmodels.data.Sample

Bases: object

Sample attributes.

class sasmodels.data.SesansData(**kw)

Bases: sasmodels.data.Data1D

SESANS data object.

This is just Data1D with a wavelength parameter.

x is spin echo length and y is polarization (P/P0).

xaxis(label: str, unit: str) → None

set the x axis label and unit

yaxis(label: str, unit: str) → None

set the y axis label and unit

isSesans = True
class sasmodels.data.Source

Bases: object

Beam attributes.

class sasmodels.data.Vector(x: Optional[float] = None, y: Optional[float] = None, z: Optional[float] = None)

Bases: object

3-space vector of x, y, z

sasmodels.data.demo() → None

Load and plot a SAS dataset.

sasmodels.data.empty_data1D()

Create empty 1D data using the given q as the x value.

rms resolution \(\Delta q/q\) defaults to 0%. If wavelength L and rms wavelength divergence dL are defined, then resolution defines rms \(\Delta \theta/\theta\) for the lowest q, with \(\theta\) derived from \(q = 4\pi/\lambda \sin(\theta)\).

sasmodels.data.empty_data2D(qx: numpy.ndarray, qy: Optional[numpy.ndarray] = None, resolution: float = 0.0)sasmodels.data.Data2D

Create empty 2D data using the given mesh.

If qy is missing, create a square mesh with qy=qx.

resolution dq/q defaults to 5%.

sasmodels.data.load_data()

Load data using a sasview loader.

sasmodels.data.plot_data(data: Data, view: str = None, limits: Optional[Tuple[float, float]] = None) → None

Plot data loaded by the sasview loader.

data is a sasview data object, either 1D, 2D or SESANS.

view is log or linear.

limits sets the intensity limits on the plot; if None then the limits are inferred from the data.

sasmodels.data.plot_theory(data: Union[sasmodels.data.Data1D, sasmodels.data.Data2D, sasmodels.data.SesansData], theory: Optional[numpy.ndarray], resid: Optional[numpy.ndarray] = None, view: Optional[str] = None, use_data: bool = True, limits: Optional[numpy.ndarray] = None, Iq_calc: Optional[numpy.ndarray] = None) → None

Plot theory calculation.

data is needed to define the graph properties such as labels and units, and to define the data mask.

theory is a matrix of the same shape as the data.

view is log or linear

use_data is True if the data should be plotted as well as the theory.

limits sets the intensity limits on the plot; if None then the limits are inferred from the data.

Iq_calc is the raw theory values without resolution smearing

sasmodels.data.protect(func: Callable) → Callable

Decorator to wrap calls in an exception trapper which prints the exception and continues. Keyboard interrupts are ignored.

sasmodels.data.set_beam_stop(data: Union[sasmodels.data.Data1D, sasmodels.data.Data2D, sasmodels.data.SesansData], radius: float, outer: Optional[float] = None) → None

Add a beam stop of the given radius. If outer, make an annulus.

sasmodels.data.set_half(data: Union[sasmodels.data.Data1D, sasmodels.data.Data2D, sasmodels.data.SesansData], half: str) → None

Select half of the data, either “right” or “left”.

sasmodels.data.set_top(data: Union[sasmodels.data.Data1D, sasmodels.data.Data2D, sasmodels.data.SesansData], cutoff: float) → None

Chop the top off the data, above cutoff.