dival.datasets.angle_subset_dataset module

dival.datasets.angle_subset_dataset.get_angle_subset_dataset(dataset, num_angles, **kwargs)[source]

Return a AngleSubsetDataset with a reduced number of angles. The angles in the subset are equidistant if the original angles are.

Parameters
  • dataset (Dataset) – Basis CT dataset. The number of angles must be divisible by num_angles.

  • num_angles (int) – Number of angles in the subset.

  • arguments are passed to AngleSubsetDataset.__init__. (Keyword) –

Raises

ValueError – If the number of angles of dataset is not divisible by num_angles.

Returns

angle_subset_dataset – The dataset with the reduced number of angles.

Return type

AngleSubsetDataset

class dival.datasets.angle_subset_dataset.AngleSubsetDataset(dataset, angle_indices, impl=None)[source]

Bases: dival.datasets.dataset.Dataset

CT dataset that selects a subset of the angles of a basis CT dataset.

__init__(dataset, angle_indices, impl=None)[source]
Parameters
  • dataset (Dataset) –

    Basis CT dataset. Requirements:

    • sample elements are (observation, ground_truth)

    • get_ray_trafo() gives corresponding ray transform.

  • angle_indices (array-like or slice) – Indices of the angles to use from the observations.

  • impl ({'skimage', 'astra_cpu', 'astra_cuda'}, optional) – Implementation passed to odl.tomo.RayTransform to construct ray_trafo.

get_ray_trafo(**kwargs)[source]

Return the ray transform that matches the subset of angles specified to the constructor via angle_indices.

generator(part='train')[source]

Yield data.

The default implementation calls get_sample() if the dataset implements it (i.e., supports random access).

Parameters

part ({'train', 'validation', 'test'}, optional) – Whether to yield train, validation or test data. Default is 'train'.

Yields

data (odl element or tuple of odl elements) – Sample of the dataset.

get_sample(index, part='train', out=None)[source]

Get single sample by index.

Parameters
  • index (int) – Index of the sample.

  • part ({'train', 'validation', 'test'}, optional) – The data part. Default is 'train'.

  • out (array-like or tuple of (array-like or bool) or None) –

    Array(s) (or e.g. odl element(s)) to which the sample is written. A tuple should be passed, if the dataset returns two or more arrays per sample (i.e. pairs, …). If a tuple element is a bool, it has the following meaning:

    True

    Create a new array and return it.

    False

    Do not return this array, i.e. None is returned.

Returns

sample – E.g. for a pair dataset: (array, None) if out=(True, False).

Return type

[tuple of ] (array-like or None)

get_samples(key, part='train', out=None)[source]

Get samples by slice or range.

The default implementation calls get_sample() if the dataset implements it.

Parameters
  • key (slice or range) – Indexes of the samples.

  • part ({'train', 'validation', 'test'}, optional) – The data part. Default is 'train'.

  • out (array-like or tuple of (array-like or bool) or None) –

    Array(s) (or e.g. odl element(s)) to which the sample is written. The first dimension must match the number of samples requested. A tuple should be passed, if the dataset returns two or more arrays per sample (i.e. pairs, …). If a tuple element is a bool, it has the following meaning:

    True

    Create a new array and return it.

    False

    Do not return this array, i.e. None is returned.

Returns

samples – If the dataset has multiple arrays per sample, a tuple holding arrays is returned. E.g. for a pair dataset: (array, None) if out=(True, False). The samples are stacked in the first (additional) dimension of each array.

Return type

[tuple of ] (array-like or None)