CHAP.tomo.processor

File : processor.py Author : Rolf Verberg Description: Module for Processors used only by tomography experiments

Module Contents

Classes

TomoCHESSMapConverter

A processor to convert a CHESS style tomography map with dark and bright field configurations to an nexusformat.nexus.NXtomo style input format.

TomoDataProcessor

A processor to reconstruct a set of tomographic images returning either a dictionary or a nexusformat.nexus.NXroot object containing the (meta) data after processing each individual step.

SetNumexprThreads

Class that sets and keeps track of the number of processors used by the code in general and by the num_expr package specifically.

Tomo

Reconstruct a set of tomographic images.

TomoSimFieldProcessor

A processor to create a simulated tomography data set returning a nexusformat.nexus.NXroot object containing the simulated tomography detector images.

TomoDarkFieldProcessor

A processor to create the dark field associated with a simulated tomography data set created by TomoSimProcessor.

TomoBrightFieldProcessor

A processor to create the bright field associated with a simulated tomography data set created by TomoSimProcessor.

TomoSpecProcessor

A processor to create a tomography SPEC file associated with a simulated tomography data set created by TomoSimProcessor.

Functions

get_nxroot

Look through data for an item whose value for the 'schema' key matches schema (if supplied) and whose value for the 'data' key matches a nexusformat.nexus.NXobject object and return this object.

Data

NUM_CORE_TOMOPY_LIMIT

API

CHAP.tomo.processor.NUM_CORE_TOMOPY_LIMIT

24

CHAP.tomo.processor.get_nxroot(data, schema=None, remove=True)

Look through data for an item whose value for the 'schema' key matches schema (if supplied) and whose value for the 'data' key matches a nexusformat.nexus.NXobject object and return this object.

Parameters:
  • data (list[PipelineData]) – Input list of PipelineData objects.

  • schema (str, optional) – Name associated with the nexusformat.nexus.NXobject object to match in data.

  • remove (bool, optional) – Removes the matching entry in data when found, defaults to True.

Raises:

ValueError – Found an invalid matching object or multiple matching objects.

Returns:

Object matching with schema or None when not found.

Return type:

None, nexusformat.nexus.NXroot

class CHAP.tomo.processor.TomoCHESSMapConverter

Bases: CHAP.processor.Processor

A processor to convert a CHESS style tomography map with dark and bright field configurations to an nexusformat.nexus.NXtomo style input format.

Initialization

Constructor of PipelineItem class

process(data)

Process the input map and configuration and return a nexusformat.nexus.NXroot object based on the nexusformat.nexus.NXtomo style format.

Parameters:

data (list[PipelineData]) – Input map and configuration for tomographic image reduction/reconstruction.

Raises:

ValueError – Invalid input or configuration parameter.

Returns:

nexusformat.nexus.NXtomo style tomography input configuration.

Return type:

nexusformat.nexus.NXroot

class CHAP.tomo.processor.TomoDataProcessor

Bases: CHAP.processor.Processor

A processor to reconstruct a set of tomographic images returning either a dictionary or a nexusformat.nexus.NXroot object containing the (meta) data after processing each individual step.

Initialization

Constructor of PipelineItem class

process(data, outputdir='.', interactive=False, reduce_data=False, find_center=False, calibrate_center=False, reconstruct_data=False, combine_data=False, save_figs='no')

Process the input map or configuration with the step specific instructions and return either a dictionary or a nexusformat.nexus.NXroot object with the processed result.

Parameters:
  • data (list[PipelineData]) – Input configuration and specific step instructions for tomographic image reduction.

  • outputdir (str, optional) – Output folder name, defaults to ‘.’.

  • interactive (bool, optional) – Allows for user interactions, defaults to False.

  • reduce_data (bool, optional) – Generate reduced tomography images, defaults to False.

  • find_center (bool, optional) – Generate calibrated center axis info, defaults to False.

  • calibrate_center (bool, optional) – Calibrate the rotation axis, defaults to False.

  • reconstruct_data (bool, optional) – Reconstruct the tomography data, defaults to False.

  • combine_data (bool, optional) – Combine the reconstructed tomography stacks, defaults to False.

  • save_figs (Literal['yes', 'no', 'only'], optional) – Safe figures to file (‘yes’ or ‘only’) and/or display figures (‘yes’ or ‘no’), defaults to ‘no’.

