pyTomoAO.reconstructor.tomographicReconstructor

class pyTomoAO.reconstructor.tomographicReconstructor(config_file, logger=<Logger pyTomoAO.reconstructor (INFO)>, force_cpu=False)[source]

Bases: object

A class for computing tomographic reconstructors for adaptive optics systems.

This class computes a tomographic reconstructor from multiple Shack-Hartmann wavefront sensors based on the turbulence model given by atmospheric parameters. The reconstruction can be done using either a model-based approach or an interaction matrix (IM) based approach.

Parameters:
  • config_file (str) – Path to the YAML configuration file containing all necessary parameters for the tomographic reconstruction.

  • logger (logging.Logger, optional) – Logger object for logging messages (default is the module-level logger)

  • force_cpu (bool, optional) – Force CPU usage even when CUDA is available (default is False)

Returns:

None – Initializes the tomographicReconstructor object with the specified configuration.

Notes

The class maintains several internal attributes:

  • _reconstructornumpy.ndarray

    The tomographic reconstructor matrix

  • _gridMasknumpy.ndarray

    Grid mask used for reconstruction

  • _wavefront2Meterfloat

    Conversion factor from wavefront to meters

  • fitfitting

    Fitting object for DM influence functions

  • modesnumpy.ndarray

    Influence function modes

  • methodstr

    Reconstruction method (“Model” or “IM”)

  • _FRnumpy.ndarray

    Combined fitting and reconstructor matrix

valid_constructor_type = (<class 'numpy.float32'>, <class 'numpy.float64'>)

dtypes accepted by the reconstructor setter.

property reconstructor

Get the tomographic reconstructor matrix. If not already computed, this will build the reconstructor.

Parameters:

None

Returns:

numpy.ndarray – The tomographic reconstructor matrix

property backend

Name of the kernel backend this reconstructor uses.

Parameters:

None

Returns:

str"gpu" or "cpu". Fixed when the object is constructed; pass force_cpu=True to select the CPU kernels even where CuPy is available.

property R

Alias for the reconstructor property.

Parameters:

None

Returns:

numpy.ndarray – The tomographic reconstructor matrix

property FR

Get the fitting-reconstructor matrix.

Parameters:

None

Returns:

numpy.ndarray – The fitting-reconstructor matrix

property gridMask

Get the grid mask used for reconstruction.

Parameters:

None

Returns:

numpy.ndarray – The grid mask for reconstruction

property nLGS

Number of laser guide stars.

Parameters:

None

Returns:

int – The guide star count, taken from the LGS asterism parameters.

property r0

Fried parameter at the observing zenith angle, in metres.

Parameters:

None

Returns:

float – Derived from r0_zenith and the zenith angle; set r0_zenith to change it.

property r0_zenith

Fried parameter at zenith, in metres.

Parameters:

None

Returns:

float

property L0

Turbulence outer scale, in metres.

Parameters:

None

Returns:

float

sparseGradientMatrixAmplitudeWeighted(amplMask=None, overSampling=2, validLenslet=None)[source]

Computes the sparse gradient matrix (3x3 or 5x5 stencil) with amplitude mask.

Parameters:
  • amplMask (numpy.ndarray, optional) – Amplitude mask to be applied to the gradient matrix

  • overSampling (int, optional) – Oversampling factor (default is 2)

  • validLenslet (numpy.ndarray, optional) – Valid lenslet map. If None, uses self.lgsWfsParams.validLLMapSupport

Returns:

tuple – A tuple containing:

  • Gammascipy.sparse.csr_matrix

    The sparse gradient matrix

  • gridMasknumpy.ndarray

    The grid mask used for the computation

auto_correlation()[source]

Computes the auto-correlation meta-matrix for tomographic atmospheric reconstruction.

Parameters:

None

Returns:

numpy.ndarray – The auto-correlation matrix (Cxx)

cross_correlation(gridMask=None)[source]

Computes the cross-correlation meta-matrix for tomographic atmospheric reconstruction.

Parameters:

gridMask (numpy.ndarray, optional) – Grid mask to be used in the computation. If None, uses self.gridMask

Returns:

numpy.ndarray – The cross-correlation matrix (Cox)

