tomoscan.esrf.scan.edfscan.EDFTomoScan

class tomoscan.esrf.scan.edfscan.EDFTomoScan(scan: Optional[str], dataset_basename: Optional[str] = None, scan_info: Optional[dict] = None, n_frames: Optional[int] = None, ignore_projections: Optional[Iterable] = None)

Bases: TomoScanBase

TomoScanBase instanciation for scan defined from .edf files

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

  • dataset_basename – prefix of the dataset to handle

  • scan_info – dictionary providing dataset information. Provided keys will overwrite information contained in .info. Valid keys are: TODO

  • n_frames (Union[int, None]=None) – Number of frames in each EDF file. If not provided, it will be inferred by reading the files. In this case, the frame number is guessed from the file name.

Type:

Optional[str]

Type:

Optional[dict]

__init__(scan: Optional[str], dataset_basename: Optional[str] = None, scan_info: Optional[dict] = None, n_frames: Optional[int] = None, ignore_projections: Optional[Iterable] = None)

Methods

__init__(scan[, dataset_basename, ...])

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_dark_n(scan[, dataset_basename, scan_info])

get_darks_url(scan_path[, dataset_basename, ...])

param scan_path:

get_dataset_basename()

get_detector_transformations(default)

get_dim1_dim2(scan[, dataset_basename, ...])

get_distance([unit])

param Union[MetricSystem, str] unit:

unit requested for the distance

get_distance_expected_location()

get_energy_expected_location()

get_ff_interval(scan[, dataset_basename, ...])

get_flat_expected_location()

get_flats_url(scan_path[, dataset_basename, ...])

param scan_path:

get_identifier()

return the dataset identifier of the scan.

get_info_file(directory[, dataset_basename])

get_info_file_path(scan)

get_pixel_size([unit])

get_pixel_size_expected_location()

get_proj_angle_url()

return a dictionary of all the projection.

get_proj_urls(scan[, dataset_basename, n_frames])

Return the dict of radios / projection for the given scan.

get_projection_expected_location()

get_projections_intensity_monitor()

return intensity monitor values for projections

get_range()

get_ref_n(scan[, dataset_basename, scan_info])

get_relative_file(file_name[, ...])

param str file_name:

name of the file to create

get_scan_range(scan[, dataset_basename, ...])

get_sinogram(line[, subsampling, norm_method])

extract the sinogram from projections

get_tomo_n(scan[, dataset_basename, scan_info])

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])

guess_index_frm_file_name(_file, basename)

Guess the index of the file.

is_a_proj_path(fileName, scanID[, ...])

Return True if the given fileName can fit to a Radio name

is_abort(**kwargs)

return:

True if the acquisition has been abort

is_tomoscan_dir(directory[, dataset_basename])

Check if the given directory is holding an acquisition

load_from_dict(desc)

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.

retrieve_information(scan, dataset_basename, ...)

Try to retrieve information a .info file, an .xml or a flat field file.

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

ABORT_FILE

DICT_PATH_KEY

DICT_TYPE_KEY

INFO_EXT

REDUCED_DARKS_DATAURLS

REDUCED_DARKS_METADATAURLS

REDUCED_FLATS_DATAURLS

REDUCED_FLATS_METADATAURLS

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

dataset_basename

detector_transformations

not handled for EDF

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_info

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

For EDF only square pixel size is handled

x_real_pixel_size

x_translation

y_flipped

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

y_pixel_size

For EDF only square pixel size is handled

y_real_pixel_size

y_translation

z_translation

FRAME_REDUCER_CLASS

alias of EDFFrameReducer

property alignment_projections: None

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=<class 'numpy.uint16'>, 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

compute_reduced_flats(reduced_method='median', overwrite=True, output_dtype=<class 'numpy.int32'>, 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: dict

list of darks files

property detector_transformations: Optional[tuple]

not handled for EDF

property distance: Union[None, float]
Returns:

sample / detector distance in meter

property electric_current: tuple

Return the sample name

property energy
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)

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)

static get_darks_url(scan_path: str, dataset_basename: Optional[str] = None, prefix: str = 'dark', file_ext: str = '.edf') dict
Parameters:
  • scan_path (str) –

  • prefix (str) – flat file prefix

  • file_ext (str) – flat file extension

Returns:

list of flat frames as silx’s DataUrl

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

static get_flats_url(scan_path: str, dataset_basename: Optional[str] = None, prefix: str = 'refHST', file_ext: str = '.edf', ignore=None) dict
Parameters:
  • scan_path (str) –

  • prefix (str) – flat frame file prefix

  • file_ext (str) – flat frame file extension

