wf_psf.psf_models.tf_psf_field module
- class wf_psf.psf_models.tf_psf_field.TF_GT_physical_field(*args, **kwargs)[source]
Bases:
Model
Ground truth PSF field forward model with a physical layer
Ground truth PSF field used for evaluation purposes.
- Parameters:
zernike_maps (Tensor(n_batch, opd_dim, opd_dim)) – Zernike polynomial maps.
obscurations (Tensor(opd_dim, opd_dim)) – Predefined obscurations of the phase.
batch_size (int) – Batch size
obs_pos (Tensor(n_stars, 2)) – The positions of all the stars
zks_prior (Tensor(n_stars, n_zks)) – The Zernike coeffients of the prior for all the stars
output_Q (float) – Oversampling used. This should match the oversampling Q used to generate the diffraction zero padding that is found in the input packed_SEDs. We call this other Q the input_Q. In that case, we replicate the original sampling of the model used to calculate the input packed_SEDs. The final oversampling of the generated PSFs with respect to the original instrument sampling depend on the division input_Q/output_Q. It is not recommended to use output_Q < 1. Although it works with float values it is better to use integer values.
output_dim (int) – Output dimension of the PSF stamps.
- Attributes:
activity_regularizer
Optional regularizer function for the output of this layer.
compute_dtype
The dtype of the layer’s computations.
distribute_strategy
The tf.distribute.Strategy this model was created under.
dtype
The dtype of the layer weights.
dtype_policy
The dtype policy associated with this layer.
dynamic
Whether the layer is dynamic (eager-only); set in the constructor.
inbound_nodes
Return Functional API nodes upstream of this layer.
input
Retrieves the input tensor(s) of a layer.
input_mask
Retrieves the input mask tensor(s) of a layer.
input_shape
Retrieves the input shape(s) of a layer.
input_spec
InputSpec instance(s) describing the input format for this layer.
- layers
losses
List of losses added using the add_loss() API.
metrics
Returns the model’s metrics added using compile(), add_metric() APIs.
metrics_names
Returns the model’s display labels for all outputs.
name
Name of the layer (string), set in the constructor.
name_scope
Returns a tf.name_scope instance for this class.
non_trainable_variables
Sequence of non-trainable variables owned by this module and its submodules.
non_trainable_weights
List of all non-trainable weights tracked by this layer.
outbound_nodes
Return Functional API nodes downstream of this layer.
output
Retrieves the output tensor(s) of a layer.
output_mask
Retrieves the output mask tensor(s) of a layer.
output_shape
Retrieves the output shape(s) of a layer.
run_eagerly
Settable attribute indicating whether the model should run eagerly.
state_updates
Deprecated, do NOT use!
- stateful
submodules
Sequence of all sub-modules.
supports_masking
Whether this layer supports computing a mask using compute_mask.
- trainable
trainable_variables
Sequence of trainable variables owned by this module and its submodules.
trainable_weights
List of all trainable weights tracked by this layer.
- updates
variable_dtype
Alias of Layer.dtype, the dtype of the weights.
variables
Returns the list of all layer variables/weights.
weights
Returns 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_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_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[, evaluate_step])Custom predict (inference) step.
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, lambda_obs, phase_N)[source]
Predict a set of monochromatic PSF at desired positions.
- 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]
Custom predict (inference) step.
It is needed as the physical layer requires a special interpolation (different from training).
- 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]
- class wf_psf.psf_models.tf_psf_field.TF_PSF_field_model(*args, **kwargs)[source]
Bases:
Model
Parametric PSF field model!
Fully parametric model based on the Zernike polynomial basis.
- Parameters:
zernike_maps (Tensor(n_batch, opd_dim, opd_dim)) – Zernike polynomial maps.
obscurations (Tensor(opd_dim, opd_dim)) – Predefined obscurations of the phase.
batch_size (int) – Batch size.
output_Q (float) – Oversampling used. This should match the oversampling Q used to generate the diffraction zero padding that is found in the input packed_SEDs. We call this other Q the input_Q. In that case, we replicate the original sampling of the model used to calculate the input packed_SEDs. The final oversampling of the generated PSFs with respect to the original instrument sampling depend on the division input_Q/output_Q. It is not recommended to use output_Q < 1. Although it works with float values it is better to use integer values.
l2_param (float) – Parameter going with the l2 loss on the opd. If it is 0. the loss is not added. Default is 0..
output_dim (int) – Output dimension of the PSF stamps.
n_zernikes (int) – Order of the Zernike polynomial for the parametric model.
d_max (int) – Maximum degree of the polynomial for the Zernike coefficient variations.
x_lims ([float, float]) – Limits for the x coordinate of the PSF field.
y_lims ([float, float]) – Limits for the x coordinate of the PSF field.
coeff_mat (Tensor or None) – Initialization of the coefficient matrix defining the parametric psf field model.
- Attributes:
activity_regularizer
Optional regularizer function for the output of this layer.
compute_dtype
The dtype of the layer’s computations.
distribute_strategy
The tf.distribute.Strategy this model was created under.
dtype
The dtype of the layer weights.
dtype_policy
The dtype policy associated with this layer.
dynamic
Whether the layer is dynamic (eager-only); set in the constructor.
inbound_nodes
Return Functional API nodes upstream of this layer.
input
Retrieves the input tensor(s) of a layer.
input_mask
Retrieves the input mask tensor(s) of a layer.
input_shape
Retrieves the input shape(s) of a layer.
input_spec
InputSpec instance(s) describing the input format for this layer.
- layers
losses
List of losses added using the add_loss() API.
metrics
Returns the model’s metrics added using compile(), add_metric() APIs.
metrics_names
Returns the model’s display labels for all outputs.
name
Name of the layer (string), set in the constructor.
name_scope
Returns a tf.name_scope instance for this class.
non_trainable_variables
Sequence of non-trainable variables owned by this module and its submodules.
non_trainable_weights
List of all non-trainable weights tracked by this layer.
outbound_nodes
Return Functional API nodes downstream of this layer.
output
Retrieves the output tensor(s) of a layer.
output_mask
Retrieves the output mask tensor(s) of a layer.
output_shape
Retrieves the output shape(s) of a layer.
run_eagerly
Settable attribute indicating whether the model should run eagerly.
state_updates
Deprecated, do NOT use!
- stateful
submodules
Sequence of all sub-modules.
supports_masking
Whether this layer supports computing a mask using compute_mask.
- trainable
trainable_variables
Sequence of trainable variables owned by this module and its submodules.
trainable_weights
List of all trainable weights tracked by this layer.
- updates
variable_dtype
Alias of Layer.dtype, the dtype of the weights.
variables
Returns the list of all layer variables/weights.
weights
Returns 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_coeff_matrix
(coeff_mat)Assign coefficient matrix.
build
(input_shape)Builds the model based on input shapes received.
call
(inputs)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 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_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_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.
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)[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
- predict_mono_psfs(input_positions, lambda_obs, phase_N)[source]
Predict a set of monochromatic PSF at desired positions.
input_positions: Tensor(batch_dim x 2)
- lambda_obs: float
Observed wavelength in um.
- phase_N: int
Required wavefront dimension. Should be calculated with as:
simPSF_np = wf.SimPSFToolkit(...)
phase_N = simPSF_np.feasible_N(lambda_obs)
- class wf_psf.psf_models.tf_psf_field.TF_SemiParam_field(*args, **kwargs)[source]
Bases:
Model
PSF field forward model!
Semi parametric model based on the Zernike polynomial basis. The
- Parameters:
zernike_maps (Tensor(n_batch, opd_dim, opd_dim)) – Zernike polynomial maps.
obscurations (Tensor(opd_dim, opd_dim)) – Predefined obscurations of the phase.
batch_size (int) – Batch sizet
output_Q (float) – Oversampling used. This should match the oversampling Q used to generate the diffraction zero padding that is found in the input packed_SEDs. We call this other Q the input_Q. In that case, we replicate the original sampling of the model used to calculate the input packed_SEDs. The final oversampling of the generated PSFs with respect to the original instrument sampling depend on the division input_Q/output_Q. It is not recommended to use output_Q < 1. Although it works with float values it is better to use integer values.
d_max_nonparam (int) – Maximum degree of the polynomial for the non-parametric variations.
l2_param (float) – Parameter going with the l2 loss on the opd. If it is 0. the loss is not added. Default is 0..
output_dim (int) – Output dimension of the PSF stamps.
n_zernikes (int) – Order of the Zernike polynomial for the parametric model.
d_max (int) – Maximum degree of the polynomial for the Zernike coefficient variations.
x_lims ([float, float]) – Limits for the x coordinate of the PSF field.
y_lims ([float, float]) – Limits for the x coordinate of the PSF field.
coeff_mat (Tensor or None) – Initialization of the coefficient matrix defining the parametric psf field model.
- Attributes:
activity_regularizer
Optional regularizer function for the output of this layer.
compute_dtype
The dtype of the layer’s computations.
distribute_strategy
The tf.distribute.Strategy this model was created under.
dtype
The dtype of the layer weights.
dtype_policy
The dtype policy associated with this layer.
dynamic
Whether the layer is dynamic (eager-only); set in the constructor.
inbound_nodes
Return Functional API nodes upstream of this layer.
input
Retrieves the input tensor(s) of a layer.
input_mask
Retrieves the input mask tensor(s) of a layer.
input_shape
Retrieves the input shape(s) of a layer.
input_spec
InputSpec instance(s) describing the input format for this layer.
- layers
losses
List of losses added using the add_loss() API.
metrics
Returns the model’s metrics added using compile(), add_metric() APIs.
metrics_names
Returns the model’s display labels for all outputs.
name
Name of the layer (string), set in the constructor.
name_scope
Returns a tf.name_scope instance for this class.
non_trainable_variables
Sequence of non-trainable variables owned by this module and its submodules.
non_trainable_weights
List of all non-trainable weights tracked by this layer.
outbound_nodes
Return Functional API nodes downstream of this layer.
output
Retrieves the output tensor(s) of a layer.
output_mask
Retrieves the output mask tensor(s) of a layer.
output_shape
Retrieves the output shape(s) of a layer.
run_eagerly
Settable attribute indicating whether the model should run eagerly.
state_updates
Deprecated, do NOT use!
- stateful
submodules
Sequence of all sub-modules.
supports_masking
Whether this layer supports computing a mask using compute_mask.
- trainable
trainable_variables
Sequence of trainable variables owned by this module and its submodules.
trainable_weights
List of all trainable weights tracked by this layer.
- updates
variable_dtype
Alias of Layer.dtype, the dtype of the weights.
variables
Returns the list of all layer variables/weights.
weights
Returns 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)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 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_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_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 non-parametric wavefront onto first n_z Zernikes and transfer their parameters to the parametric model.
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 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 the layers to be trainable or not.
set_weights
(weights)Sets the weights of the layer, from NumPy arrays.
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
- call(inputs)[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
- predict_mono_psfs(input_positions, lambda_obs, phase_N)[source]
Predict a set of monochromatic PSF at desired positions.
input_positions: Tensor(batch_dim x 2)
- lambda_obs: float
Observed wavelength in um.
- phase_N: int
Required wavefront dimension. Should be calculated with as:
simPSF_np = wf.SimPSFToolkit(...)
phase_N = simPSF_np.feasible_N(lambda_obs)
- predict_opd(input_positions)[source]
Predict the OPD at some positions.
- Parameters:
input_positions (Tensor(batch_dim x 2)) – Positions to predict the OPD.
- Returns:
opd_maps – OPD at requested positions.
- Return type:
Tensor [batch x opd_dim x opd_dim]
- project_DD_features(tf_zernike_cube)[source]
Project non-parametric wavefront onto first n_z Zernikes and transfer their parameters to the parametric model.
- set_output_Q(output_Q, output_dim=None)[source]
Set the value of the output_Q parameter. Useful for generating/predicting PSFs at a different sampling wrt the observation sampling.
- class wf_psf.psf_models.tf_psf_field.TF_physical_poly_field(*args, **kwargs)[source]
Bases:
Model
PSF field forward model with a physical layer
WaveDiff-original with a physical layer
- Parameters:
zernike_maps (Tensor(n_batch, opd_dim, opd_dim)) – Zernike polynomial maps.
obscurations (Tensor(opd_dim, opd_dim)) – Predefined obscurations of the phase.
batch_size (int) – Batch size
obs_pos (Tensor(n_stars, 2)) – The positions of all the stars
zks_prior (Tensor(n_stars, n_zks)) – The Zernike coeffients of the prior for all the stars
output_Q (float) – Oversampling used. This should match the oversampling Q used to generate the diffraction zero padding that is found in the input packed_SEDs. We call this other Q the input_Q. In that case, we replicate the original sampling of the model used to calculate the input packed_SEDs. The final oversampling of the generated PSFs with respect to the original instrument sampling depend on the division input_Q/output_Q. It is not recommended to use output_Q < 1. Although it works with float values it is better to use integer values.
d_max_nonparam (int) – Maximum degree of the polynomial for the non-parametric variations.
l2_param (float) – Parameter going with the l2 loss on the opd. If it is 0. the loss is not added. Default is 0..
output_dim (int) – Output dimension of the PSF stamps.
n_zks_param (int) – Order of the Zernike polynomial for the parametric model.
d_max (int) – Maximum degree of the polynomial for the Zernike coefficient variations.
x_lims ([float, float]) – Limits for the x coordinate of the PSF field.
y_lims ([float, float]) – Limits for the x coordinate of the PSF field.
coeff_mat (Tensor or None) – Initialization of the coefficient matrix defining the parametric psf field model.
interpolation_type (str) – Option for the interpolation type of the physical layer. Default is no interpolation.
interpolation_args (dict) – Additional arguments for the interpolation.
- Attributes:
activity_regularizer
Optional regularizer function for the output of this layer.
compute_dtype
The dtype of the layer’s computations.
distribute_strategy
The tf.distribute.Strategy this model was created under.
dtype
The dtype of the layer weights.
dtype_policy
The dtype policy associated with this layer.
dynamic
Whether the layer is dynamic (eager-only); set in the constructor.
inbound_nodes
Return Functional API nodes upstream of this layer.
input
Retrieves the input tensor(s) of a layer.
input_mask
Retrieves the input mask tensor(s) of a layer.
input_shape
Retrieves the input shape(s) of a layer.
input_spec
InputSpec instance(s) describing the input format for this layer.
- layers
losses
List of losses added using the add_loss() API.
metrics
Returns the model’s metrics added using compile(), add_metric() APIs.
metrics_names
Returns the model’s display labels for all outputs.
name
Name of the layer (string), set in the constructor.
name_scope
Returns a tf.name_scope instance for this class.
non_trainable_variables
Sequence of non-trainable variables owned by this module and its submodules.
non_trainable_weights
List of all non-trainable weights tracked by this layer.
outbound_nodes
Return Functional API nodes downstream of this layer.
output
Retrieves the output tensor(s) of a layer.
output_mask
Retrieves the output mask tensor(s) of a layer.
output_shape
Retrieves the output shape(s) of a layer.
run_eagerly
Settable attribute indicating whether the model should run eagerly.
state_updates
Deprecated, do NOT use!
- stateful
submodules
Sequence of all sub-modules.
supports_masking
Whether this layer supports computing a mask using compute_mask.
- trainable
trainable_variables
Sequence of trainable variables owned by this module and its submodules.
trainable_weights
List of all trainable weights tracked by this layer.
- updates
variable_dtype
Alias of Layer.dtype, the dtype of the weights.
variables
Returns the list of all layer variables/weights.
weights
Returns 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_coeff_matrix
(coeff_mat)Assign coefficient matrix.
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 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_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_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[, evaluate_step])Custom predict (inference) step.
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 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 the layers to be trainable or not.
set_weights
(weights)Sets the weights of the layer, from NumPy arrays.
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.
zks_pad
(zk_param, zk_prior)Pad the zernike coefficients with zeros to have the same length.
__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 includes the parametric model and 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, lambda_obs, phase_N)[source]
Predict a set of monochromatic PSF at desired positions.
- 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]
Custom predict (inference) step.
It is needed as the physical layer requires a special interpolation (different from training).
- predict_zernikes(input_positions)[source]
Predict Zernike coefficients at a batch of positions
This includes the parametric model and the physical layer. The prediction of the physical layer to positions is not used at training time.
- 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, output_dim=None)[source]
Set the value of the output_Q parameter. Useful for generating/predicting PSFs at a different sampling wrt the observation sampling.
- set_trainable_layers(param_bool=True, nonparam_bool=True)[source]
Set the layers to be trainable or not.
- zks_pad(zk_param, zk_prior)[source]
Pad the zernike coefficients with zeros to have the same length.
Pad them to have n_zks_total length.
- Parameters:
zk_param (Tensor [batch, n_zks_param, 1, 1]) – Zernike coefficients for the parametric part
zk_prior (Tensor [batch, n_zks_prior, 1, 1]) – Zernike coefficients for the prior part
- Returns:
zk_param (Tensor [batch, n_zks_total, 1, 1]) – Zernike coefficients for the parametric part
zk_prior (Tensor [batch, n_zks_total, 1, 1]) – Zernike coefficients for the prior part