Skip to content

nabu.resources.dataset_base

source module nabu.resources.dataset_base

Classes

  • Dataset Base class for datasets analyzers. This class is a "blueprint" for all dataset that will be processed by Nabu. It exposes the fields that will be used by processing classes.

Functions

  • dataset_field Some dark arts to avoid boilerplate for many setters/getters. Not sure if it's a good idea.

  • check_dataset_fields Validate a "dataset" instance by checking it has all required fields/methods.

  • get_angle_at_index Return the rotation angle corresponding to image index 'index'

  • get_radio_pair Get closest radios at radio_angles[0] and radio_angles[1] angles must be in angles

source class Dataset(location, extra_options=None)

Base class for datasets analyzers. This class is a "blueprint" for all dataset that will be processed by Nabu. It exposes the fields that will be used by processing classes.

Initialize a Dataset analyzer.

Parameters

  • location : str Dataset location (directory, file name, ...)

  • extra_options : dict, optional Extra options on how to interpret the dataset.

Methods

  • get_frame Get the frame(s) corresponding to index 'idx'. The frame can be a projection, dark, flat, ...

  • get_frames_indices Return an array of indices corresponding to frames 'frame_type'. For example, if all the data consists in 1 dark, 10 flats, and then 1000 projections, then get_frames_indices("projections") will return np.arange(11, 1011)

  • index_to_proj_number Return the projection number, from its frame index.

  • get_index_from_angle Return the index of the image taken at rotation angle 'angle' (in radians). By default look at the projections.

  • get_image_at_angle Get the frame corresponding to angle "angle".

  • get_excluded_projections_indices Return a list of indices corresponding to excluded projections. Depending on 'including_other_frames_types', this can be either: - A list of frames indices: the indices account for other frames types (flats, darks, etc) - A list of projection numbers otherwise

  • get_alignment_projections Get the extra projections (if any) that are used as "reference projections" for alignment. For certain scan, when completing a (half) turn, sometimes extra projections are acquired for alignment purpose.

source method Dataset.get_frame(idx)

Get the frame(s) corresponding to index 'idx'. The frame can be a projection, dark, flat, ...

source method Dataset.get_frames_indices(frame_type)

Return an array of indices corresponding to frames 'frame_type'. For example, if all the data consists in 1 dark, 10 flats, and then 1000 projections, then get_frames_indices("projections") will return np.arange(11, 1011)

source method Dataset.index_to_proj_number(proj_index)

Return the projection number, from its frame index.

For example if there are 11 flats before projections, then projections will have indices [11, 12, .....] (possibly not contiguous) while their number is [0, 1, ..., ] (contiguous, starts from 0)

source method Dataset.get_index_from_angle(angle_rad, frame_type='projection', return_found_angle=False)

Return the index of the image taken at rotation angle 'angle' (in radians). By default look at the projections.

source method Dataset.get_image_at_angle(angle_rad, frame_type='projection', sub_region=None, return_angle_and_index=False)

Get the frame corresponding to angle "angle".

Parameters

  • angle : float Rotation angle in radians.

  • frame_type : str, optional Frame type to select. Default is "projection"

  • sub_region : tuple, optional Tuple defining a region of interest in the image to return. Shold be in the form (slice(y_start, y_end), slice(x_start, x_stop))

  • return_angle_and_index : bool optional Whether to also return angle found and index found (by bisection)

source method Dataset.get_excluded_projections_indices(including_other_frames_types=True)

Return a list of indices corresponding to excluded projections. Depending on 'including_other_frames_types', this can be either: - A list of frames indices: the indices account for other frames types (flats, darks, etc) - A list of projection numbers otherwise

Example

Let's suppose that the dataset consists in 1 dark, 3 flats, 10 projections, 3 flats, 10 projections, and that the two last projections are excluded. Before excluding projections : - The projections numbers are: [0, 1, ..., 19] (there are 20 projections before exclusion) - The projections frames indices are: [4, 5, 6, ..., 12, 13, 17, 18, ..., 26] Therefore, get_excluded_projections_indices() will return: - [25, 26] if including_other_frames_types is True - [18, 19] otherwise

source method Dataset.get_alignment_projections(image_sub_region=None, return_in_radians=None)

Get the extra projections (if any) that are used as "reference projections" for alignment. For certain scan, when completing a (half) turn, sometimes extra projections are acquired for alignment purpose.

Returns

  • projs : numpy.ndarray Array with shape (n_projections, n_y, n_x)

  • angles : numpy.ndarray Corresponding angles in degrees

  • indices Indices of projections

source dataset_field(name, doc=None, raise_error_if_not_implemented=False)

Some dark arts to avoid boilerplate for many setters/getters. Not sure if it's a good idea.

Raises

  • NotImplementedError

source check_dataset_fields(dataset_info, ignore_fields=None, other_required_fields=None, on_missing='raise')

Validate a "dataset" instance by checking it has all required fields/methods.

Parameters

  • dataset_info : Dataset Instance of a Dataset (sub)class

  • ignore_fields : list, optional Attribute names to ignore for this specific class. For example, if you don't want that a missing energy field raise an error, then you can use ignore_fields=["energy"]

  • other_required_fields : list, optional Extra required fields that should be checked

  • on_missing : str, optional What to do if a required field is missing. Can be: - "raise": raise an error - "warn": issue a warning

Caution

Calling this function on a "dataset_info" instance might cause it to do some calculations. For example, for NXTomoDataset, dataset_info.flats might perform flats reduction under the hood.

Raises

  • ValueError

source get_angle_at_index(all_angles, index)

Return the rotation angle corresponding to image index 'index'

source get_radio_pair(dataset_info, query_angles, return_indices=False)

Get closest radios at radio_angles[0] and radio_angles[1] angles must be in angles

Parameters

  • dataset_info : DatasetAnalyzer instance Data structure with the dataset information

  • radio_angles : tuple tuple of two elements: angles (in radian) to get

  • return_indices : bool, optional Whether to return radios indices along with the radios array.

Returns

  • res : array or tuple If return_indices is True, return a tuple (radios, indices). Otherwise, return an array with the radios.

Notes

The query angles are searched in 'dataset_info.all_angles', where the angles are unwrapped. So it's possible to use values like 4*pi.