wf_psf.metrics.metrics module

wf_psf.metrics.metrics.compute_metrics(tf_semiparam_field, simPSF_np, test_SEDs, train_SEDs, tf_test_pos, tf_train_pos, tf_test_stars, tf_train_stars, n_bins_lda, batch_size=16)[source]
wf_psf.metrics.metrics.compute_mono_metric(tf_semiparam_field, GT_tf_semiparam_field, simPSF_np, tf_pos, lambda_list, batch_size=32)[source]

Calculate metrics for monochromatic reconstructions.

The tf_semiparam_field should be the model to evaluate, and the GT_tf_semiparam_field should be loaded with the ground truth PSF field.

Relative values returned in [%] (so multiplied by 100).

Parameters:
  • tf_semiparam_field (PSF field object) – Trained model to evaluate.

  • GT_tf_semiparam_field (PSF field object) – Ground truth model to produce GT observations at any position and wavelength.

  • simPSF_np (PSF simulator object) – Simulation object capable of calculating phase_N values from wavelength values.

  • tf_pos (list of floats [batch x 2]) – Positions to evaluate the model.

  • lambda_list (list of floats [wavelength_values]) – List of wavelength values in [um] to evaluate the model.

  • batch_size (int) – Batch size to process the monochromatic PSF calculations.

Returns:

  • rmse_lda (list of float) – List of RMSE as a function of wavelength.

  • rel_rmse_lda (list of float) – List of relative RMSE as a function of wavelength. Values in %.

  • std_rmse_lda (list of float) – List of standard deviation of RMSEs as a function of wavelength.

  • std_rel_rmse_lda (list of float) – List of standard deviation of relative RMSEs as a function of wavelength. Values in %.

wf_psf.metrics.metrics.compute_one_opd_rmse(GT_tf_semiparam_field, tf_semiparam_field, pos, is_poly=False)[source]

Compute the OPD map for one position.

wf_psf.metrics.metrics.compute_opd_metrics(tf_semiparam_field, GT_tf_semiparam_field, pos, batch_size=16)[source]

Compute the OPD metrics.

Need to handle a batch size to avoid Out-Of-Memory errors with the GPUs. This is specially due to the fact that the OPD maps have a higher dimensionality than the observed PSFs.

The OPD RMSE is computed after having removed the mean from the different reconstructions. It is computed only on the non-obscured elements from the OPD.

Parameters:
  • tf_semiparam_field (PSF field object) – Trained model to evaluate.

  • GT_tf_semiparam_field (PSF field object) – Ground truth model to produce GT observations at any position and wavelength.

  • pos (numpy.ndarray [batch x 2]) – Positions at where to predict the OPD maps.

  • batch_size (int) – Batch size to process the OPD calculations.

Returns:

  • rmse (float) – Absolute RMSE value.

  • rel_rmse (float) – Relative RMSE value.

  • rmse_std (float) – Absolute RMSE standard deviation.

  • rel_rmse_std (float) – Relative RMSE standard deviation.

wf_psf.metrics.metrics.compute_opd_metrics_mccd(tf_semiparam_field, GT_tf_semiparam_field, test_pos, train_pos)[source]

Compute the OPD metrics.

wf_psf.metrics.metrics.compute_opd_metrics_param_model(tf_semiparam_field, GT_tf_semiparam_field, test_pos, train_pos)[source]

Compute the OPD metrics.

wf_psf.metrics.metrics.compute_opd_metrics_polymodel(tf_semiparam_field, GT_tf_semiparam_field, test_pos, train_pos)[source]

Compute the OPD metrics.

wf_psf.metrics.metrics.compute_poly_metric(tf_semiparam_field, GT_tf_semiparam_field, simPSF_np, tf_pos, tf_SEDs, n_bins_lda=20, n_bins_gt=20, batch_size=16, dataset_dict=None)[source]

Calculate metrics for polychromatic reconstructions.

The tf_semiparam_field should be the model to evaluate, and the GT_tf_semiparam_field should be loaded with the ground truth PSF field.

Relative values returned in [%] (so multiplied by 100).

