pytomography.callbacks#

Callbacks can be used to compute various metrics on a reconstructed object throughout each iteration in an iterative reconstruction algorithm. For example, you may want to look at the noise in the liver as a function of iteration number in OSEM. A callback is simply a class which can take in an object and perform an operation. Callbacks are optional input to reconstruction algorithms; the run method of a callback is called after each subiteration of an iterative reconstruction algorithm. All user-defined callbacks should inherit from the base class CallBack. A subclass of this class could be used to compute noise-bias curves provided the __init__ method was redefined to take in some ground truth, and the run method was redefined to compare the obj to the ground truth.

Submodules#

Package Contents#

Classes#

Callback

Abstract class used for callbacks. Subclasses must redefine the __init__ and run methods. If a callback is used as an argument in an iterative reconstruction algorihtm, the __run__ method is called after each subiteration.

MultiCallback

Class for combining multiple callbacks into a single callback. This is useful for passing multiple callbacks to an iterative reconstruction algorithm.

DataStorageCallback

Callback that stores the object and forward projection at each iteration

class pytomography.callbacks.Callback[source]#

Abstract class used for callbacks. Subclasses must redefine the __init__ and run methods. If a callback is used as an argument in an iterative reconstruction algorihtm, the __run__ method is called after each subiteration.

abstract run(object, n_iter)[source]#

Abstract method for run.

Parameters:
  • object (torch.Tensor[Lx, Ly, Lz]) – Object at current iteration/subset in the reconstruction algorithm

  • n_iter (int) – The iteration number

Returns:

Modified object from callback. This must be returned by all callbacks (if the callback doesn’t change the object, then the passed object is returned)

Return type:

torch.Tensor

finalize(object)[source]#

Abstract method for run.

Parameters:

object (torch.Tensor[Lx, Ly, Lz]) – Reconstructed object (all iterations/subsets completed)

class pytomography.callbacks.MultiCallback(callbacks)[source]#

Bases: Callback

Class for combining multiple callbacks into a single callback. This is useful for passing multiple callbacks to an iterative reconstruction algorithm.

Parameters:

callbacks (list[Callback]) –

run(object, n_iter, n_subset)[source]#

Runs the callbacks sequentially

Parameters:
  • object (torch.Tensor) – Object at current iteration/subset in the reconstruction algorithm

  • n_iter (int) – Iteration number

  • n_subset (int) – Subset number

Returns:

Modified object from callback. This must be returned by all callbacks (if the callback doesn’t change the object, then the passed object is returned)

Return type:

torch.Tensor

finalize(object)[source]#

Finalizes the callback

Parameters:

object (torch.Tensor) – Reconstructed object

class pytomography.callbacks.DataStorageCallback(likelihood, object_initial)[source]#

Bases: pytomography.callbacks.callback.Callback

Callback that stores the object and forward projection at each iteration

Parameters:
  • likelihood (Likelihood) – Likelihood function used in reconstruction

  • object_initial (torch.Tensor[Lx, Ly, Lz]) – Initial object in the reconstruction algorithm

run(object, n_iter, n_subset)[source]#

Applies the callback

Parameters:
  • object (torch.Tensor[Lx, Ly, Lz]) – Object at current iteration

  • n_iter (int) – Current iteration number

  • n_subset (int) – Current subset index

Returns:

Original object passed (object is not modifed)

Return type:

torch.Tensor

finalize(object)[source]#

Finalizes the callback after all iterations are called

Parameters:

object (torch.Tensor[Lx, Ly, Lz]) – Reconstructed object (all iterations/subsets completed)