trinidi.reconstruct#

Some reconstruction functions and classes.

Functions

background_basis(N_b, N_t)

Creates the (N_b, N_t) background basis matrix

Classes

DensityEstimator(Y_s, par[, D, R, ...])

DensityEstimator class

Forward_0α1α2θ(input_shape, y_o, P[, jit])

Pseudo forward operator

Forward_0α1α2θ_arr(N_m, y_o, P[, jit])

Pseudo forward operator

Forward_Z(input_shape, α_1, α_2, Φ, B, D, R)

Pseudo forward operator F(Z) = ε (Φ * Q(Z) + B_s)

Forward_zα1α2θ(input_shape, y_o, D, R, P[, jit])

Pseudo forward operator

Forward_zα1α2θ_arr(N_m, y_o, D, R, P[, jit])

Pseudo forward operator

FunctionalSum(functional1, functional2)

A sum of two functionals.

ParameterEstimator(Y_o, Y_s, R, D, Ω_z, Ω_0=None)

ParameterEstimator class for nuisance parameters.

Preconditioner(D)

    1. = (ZC) (C_inverse D) original conditioned where (C_inverse D) has unit norm rows

ProjectionRegion(projection_mask)

ProjectionRegion class.

class trinidi.reconstruct.ProjectionRegion(projection_mask)[source]#

Bases: object

ProjectionRegion class.

This class is used to handle the Ω regions indicating the regions where the sample image has no areal density, or uniformly dense areal density. Used for averaging over many pixels.

Initialize a ProjectionRegion object.

If the counting data, Y, has shape projection_shape + (N_A,), the projection_mask array must have size projection_shape + (1,).

Parameters:

projection_mask (boolean or binary array) – projection_mask array used for averaging.

average(Y)[source]#

Compute \(\omega^\top Y\),

where \(\omega\) has shape projection_shape + (1,) and \(Y\) has shape projection_shape + (N_A,), thus the result has shape (1, N_A).

Parameters:

Y\(Y\) array.

Returns:

The \(\omega^\top Y\) array.

imshow(ax, title=None)[source]#

Show the projection_mask as an image

plot_contours(ax, color='red', alpha=0.5)[source]#

Show the projection_mask as contour

class trinidi.reconstruct.FunctionalSum(functional1, functional2)[source]#

Bases: Functional

A sum of two functionals.

__call__(x)[source]#

Evaluate this functional at point \(\mb{x}\).

Parameters:

x – Point at which to evaluate this functional.

Return type:

float

class trinidi.reconstruct.Forward_zα1α2θ(input_shape, y_o, D, R, P, jit=True)[source]#

Bases: Operator

Pseudo forward operator

f(z,ε,μ,θ) = ε[ {c_o - b(θ)} * q(z) + μ b(θ)]

c_o = (ω’ C_o) / (ω’v) q(z) = exp(-z D) R b(θ) = exp(θ P)

This gets fitted to c_s = (ω’ C_s) / (ω’v)

Parameters:
  • input_shape – Shape of input array.

  • output_shape – Shape of output array. Defaults to None. If None, output_shape is determined by evaluating self.__call__ on an input array of zeros.

  • eval_fn – Function used in evaluating this Operator. Defaults to None. Required unless __init__ is being called from a derived class with an _eval method.

  • input_dtypedtype for input argument. Defaults to float32. If the Operator implements complex-valued operations, this must be a complex dtype (typically complex64) for correct adjoint and gradient calculation.

  • output_dtypedtype for output argument. Defaults to None. If None, output_dtype is determined by evaluating self.__call__ on an input array of zeros.

  • jit (bool) – If True, call Operator.jit on this Operator to jit the forward, adjoint, and gram functions. Same as calling Operator.jit after the Operator is created.

Raises:

NotImplementedError – If the eval_fn parameter is not specified and the _eval method is not defined in a derived class.

class trinidi.reconstruct.Forward_zα1α2θ_arr(N_m, y_o, D, R, P, jit=True)[source]#

Bases: object

Pseudo forward operator

f(z,ε,μ,θ) = ε[ {c_o - b(θ)} * q(z) + μ b(θ)]

c_o = (ω’ C_o) / (ω’v) q(z) = exp(-z D) R b(θ) = exp(θ P)

This gets fitted to c_s = (ω’ C_s) / (ω’v)

__call__(zα1α2θ)[source]#

Call self as a function.

class trinidi.reconstruct.Forward_0α1α2θ(input_shape, y_o, P, jit=True)[source]#

Bases: Operator

Pseudo forward operator

f(0,ε,μ,θ) = ε[ {c_o - b(θ)} * q(z) + μ b(θ)]

= ε[ c_o + (μ-1) b(θ)]

c_o = (ω’ C_o) / (ω’v) q(0) = exp(-z D) R = 1 b(θ) = exp(θ P)

This gets fitted to c_s = (ω’ C_s) / (ω’v)

Parameters:
  • input_shape – Shape of input array.

  • output_shape – Shape of output array. Defaults to None. If None, output_shape is determined by evaluating self.__call__ on an input array of zeros.

  • eval_fn – Function used in evaluating this Operator. Defaults to None. Required unless __init__ is being called from a derived class with an _eval method.

  • input_dtypedtype for input argument. Defaults to float32. If the Operator implements complex-valued operations, this must be a complex dtype (typically complex64) for correct adjoint and gradient calculation.

  • output_dtypedtype for output argument. Defaults to None. If None, output_dtype is determined by evaluating self.__call__ on an input array of zeros.

  • jit (bool) – If True, call Operator.jit on this Operator to jit the forward, adjoint, and gram functions. Same as calling Operator.jit after the Operator is created.

