Main THD
- class Asterix.main_THD.THD2(config, model_local_dir, silence=False)
Bases:
Testbed
Testbed object configured for THD2, from input configfile.
AUTHOR : ILa, Nov 2022
- Attributes:
- configdict
A read-in .ini parameter file.
Methods
EF_from_phase_and_ampl
([phase_abb, ...])Create an electrical field from an phase and amplitude aberrations as follows:
EF_through
([entrance_EF])Propagate the electric field from entrance pupil to exit pupil.
add_photon_noise
(focal_plane_intensity, ...)Add photon noise to an image in contrast.
basis_vector_to_act_vector
(vector_basis_voltage)transform a vector of voltages on the mode of a basis in a vector of voltages of the actuators of the DMs of the system.
generate_ampl_aberr
(SIMUconfig[, ...])Generate and save amplitude aberations.
generate_phase_aberr
(SIMUconfig[, ...])Generate and save phase aberrations.
individual_normalizations
([wavelengths])For a given wavelength list, this function is used to measure the maximum and total energy for each wavelength and then for the whole bandwidth.
Measure several values to normalize the data.
todetector
([entrance_EF, wavelength, ...])Propagate the electric field from entrance plane through the system and then to Science focal plane.
todetector_intensity
([entrance_EF, ...])Propagate the electric field from entrance plane through the system, then to Science focal plane and measure intensity.
transmission
([noFPM])Measure ratio of photons lost when crossing the system compared to a clear round aperture of radius self.prad.
voltage_to_phases
(actu_vect[, einstein_sum])Generate the phase applied on each DMs of the testbed from a given vector of actuator amplitude.
- EF_from_phase_and_ampl(phase_abb=0.0, ampl_abb=0.0, wavelengths=-1.0)
Create an electrical field from an phase and amplitude aberrations as follows:
EF = (1 + ample_abb)*exp(i*phase_abb * self.wavelength_0 / wavelength) can be monochromatic (return 2d compex array) or polychromatic (return 3d compex array) if no phase nor amplitude, return 1.
AUTHOR : Johan Mazoyer
- Parameters:
- phase_abb2D array of size [self.dim_overpad_pupil, self.dim_overpad_pupil]. real
Phase aberration at reference wavelength self.wavelength_0. if 0, no phase aberration (default)
- ampl_abb2D array of size [self.dim_overpad_pupil, self.dim_overpad_pupil]. real
Amplitude aberration at reference wavelength self.wavelength_0. if 0, no amplitude aberration (default)
- wavelengthsfloat or list of floats
Default is all the wl of the testbed self.wav_vec wavelengths in m.
- Returns:
- EFscalar or numpy 2D array or numpy 3d array
- Electric field in the pupil plane a the exit of the system:
1. if no phase / amplitude 2D array, of size phase_abb.shape if monochromatic or 3D array of size [self.nb_wav,phase_abb.shape] in case of polychromatic
- EF_through(entrance_EF=1.0, **kwargs)
Propagate the electric field from entrance pupil to exit pupil.
NEED TO BE DEFINED FOR ALL OpticalSystem subclasses
AUTHOR : Johan Mazoyer
- Parameters:
- entrance_EF2D array of size [self.dim_overpad_pupil, self.dim_overpad_pupil], or complex/float scalar (entrance_EF is constant), default is 1.
Electric field in the pupil plane a the entrance of the system.
- dir_save_all_planesstring or None, default None
If not None, absolute directory to save all planes in fits for debugging purposes. This can generate a lot of fits especially if in a loop, use with caution.
- **kwargs
other parameters can be passed for OpticalSystem objects EF_trough functions
- Returns:
- exit_EF2D array, of size [self.dim_overpad_pupil, self.dim_overpad_pupil]
Electric field in the pupil plane a the exit of the system
- add_photon_noise(focal_plane_intensity, nb_photons, in_contrast=True)
Add photon noise to an image in contrast.
This is only applied to images for which the normalization factors have been measured (for wavelength in self.wave_vec). You need to have measured the normalization previously (running self.measure_normalization). Making it separate allow us to run the propagation only once in cases where we want both the image with and without photon noise.
AUTHOR : Johan Mazoyer
- Parameters:
focal_plane_intensity (numpy array of shape (self.dimScience,self.dimScience)) – the focal plane intensity, normalized in contrast
nb_photons (float) – Number of photons entering the pupil.
in_contrast (bool, default True.) – If True, the data are normalized in contrast
- Returns:
- focal_plane_intensitynumpy array of shape (self.dimScience,self.dimScience)
the focal plane intensity, with photon noise, normalized in contrast
- basis_vector_to_act_vector(vector_basis_voltage)
transform a vector of voltages on the mode of a basis in a vector of voltages of the actuators of the DMs of the system.
AUTHOR : Johan Mazoyer
- Parameters:
- vector_basis_voltage1D-array real
Vector of voltages of size (total(basisDM sizes)) on the mode of the basis for all DMs by order of the light path.
- Returns:
- vector_actuator_voltage1D-array real
Vector of base coefficients for all actuators of the DMs by order of the light path size (total(DM actuators)).
- generate_ampl_aberr(SIMUconfig, Model_local_dir=None, silence=False)
Generate and save amplitude aberations.
AUTHOR : Johan Mazoyer
- Parameters:
- SIMUconfigdict
Parameter of this simualtion (describing the amplitude)
- Model_local_dirstring or None, default None
Directory output path for model-related files created on the file for later reuse.
- silenceboolean, default False.
Whether to silence print outputs.
- Returns
- ——–
- return_ampl2D array, real of size [self.dim_overpad_pupil, self.dim_overpad_pupil]
Amplitude abberation
- generate_phase_aberr(SIMUconfig, up_or_down='up', Model_local_dir=None, silence=False)
Generate and save phase aberrations.
AUTHOR : Johan Mazoyer
- Parameters:
- SIMUconfigdict
parameter of this simualtion (describing the phase)
- up_or_downstring, default, ‘up’
‘up’ or ‘do’, use to access the right parameters in the parameter file for upstream (entrance pupil) or downstream (Lyot plane) aberrations
- Model_local_dirstring or None, default None
Directory output path for model-related files created on the file for later reuse. In this case the phase aberrations is saved if Model_local_dir is not None
- silenceboolean, default False.
Whether to silence print outputs.
- Returns
- ——–
- return_phase2D array, real of size [self.dim_overpad_pupil, self.dim_overpad_pupil]
phase aberration at the reference wavelength
- individual_normalizations(wavelengths=None)
For a given wavelength list, this function is used to measure the maximum and total energy for each wavelength and then for the whole bandwidth.
AUTHOR : Johan Mazoyer
- Parameters:
- wavelengthsfloat or list of floats.
Default is all the wl of the testbed self.wav_vec wavelengths in m.
- Returns:
- norm_polychromfloat
Maximum value of the PSF in polychrom light. Used to normalize to_detector_intensity().
- sum_polychromfloat
Sum of the PSF in polychrom light. Used to normalize for photon noise.
- norm_monochromnumpy array of the same length as wavelengths
Norm of PSFs at each wavelength. Can be used to individually normalize PSFs in monochromatic light.
- sum_monochromnumpy array of the same length as wavelengths
Sum of PSFs at each wavelength. Not sure if useful at all but comes for free here.
- measure_normalization()
Measure several values to normalize the data.
Function must be used at the end of all Optical Systems initalization.
- Measure 3 values:
- self.norm_monochrom. Array of size len(self.wav_vec)
the PSF per WL, use to normalize to_detector
- self.norm_polychrom. float
the polychromatic PSF used to normalize to_detector_Intensity
- self.normPupto1, which is used to measure the photon noise
This is the factor that we use to measure photon noise. From an image in contrast, we now normalize by the total amount of energy (*self.norm_polychrom / self.sum_polychrom) and then account for the energy lost in the process (self.transmission()). Can be used as follow: Im_intensity_photons = Im_Intensity_contrast * self.normPupto1 * nb_photons
AUTHOR : Johan Mazoyer
- todetector(entrance_EF=1.0, wavelength=None, center_on_pixel=False, in_contrast=True, dir_save_all_planes=None, **kwargs)
Propagate the electric field from entrance plane through the system and then to Science focal plane.
AUTHOR : Johan Mazoyer
- Parameters:
- entrance_EF2D complex array of size [self.dim_overpad_pupil, self.dim_overpad_pupil], or complex/float scalar (entrance_EF is constant), default is 1.
Electric field in the pupil plane a the entrance of the system.
- wavelengthfloat. Default is self.wavelength_0 the reference wavelength
Current wavelength in m.
- in_contrastbool, default True
Normalize to np.sqrt(self.norm_monochrom[self.wav_vec.tolist().index(wavelength)])) (see self.measure_normalization)
- center_on_pixelbool Default False
If True, the PSF will be centered on a pixel If False, the PSF will be centered between 4 pixels This of course assume that no tip-tilt have been introduced in the entrance_EFor during self.EF_through
- dir_save_all_planesstring or None, default None
If not None, absolute directory to save all planes in fits for debugging purposes. This can generate a lot of fits especially if in a loop, use with caution.
- **kwargs
other kw parameters can be passed direclty to self.EF_through function
- Returns:
- ef_focal_plane2D array of size [self.dimScience, self.dimScience]
Electric field in the focal plane. the lambda / D is defined with the entrance pupil diameter, such as: self.wavelength_0 / (2*self.prad) = self.Science_sampling pixels
- todetector_intensity(entrance_EF=1.0, wavelengths=None, in_contrast=True, center_on_pixel=False, nb_photons=0, dir_save_all_planes=None, **kwargs)
Propagate the electric field from entrance plane through the system, then to Science focal plane and measure intensity.
AUTHOR : Johan Mazoyer
- Parameters:
- entrance_EF3D complex array of size [nb_wav, self.dim_overpad_pupil, self.dim_overpad_pupil]
or 2D complex array of size [self.dim_overpad_pupil, self.dim_overpad_pupil] or complex/float scalar (entrance_EF is constant), default is 1.
Electric field in the pupil plane a the entrance of the system.
- wavelengthsfloat or float array of wavelength in m.
Default is all wavelenthg in self.wav_vec
- in_contrastbool, default True. normalize to
self.norm_polychrom (see self.measure_normalization)
- center_on_pixelbool Default False
If True, the PSF will be centered on a pixel If False, the PSF will be centered between 4 pixels This of course assume that no tip-tilt have been introduced in the entrance_EF or during self.EF_through
- dir_save_all_planesstring or None, default None
If not None, absolute directory to save all planes in fits for debugging purposes. This can generate a lot of fits especially if in a loop, use with caution.
- nb_photonsfloat, optional, default 0
Number of photons entering the pupil. If 0, no photon noise.
- **kwargs
Other kw parameters can be passed direclty to self.EF_through function
- Returns:
- focal_plane_intensity2D array of size [self.dimScience, self.dimScience]
Intensity in the focal plane. the lambda / D is defined with the entrance pupil diameter, such as: self.wavelength_0 / (2*self.prad) = self.Science_sampling pixels
- transmission(noFPM=True, **kwargs)
Measure ratio of photons lost when crossing the system compared to a clear round aperture of radius self.prad.
By default, transmission is done at the reference WL, and there is no reason to depend heavily on the WL.
AUTHOR : Johan Mazoyer
- Parameters:
noFPM (bool, defaut True) – if the optical transfert function EF_through has a noFPM parameter
**kwargs – other kw parameters can be passed direclty to self.EF_through function
- Returns:
- transmissionfloat
ratio exit flux / clear entrance pupil flux
- voltage_to_phases(actu_vect, einstein_sum=False)
Generate the phase applied on each DMs of the testbed from a given vector of actuator amplitude. I split theactu_vect and then for each DM, it uses DM.voltage_to_phase (no s)
AUTHOR : Johan Mazoyer
- Parameters:
- actu_vectfloat or 1D array of size testbed.number_act
Values of the amplitudes for each actuator and each DM.
- einstein_sumboolean. default False
Use numpy Einstein sum to sum the pushact[i]*actu_vect[i] gives the same results as normal sum. Seems ot be faster for unique actuator but slower for more complex phases.
- Returns:
- phases3D array of size [testbed.number_DMs, testbed.dim_overpad_pupil,testbed.dim_overpad_pupil]
Phase maps for each DMs by order of light path in the same unit as actu_vect * DM_pushact.
- Asterix.main_THD.runthd2(parameter_file_path, NewMODELconfig={}, NewDMconfig={}, NewCoronaconfig={}, NewEstimationconfig={}, NewCorrectionconfig={}, NewLoopconfig={}, NewSIMUconfig={}, silence=False, **kwargs)
Run a simulation of a correction loop for the THD2 testbed.
Initialize the THD2 testbed, the estimation method, the correction method from parameter_file_path. Run the loop and save the results.
All NewXXXconfig input variables can be used to update a single parameter in one of the subsections of the parameter file. This will replace only the overwritten value in the parameter file. e.g.: NewCoronaconfig = {‘paramXXX’: YYY}
AUTHOR : Johan Mazoyer
- Parameters:
- parameter_file_path: string
Absolute path to a .ini parameter file
- NewMODELconfigdict, optional
Can be used to directly change a parameter in the MODELconfig section of the input parameter file.
- NewDMconfigdict, optional
Can be used to directly change a parameter in the DMconfig section of the input parameter file.
- NewCoronaconfigdict, optional
Can be used to directly change a parameter in the Coronaconfig section of the input parameter file.
- NewEstimationconfigdict, optional
Can be used to directly change a parameter in the Estimationconfig section of the input parameter file.
- NewCorrectionconfigdict, optional
Can be used to directly change a parameter in the Correctionconfig section of the input parameter file.
- NewSIMUconfigdict, optional
Can be used to directly change a parameter in the SIMUconfig section of the input parameter file.
- silenceboolean, default False.
Whether to silence print outputs.