Raises:
  • ValueError – Invalid input or configuration parameter.

  • RuntimeError – Missing map configuration to generate reduced tomography images.

Returns:

Processed (meta)data of the last step.

Return type:

Union[dict, nexusformat.nexus.NXroot]

class CHAP.tomo.processor.SetNumexprThreads(num_core)

Class that sets and keeps track of the number of processors used by the code in general and by the num_expr package specifically.

Initialization

Initialize SetNumexprThreads.

Parameters:

num_core (int) – Number of processors used by the num_expr package.

__enter__()
__exit__(exc_type, exc_value, traceback)
class CHAP.tomo.processor.Tomo(logger=None, outputdir='.', interactive=False, num_core=-1, save_figs='no')

Reconstruct a set of tomographic images.

Initialization

Initialize Tomo.

Parameters:
  • interactive (bool, optional) – Allows for user interactions, defaults to False.

  • num_core (int) – Number of processors.

  • outputdir (str, optional) – Output folder name, defaults to ‘.’.

  • save_figs (Literal['yes', 'no', 'only'], optional) – Safe figures to file (‘yes’ or ‘only’) and/or display figures (‘yes’ or ‘no’), defaults to ‘no’.

Raises:

ValueError – Invalid input parameter.

reduce_data(nxroot, tool_config=None, calibrate_center_rows=False)

Reduced the tomography images.

Parameters:
  • nxroot (nexusformat.nexus.NXroot) – Data object containing the raw data info and metadata required for a tomography data reduction.

  • tool_config (CHAP.tomo.models.TomoReduceConfig, optional) – Tool configuration.

Raises:

ValueError – Invalid input or configuration parameter.

Returns:

Reduced tomography data.

Return type:

nexusformat.nexus.NXroot

find_centers(nxroot, tool_config, calibrate_center_rows=False)

Find the calibrated center axis info

Parameters:
  • nxroot – Data object containing the reduced data and metadata required to find the calibrated center axis info.

  • tool_config (CHAP.tomo.models.TomoFindCenterConfig) – Tool configuration.

Raises:

ValueError – Invalid or missing input or configuration parameter.

Returns:

Calibrated center axis info.

Return type:

dict

reconstruct_data(nxroot, center_info, tool_config)

Reconstruct the tomography data.

Parameters:
  • nxroot – Data object containing the reduced data and metadata required for a tomography data reconstruction.

  • center_info (dict) – Calibrated center axis info.

  • tool_config (CHAP.tomo.models.TomoReconstructConfig) – Tool configuration.

Raises:

ValueError – Invalid or missing input or configuration parameter.

Returns:

Reconstructed tomography data.

Return type:

nexusformat.nexus.NXroot

combine_data(nxroot, tool_config)

Combine the reconstructed tomography stacks.

Parameters:
  • nxroot – Data object containing the reconstructed data and metadata required to combine the tomography stacks.

  • tool_config (CHAP.tomo.models.TomoCombineConfig) – Tool configuration.

Raises:

ValueError – Invalid or missing input or configuration parameter.

Returns:

Combined reconstructed tomography data.

Return type:

nexusformat.nexus.NXroot

_gen_dark(nxentry, reduced_data, image_key)

Generate dark field.

_gen_bright(nxentry, reduced_data, image_key)

Generate bright field.

_set_detector_bounds(nxentry, reduced_data, image_key, theta, img_row_bounds, calibrate_center_rows)

Set vertical detector bounds for each image stack.Right now the range is the same for each set in the image stack.

_gen_thetas(nxentry, image_key)

Get the rotation angles for the image stacks.

_set_zoom_or_delta_theta(thetas, delta_theta=None)

Set zoom and/or delta theta to reduce memory the requirement for the analysis.

_gen_tomo(nxentry, reduced_data, image_key, calibrate_center_rows)

