ScanSamples#

class cbclib.ScanSamples(items=[])[source]#

A collection of sample cbclib.Sample objects. Provides an interface to import from and exprort to a pandas.DataFrame table and a set of dictionary methods.

detector_to_kout(x, y, setup, idxs, rec_vec=None, num_threads=1)[source]#

Project detector coordinates (x, y) to the output wave-vectors space originating from the samples’ locations.

Parameters
  • x (ndarray) – A set of x coordinates.

  • y (ndarray) – A set of y coordinates.

  • setup (ScanSetup) – Experimental setup.

  • idxs (ndarray) – Sample indices.

  • rec_vec (Optional[ndarray]) – A set of scattering vectors corresponding to the detector points.

  • num_threads (int) – Number of threads used in the calculations.

Return type

ndarray

Returns

An array of output wave-vectors.

find_rotations(from_frames, to_frames)[source]#

Find a rotation that rotates from_frames samples to to_frames.

Parameters
  • from_frames (Union[int, Sequence[int]]) – A set of indices of the samples from which rotations are calculated.

  • to_frames (Union[int, Sequence[int]]) – A set of indices of the sample to which rotations are calculated.

Return type

Union[Rotation, List[Rotation]]

Returns

A set of rotations.

classmethod import_dataframe(df)[source]#

Initialize a new ScanSamples container with a pandas.DataFrame table. The table must contain the following columns:

  • Rxx, Rxy, Rxz, Ryx, Ryy, Ryz, Rzx, Rzy, Rzz : Rotational matrix.

  • z : z coordinate [m].

Parameters

data – A pandas.DataFrame table.

Return type

ScanSamples

Returns

A new ScanSamples container.

items()[source]#

Return (index, sample) pairs stored in the container.

Return type

ItemsView[str, Sample]

Returns

(index, sample) pairs stored in the container.

keys()[source]#

Return a list of sample indices available in the container.

Return type

KeysView[str]

Returns

List of sample indices available in the container.

kin_to_sample(setup, kin=None, idxs=None, num_threads=1)[source]#

Project incident wave-vectors to the sample planes.

Parameters
  • setup (ScanSetup) – Experimental setup.

  • kin (Optional[ndarray]) – An array of incident wave-vectors.

  • idxs (Optional[ndarray]) – Sample indices.

  • num_threads (int) – Number of threads used in the calculations.

Return type

ndarray

Returns

Array of sample coordinates.

kout_to_detector(kout, setup, idxs, rec_vec=None, num_threads=1)[source]#

Project output wave-vectors originating from the samples’ locations to the detector plane.

Parameters
  • kout (ndarray) – Output wave-vectors.

  • setup (ScanSetup) – Experimental setup.

  • idxs (ndarray) – Sample indices.

  • rec_vec (Optional[ndarray]) – A set of scattering vectors corresponding to the output wave-vectors.

  • num_threads (int) – Number of threads used in the calculations.

Return type

Tuple[ndarray, ndarray]

Returns

A tuple of x and y detector coordinates.

regularise(kernel_bandwidth)[source]#

Regularise sample positions by applying a Gaussian Process with a gaussian kernel bandwidth in the given interval.

Parameters

kernel_bandwidth (Tuple[int, int]) – Inverval of gaussian kernel bandwidths to use.

Return type

ScanSamples

Returns

A new ScanSamples container with regularised sample positions.

rotate(vectors, idxs, reciprocate=False, num_threads=1)[source]#

Rotate an array of vectors into the samples’ system of coordinates.

Parameters
  • vectors (ndarray) – An array of vectors.

  • idxs (ndarray) – Sample indices.

  • reciprocate (bool) – Apply the inverse sample rotations if True.

  • num_threads (int) – Number of threads used in the calculations.

Return type

ndarray

Returns

An array of rotated vectors.

to_dataframe()[source]#

Export the sample object to a pandas.DataFrame table.

Returns

  • Rxx, Rxy, Rxz, Ryx, Ryy, Ryz, Rzx, Rzy, Rzz : Rotational matrix.

  • z : z coordinate [m].

Return type

A pandas.DataFrame table with the following columns

to_dict()[source]#

Export the sample container to a dict.

Return type

Dict[str, Sample]

Returns

A dictionary of Sample objects.

values()[source]#

Return a set of samples stored in the container.

Return type

ValuesView[Sample]

Returns

List of samples stored in the container.