wf_psf.psf_models.psf_model_physical_polychromatic

PSF Model Physical Semi-Parametric Polychromatic.

A module which defines the classes and methods to manage the parameters of the psf physical polychromatic model.

Authors:

Tobias Liaudat <tobias.liaudat@cea.fr> and Jennifer Pollack <jennifer.pollack@cea.fr>

Classes

PhysicalPolychromaticFieldFactory()

Factory class for the TensorFlow Physical Polychromatic PSF Field Model.

TFPhysicalPolychromaticField(*args, **kwargs)

TensorFlow Physical Polychromatic PSF Field class.

class wf_psf.psf_models.psf_model_physical_polychromatic.PhysicalPolychromaticFieldFactory[source]

Bases: PSFModelBaseFactory

Factory class for the TensorFlow Physical Polychromatic PSF Field Model.

This factory class is responsible for instantiating instances of the TensorFlow Physical Polychromatic PSF Field Model. It is registered with the PSF model factory registry.

Parameters:

ids (tuple) – A tuple containing identifiers for the factory class.

get_model_instance(model_params, training_params, data=None, coeff_mat=None)[source]

Instantiates an instance of the TensorFlow Physical Polychromatic Field class with the provided parameters.

Methods

get_model_instance(model_params, ...[, ...])

Create an instance of the TensorFlow Physical Polychromatic Field model.

get_model_instance(model_params, training_params, data, coeff_mat=None)[source]

Create an instance of the TensorFlow Physical Polychromatic Field model.

This method instantiates a TFPhysicalPolychromaticField object with the given model and training parameters, and data containing prior information like Zernike coefficients. Optionally, a coefficient matrix can be provided.

Parameters:
  • model_params (Recursive Namespace) – A Recursive Namespace object containing parameters for this PSF model class.

  • training_params (Recursive Namespace) – A Recursive Namespace object containing training hyperparameters for this PSF model class.

  • data (DataConfigHandler) – A DataConfigHandler object that provides access to training and test datasets, as well as prior knowledge like Zernike coefficients.

  • coeff_mat (Tensor or None, optional) – Coefficient matrix defining the parametric PSF field model.

Returns:

An instance of the TensorFlow Physical Polychromatic Field model.

Return type:

TFPhysicalPolychromaticField

ids = ('physical_poly',)
class wf_psf.psf_models.psf_model_physical_polychromatic.TFPhysicalPolychromaticField(*args: Any, **kwargs: Any)[source]

Bases: Model

TensorFlow Physical Polychromatic PSF Field class.

This class represents a polychromatic PSF field model with a physical layer. It incorporates parametric and non-parametric modeling approaches to accurately reconstruct the point spread function (PSF) across multiple wavelengths.

The model provides functionalities for: - Initializing model parameters and defining the physical PSF layer. - Performing forward passes and computing wavefront transformations. - Handling Zernike parameterization and coefficient matrices. - Evaluating model performance and saving optimization history.

See individual method docstrings for more details.

Methods

__call__(*args, **kwargs)

Call self as a function.

assign_coeff_matrix(coeff_mat)

Assign a coefficient matrix to the parametric PSF field model.

call(inputs[, training])

Define the PSF (Point Spread Function) field forward model.

compute_zernikes(input_positions)

Compute Zernike coefficients at a batch of positions.

get_coeff_matrix()

Get coefficient matrix.

pad_zernikes(zk_param, zk_prior)

Pad the Zernike coefficients to match the maximum length.

predict_mono_psfs(input_positions, ...)

Predict a set of monochromatic Point Spread Functions (PSFs) at desired positions.

predict_opd(input_positions)

Predict the OPD at some positions.

predict_step(data[, evaluate_step])

Predict (inference) step.

predict_zernikes(input_positions)

Predict Zernike coefficients at a batch of positions.

set_nonzero_nonparam()

Set the non-parametric part to non-zero values.

set_output_Q(output_Q[, output_dim])

Set the output sampling rate (output_Q) for PSF generation.

set_trainable_layers([param_bool, nonparam_bool])

Set the layers to be trainable.

set_zero_nonparam()

Set the non-parametric part of the OPD (Optical Path Difference) to zero.

assign_coeff_matrix(coeff_mat: tensorflow.Tensor | None) None[source]

Assign a coefficient matrix to the parametric PSF field model.

This method updates the coefficient matrix used by the parametric PSF field model, allowing for customization or modification of the model’s parameters. If coeff_mat is None, the model will revert to using its default coefficient matrix.

Parameters:

coeff_mat (Optional[tf.Tensor]) – A TensorFlow tensor representing the coefficient matrix for the PSF field model. If None, the model will use the default coefficient matrix.

Return type:

None

call(inputs, training=True)[source]

Define the PSF (Point Spread Function) field forward model.

This method defines the forward model of the PSF field, which involves several steps: 1. Transforming input positions into Zernike coefficients. 2. Converting Zernike coefficients into Optical Path Difference (OPD) maps. 3. Combining OPD maps with Spectral Energy Distribution (SED) information to generate

polychromatic PSFs.

Parameters:
  • inputs (list) –

    List containing input data required for PSF computation. It should contain two elements: - input_positions: Tensor [batch_dim, 2]

    Positions at which to compute the PSFs.

    • packed_SEDs: Tensor [batch_dim, …]

      Packed Spectral Energy Distributions (SEDs) for the corresponding positions.

  • training (bool, optional) – Indicates whether the model is being trained or used for inference. Defaults to True.

Returns:

poly_psfs – Polychromatic PSFs generated by the forward model.

Return type:

Tensor

