tomoscan.scanbase.TomoScanBase

class tomoscan.scanbase.TomoScanBase(scan: Union[None, str], type_: str, ignore_projections: Optional[Iterable] = None)

Bases: TomoObject

Base Class representing a scan. It is used to obtain core information regarding an aquisition like projections, dark and flat field…

Parameters:

scan (Union[str,None]) – path to the root folder containing the scan.

__init__(scan: Union[None, str], type_: str, ignore_projections: Optional[Iterable] = None)

Methods

__init__(scan, type_[, ignore_projections])

clear_caches()

clear caches.

clear_frames_caches()

compute_reduced_darks([reduced_method, ...])

param ReduceMethod method:

method to compute the flats

compute_reduced_flats([reduced_method, ...])

param ReduceMethod method:

method to compute the flats

equal(other)

:param ScanBase other: instance to compare with :return: True if instance are equivalent

flat_field_correction(projs, proj_indexes[, ...])

Apply flat field correction on the given data

from_identifier(identifier)

Return the Dataset from a identifier

get_bounding_box([axis])

Return the bounding box covered by the Tomo object axis is expected to be in (0, 1, 2) or (x==0, y==1, z==2)

get_dark_expected_location()

get_dataset_basename()

get_detector_transformations(default)

get_distance([unit])

param Union[MetricSystem, str] unit:

unit requested for the distance

get_distance_expected_location()

get_energy_expected_location()

get_flat_expected_location()

get_identifier()

return the dataset identifier of the scan.

get_pixel_size([unit])

get_pixel_size_expected_location()

get_proj_angle_url()

return a dictionary of all the projection.

get_projection_expected_location()

get_projections_intensity_monitor()

return intensity monitor values for projections

get_relative_file(file_name[, ...])

param str file_name:

name of the file to create

get_sinogram(line[, subsampling, norm_method])

extract the sinogram from projections

get_volume_output_file_name([z, suffix])

if used by tomwer and nabu this should help for tomwer to find out the output files of anbu from a configuration file.

get_x_flipped([default])

get_y_flipped([default])

is_abort(**kwargs)

return:

True if the acquisition has been abort

is_tomoscan_dir(directory, **kwargs)

Check if the given directory is holding an acquisition

load_from_dict(_dict)

Load properties contained in the dictionnary.

load_reduced_darks(inputs_urls[, ...])

load reduced dark (median / mean...) into files

load_reduced_flats(inputs_urls[, ...])

load reduced dark (median / mean...) into files

map_urls_on_scan_range(urls, n_projection, ...)

map given urls to an angle regarding scan_range and number of projection.

save_reduced_darks(darks, output_urls[, ...])

Dump computed dark (median / mean...) into files

save_reduced_flats(flats, output_urls[, ...])

Dump reduced flats (median / mean...) into files

set_normed_darks(darks[, darks_infos])

set_normed_flats(flats[, flats_infos])

set_reduced_darks(darks[, darks_infos])

set_reduced_flats(flats[, flats_infos])

to_dict()

return:

convert the TomoScanBase object to a dictionary.

update()

Parse the root folder and files to update informations

Attributes

DICT_PATH_KEY

DICT_TYPE_KEY

FRAME_REDUCER_CLASS

Frame reducer class to be use in order to compute reduced darks and reduced flats

alignment_projections

dict of projections made for alignment with acquisition index as key None if not found

count_time

dark_n

darks

list of darks files

detector_transformations

return tuple of Transformation applied to the detector

dim_1

dim_2

distance

return:

sample / detector distance in meter

electric_current

Return the sample name

energy

return:

incident beam energy in keV

estimated_cor_frm_motor

return:

Estimated center of rotation estimated from motor position

ff_interval

field_of_view

return:

field of view of the scan. None if unknow else Full or Half

flat_n

flats

list of flats files

group_size

Used in the case of zseries for example.

instrument_name

return:

instrument name

intensity_monitor

intensity_normalization

magnification

normed_darks

normed_flats

path

return:

path of the scan root folder.

pixel_size

projections

