wf_psf.sims.psf_simulator
PSF simulator.
A module to simulate PSFs from Zernike coefficients.
- Authors:
Tobias Liaudat <tobias.liaudat@cea.fr> & Jennifer Pollack <jennifer.pollack@cea.fr>
Classes
|
Simulate PSFs. |
- class wf_psf.sims.psf_simulator.PSFSimulator(max_order=45, max_wfe_rms=0.1, output_dim=64, rand_seed=None, plot_opt=False, oversampling_rate=3.0, output_Q=1, pix_sampling=12, tel_diameter=1.2, tel_focal_length=24.5, pupil_diameter=1024, euclid_obsc=True, LP_filter_length=3, verbose=0, SED_sigma=0, SED_interp_pts_per_bin=0, SED_extrapolate=True, SED_interp_kind='linear')[source]
Bases:
objectSimulate PSFs.
In the future the zernike maps could be created with galsim or some other alternative.
- Parameters:
max_order (int) – Maximum Zernike polynomial order. Default is 45.
max_wfe_rms (float) – Maximum allowed WFE in RMS. Used for normalization. Units in [μm]. Default is
0.1.output_dim (int) – Output dimension of the square PSF stamp. Default is 64.
rand_seed (int) – Random seed to be used to generate random zernike values. Default is None.
plot_opt (bool) – Option to plot some characteristics of the PSF generated. Default is False.
oversampling_rate (float) – Oversampling rate for the wavefront PSF simulation. Default is 2.14 that is the minumum number required by Euclid so that there is no aliasing at any wavelength in the pass band [0.55um, 0.9um].
output_Q (float) – 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.
pix_sampling (float) – Pixel sampling in [um]. Default is `12`[um] (Euclid-like).
tel_diameter (float) – Telescope’s main mirror diameter in [m]. Default is `1.2`[m] (Euclid-like).
tel_focal_length (float) – Telescope’s focal length in [m]. Default is `24.5`[m] (Euclid-like).
pupil_diameter (int) – Pupil diameter in pixels. Number of samples of the wavefront in the pupil plane. More specifically, the Optical Path Differences map. Default is 1024 [pix].
euclid_obsc (bool) – Wheter to use Euclid-like obscurations. Defualt is True.
LP_filter_length (int) – Length of one dimension of the Low-Pass (LP) filter to apply to the obscurations to avoid the aliasing effect. The filter is a simple top-hat filter. Default is 3.
verbose (int) – Self-explanatory variable. Default is 0, use a value >0 to activate.
SED_sigma (float) – Standard deviation of the multiplicative SED Gaussian noise.
SED_interp_pts_per_bin (int) – Number of points to interpolate in between SED values. It can be 0, 1 or 2.
SED_extrapolate (bool) – SED interpolation mode. Default mode uses extrapolation.
SED_interp_kind (str) – SED interpolation kind. Options are ‘cubic’ or ‘linear’.
Methods
SED_gen_noise(n_bins, SED_sigma)Generate random normal errors for the binned SED.
calc_SED_wave_values(SED[, n_bins])Calculate feasible wavelength and SED values.
calculate_opd([regen_sample])Calculate the OPD from the Zernike coefficients.
calculate_wfe_rms([z_coeffs])Calculate WFE rms from a set of zernike coefficients.
check_wfe_rms([z_coeffs, max_wfe_rms])Check if Zernike coefficients are within the maximum admitted error.
crop_img(to_crop_img, ref_im)Crop image.
decimate_im(input_im, decim_f)Decimate image.
diffract_phase([lambda_obs])Diffract the phase map.
feasible_N(lambda_obs)Calculate the feasible N for a lambda_obs diffraction.
feasible_wavelength(lambda_obs)Calculate closest feasible wavelength to target wavelength.
fft_diffract(wf, output_Q[, output_dim])Perform a fft-based diffraction.
filter_SED(SED, n_bins[, filter_lims])Generate filtered SED.
gen_SED_interp(SED[, n_bins, interp_kind])Generate SED interpolator.
gen_SED_sampler(SED, n_bins[, interp_kind])Generate SED sampler.
gen_random_Z_coeffs([max_order, rand_seed])Generate a random set of Zernike coefficients.
generate_euclid_pupil_obscurations([N_pix, ...])Generate Euclid like pupil obscurations.
generate_mono_PSF([lambda_obs, ...])Generate monochromatic PSF.
generate_poly_PSF(SED[, n_bins])Generate polychromatic PSF with a specific SED.
get_psf()Get computed PSF.
get_radial_idx([max_order])Get radial zernike indices.
Get random coefficients.
interp_SED(SED_filt[, n_points, n_bins, ...])Interpolate the binned SED.
normalize_zernikes([z_coeffs, max_wfe_rms])Normalize zernike coefficients.
opd_phase_plotter(pupil_mask, opd, phase, ...)Plot OPD and phase maps.
plot_opd_phase([cmap, save_img])Plot OPD and phase maps.
plot_psf([cmap, save_img])Plot PSF maps.
plot_z_coeffs([save_img])Plot random Zernike coefficients.
psf_plotter(psf[, lambda_obs, cmap, save_img])Plot PSF maps.
set_z_coeffs(z_coeffs)Set zernike coefficients.
- static SED_gen_noise(n_bins, SED_sigma)[source]
Generate random normal errors for the binned SED.
Returns a vector of size n_bins containing each bin error.
- Parameters:
n_bins (int) – Number of bins of the SED. It will be the length of the output noise vector.
SED_sigma (positive float) – Standard deviation value of the Gaussian noise vector.
- calc_SED_wave_values(SED, n_bins=35)[source]
Calculate feasible wavelength and SED values.
Feasible so that the padding number N is integer. Meaning choice of wavelengths matters in speeding up the diffraction computation.
- Parameters:
SED (np.ndarray) – Spectral energy distribution for a star at given wavelength positions. The first column contains the wavelength positions; the second column contains the SED value at each wavelength.
n_bins (int) – Number of bins
- Returns:
feasible_wv (np.ndarray) – Feasible wavelength positions in [um]
SED_norm (np.ndarray) – Normalized SED values at each feasible wavelength position
- calculate_opd(regen_sample=False)[source]
Calculate the OPD from the Zernike coefficients.
- Parameters:
regen_sample (bool) – Whether to regenerate a new random sample of Zernike coefficients.
- Returns:
opd – 2D array corresponding to the Optical Path Differences map.
- Return type:
np.ndarray
- check_wfe_rms(z_coeffs=None, max_wfe_rms=None)[source]
Check if Zernike coefficients are within the maximum admitted error.
- static crop_img(to_crop_img, ref_im)[source]
Crop image.
- Parameters:
to_crop_img (np.ndarray) – Image to be cropped.
ref_im (np.ndarray) – Reference image to match the size.
- Returns:
cropped_img – Cropped image.
- Return type:
np.ndarray
- static decimate_im(input_im, decim_f)[source]
Decimate image.
Decimated by a factor of decim_f. Based on the PIL library using the default interpolator.
- diffract_phase(lambda_obs=None)[source]
Diffract the phase map.
- Parameters:
lambda_obs (float) – Wavelength of observation in [um]. If None, use the stored wavelength.
- feasible_N(lambda_obs)[source]
Calculate the feasible N for a lambda_obs diffraction.
Input wavelength must be in [um].
- Parameters:
lambda_obs (float) – Target wavelength in [um].
- feasible_wavelength(lambda_obs)[source]
Calculate closest feasible wavelength to target wavelength.
Input wavelength must be in [um].
- Parameters:
lambda_obs (float) – Target wavelength in [um].
- static fft_diffract(wf, output_Q, output_dim=64)[source]
Perform a fft-based diffraction.
- Parameters:
- Returns:
psf – A real 2D array corresponding to the PSF.
- Return type:
np.ndarray
- static filter_SED(SED, n_bins, filter_lims=None)[source]
Generate filtered SED.
Returns a ‘n_bins’ point SED and wvlength vector. Each bin ‘i’ is obtained integrating the SED from filter_lims[i][0] and filter_lims[i][1]
- Parameters:
n_bins (int) – Number of desired bins for the integrated SED. It should be less or equal to the bins of the unfilterd SED.
SED (np.ndarray) – The unfiltered SED. The first column contains the wavelength positions. The second column contains the SED value at each wavelength.
filter_lims (list of np.ndarray) – Each element on the list contains the lower und upper integration limits for the bins. Midpoints of bins should be in increasing order. Bins can overlap or be disjoint.
- static gen_SED_interp(SED, n_bins=35, interp_kind='cubic')[source]
Generate SED interpolator.
Returns the interpolator and the wavelengths in [nm].
- Parameters:
SED (np.ndarray) – The SED. In the first column it contains the wavelength positions. In the second column the SED value at each wavelength.
n_bins (int) – Number of desired bins for the SED interpolation.
interp_kind (str) – Type of interpolation to be used. See scipy.interpolate.interp1d documentation.
- gen_SED_sampler(SED, n_bins, interp_kind='cubic')[source]
Generate SED sampler.
Returns the sampler and the wavelengths in [nm]
- Parameters:
- Returns:
wvlength (np.ndarray) – Wavelength positions in [nm]
SED_sampler (callable) – Interpolator function for the SED
weights (np.ndarray) – Weights for each wavelength bin in the SED
- gen_random_Z_coeffs(max_order=45, rand_seed=None)[source]
Generate a random set of Zernike coefficients.
The coefficients are generated following a uniform law U~[-1,1] divided by their radial zernike index. Ex: u_i / r(i) (u_i is a realization of U)
- static generate_euclid_pupil_obscurations(N_pix=1024, N_filter=3, rotation_angle=0)[source]
Generate Euclid like pupil obscurations.
This method simulates the 2D pupil obscurations for the Euclid telescope, considering the aperture stop, mirror obscurations, and spider arms. It does not account for any 3D projections or the angle of the Field of View (FoV).
- generate_mono_PSF(lambda_obs=0.725, regen_sample=False, get_psf=False)[source]
Generate monochromatic PSF.
- generate_poly_PSF(SED, n_bins=35)[source]
Generate polychromatic PSF with a specific SED.
The wavelength space will be the Euclid VIS instrument band: [550,900]nm and will be sampled in
n_bins.
- get_psf()[source]
Get computed PSF.
- Returns:
psf – A real 2D array corresponding to the PSF.
- Return type:
np.ndarray
- static get_radial_idx(max_order=45)[source]
Get radial zernike indices.
- Parameters:
max_order (int) – Maximum Zernike polynomial order.
- Returns:
radial_idxs – Array of radial indices up to the specified maximum order.
- Return type:
np.ndarray
- get_z_coeffs()[source]
Get random coefficients.
- Returns:
z_coeffs – List containing the random coefficients.
- Return type:
list of floats
- interp_SED(SED_filt, n_points=0, n_bins=35, interp_kind='cubic')[source]
Interpolate the binned SED.
Returns a (‘n_bins’)x(‘n_points’+1) point SED and wvlength vector.
- Parameters:
SED_filt (np.ndarray) – The filtered SED. The first column contains the wavelength positions. The second column contains the SED value for each bin.
n_points (int) – Number of points to add in each of the filtered SED bins. It can only be 1 or 2.
- normalize_zernikes(z_coeffs=None, max_wfe_rms=None)[source]
Normalize zernike coefficients.
Returns a set of zernike coefficients normalized to the maximum allowed WFE rms.
- static opd_phase_plotter(pupil_mask, opd, phase, lambda_obs, cmap='viridis', save_img=False)[source]
Plot OPD and phase maps.
- Parameters:
pupil_mask (np.ndarray) – 2D array corresponding to the pupil mask.
opd (np.ndarray) – 2D array corresponding to the Optical Path Differences map.
phase (np.ndarray) – 2D array corresponding to the wavefront phase map.
lambda_obs (float) – Wavelength of observation in [um].
cmap (str) – Colormap to be used for the plots.
save_img (bool) – Whether to save the image as a PDF.