build_reconstructor(IM=None, use_float32=False, alpha=10)[source]

Build the tomographic reconstructor based on parameters.

Parameters:
  • IM (numpy.ndarray, optional) – Interaction matrix for interaction matrix-based reconstructor. If None, a model-based reconstructor is built (default is None)

  • use_float32 (bool, optional) – Whether to use float32 precision for computations to reduce memory usage (default is False, which uses float64)

  • alpha (float, optional) – Regularization parameter for the reconstructor (default is 10)

Returns:

numpy.ndarray – The computed tomographic reconstructor matrix

Notes

This method computes different internal matrices depending on whether the model-based or IM-based approach is used: - Model-based: Gamma, gridMask, Cxx, Cox, Cnz, RecStatSA - IM-based: gridMask, Cxx, Cox, Cnz, RecStatSA

assemble_reconstructor_and_fitting(nChannels=4, slopesOrder='simu', scalingFactor=16500000.0, stretch_factor=1.03, rotation=None, flip=None)[source]

Assemble the reconstructor and fitting matrices together.

Parameters:
  • nChannels (int, optional) – Number of wavefront sensor channels (default is 4)

  • slopesOrder (str, optional) – Order of slopes in the input data. Options are: - “keck”: [slopeXY, …, slopeXY] interleaved X,Y slopes - “simu”: [slopeX, slopeY] all X slopes followed by all Y slopes - “inverted”: [slopeY, slopeX] all Y slopes followed by all X slopes (default is “simu”)

  • scalingFactor (float, optional) – Scaling factor applied to the reconstructor (default is 1.65e7)

  • stretch_factor (float, optional) – Stretch factor for the influence functions (default is 1.03)

  • rotation (int, optional) – Rotation of the modes (0, 1, 2, or 3) to apply to the reconstructor (default is None, no rotation)

Returns:

numpy.ndarray – The assembled reconstructor and fitting matrix (FR)

Raises:

ValueError – If an invalid slopes order is provided

sort_row(row)[source]

Sorts a row into [XY, …, XY] format (interleaved X and Y measurements).

Parameters:

row (numpy.ndarray) – Input row with X and Y measurements in separate blocks

Returns:

numpy.ndarray – Row rearranged into interleaved [XY, …, XY] format

swap_xy_blocks(matrix, n_valid_subap, nChannels=1)[source]

Swap the X and Y column blocks in a matrix, preserving channel organization.

Parameters:
  • matrix (numpy.ndarray) – The input matrix to swap columns

  • n_valid_subap (int) – Number of valid subapertures

  • nChannels (int, optional) – Number of wavefront sensor channels (default is 1)

Returns:

numpy.ndarray – Matrix with swapped X and Y column blocks for each channel

mask_DM_actuators(actuIndex)[source]

Masks specific DM actuators in the reconstructor.

Parameters:

actuIndex (int or list of int) – Index or indices of the actuator(s) to be masked (set to zero)

Returns:

numpy.ndarray – The reconstructor with masked actuators

Raises:

ValueError – If the reconstruction method is not defined or the reconstructor is not built

reconstruct_wavefront(slopes)[source]

Reconstruct the wavefront from slope measurements using the computed reconstructor.

Parameters:

slopes (numpy.ndarray) – Slope measurements from wavefront sensors

Returns:

numpy.ndarray – Reconstructed wavefront as a 2D array with NaN values where the grid mask is zero

Raises:

ValueError – If the reconstructor is not built

visualize_commands(slopes)[source]

Visualize the DM commands derived from slope measurements.

Parameters:

slopes (numpy.ndarray) – Slope measurements from wavefront sensors

Returns:

matplotlib.figure.Figure – Figure object containing the visualization of DM commands as a bar plot and the DM surface as a 2D image

Raises:

ValueError – If the reconstruction method is not defined or the reconstructor is not built

visualize_reconstruction(slopes, reference_wavefront=None)[source]

Visualize the reconstruction results and optionally compare with reference.

Parameters:
  • slopes (numpy.ndarray) – Slope measurements from wavefront sensors

  • reference_wavefront (numpy.ndarray, optional) – Reference wavefront for comparison

Returns:

matplotlib.figure.Figure – Figure object containing the visualization of reconstructed wavefront