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

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

param scan_path

get_dataset_basename()

rtype

str

get_detector_transformations(default)

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

get_distance(*args, **kwargs)

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

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 file_name

name of the file to create

get_sample_detector_distance([unit])

param unit

unit requested for the distance

get_sample_detector_distance_expected_location()

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)

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

dark_n

darks

list of darks files

dataset_basename

detector_transformations

not handled for EDF

dim_1

dim_2

distance

electric_current

Return the sample name

energy

return

incident beam energy in keV

estimated_cor_frm_motor

ff_interval

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

return

instrument name

intensity_monitor

intensity_normalization

magnification

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_detector_distance

return

sample / detector distance in meter

sample_name

Return the sample name

scan_info

scan_range

sequence_name

Return the sequence name

source

source_name

source_sample_distance

Not handled for EDF

source_type

title

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

For EDF only square pixel size is handled

x_real_pixel_size

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

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

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_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 – 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

property electric_current: tuple#

Return the sample name

Return type

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

property flats: dict | None#

list of flats files

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)

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

  • prefix – flat file prefix

  • file_ext – flat file extension

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

  • prefix – flat frame file prefix

  • file_ext – flat frame file extension

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 – is the path to the folder of acquisition

  • n_frames – 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

get_projections_intensity_monitor()#

return intensity monitor values for projections

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

  • with_dataset_prefix – 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

get_sample_detector_distance(unit='m')#
Parameters

unit – unit requested for the distance

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

  • basename

property instrument_name: str | None#
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

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

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

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#
Returns

path of the scan root folder.

property projections: dict | None#

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

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 – 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 – the key (information) we are looking for

  • type – required out type if the information is found

  • key_aliases – 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_detector_distance: float | None#
Returns

sample / detector distance in meter

property sample_name#

Return the sample name

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 electric 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_electric_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 electric 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_electric_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 electric current
# the second reduced flat frame (at index 1002) will have 1.2 as count time and 13.1 as machine electric 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

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

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_pixel_size: float | None#

For EDF only square pixel size is handled

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

property y_pixel_size: float | None#

For EDF only square pixel size is handled