wf_psf.sims.SimPSFToolkit module

class wf_psf.sims.SimPSFToolkit.SimPSFToolkit(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: object

Simulate PSFs.

In the future the zernike maps could be created with galsim or some other alternative.

Parameters:
  • zernike_maps (Remove) –

  • XXXzernike_maps (list of np.ndarray) –

    Each element of the list should contain a Zernike map of the order

    (OSA/ANSI index convention) corresponding to the position in the list.

  • max_order (int) – Maximum Zernike polynomial order. Default is 45.

  • max_wfe_rms (float) – Maximum allowed WFE in RMS. Used forvnormalization. Units in [mu 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.

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.

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_mono_PSF([lambda_obs, ...])

Generate monochromatic PSF.

generate_poly_PSF(SED[, n_bins])

Generate polychromatic PSF with a specific SED.

generate_pupil_obscurations([N_pix, N_filter])

Generate Euclid like pupil obscurations.

get_z_coeffs()

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.

plot_z_coeffs([save_img])

Plot random Zernike coefficients.

set_z_coeffs(z_coeffs)

Set zernike coefficients.

crop_img

fft_diffract

get_psf

get_radial_idx

opd_phase_plotter

plot_opd_phase

plot_psf

psf_plotter

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 – Spectral energy distribution for a star

  • n_bins (int) – Number of bins

calculate_opd(regen_sample=False)[source]

Calculate the OPD from the Zernike coefficients.

calculate_wfe_rms(z_coeffs=None)[source]

Calculate WFE rms from a set of zernike coefficients.

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]
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.

feasible_N(lambda_obs)[source]

Calculate the feasible N for a lambda_obs diffraction.

Input wavelength must be in [um].

feasible_wavelength(lambda_obs)[source]

Calculate closest feasible wavelength to target wavelength.

Input wavelength must be in [um].

Parameters:

lambda_obs (float) –

static fft_diffract(wf, output_Q, output_dim=64)[source]
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. In the first column it contains the wavelength positions. In the second column 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].

gen_SED_sampler(SED, n_bins, interp_kind='cubic')[source]

Generate SED sampler.

Returns the sampler and the wavelengths in [nm]

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)

Parameters:
  • max_order (int) – Maximum order of Zernike polynomials.

  • rand_seed (int) – Seed for the random initialization.

Returns:

rand_coeffs – List containing the random coefficients.

Return type:

list of floats

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.

static generate_pupil_obscurations(N_pix=1024, N_filter=3)[source]

Generate Euclid like pupil obscurations.

Simple procedure considering only the 2D plane. No 3D projections wrt the angle of the FoV is done.

Parameters:
  • N_pix (int) – Total number of pixels

  • N_filter (int) – Length of the low-pass filter [pixels]

get_psf()[source]
static get_radial_idx(max_order=45)[source]
get_z_coeffs()[source]

Get random coefficients

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. In the first column it contains the wavelength positions. In the second column 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.

static opd_phase_plotter(pupil_mask, opd, phase, lambda_obs, cmap='viridis', save_img=False)[source]
plot_opd_phase(cmap='viridis', save_img=False)[source]
plot_psf(cmap='gist_stern', save_img=False)[source]
plot_z_coeffs(save_img=False)[source]

Plot random Zernike coefficients.

static psf_plotter(psf, lambda_obs=0.0, cmap='gist_stern', save_img=False)[source]
set_z_coeffs(z_coeffs)[source]

Set zernike coefficients.

wf_psf.sims.SimPSFToolkit.resize(src, dsize[, dst[, fx[, fy[, interpolation]]]]) dst

. @brief Resizes an image. . . The function resize resizes the image src down to or up to the specified size. Note that the . initial dst type or size are not taken into account. Instead, the size and type are derived from . the src,`dsize`,`fx`, and fy. If you want to resize src so that it fits the pre-created dst, . you may call the function as follows: . @code . // explicitly specify dsize=dst.size(); fx and fy will be computed from that. . resize(src, dst, dst.size(), 0, 0, interpolation); . @endcode . If you want to decimate the image by factor of 2 in each direction, you can call the function this . way: . @code . // specify fx and fy and let the function compute the destination image size. . resize(src, dst, Size(), 0.5, 0.5, interpolation); . @endcode . To shrink an image, it will generally look best with #INTER_AREA interpolation, whereas to . enlarge an image, it will generally look best with #INTER_CUBIC (slow) or #INTER_LINEAR . (faster but still looks OK). . . @param src input image. . @param dst output image; it has the size dsize (when it is non-zero) or the size computed from . src.size(), fx, and fy; the type of dst is the same as of src. . @param dsize output image size; if it equals zero (None in Python), it is computed as: . f[texttt{dsize = Size(round(fx*src.cols), round(fy*src.rows))}f] . Either dsize or both fx and fy must be non-zero. . @param fx scale factor along the horizontal axis; when it equals 0, it is computed as . f[texttt{(double)dsize.width/src.cols}f] . @param fy scale factor along the vertical axis; when it equals 0, it is computed as . f[texttt{(double)dsize.height/src.rows}f] . @param interpolation interpolation method, see #InterpolationFlags . . @sa warpAffine, warpPerspective, remap