tomoscan.esrf.scan.edfscan.EDFTomoScan#

class tomoscan.esrf.scan.edfscan.EDFTomoScan(scan, dataset_basename=None, scan_info=None, n_frames=None, ignore_projections=None)#

Bases: TomoScanBase

TomoScanBase instanciation for scan defined from .edf files

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

  • dataset_basename (Optional[str]) – prefix of the dataset to handle

  • scan_info (Optional[dict]) – dictionary providing dataset information. Provided keys will overwrite information contained in .info. Valid keys are: TODO

  • n_frames (Optional[int]) – 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.

__init__(scan, dataset_basename=None, scan_info=None, n_frames=None, ignore_projections=None)#

Methods

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

build_drac_metadata()

build icat metadata dictionary filling NXtomo definition following icat definition: https://gitlab.esrf.fr/icat/hdf5-master-config/-/blob/88a975039694d5dba60e240b7bf46c22d34065a0/hdf5_cfg.xml

clear_cache()

clear caches.

clear_caches()

rtype:

None

clear_frames_cache()

clear_frames_caches()

rtype:

None

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 instance to compare with :rtype:

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

rtype:

Optional[int]

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

type scan_path:

str

get_dataset_basename()

rtype:

str

get_detector_transformations(default)

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

rtype:

Optional[tuple]

get_distance(*args, **kwargs)

get_energy_expected_location()

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

rtype:

Optional[int]

get_flat_expected_location()

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

type scan_path:

str

get_identifier()

return the dataset identifier of the scan.

get_ignored_projection_indices()

get_info_file(directory[, dataset_basename])

rtype:

str

get_info_file_path(scan)

get_pixel_size([unit])

rtype:

Optional[float]

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

rtype:

Optional[int]

get_relative_file(file_name[, ...])

type file_name:

str

get_sample_detector_distance([unit])

param unit:

unit requested for the distance

get_sample_detector_distance_expected_location()

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

rtype:

Optional[int]

get_sinogram(line[, subsampling, norm_method])

extract the sinogram from projections

get_tomo_n(scan[, dataset_basename, scan_info])

rtype:

Optional[int]

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)

rtype:

bool

is_tomoscan_dir(directory[, dataset_basename])

Check if the given directory is holding an acquisition

load_from_dict(desc)

Load properties contained in the dictionary.

load_reduced_darks([inputs_urls, ...])

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

load_reduced_flats([inputs_urls, ...])

load reduced flats frames

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.

rotation_angle()

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

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

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

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

set_reduced_darks(darks[, darks_infos])

set_reduced_flats(flats[, flats_infos])

to_dict()

rtype:

dict

update()

Parse the root folder and files to update information

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

rtype:

Optional[list]

dark_n

rtype:

Optional[int]

darks

list of darks files

dataset_basename

rtype:

Optional[str]

detector_transformations

not handled for EDF

detector_x_pixel_size

rtype:

Optional[float]

detector_y_pixel_size

rtype:

Optional[float]

dim_1

rtype:

Optional[int]

dim_2

rtype:

Optional[int]

distance

rtype:

Optional[float]

electric_current

rtype:

tuple

energy

return:

incident beam energy in keV

estimated_cor_frm_motor

ff_interval

rtype:

Optional[int]

field_of_view

return:

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

flat_n

number of flat per series (computed on the first series)

flats

list of flats files

group_size

Used in the case of z-series for example.

ignore_projections

instrument_name

rtype:

Optional[str]

intensity_monitor

intensity_normalization

machine_current

Return the sample name

magnification

rtype:

Optional[float]

path

rtype:

Optional[str]

pixel_size

rtype:

Optional[int]

projections

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

propagation_distance

Not handled by EDF

reduced_darks

reduced_darks_infos

reduced_flats

reduced_flats_infos

sample_detector_distance

rtype:

Optional[float]

sample_name

Return the sample name

sample_x_pixel_size