Notes

  • The input_positions tensor should have a shape of [batch_dim, 2], where each row represents the x and y coordinates of a position.

  • The packed_SEDs tensor should have a shape of [batch_dim, …], containing the SED information for each position.

  • During training, this method computes the Zernike coefficients from the input positions and calculates the corresponding OPD maps. Additionally, it adds an L2 loss term based on the parametric OPD maps.

  • During inference, this method generates predictions using precomputed OPD maps or by propagating through the forward model.

Examples

# Usage during training inputs = [input_positions, packed_SEDs] poly_psfs = psf_model(inputs)

# Usage during inference inputs = [input_positions, packed_SEDs] poly_psfs = psf_model(inputs, training=False)

compute_zernikes(input_positions)[source]

Compute Zernike coefficients at a batch of positions.

This method computes the Zernike coefficients for a batch of input positions using both the parametric model and the physical layer.

Parameters:

input_positions (Tensor [batch_dim, 2]) – Positions for which to compute the Zernike coefficients.

Returns:

zernike_coefficients – Computed Zernike coefficients for the input positions.

Return type:

Tensor [batch, n_zks_total, 1, 1]

Notes

This method combines the predictions from both the parametric model and the physical layer to obtain the final Zernike coefficients.

get_coeff_matrix()[source]

Get coefficient matrix.

pad_zernikes(zk_param, zk_prior)[source]

Pad the Zernike coefficients to match the maximum length.

Pad the input Zernike coefficient tensors to match the length of the maximum number of Zernike coefficients among the parametric and prior parts.

Parameters:
  • zk_param (tf.Tensor) – Zernike coefficients for the parametric part. Shape [batch, n_zks_param, 1, 1].

  • zk_prior (tf.Tensor) – Zernike coefficients for the prior part. Shape [batch, n_zks_prior, 1, 1].

Returns:

  • padded_zk_param (tf.Tensor) – Padded Zernike coefficients for the parametric part. Shape [batch, n_zks_total, 1, 1].

  • padded_zk_prior (tf.Tensor) – Padded Zernike coefficients for the prior part. Shape [batch, n_zks_total, 1, 1].

predict_mono_psfs(input_positions, lambda_obs, phase_N)[source]

Predict a set of monochromatic Point Spread Functions (PSFs) at desired positions.

This method calculates monochromatic PSFs based on the provided input positions, observed wavelength, and required wavefront dimension.

Parameters:
  • input_positions (Tensor [batch_dim, 2]) – Positions at which to compute the PSFs.

  • lambda_obs (float) – Observed wavelength in micrometers (um).

  • phase_N (int) – Required wavefront dimension. This should be calculated using a SimPSFToolkit instance. Example: ` simPSF_np = wf.SimPSFToolkit(...) phase_N = simPSF_np.feasible_N(lambda_obs) `

Returns:

mono_psf_batch – Batch of monochromatic PSFs.

Return type:

Tensor

predict_opd(input_positions)[source]

Predict the OPD at some positions.

Parameters:

input_positions (Tensor [batch_dim, 2]) – Positions to predict the OPD.

Returns:

opd_maps – OPD at requested positions.

Return type:

Tensor [batch, opd_dim, opd_dim]

predict_step(data, evaluate_step=False)[source]

Predict (inference) step.

A method to enable a special type of interpolation (different from training) for the physical layer.

Parameters:
  • data (NOT SURE)

  • evaluate_step (bool) – Boolean flag to evaluate step

Returns:

Instance of TFBatchPolychromaticPSF class containing computed polychromatic PSFs.

Return type:

poly_psfs TFBatchPolychromaticPSF

predict_zernikes(input_positions)[source]

Predict Zernike coefficients at a batch of positions.

This method predicts the Zernike coefficients for a batch of input positions using both the parametric model and the physical layer. During training, the prediction from the physical layer is typically not used.

Parameters:

input_positions (Tensor [batch_dim, 2]) – Positions for which to predict the Zernike coefficients.

Returns:

zernike_coeffs – Predicted Zernike coefficients for the input positions.

Return type:

Tensor [batch, n_zks_total, 1, 1]

Notes

At training time, the prediction from the physical layer may not be utilized, as the model might be trained to rely solely on the parametric part.

set_nonzero_nonparam()[source]

Set the non-parametric part to non-zero values.

This method sets the non-parametric component of the Optical Path Difference (OPD) to non-zero values, allowing it to contribute to the overall PSF (Point Spread Function).

set_output_Q(output_Q: float, output_dim: int | None = None) None[source]

Set the output sampling rate (output_Q) for PSF generation.

This method updates the output_Q parameter, which defines the resampling factor for generating PSFs at different resolutions relative to the telescope’s native sampling. It also allows optionally updating output_dim, which sets the output resolution of the PSF model.

If output_dim is provided, the PSF model’s output resolution is updated. The method then reinitializes the batch polychromatic PSF generator to reflect the updated parameters.

Parameters:
  • output_Q (float) – The resampling factor that determines the output PSF resolution relative to the telescope’s native sampling.

  • output_dim (Optional[int], default=None) – The new output dimension for the PSF model. If None, the output dimension remains unchanged.

Return type:

None

set_trainable_layers(param_bool=True, nonparam_bool=True)[source]

Set the layers to be trainable.

A method to set layers to be trainable.

Parameters:
  • param_bool (bool) – Boolean flag for parametric model layers

  • nonparam_bool (bool) – Boolean flag for non-parametric model layers

set_zero_nonparam()[source]

Set the non-parametric part of the OPD (Optical Path Difference) to zero.

This method sets the non-parametric component of the Optical Path Difference (OPD) to zero, effectively removing its contribution from the overall PSF (Point Spread Function).