if found dict of projections urls with index during acquisition as key

reduced_darks

reduced_darks_infos

reduced_flats

reduced_flats_infos

sample_name

Return the sample name

scan_range

sequence_name

Return the sequence name

source

source_name

source_type

title

tomo_n

number of projection WITHOUT the return projections

type

return:

type of the scanBase (can be 'edf' or 'hdf5' for now).

x_flipped

warning: deprecated !!!!! return True if the frames are flip through x

x_pixel_size

x_real_pixel_size

x_translation

y_flipped

warning: deprecated !!!!! return True if the frames are flip through y

y_pixel_size

y_real_pixel_size

y_translation

z_translation

ignore_projections

Extra information for normalization

FRAME_REDUCER_CLASS = None

Frame reducer class to be use in order to compute reduced darks and reduced flats

property alignment_projections: Union[None, dict]

dict of projections made for alignment with acquisition index as key None if not found

clear_caches()

clear caches. Might be call if some data changed after first read of data or metadata

compute_reduced_darks(reduced_method='mean', overwrite=True, output_dtype=None, return_info=False)
Parameters:
  • method (ReduceMethod) – method to compute the flats

  • overwrite (bool) – if some darks have already been computed will overwrite them

  • return_info (bool) – do we return (reduced_frames, info) or directly reduced_frames

compute_reduced_flats(reduced_method='median', overwrite=True, output_dtype=None, return_info=False)
Parameters:
  • method (ReduceMethod) – method to compute the flats

  • overwrite (bool) – if some flats have already been computed will overwrite them

  • return_info (bool) – do we return (reduced_frames, info) or directly reduced_frames

property darks: Union[None, dict]

list of darks files

property detector_transformations: Optional[tuple]

return tuple of Transformation applied to the detector

property distance: Union[None, float]
Returns:

sample / detector distance in meter

property electric_current: tuple

Return the sample name

property energy: Union[None, float]
Returns:

incident beam energy in keV

equal(other) bool

:param ScanBase other: instance to compare with :return: True if instance are equivalent

..note:: we cannot use the __eq__ function because this object need to be

pickable

property estimated_cor_frm_motor
Returns:

Estimated center of rotation estimated from motor position

Return type:

Union[None, float]. If return value is in [-frame_width, +frame_width]

property field_of_view
Returns:

field of view of the scan. None if unknow else Full or Half

flat_field_correction(projs: Iterable, proj_indexes: Iterable, line: Optional[int] = None)

Apply flat field correction on the given data

Parameters:
  • projs (Iterable) – list of projection (numpy array) to apply correction on

  • proj_indexes (Iterable data) – list of indexes of the projection in the acquisition sequence. Values can be int or None. If None then the index take will be the one in the middle of the flats taken.

  • line (None or int) – index of the line to apply flat filed. If not provided consider we want to apply flat filed on the entire frame

Returns:

corrected data: list of numpy array

Return type:

list

property flats: Union[None, dict]

list of flats files

static from_identifier(identifier: Union[str, BaseIdentifier])

Return the Dataset from a identifier

get_bounding_box(axis: Optional[Union[str, int]] = None) BoundingBox1D

Return the bounding box covered by the Tomo object axis is expected to be in (0, 1, 2) or (x==0, y==1, z==2)

get_distance(unit='m') Union[None, float]
Parameters:

unit (Union[MetricSystem, str]) – unit requested for the distance

Returns:

sample / detector distance with the requested unit

get_identifier() ScanIdentifier

return the dataset identifier of the scan. The identifier is insure to be unique for each scan and allow the user to store the scan as a string identifier and to retrieve it later from this single identifier.

get_proj_angle_url() dict

return a dictionary of all the projection. key is the angle of the projection and value is the url.

Keys are int for ‘standard’ projections and strings for return projections.

Return dict:

angles as keys, radios as value.

get_projections_intensity_monitor()

return intensity monitor values for projections

get_relative_file(file_name: str, with_dataset_prefix=True) Optional[str]
Parameters:
  • file_name (str) – name of the file to create

  • with_dataset_prefix (bool) – If True will prefix the requested file by the dataset name like datasetname_file_name