For EDF only square pixel size is handled

sample_y_pixel_size

For EDF only square pixel size is handled

scan_info

rtype:

Optional[dict]

scan_range

rtype:

Optional[int]

sequence_name

Return the sequence name

source

source_name

rtype:

Optional[str]

source_sample_distance

Not handled for EDF

source_type

rtype:

Optional[str]

title

rtype:

Optional[str]

tomo_n

number of projection WITHOUT the return projections

type

rtype:

str

x_flipped

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

x_pixel_size

rtype:

Optional[float]

x_real_pixel_size

rtype:

Optional[float]

x_rotation_axis_pixel_position

return:

Estimated center of rotation estimated from motor position. In [-frame_width, +frame_width]. None if unable to find it

x_translation

rtype:

Optional[tuple]

y_flipped

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

y_pixel_size

rtype:

Optional[float]

y_real_pixel_size

rtype:

Optional[float]

y_translation

rtype:

Optional[tuple]

z_translation

rtype:

Optional[tuple]

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

Return type:

None

build_drac_metadata()#

build icat metadata dictionary filling NXtomo definition following icat definition: https://gitlab.esrf.fr/icat/hdf5-master-config/-/blob/88a975039694d5dba60e240b7bf46c22d34065a0/hdf5_cfg.xml

Return type:

dict

clear_cache()#

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 – if some flats have already been computed will overwrite them

  • return_info – 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 – if some flats have already been computed will overwrite them

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

property darks: dict#

list of darks files

Return type:

dict

property detector_transformations: tuple | None#

not handled for EDF

Return type:

Optional[tuple]

property energy#
Returns:

incident beam energy in keV

equal(other)#

:param instance to compare with :rtype: bool :return: True if instance are equivalent

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

picklable

property field_of_view#
Returns:

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

flat_field_correction(projs, proj_indexes, line=None)#

Apply flat field correction on the given data