Returns:

list of refs as silx’s DataUrl

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.

static get_proj_urls(scan: str, dataset_basename: Optional[str] = None, n_frames: Optional[int] = None) dict

Return the dict of radios / projection for the given scan. Keys of the dictionary is the slice number Return all the file on the root of scan starting by the name of scan and ending by .edf

Parameters:
  • scan (str) – is the path to the folder of acquisition

  • n_frames (int) – Number of frames in each EDF file. If not provided, it is inferred by reading each file.

Returns:

dict of radios files with radio index as key and file as value

Return type:

dict

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

static guess_index_frm_file_name(_file: str, basename: str) Union[None, int]

Guess the index of the file. Index is most of the an integer but can be a float for ‘ref’ for example if several are taken.

Parameters:
  • _file

  • basename

ignore_projections

Extra information for normalization

property instrument_name: Union[None, str]
Returns:

instrument name

static is_a_proj_path(fileName: str, scanID: str, dataset_basename: Optional[str] = None) bool

Return True if the given fileName can fit to a Radio name

is_abort(**kwargs) bool
Returns:

True if the acquisition has been abort

Return type:

bool

static is_tomoscan_dir(directory: str, dataset_basename: Optional[str] = None, **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(desc: Union[dict, TextIOWrapper])

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 = (DataUrl(valid=True, scheme='silx', file_path='{scan_prefix}_darks.hdf5', data_path='{entry}/darks/{index}', data_slice=None), DataUrl(valid=True, scheme='fabio', file_path='dark.edf', data_path=None, data_slice=None)), metadata_input_urls: tuple = (DataUrl(valid=True, scheme='silx', file_path='{scan_prefix}_darks.hdf5', data_path='{entry}/darks/', data_slice=None),), return_as_url: bool = False, return_info: bool = False) dict

load reduced dark (median / mean…) into files

load_reduced_flats(inputs_urls: tuple = (DataUrl(valid=True, scheme='silx', file_path='{scan_prefix}_flats.hdf5', data_path='{entry}/flats/{index}', data_slice=None), DataUrl(valid=True, scheme='fabio', file_path='refHST{index_zfill4}.edf', data_path=None, data_slice=None)), metadata_input_urls: tuple = (DataUrl(valid=True, scheme='silx', file_path='{scan_prefix}_flats.hdf5', data_path='{entry}/flats/', data_slice=None),), return_as_url: bool = False, return_info=False) dict

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

static retrieve_information(scan: str, dataset_basename: Optional[str], ref_file: Optional[str], key: str, type_: type, key_aliases: Optional[Union[list, tuple]] = None, scan_info: Optional[dict] = None)

Try to retrieve information a .info file, an .xml or a flat field file.

file. Look for the key ‘key’ or one of it aliases.

Parameters:
  • scan – root folder of an acquisition. Must be an absolute path

  • ref_file – the refXXXX_YYYY which should contain information about the scan. Ref in esrf reference is a flat.

  • key (str) – the key (information) we are looking for

  • type (return type if the information is found.) – requestde out type if the information is found

  • key_aliases (list) – aliases of the key in the different file

  • scan_info – dict containing keys that could overwrite .info file content

Returns:

the requested information or None if not found

property sample_name

Return the sample name

save_reduced_darks(darks: dict, output_urls: tuple = (DataUrl(valid=True, scheme='silx', file_path='{scan_prefix}_darks.hdf5', data_path='{entry}/darks/{index}', data_slice=None), DataUrl(valid=True, scheme='fabio', file_path='dark.edf', data_path=None, data_slice=None)), darks_infos=None, metadata_output_urls=(DataUrl(valid=True, scheme='silx', file_path='{scan_prefix}_darks.hdf5', data_path='{entry}/darks/', data_slice=None),), overwrite: bool = False)

Dump computed dark (median / mean…) into files

save_reduced_flats(flats: dict, output_urls: tuple = (DataUrl(valid=True, scheme='silx', file_path='{scan_prefix}_flats.hdf5', data_path='{entry}/flats/{index}', data_slice=None), DataUrl(valid=True, scheme='fabio', file_path='refHST{index_zfill4}.edf', data_path=None, data_slice=None)), flats_infos=None, metadata_output_urls=(DataUrl(valid=True, scheme='silx', file_path='{scan_prefix}_flats.hdf5', data_path='{entry}/flats/', data_slice=None),), overwrite: bool = False) dict

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()

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 x_pixel_size: Optional[float]

For EDF only square pixel size is handled

property y_flipped: bool

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

property y_pixel_size: Optional[float]

For EDF only square pixel size is handled