Data and Datastack

Data

The escape.core.data module provides methods to create data_obj and datastack_obj.

The data_obj is a container class for experimental data. Data object is created with the following command:

>>> d = esc.data(name="Data name", coordinates, experiment, errors=None, mask=None, copy=False)

The data command expects all input arrays to have numpy.ndarray type. If not, they will be comverted and copied regardless of copy parameter.

All arrays will be copied if copy parameter is True, otherwise data_obj operates with wrappers of arrays if possible. If errors parameter is None, the experimental errors will be calculated according to Poisson distribution, i.e. errors=sqrt(experiment). The mask parameter is an array of boolean type and is used if some data points should be hidden.

Data object has a domain_size property which returns number of coordinates corresponding to a single intensity value in the input array. For example, two-dimensional data correspond to a modeled function \(F(x, y)\) and its coordinates array is expected to have the form of \([x0, y0, x1, y1, x2, y2, ...]\).

Two-dimensional arrays of the following form

coordinates=[
     [x0, y0],
     [x1, y1],
     [x2, y2]
 ]

are also supported will be flatten and always copied.

Datastack

Datastack class datastack_obj is a container for data objects. It is used in modelstack to set or return all data for all models at once.

To create a datastack object use Helper function of the same name:

>>> s = datastack("Name")
escape.core.data.data(name, coordinates, intensities, errors=None, mask=None, copy=False)

Returns a data_obj - container for experimental data.

Parameters:
name: string

Name of data object

coordinates: numpy.ndarray or list

Array with coordinates of intensity values, for example, on the detector. Scattering functors normally require scattering or wave-vector components as coordinates.

intensities: numpy.ndarray or list

Array with intensity values. The ratio between length of the coordinates array and intensities array defines data domain size.

errors: numpy.ndarray or list

Array with errors values. By default errors are calculated as square root of intensities, i.e. Poisson distribution. Set custom errors values if Poisson distribution is not the proper choice for your application. Errors should have the same length as intensities array.

mask: numpy.ndarray or list

Use mask array to mask unnecessary data points. Intensities with False mask will not be taken into account. Mask should have the same length as intensities array.

copy: boolean

If True all arrays will be copied and handled by data_obj. In the case of limited memory or very large data, set it to False (default), all arrays data pointers, if possible, will be wrapped.

Returns:

object of type data_obj

escape.core.data.datastack(name, data=None)

Returns a datastack_obj - container for data objects.

Parameters:
name: string

Name of data object

data: data_obj or list of data_obj

Single instance of data_obj or list with data_obj instances

Returns:

object of type datastack_obj

class escape.core.data.data_obj
coordinates
Returns:

Coordinates array. Masked points are ignored.

domain_size
Returns:

Domain size of data instance. Number of coordinates per single intensity point.

errors
Returns:

Errors array. Masked points are ignored.

ini_coordinates
Returns:

Initial coordinates array. Mask is ignored.

ini_errors
Returns:

Initial errors array. Mask is ignored.

ini_intensities
Returns:

Initial intensities array. Mask is ignored.

intensities
Returns:

Intensities array. Masked points are ignored.

mask
Returns:

Mask array.

name
Returns:

Name of data object

num_of_params
parameter(self, size_t i)
reset_mask(self)

Erases mask from the data.

set_mask(self, mask, copy=False)

Set mask array for the data. Mask is used to hide certain data points.

Parameters:
mask: list or ndarray

Mask array. It should be an array with elements of boolean type. The length of mask array should be the same as of intensities array.

copy: bool

If True the source data will be always copied. If False and source doesn’t own its data, i.e. source is an array view, source array will be not copied. If source doesn’t own its data and copying is not required, the returned object will always hold a source copy.

class escape.core.data.datastack_obj
add(self, data_obj obj)

Appends data object to the end of the datastack

Parameters:
obj: data_obj

data object to add

data(self, size_t idx)

Returns data object.

Parameters:
idx: size_t

Data index

Returns:

object of type data_obj

data_length

Returns full data length.

Returns:

positive integer

erase(self, size_t idx)

Erases existing data object

Parameters:
idx: size_t

data index

erase_all(self)

Erases all data objects

name

Returns name of datastack instance

num_of_params

Returns number of parameters

parameter(self, size_t idx)

Returns parameter

Parameters:
idx: size_t

parameter index

Returns:

parameter instance of type parameter_obj

set(self, size_t idx, data_obj obj)

Replaces existing data object at the given index by a new data object

Parameters:
idx: size_t

data index

obj: data_obj

new data