Generate tomography fields.

_find_center_one_plane(tomo_stacks, stack_index, row, offset_row, thetas, eff_pixel_size, cross_sectional_dim, path=None, num_core=1, center_offset_min=-50, center_offset_max=50, center_search_range=None, gaussian_sigma=None, ring_width=None, prev_center_offset=None)

Find center for a single tomography plane.

tomo_stacks data axes order: stack,theta,row,column thetas in radians

_reconstruct_planes(tomo_planes, center_offset, thetas, num_core=1, gaussian_sigma=None, ring_width=None)

Invert the sinogram for a single or multiple tomography planes using tomopy’s recon routine.

_select_center_offset(recon_planes, row, preselected_offsets, default_offset_index=0, fig_titles=None, search_button=True, include_all_bad=False)

Select a center offset value from reconstructed images for a single reconstructed tomography data plane.

_reconstruct_one_tomo_stack(tomo_stack, thetas, center_offsets=None, num_core=1, algorithm='gridrec', secondary_iters=0, gaussian_sigma=None, remove_stripe_sigma=None, ring_width=None)

Reconstruct a single tomography stack.

_resize_reconstructed_data(data, x_bounds=None, y_bounds=None, z_bounds=None, combine_data=False)

Resize the reconstructed tomography data.

class CHAP.tomo.processor.TomoSimFieldProcessor

Bases: CHAP.processor.Processor

A processor to create a simulated tomography data set returning a nexusformat.nexus.NXroot object containing the simulated tomography detector images.

Initialization

Constructor of PipelineItem class

process(data)

Process the input configuration and return a nexusformat.nexus.NXroot object with the simulated tomography detector images.

Parameters:

data (list[PipelineData]) – Input configuration for the simulation.

Raises:

ValueError – Invalid input or configuration parameter.

Returns:

Simulated tomographic images.

Return type:

nexusformat.nexus.NXroot

_create_pathlength_solid_square(dim, thetas, pixel_size, detector_size)

Create the x-ray path length through a solid square crosssection for a set of rotation angles.

class CHAP.tomo.processor.TomoDarkFieldProcessor

Bases: CHAP.processor.Processor

A processor to create the dark field associated with a simulated tomography data set created by TomoSimProcessor.

Initialization

Constructor of PipelineItem class

process(data, num_image=5)

Process the input configuration and return a nexusformat.nexus.NXroot object with the simulated dark field detector images.

Parameters:
  • data (list[PipelineData]) – Input configuration for the simulation.

  • num_image (int, optional.) – Number of dark field images, defaults to 5.

Raises:

ValueError – Missing or invalid input or configuration parameter.

Returns:

Simulated dark field images.

Return type:

nexusformat.nexus.NXroot

class CHAP.tomo.processor.TomoBrightFieldProcessor

Bases: CHAP.processor.Processor

A processor to create the bright field associated with a simulated tomography data set created by TomoSimProcessor.

Initialization

Constructor of PipelineItem class

process(data, num_image=5)

Process the input configuration and return a nexusformat.nexus.NXroot object with the simulated bright field detector images.

Parameters:
  • data (list[PipelineData]) – Input configuration for the simulation.

  • num_image (int, optional.) – Number of bright field images, defaults to 5.

Raises:

ValueError – Missing or invalid input or configuration parameter.

Returns:

Simulated bright field images.

Return type:

nexusformat.nexus.NXroot

class CHAP.tomo.processor.TomoSpecProcessor

Bases: CHAP.processor.Processor

A processor to create a tomography SPEC file associated with a simulated tomography data set created by TomoSimProcessor.

Initialization

Constructor of PipelineItem class

process(data, scan_numbers=[1])

Process the input configuration and return a list of strings representing a plain text SPEC file.

Parameters:
  • data (list[PipelineData]) – Input configuration for the simulation.

  • scan_numbers (list[int]) – List of SPEC scan numbers, defaults to [1].

Raises:

ValueError – Invalid input or configuration parameter.

Returns:

Simulated SPEC file.

Return type:

list[str]