wf_psf.psf_models.tf_modules.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 Zernikes from the provided dataset. |
Classes
Factory class for the Tensor Flow Ground Truth Physical PSF Field Model. |
|
Factory class for the TensorFlow Ground Truth Physical PSF Field Model. |
|
|
Ground Truth PSF field forward model with a physical layer. |
|
A TensorFlow-based Ground Truth Semi-Parametric PSF Field Model. |
- class wf_psf.psf_models.tf_modules.tf_psf_field.GroundTruthPhysicalFieldFactory[source]
Bases:
PSFModelBaseFactoryFactory 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:
- ids = ('ground_truth_physical_poly',)
- class wf_psf.psf_models.tf_modules.tf_psf_field.GroundTruthSemiParamFieldFactory[source]
Bases:
PSFModelBaseFactoryFactory 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:
- ids = ('ground_truth_poly',)
- class wf_psf.psf_models.tf_modules.tf_psf_field.TFGroundTruthPhysicalField(*args, **kwargs)[source]
Bases:
ModelGround 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.
- Attributes:
activity_regularizerOptional regularizer function for the output of this layer.
compute_dtypeThe dtype of the layer’s computations.
distribute_reduction_methodThe method employed to reduce per-replica values during training.
distribute_strategyThe tf.distribute.Strategy this model was created under.
dtypeThe dtype of the layer weights.
dtype_policyThe dtype policy associated with this layer.
dynamicWhether the layer is dynamic (eager-only); set in the constructor.
inbound_nodesReturn Functional API nodes upstream of this layer.
inputRetrieves the input tensor(s) of a layer.
input_maskRetrieves the input mask tensor(s) of a layer.
input_shapeRetrieves the input shape(s) of a layer.
input_specInputSpec instance(s) describing the input format for this layer.
- layers
lossesList of losses added using the add_loss() API.
metricsReturns the model’s metrics added using compile(), add_metric() APIs.
metrics_namesReturns the model’s display labels for all outputs.
nameName of the layer (string), set in the constructor.
name_scopeReturns a tf.name_scope instance for this class.
non_trainable_variablesSequence of non-trainable variables owned by this module and its submodules.
non_trainable_weightsList of all non-trainable weights tracked by this layer.
outbound_nodesReturn Functional API nodes downstream of this layer.
outputRetrieves the output tensor(s) of a layer.
output_maskRetrieves the output mask tensor(s) of a layer.
output_shapeRetrieves the output shape(s) of a layer.
run_eagerlySettable attribute indicating whether the model should run eagerly.
state_updatesDeprecated, do NOT use!
- stateful
submodulesSequence of all sub-modules.
supports_maskingWhether this layer supports computing a mask using compute_mask.
- trainable
trainable_variablesSequence of trainable variables owned by this module and its submodules.
trainable_weightsList of all trainable weights tracked by this layer.
- updates
variable_dtypeAlias of Layer.dtype, the dtype of the weights.
variablesReturns the list of all layer variables/weights.
weightsReturns the list of all layer variables/weights.
Methods
add_loss(losses, **kwargs)Add loss tensor(s), potentially dependent on layer inputs.
add_metric(value[, name])Adds metric tensor to the layer.
add_update(updates)Add update op(s), potentially dependent on layer inputs.
add_variable(*args, **kwargs)Deprecated, do NOT use! Alias for add_weight.
add_weight([name, shape, dtype, ...])Adds a new variable to the layer.
build(input_shape)Builds the model based on input shapes received.
call(inputs[, training])Define the PSF field forward model.
compile([optimizer, loss, metrics, ...])Configures the model for training.
compute_loss([x, y, y_pred, sample_weight])Compute the total loss, validate it, and return it.
compute_mask(inputs[, mask])Computes an output mask tensor.
compute_metrics(x, y, y_pred, sample_weight)Update metric states and collect all metrics to be returned.
compute_output_shape(input_shape)Computes the output shape of the layer.
compute_output_signature(input_signature)Compute the output tensor signature of the layer based on the inputs.
compute_zernikes(input_positions)Compute Zernike coefficients at a batch of positions.
count_params()Count the total number of scalars composing the weights.
evaluate([x, y, batch_size, verbose, ...])Returns the loss value & metrics values for the model in test mode.
evaluate_generator(generator[, steps, ...])Evaluates the model on a data generator.
finalize_state()Finalizes the layers state after updating layer weights.
fit([x, y, batch_size, epochs, verbose, ...])Trains the model for a fixed number of epochs (iterations on a dataset).
fit_generator(generator[, steps_per_epoch, ...])Fits the model on data yielded batch-by-batch by a Python generator.
from_config(config[, custom_objects])Creates a layer from its config.
get_config()Returns the config of the Model.
get_input_at(node_index)Retrieves the input tensor(s) of a layer at a given node.
get_input_mask_at(node_index)Retrieves the input mask tensor(s) of a layer at a given node.
get_input_shape_at(node_index)Retrieves the input shape(s) of a layer at a given node.
get_layer([name, index])Retrieves a layer based on either its name (unique) or index.
get_metrics_result()Returns the model's metrics values as a dict.
get_output_at(node_index)Retrieves the output tensor(s) of a layer at a given node.
get_output_mask_at(node_index)Retrieves the output mask tensor(s) of a layer at a given node.
get_output_shape_at(node_index)Retrieves the output shape(s) of a layer at a given node.
get_weight_paths()Retrieve all the variables and their paths for the model.
get_weights()Retrieves the weights of the model.
load_weights(filepath[, by_name, ...])Loads all layer weights, either from a TensorFlow or an HDF5 weight file.
make_predict_function([force])Creates a function that executes one step of inference.
make_test_function([force])Creates a function that executes one step of evaluation.
make_train_function([force])Creates a function that executes one step of training.
predict(x[, batch_size, verbose, steps, ...])Generates output predictions for the input samples.
predict_generator(generator[, steps, ...])Generates predictions for the input samples from a data generator.
predict_mono_psfs(input_positions, ...)Predict a batch of monochromatic PSFs at the specified positions.
predict_on_batch(x)Returns predictions for a single batch of samples.
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.
reset_metrics()Resets the state of all the metrics in the model.
save(filepath[, overwrite, ...])Saves the model to Tensorflow SavedModel or a single HDF5 file.
save_spec([dynamic_batch])Returns the tf.TensorSpec of call inputs as a tuple (args, kwargs).
save_weights(filepath[, overwrite, ...])Saves all layer weights.
set_output_Q(output_Q[, output_dim])Set the value of the output_Q parameter.
set_weights(weights)Sets the weights of the layer, from NumPy arrays.
summary([line_length, positions, print_fn, ...])Prints a string summary of the network.
test_on_batch(x[, y, sample_weight, ...])Test the model on a single batch of samples.
test_step(data)The logic for one evaluation step.
to_json(**kwargs)Returns a JSON string containing the network configuration.
to_yaml(**kwargs)Returns a yaml string containing the network configuration.
train_on_batch(x[, y, sample_weight, ...])Runs a single gradient update on a single batch of data.
train_step(data)The logic for one training step.
with_name_scope(method)Decorator to automatically enter the module name scope.
__call__
reset_states
- 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: 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: 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) 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:
- 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_modules.tf_psf_field.TFGroundTruthSemiParametricField(*args, **kwargs)[source]
Bases:
TFSemiParametricFieldA 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:
- __init__(model_params, training_params, data, coeff_mat)[source]
Initializes the TFGroundTruthSemiParametricField instance.
- Attributes:
activity_regularizerOptional regularizer function for the output of this layer.
compute_dtypeThe dtype of the layer’s computations.
distribute_reduction_methodThe method employed to reduce per-replica values during training.
distribute_strategyThe tf.distribute.Strategy this model was created under.
dtypeThe dtype of the layer weights.
dtype_policyThe dtype policy associated with this layer.
dynamicWhether the layer is dynamic (eager-only); set in the constructor.
inbound_nodesReturn Functional API nodes upstream of this layer.
inputRetrieves the input tensor(s) of a layer.
input_maskRetrieves the input mask tensor(s) of a layer.
input_shapeRetrieves the input shape(s) of a layer.
input_specInputSpec instance(s) describing the input format for this layer.
- layers
lossesList of losses added using the add_loss() API.
metricsReturns the model’s metrics added using compile(), add_metric() APIs.
metrics_namesReturns the model’s display labels for all outputs.
nameName of the layer (string), set in the constructor.
name_scopeReturns a tf.name_scope instance for this class.
non_trainable_variablesSequence of non-trainable variables owned by this module and its submodules.
non_trainable_weightsList of all non-trainable weights tracked by this layer.
outbound_nodesReturn Functional API nodes downstream of this layer.
outputRetrieves the output tensor(s) of a layer.
output_maskRetrieves the output mask tensor(s) of a layer.
output_shapeRetrieves the output shape(s) of a layer.
run_eagerlySettable attribute indicating whether the model should run eagerly.
state_updatesDeprecated, do NOT use!
- stateful
submodulesSequence of all sub-modules.
supports_maskingWhether this layer supports computing a mask using compute_mask.
- trainable
trainable_variablesSequence of trainable variables owned by this module and its submodules.
trainable_weightsList of all trainable weights tracked by this layer.
- updates
variable_dtypeAlias of Layer.dtype, the dtype of the weights.
variablesReturns the list of all layer variables/weights.
weightsReturns the list of all layer variables/weights.
Methods
add_loss(losses, **kwargs)Add loss tensor(s), potentially dependent on layer inputs.
add_metric(value[, name])Adds metric tensor to the layer.
add_update(updates)Add update op(s), potentially dependent on layer inputs.
add_variable(*args, **kwargs)Deprecated, do NOT use! Alias for add_weight.
add_weight([name, shape, dtype, ...])Adds a new variable to the layer.
assign_S_mat(s_mat)Assign DD features matrix.
assign_coeff_matrix(coeff_mat)Assign coefficient matrix.
build(input_shape)Builds the model based on input shapes received.
call(inputs, **kwargs)Define the PSF field forward model.
compile([optimizer, loss, metrics, ...])Configures the model for training.
compute_loss([x, y, y_pred, sample_weight])Compute the total loss, validate it, and return it.
compute_mask(inputs[, mask])Computes an output mask tensor.
compute_metrics(x, y, y_pred, sample_weight)Update metric states and collect all metrics to be returned.
compute_output_shape(input_shape)Computes the output shape of the layer.
compute_output_signature(input_signature)Compute the output tensor signature of the layer based on the inputs.
count_params()Count the total number of scalars composing the weights.
evaluate([x, y, batch_size, verbose, ...])Returns the loss value & metrics values for the model in test mode.
evaluate_generator(generator[, steps, ...])Evaluates the model on a data generator.
finalize_state()Finalizes the layers state after updating layer weights.
fit([x, y, batch_size, epochs, verbose, ...])Trains the model for a fixed number of epochs (iterations on a dataset).
fit_generator(generator[, steps_per_epoch, ...])Fits the model on data yielded batch-by-batch by a Python generator.
from_config(config[, custom_objects])Creates a layer from its config.
get_coeff_matrix()Get coefficient matrix.
get_config()Returns the config of the Model.
get_input_at(node_index)Retrieves the input tensor(s) of a layer at a given node.
get_input_mask_at(node_index)Retrieves the input mask tensor(s) of a layer at a given node.
get_input_shape_at(node_index)Retrieves the input shape(s) of a layer at a given node.
get_layer([name, index])Retrieves a layer based on either its name (unique) or index.
get_metrics_result()Returns the model's metrics values as a dict.
get_output_at(node_index)Retrieves the output tensor(s) of a layer at a given node.
get_output_mask_at(node_index)Retrieves the output mask tensor(s) of a layer at a given node.
get_output_shape_at(node_index)Retrieves the output shape(s) of a layer at a given node.
get_weight_paths()Retrieve all the variables and their paths for the model.
get_weights()Retrieves the weights of the model.
load_weights(filepath[, by_name, ...])Loads all layer weights, either from a TensorFlow or an HDF5 weight file.
make_predict_function([force])Creates a function that executes one step of inference.
make_test_function([force])Creates a function that executes one step of evaluation.
make_train_function([force])Creates a function that executes one step of training.
predict(x[, batch_size, verbose, steps, ...])Generates output predictions for the input samples.
predict_generator(generator[, steps, ...])Generates predictions for the input samples from a data generator.
predict_mono_psfs(input_positions, ...)Predict a set of monochromatic PSF at desired positions.
predict_on_batch(x)Returns predictions for a single batch of samples.
predict_opd(input_positions)Predict the OPD at some positions.
predict_step(data)The logic for one inference step.
project_DD_features([tf_zernike_cube])Project data-driven features.
reset_metrics()Resets the state of all the metrics in the model.
save(filepath[, overwrite, ...])Saves the model to Tensorflow SavedModel or a single HDF5 file.
save_spec([dynamic_batch])Returns the tf.TensorSpec of call inputs as a tuple (args, kwargs).
save_weights(filepath[, overwrite, ...])Saves all layer weights.
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_weights(weights)Sets the weights of the layer, from NumPy arrays.
set_zero_nonparam()Set to zero the non-parametric part.
summary([line_length, positions, print_fn, ...])Prints a string summary of the network.
test_on_batch(x[, y, sample_weight, ...])Test the model on a single batch of samples.
test_step(data)The logic for one evaluation step.
to_json(**kwargs)Returns a JSON string containing the network configuration.
to_yaml(**kwargs)Returns a yaml string containing the network configuration.
train_on_batch(x[, y, sample_weight, ...])Runs a single gradient update on a single batch of data.
train_step(data)The logic for one training step.
with_name_scope(method)Decorator to automatically enter the module name scope.
__call__
reset_states
- wf_psf.psf_models.tf_modules.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.