wf_psf.psf_models.tf_psf_field

Ground-Truth TensorFlow PSF Field Model.

A module with classes for the Ground-Truth TensorFlow-based PSF field models.

Authors:

Tobias Liaudat <tobiasliaudat@gmail.com> and Jennifer Pollack <jennifer.pollack@cea.fr>

Functions

get_ground_truth_zernike(data)

Get Ground Truth Zernikes from the provided dataset.

Classes

GroundTruthPhysicalFieldFactory()

Factory class for the Tensor Flow Ground Truth Physical PSF Field Model.

GroundTruthSemiParamFieldFactory()

Factory class for the TensorFlow Ground Truth Physical PSF Field Model.

TFGroundTruthPhysicalField(*args, **kwargs)

Ground Truth PSF field forward model with a physical layer.

TFGroundTruthSemiParametricField(*args, **kwargs)

A TensorFlow-based Ground Truth Semi-Parametric PSF Field Model.

class wf_psf.psf_models.tf_psf_field.GroundTruthPhysicalFieldFactory[source]

Bases: PSFModelBaseFactory

Factory class for the Tensor Flow Ground Truth Physical PSF Field Model.

This factory class is responsible for instantiating instances of the TensorFlow Ground Truth Physical 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, coeff_mat=None)[source]

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

Methods

get_model_instance(model_params, ...)

Get Model Instance.

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

Get Model Instance.

This method creates an instance of the TensorFlow Ground Truth SemiParametric PSF Field Model using the provided parameters.

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 Ground Truth SemiParametric PSF Field model.

Return type:

TFGroundTruthPhysicalField

ids = ('ground_truth_physical_poly',)
class wf_psf.psf_models.tf_psf_field.GroundTruthSemiParamFieldFactory[source]

Bases: PSFModelBaseFactory

Factory class for the TensorFlow Ground Truth Physical PSF Field Model.

This factory class is responsible for instantiating instances of the TensorFlow Ground Truth SemiParametric 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, coeff_mat=None)[source]

Instantiates an instance of the TensorFlow Ground Truth SemiParametric Field class with the provided parameters.

Methods

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

Get Model Instance.

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

Get Model Instance.

This method creates an instance of the TensorFlow Ground Truth SemiParametric PSF Field Model using the provided parameters.

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. Note: This parameter is not used in this method.

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

Returns:

An instance of the TensorFlow Ground Truth SemiParametric PSF Field model.

Return type:

TFGroundTruthSemiParametricField

ids = ('ground_truth_poly',)
class wf_psf.psf_models.tf_psf_field.TFGroundTruthPhysicalField(*args: Any, **kwargs: Any)[source]

Bases: Model

Ground Truth PSF field forward model with a physical layer.

Ground truth PSF field used for evaluation purposes.

Parameters:
  • ids (tuple) – A tuple storing the string attribute of the PSF model class

  • 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 object) – A DataConfigHandler object containing training and tests datasets, as well as prior knowledge like Zernike coefficients.

  • coeff_mat (Tensor or None) – Initialization of the coefficient matrix defining the parametric PSF field model.

Methods

__call__(*args, **kwargs)

Call self as a function.

call(inputs[, training])

Define the PSF field forward model.

compute_zernikes(input_positions)

Compute Zernike coefficients at a batch of positions.

predict_mono_psfs(input_positions, ...)

Predict a batch of monochromatic PSFs at the specified positions.

predict_opd(input_positions)

Predict the Optical Path Difference (OPD) at the specified positions.

predict_step(data[, evaluate_step])

Apply custom prediction (inference) step for the PSF model.

predict_zernikes(input_positions)

Predict Zernike coefficients at a batch of positions.

set_output_Q(output_Q[, output_dim])

Set the value of the output_Q parameter.

call(inputs, training=True)[source]

Define the PSF field forward model.

[1] From positions to Zernike coefficients [2] From Zernike coefficients to OPD maps [3] From OPD maps and SED info to polychromatic PSFs

OPD: Optical Path Differences

compute_zernikes(input_positions)[source]

Compute Zernike coefficients at a batch of positions.

This only includes the physical layer

Parameters:

input_positions (Tensor [batch_dim, 2]) – Positions to compute the Zernikes.

Returns:

zks_coeffs – Zernikes at requested positions

Return type:

Tensor [batch, n_zks_total, 1, 1]

predict_mono_psfs(input_positions: tensorflow.Tensor, lambda_obs: float, phase_N: int)[source]

Predict a batch of monochromatic PSFs at the specified positions.

This method calculates the monochromatic Point Spread Functions (PSFs) for a given set of input positions, using the observed wavelength and wavefront dimension. The PSFs are computed using a parametric model and a physical layer.

Parameters:
  • input_positions (tf.Tensor [batch_dim, 2]) – A tensor containing the positions (in 2D space) at which to compute the PSF. Shape should be [batch_dim, 2], where batch_dim is the batch size.

  • lambda_obs (float) – The observed wavelength (in micrometers) for which the monochromatic PSFs are to be computed.

  • phase_N (int) – The required wavefront dimension. This should be calculated using the following: ` simPSF_np = wf_psf.sims.psf_simulator.PSFSimulator(...) phase_N = simPSF_np.feasible_N(lambda_obs) `

Returns:

mono_psf_batch – A tensor containing the computed batch of monochromatic PSFs for the input positions. The shape of the tensor depends on the model’s implementation.