Parameters:
  • projs (list | tuple | ndarray) – list, tuple or numpy.ndarray of projections (numpy array) to apply correction on

  • proj_indexes (UnionType[list, tuple, ndarray, None]) – list, tuple or numpy.ndarray of indexes of the projection in the acquisition sequence. Provide None to use the index in the middle of the flats taken.

  • line (Optional[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

property flat_n: int | None#

number of flat per series (computed on the first series)

Return type:

Optional[int]

property flats: dict | None#

list of flats files

Return type:

Optional[dict]

static from_identifier(identifier)#

Return the Dataset from a identifier

get_bounding_box(axis=None)#

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)

Return type:

BoundingBox1D

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

  • prefix (str) – flat file prefix

  • file_ext (str) – flat file extension

Return type:

dict

Returns:

list of flat frames as silx’s DataUrl

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

  • prefix (str) – flat frame file prefix

  • file_ext (str) – flat frame file extension

Return type:

dict

Returns:

list of refs as silx’s DataUrl

get_identifier()#

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.

Return type:

ScanIdentifier

get_proj_angle_url()#

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 type:

dict

Returns:

angles as keys, radios as value.

static get_proj_urls(scan, dataset_basename=None, n_frames=None)#

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 (Optional[int]) – Number of frames in each EDF file. If not provided, it is inferred by reading each file.

Return type:

dict

Returns:

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

get_projections_intensity_monitor()#

return intensity monitor values for projections

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

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

Return type:

Optional[str]

Returns:

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

get_sample_detector_distance(unit='m')#
Parameters:

unit – unit requested for the distance

Return type:

Optional[float]

Returns:

sample / detector distance with the requested unit

get_sinogram(line, subsampling=1, norm_method=None, **kwargs)#

extract the sinogram from projections

Parameters:
  • line – which sinogram we want

  • subsampling – subsampling to apply. Allows to skip some io

Returns:

computed sinogram from projections

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 z-series for example. Return the number of sequence expected on the acquisition

static guess_index_frm_file_name(_file, basename)#

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

  • basename (str) –

Return type:

Optional[int]

property instrument_name: str | None#
Return type:

Optional[str]

Returns:

instrument name

static is_a_proj_path(fileName, scanID, dataset_basename=None)#

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

Return type:

bool

is_abort(**kwargs)#
Return type:

bool

Returns:

True if the acquisition has been abort

static is_tomoscan_dir(directory, dataset_basename=None, **kwargs)#

Check if the given directory is holding an acquisition

Parameters:

directory (str) –

Return type:

bool

Returns:

does the given directory contains any acquisition

load_from_dict(desc)#

Load properties contained in the dictionary.

Parameters:

_dict – dictionary to load

Returns:

self

Raises:

ValueError if dict is invalid

load_reduced_darks(inputs_urls=(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=(DataUrl(valid=True, scheme='silx', file_path='{scan_prefix}_darks.hdf5', data_path='{entry}/darks/', data_slice=None),), return_as_url=False, return_info=False)#

load reduced dark (median / mean…) into files

Parameters:
  • inputs_urls (tuple) – where to load the reduced darks. A default value is provided by the children class. You better know what you are doing if you modify the default value.

  • metadata_input_urls (tuple) – where to load the reduced darks metadata. A default value is provided by the children class. You better know what you are doing if you modify the default value.

  • return_as_url (bool) – if True then instead of returning the reduced frames as 2D numpy arrays it will return them as a silx DataUrl

  • return_info (bool) – if False only return return the dict of reduced frames (frame index as key (int) and frame as a 2D numpy array or silx Data Url as value) if True then return (dict of reduced frames, darks info / metadata)

Here is an example of usage:

scan = ... # scan must be an instance of TomoScanBase like NXtomoScan()
reduced_darks = scan.load_reduced_darks()
reduced_darks, darks_infos = scan.load_reduced_darks(return_info=True)

dark_frame_np_array = reduced_darks[0]
Return type:

dict

load_reduced_flats(inputs_urls=(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=(DataUrl(valid=True, scheme='silx', file_path='{scan_prefix}_flats.hdf5', data_path='{entry}/flats/', data_slice=None),), return_as_url=False, return_info=False)#

load reduced flats frames

Parameters:
  • inputs_urls (tuple) – where to load the reduced flats. A default value is provided by the children class. You better know what you are doing if you modify the default value.

  • metadata_input_urls (tuple) – where to load the reduced flats metadata. A default value is provided by the children class. You better know what you are doing if you modify the default value.

  • return_as_url (bool) – if True then instead of returning the reduced frames as 2D numpy arrays it will return them as a silx DataUrl

  • return_info – if False only return return the dict of reduced frames (frame index as key (int) and frame as a 2D numpy array or silx Data Url as value) if True then return (dict of reduced frames, flats info / metadata)

Here is an example of usage:

scan = ... # scan must be an instance of TomoScanBase like NXtomoScan()
reduced_flats = scan.load_reduced_flats()
reduced_flats, flats_infos = scan.load_reduced_flats(return_info=True)
Return type:

dict

property machine_current: tuple#

Return the sample name

Return type:

tuple

static map_urls_on_scan_range(urls, n_projection, scan_range)#

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 with all the urls. First url should be the first radio acquire, last url should match the last radio acquire.

  • n_projection – number of projection for the sample.

  • scan_range – acquisition range (usually 180 or 360)

Return type:

dict

Returns:

angle in degree as key and url as value

Raises:

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

property path: str | None#
Return type:

Optional[str]

Returns:

path of the scan root folder.

property projections: dict | None#

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

Return type:

Optional[dict]

property propagation_distance: float | None#

Not handled by EDF

Return type:

Optional[float]

static retrieve_information(scan, dataset_basename, ref_file, key, type_, key_aliases=None, scan_info=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 (str) – root folder of an acquisition. Must be an absolute path

  • ref_file (Optional[str]) – 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 – required out type if the information is found

  • key_aliases (UnionType[list, tuple, None]) – aliases of the key in the different file

  • scan_info (Optional[dict]) – dict containing keys that could overwrite .info file content

Returns:

the requested information or None if not found

property sample_detector_distance: float | None#
Return type:

Optional[float]

Returns:

sample / detector distance in meter

property sample_name#

Return the sample name

property sample_x_pixel_size: float | None#

For EDF only square pixel size is handled

Return type:

Optional[float]

property sample_y_pixel_size: float | None#

For EDF only square pixel size is handled

Return type:

Optional[float]

save_reduced_darks(darks, output_urls=(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=False)#

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

Parameters:
  • darks (dict) – dictionary with frame indices as key (int) and a 2D numpy array as value.

  • output_urls (tuple) – tuple of silx DataUrl, where to save the darks. Default value is usually provided by children class directly. You better know what you are doing if you modify the default value.

  • darks_infos – information regarding darks (metadata) like the machine current, exposure time…

  • metadata_output_urls – tuple of silx DataUrl, where to save the metadata / darks information. Default value is usually provided by children class directly You better know what you are doing if you modify the default value.

  • overwrtie – if the output files exist then will overwrite them.

Here is an example on how to save your own reduced dark / flat

from tomoscan.framereducer.reducedframesinfos import ReducedFramesInfos
...

scan = ... # scan must be an instance of TomoScanBase like NXtomoScan()
darks_infos.count_time = [2.5]
darks_infos.machine_current = [13.1]
scan.save_reduced_darks(
    darks={
        0: dark_frame,  # dark_frame is a 2d numpy array
    },
    darks_infos=darks_infos,
    overwrite=True,
)
save_reduced_flats(flats, output_urls=(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=False)#

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

Parameters:
  • flats (dict) – dictionary with frame indices as key (int) and a 2D numpy array as value.

  • output_urls (tuple) – tuple of silx DataUrl, where to save the flats. Default value is usually provided by children class directly. You better know what you are doing if you modify the default value.

  • flats_infos – information regarding flats (metadata) like the machine current, exposure time…

  • metadata_output_urls – tuple of silx DataUrl, where to save the metadata / flats information. Default value is usually provided by children class directly You better know what you are doing if you modify the default value.

  • overwrite (bool) – if the output files exist then will overwrite them.

Here is an example on how to save your own reduced dark / flat

from tomoscan.framereducer.reducedframesinfos import ReducedFramesInfos
...

scan = ... # scan must be an instance of TomoScanBase like NXtomoScan()
flats_infos = ReducedFramesInfos()
flats_infos.count_time = [2.5, 1.2]
flats_infos.machine_current = [12.5, 13.1]
# for normalization the first reduced flat (at index 1) will have 2.5 as count time and 12.5 as machine current
# the second reduced flat frame (at index 1002) will have 1.2 as count time and 13.1 as machine current
scan.save_reduced_darks(
    darks={
        1: flat_frame_1,     # flat_frame_1 is a 2d numpy array
        1002: flat_frame_2,  # flat_frame_2 is another 2d numpy array
    },
    flats_infos=flats_infos,
    overwrite=True,
)
Return type:

dict

property sequence_name#

Return the sequence name

property source_sample_distance: float | None#

Not handled for EDF

Return type:

Optional[float]

to_dict()#
Return type:

dict

Returns:

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

property tomo_n: int | None#

number of projection WITHOUT the return projections

Return type:

Optional[int]

property type: str#
Return type:

str

Returns:

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

update()#

Parse the root folder and files to update information

property x_flipped: bool#

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

Return type:

bool

property x_rotation_axis_pixel_position#
Returns:

Estimated center of rotation estimated from motor position. In [-frame_width, +frame_width]. None if unable to find it

property y_flipped: bool#

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

Return type:

bool