Raises:

NotImplementedError – If the eval_fn parameter is not specified and the _eval method is not defined in a derived class.

class trinidi.reconstruct.Forward_0α1α2θ_arr(N_m, y_o, P, jit=True)[source]#

Bases: object

Pseudo forward operator

f(0,ε,μ,θ) = ε[ {c_o - b(θ)} * q(z) + μ b(θ)]

= ε[ c_o + (μ-1) b(θ)]

c_o = (ω’ C_o) / (ω’v) q(0) = exp(-z D) R = 1 b(θ) = exp(θ P)

This gets fitted to c_s = (ω’ C_s) / (ω’v)

__call__(zα1α2θ)[source]#

Call self as a function.

trinidi.reconstruct.background_basis(N_b, N_t)[source]#

Creates the (N_b, N_t) background basis matrix

class trinidi.reconstruct.Preconditioner(D)[source]#

Bases: object

(Z) (D) = (ZC) (C_inverse D) original conditioned where (C_inverse D) has unit norm rows

C = np.diag(np.diag(np.matmul(D, D.T)))**0.5

condition_Z(Z)[source]#

Condition Z

uncondition_Z(Z_conditioned)[source]#

Uncondition Z

condition_zα1α2θ(zα1α2θ)[source]#

Condition zα1α2θ

uncondition_zα1α2θ(zα1α2θ_conditioned)[source]#

Uncondition zα1α2θ

class trinidi.reconstruct.ParameterEstimator(Y_o, Y_s, R, D, Ω_z, Ω_0=None, N_b=5, non_negative_z=False, verbose=False, dispperiod=10)[source]#

Bases: object

ParameterEstimator class for nuisance parameters.

projection_shape is the shape of the detector so usually this will be (N_pixels_x, N_pixels_y) but it may be any shape including singleton shape. N_p number of projections, np.prod(projection_shape) = N_p. Y_o, Y_s measurements have shape projection_shape +  (N_A,) N_A is the number of measured TOF bins (TOA’s) D has shape (N_F, N_A) N_F is the number of theoretical TOF bins. \(N_F \geq N_A\) ω_sz, ω_s0 have shape projection_shape + (1,). \(ω_sz^\top\) has shape (1,) + projection_shape. R has shape (N_F, N_A).

Parameters:
  • Y_o – Open beam measurement.

  • Y_s – Sample measurement.

  • D – Cross section dictionary.

  • ω_sz – Uniformly dense region averaging vector.

  • ω_s0 – Open beam region averaging vector. When None, parameters will be computed equivalent to β=0.

  • R – Resolution operator of class ResolutionOperator. When None, R is chosen internally as identity operator.

  • β – Balancing weight between solving equation for ω_sz (β=0), and solving equation for ω_s0 (β infinite). Equal weight when β=1.0 (default).

plot_regions()[source]#

Plot Ω regions and corresponding spectra

plot_results()[source]#

Add docstring here.

apgm_plot_convergence(plot_residual=True, ground_truth=None, figsize=[6, 4])[source]#

Plot convergence behaviour.

apgm_solve(iterations=100)[source]#

Find parameters.

get()[source]#

Get Parameters.

set(z=None, α_1=None, α_2=None, θ=None)[source]#

Set Parameters.

save(file_name)[source]#

Save Parameters to file.

load(file_name)[source]#

Load Parameters from file.

class trinidi.reconstruct.Forward_Z(input_shape, α_1, α_2, Φ, B, D, R, jit=True)[source]#

Bases: Operator

Pseudo forward operator F(Z) = ε (Φ * Q(Z) + B_s)

Q(Z) = exp(-Z D) R B_s = μ B

Parameters:
  • input_shape – Shape of input array.

  • output_shape – Shape of output array. Defaults to None. If None, output_shape is determined by evaluating self.__call__ on an input array of zeros.

  • eval_fn – Function used in evaluating this Operator. Defaults to None. Required unless __init__ is being called from a derived class with an _eval method.

  • input_dtypedtype for input argument. Defaults to float32. If the Operator implements complex-valued operations, this must be a complex dtype (typically complex64) for correct adjoint and gradient calculation.

  • output_dtypedtype for output argument. Defaults to None. If None, output_dtype is determined by evaluating self.__call__ on an input array of zeros.

  • jit (bool) – If True, call Operator.jit on this Operator to jit the forward, adjoint, and gram functions. Same as calling Operator.jit after the Operator is created.

Raises:

NotImplementedError – If the eval_fn parameter is not specified and the _eval method is not defined in a derived class.

class trinidi.reconstruct.DensityEstimator(Y_s, par, D=None, R=None, non_negative_Z=False, projection_transform=None, dispperiod=10)[source]#

Bases: object

DensityEstimator class

Initialize an DensityEstimator object.

plot_convergence(plot_residual=True, ground_truth=None, figsize=[6, 4])[source]#

Plot convergence behaviour.

solve(iterations=100)[source]#

Find parameters.