Return type:

tf.Tensor

Notes

The method uses the TFBatchMonochromaticPSF class to handle the computation of monochromatic PSFs. The set_lambda_phaseN method is called to set the observed wavelength and wavefront dimension before the PSFs are computed.

predict_opd(input_positions: tensorflow.Tensor)[source]

Predict the Optical Path Difference (OPD) at the specified positions.

This method uses the predict_zernikes method to compute Zernike coefficients.

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: tuple, evaluate_step: bool = False) tensorflow.Tensor[source]

Apply custom prediction (inference) step for the PSF model.

This method applies a specialized interpolation required by the physical layer, distinct from the training process. It processes the input data, computes the Zernike coefficients, propagates them to obtain the Optical Path Difference (OPD), and generates the corresponding polychromatic PSFs.

Parameters:
  • data (tuple) – Input data for prediction. Expected to be a tuple containing positions (tf.Tensor) and Spectral Energy Distributions (SEDs) (tf.Tensor), or a batch of data.

  • evaluate_step (bool, optional) – If True, data is used as-is. Otherwise, it is formatted and unpacked using data_adapter.expand_1d and data_adapter.unpack_x_y_sample_weight. Default is False.

Returns:

poly_psfs – A tensor of shape [batch_size, output_dim, output_dim] containing the computed polychromatic PSFs.

Return type:

tf.Tensor

Notes

  • The method assumes data_adapter.expand_1d and data_adapter.unpack_x_y_sample_weight

are used to properly format and extract input_positions and packed_SEDs. - Unlike standard Keras predict_step, this implementation does not expect sample_weight.

predict_zernikes(input_positions)[source]

Predict Zernike coefficients at a batch of positions.

This only includes the physical layer. For the moment, it is the same as the compute_zernikes. No interpolation done to avoid interpolation error in the metrics.

Parameters:

input_positions (Tensor [batch_dim, 2]) – Positions to compute the Zernikes.

Returns:

zks_coeffs – Zernikes at requested positions

Return type:

Tensor [batch, n_zks_total, 1, 1]

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

Set the value of the output_Q parameter.

This method is useful for generating or predicting Point Spread Functions (PSFs) at a different sampling rate compared to the observation sampling. It allows for adjusting the resolution of the generated PSFs.

Parameters:
  • output_Q (float) – The output sampling rate factor, which determines the resolution of the PSFs to be generated.

  • output_dim (int, optional) – The output dimension of the generated PSFs. If not provided, the existing dimension will be used.

Returns:

This method does not return any value.

Return type:

None

Notes

After setting the output_Q and optionally the output_dim, the PSF batch polynomial generator is reinitialized with the new parameters.

class wf_psf.psf_models.tf_psf_field.TFGroundTruthSemiParametricField(*args: Any, **kwargs: Any)[source]

Bases: TFSemiParametricField

A TensorFlow-based Ground Truth Semi-Parametric PSF Field Model.

This class represents a ground truth semi-parametric PSF (Point Spread Function) field model implemented using TensorFlow. The model generates a ground truth PSF field based on the provided Zernike coefficient matrix. If the coefficient matrix (coeff_mat) is provided, it will be used to produce the ground truth PSF model, which serves as the reference for the previously simulated PSF fields. If no coefficient matrix is provided, the model proceeds without it.

Parameters:
  • model_params (RecursiveNamespace) – A RecursiveNamespace object containing parameters for configuring the PSF model.

  • training_params (RecursiveNamespace) – A RecursiveNamespace object containing training hyperparameters for the PSF model.

  • coeff_mat (Tensor or None) – The Zernike coefficient matrix used in generating simulations of the PSF model. This matrix defines the Zernike polynomials up to a given order used to simulate the PSF field. It is only used by this model if present to produce the ground truth PSF model. If not provided, the model will proceed without it.

GT_tf_semiparam_field

An instance of the TensorFlow-based Semi-Parametric PSF Field Model used for generating ground truth PSF fields.

Type:

TFSemiParametricField

__init__(model_params, training_params, data, coeff_mat)[source]

Initializes the TFGroundTruthSemiParametricField instance.

Methods

__call__(*args, **kwargs)

Call self as a function.

assign_S_mat(s_mat)

Assign DD features matrix.

assign_coeff_matrix(coeff_mat)

Assign coefficient matrix.

call(inputs)

Define the PSF field forward model.

get_coeff_matrix()

Get coefficient matrix.

predict_mono_psfs(input_positions, ...)

Predict a set of monochromatic PSF at desired positions.

predict_opd(input_positions)

Predict the OPD at some positions.

project_DD_features([tf_zernike_cube])

Project data-driven features.

set_nonzero_nonparam()

Set to non-zero the non-parametric part.

set_output_Q(output_Q[, output_dim])

Set the value of the output_Q parameter.

set_trainable_layers([param_bool, nonparam_bool])

Set Trainable Layers.

set_zero_nonparam()

Set to zero the non-parametric part.

wf_psf.psf_models.tf_psf_field.get_ground_truth_zernike(data)[source]

Get Ground Truth Zernikes from the provided dataset.

This method concatenates the Ground Truth Zernike from both the training and test datasets.

Parameters:

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

Returns:

Tensor containing the observed positions of the stars.

Return type:

tf.Tensor

Notes

The Zernike Ground Truth are obtained by concatenating the Ground Truth Zernikes from both the training and test datasets along the 0th axis.