Returns:

path to the requested file according to the ‘Scan’ / ‘dataset’ location. Return none if Scan has no path

Return type:

Optional[str]

get_sinogram(line, subsampling=1, norm_method: Optional[str] = None, **kwargs)

extract the sinogram from projections

Parameters:
  • line (int) – which sinogram we want

  • subsampling (int) – subsampling to apply. Allows to skip some io

Returns:

computed sinogram from projections

Return type:

numpy.array

static get_volume_output_file_name(z=None, suffix=None)

if used by tomwer and nabu this should help for tomwer to find out the output files of anbu from a configuration file. Could help to get some normalization there

property group_size

Used in the case of zseries for example. Return the number of sequence expected on the acquisition

ignore_projections

Extra information for normalization

property instrument_name: Union[None, str]
Returns:

instrument name

is_abort(**kwargs) bool
Returns:

True if the acquisition has been abort

Return type:

bool

static is_tomoscan_dir(directory: str, **kwargs) bool

Check if the given directory is holding an acquisition

Parameters:

directory (str) –

Returns:

does the given directory contains any acquisition

Return type:

bool

load_from_dict(_dict: dict)

Load properties contained in the dictionnary.

Parameters:

_dict (dict) – dictionary to load

Returns:

self

Raises:

ValueError if dict is invalid

load_reduced_darks(inputs_urls: tuple, metadata_input_urls=None, return_as_url: bool = False, return_info: bool = False) Union[dict, tuple]

load reduced dark (median / mean…) into files

load_reduced_flats(inputs_urls: tuple, metadata_input_urls=None, return_as_url: bool = False, return_info: bool = False) Union[dict, tuple]

load reduced dark (median / mean…) into files

static map_urls_on_scan_range(urls, n_projection, scan_range) dict

map given urls to an angle regarding scan_range and number of projection. We take the hypothesis that ‘extra projection’ are taken regarding the ‘id19’ policy:

  • If the acquisition has a scan range of 360 then:

    • if 4 extra projection, the angles are (270, 180, 90, 0)

    • if 5 extra projection, the angles are (360, 270, 180, 90, 0)

  • If the acquisition has a scan range of 180 then:

    • if 2 extra projections: the angles are (90, 0)

    • if 3 extra projections: the angles are (180, 90, 0)

..warning:: each url should contain only one radio.

Parameters:
  • urls (dict) – dict with all the urls. First url should be the first radio acquire, last url should match the last radio acquire.

  • n_projection (int) – number of projection for the sample.

  • scan_range (float) – acquisition range (usually 180 or 360)

Returns:

angle in degree as key and url as value

Return type:

dict

Raises:

ValueError if the number of extra images found and scan_range are incoherent

property path: Union[None, str]
Returns:

path of the scan root folder.

Return type:

Union[str,None]

property projections: Union[None, dict]

if found dict of projections urls with index during acquisition as key

property sample_name

Return the sample name

save_reduced_darks(darks: dict, output_urls: tuple, darks_infos: Optional[ReducedFramesInfos] = None, metadata_output_urls: Optional[tuple] = None, overwrite: bool = False) None

Dump computed dark (median / mean…) into files

save_reduced_flats(flats: dict, output_urls: tuple, flats_infos: Optional[ReducedFramesInfos] = None, metadata_output_urls: Optional[tuple] = None, overwrite: bool = False) None

Dump reduced flats (median / mean…) into files

property sequence_name

Return the sequence name

to_dict() dict
Returns:

convert the TomoScanBase object to a dictionary. Used to serialize the object for example.

Return type:

dict

property tomo_n: Union[None, int]

number of projection WITHOUT the return projections

property type: str
Returns:

type of the scanBase (can be ‘edf’ or ‘hdf5’ for now).

Return type:

str

update() None

Parse the root folder and files to update informations

property x_flipped: bool

warning: deprecated !!!!! return True if the frames are flip through x

property y_flipped: bool

warning: deprecated !!!!! return True if the frames are flip through y