Parameters:
  • tf_semiparam_field (PSF field object) – Trained model to evaluate.

  • GT_tf_semiparam_field (PSF field object) – Ground truth model to produce GT observations at any position and wavelength.

  • simPSF_np (PSF simulator object) – Simulation object to be used by generate_packed_elems function.

  • tf_pos (Tensor or numpy.ndarray [batch x 2] floats) – Positions to evaluate the model.

  • tf_SEDs (numpy.ndarray [batch x SED_samples x 2]) – SED samples for the corresponding positions.

  • n_bins_lda (int) – Number of wavelength bins to use for the polychromatic PSF.

  • n_bins_gt (int) – Number of wavelength bins to use for the ground truth polychromatic PSF.

  • batch_size (int) – Batch size for the PSF calcualtions.

  • dataset_dict (dict) – Dictionary containing the dataset information. If provided, and if the ‘stars’ key is present, the noiseless stars from the dataset are used to compute the metrics. Otherwise, the stars are generated from the GT model. Default is None.

Returns:

  • rmse (float) – RMSE value.

  • rel_rmse (float) – Relative RMSE value. Values in %.

  • std_rmse (float) – Sstandard deviation of RMSEs.

  • std_rel_rmse (float) – Standard deviation of relative RMSEs. Values in %.

wf_psf.metrics.metrics.compute_shape_metrics(tf_semiparam_field, GT_tf_semiparam_field, simPSF_np, SEDs, tf_pos, n_bins_lda, n_bins_gt, output_Q=1, output_dim=64, batch_size=16, opt_stars_rel_pix_rmse=False, dataset_dict=None)[source]

Compute the pixel, shape and size RMSE of a PSF model.

This is done at a specific sampling and output image dimension. It is done for polychromatic PSFs so SEDs are needed.

Parameters:
  • tf_semiparam_field (PSF field object) – Trained model to evaluate.

  • GT_tf_semiparam_field (PSF field object) – Ground truth model to produce GT observations at any position and wavelength.

  • simPSF_np

  • SEDs (numpy.ndarray [batch x SED_samples x 2]) – SED samples for the corresponding positions.

  • tf_pos (Tensor [batch x 2]) – Positions at where to predict the PSFs.

  • n_bins_lda (int) – Number of wavelength bins to use for the polychromatic PSF.

  • n_bins_gt (int) – Number of wavelength bins to use for the ground truth polychromatic PSF.

  • output_Q (int) – Downsampling rate to match the specified telescope’s sampling. The value of output_Q should be equal to oversampling_rate in order to have the right pixel sampling corresponding to the telescope characteristics pix_sampling, tel_diameter, tel_focal_length. The final oversampling obtained is oversampling_rate/output_Q. Default is 1, so the output psf will be super-resolved by a factor of oversampling_rate. TLDR: better use 1 and measure shapes on the super-resolved PSFs.

  • output_dim (int) – Output dimension of the square PSF stamps.

  • batch_size (int) – Batch size to process the PSF estimations.

  • opt_stars_rel_pix_rmse (bool) – If True, the relative pixel RMSE of each star is added to ther saving dictionary. The summary statistics are always computed. Default is False.

  • dataset_dict (dict) – Dictionary containing the dataset information. If provided, and if the ‘super_res_stars’ key is present, the noiseless super resolved stars from the dataset are used to compute the metrics. Otherwise, the stars are generated from the GT model. Default is None.

Returns:

result_dict – Dictionary with all the results.

Return type:

dict

wf_psf.metrics.metrics.gen_GT_wf_model(test_wf_file_path, pred_output_Q=1, pred_output_dim=64)[source]

Generate the ground truth model and output test PSF ar required resolution.

If pred_output_Q=1 the resolution will be 3 times the one of Euclid.

wf_psf.metrics.metrics.plot_function(mesh_pos, residual, tf_train_pos, tf_test_pos, title='Error')[source]
wf_psf.metrics.metrics.plot_imgs(mat, cmap='gist_stern', figsize=(20, 20))[source]

Function to plot 2D images of a tensor. The Tensor is (batch,xdim,ydim) and the matrix of subplots is chosen “intelligently”.

wf_psf.metrics.metrics.plot_residual_maps(GT_tf_semiparam_field, tf_semiparam_field, simPSF_np, train_SEDs, tf_train_pos, tf_test_pos, n_bins_lda=20, n_points_per_dim=30, is_poly=False)[source]