def _addAdditionalOptics(self, optsys, oversample=4): """Add coronagraphic or spectrographic optics for RomanCoronagraph.""" trySAM = False if ('pupil_shift_x' in self.options and self.options['pupil_shift_x'] != 0) or \ ('pupil_shift_y' in self.options and self.options['pupil_shift_y'] != 0): shift = (self.options['pupil_shift_x'], self.options['pupil_shift_y']) else: shift = None # Add the shaped pupil apodizer optsys.add_pupil(transmission=self._apodizer_fname, name=self.apodizer, shift=None) # Add the FPM optsys.add_image(transmission=self._fpm_fname, name=self.fpm) # Add Lyot stop self.pupil_mask = self.lyotstop optsys.add_pupil(transmission=self._lyotstop_fname, name=self.lyotstop, shift=shift) # Cast as MatrixFTCoronagraph; this configures the detector occ_box_size = 1. mft_optsys = poppy.MatrixFTCoronagraph(optsys, oversample=oversample, occulter_box=occ_box_size) return mft_optsys, trySAM, occ_box_size
def test_MatrixFT_FFT_Lyot_propagation_equivalence(display=False): """ Using a simple Lyot coronagraph prescription, perform a simple numerical check for consistency between calcPSF result of standard (FFT) propagation and MatrixFTCoronagraph subclass of OpticalSystem.""" D = 2. wavelen = 1e-6 ovsamp = 4 fftcoron_annFPM_osys = poppy.OpticalSystem(oversample=ovsamp) fftcoron_annFPM_osys.addPupil(poppy.CircularAperture(radius=D / 2)) spot = poppy.CircularOcculter(radius=0.4) diaphragm = poppy.InverseTransmission(poppy.CircularOcculter(radius=1.2)) annFPM = poppy.CompoundAnalyticOptic(opticslist=[diaphragm, spot]) fftcoron_annFPM_osys.addImage(annFPM) fftcoron_annFPM_osys.addPupil(poppy.CircularAperture(radius=0.9 * D / 2)) fftcoron_annFPM_osys.addDetector(pixelscale=0.05, fov_arcsec=3.) # Re-cast as MFT coronagraph with annular diaphragm FPM matrixFTcoron_annFPM_osys = poppy.MatrixFTCoronagraph( fftcoron_annFPM_osys, occulter_box=diaphragm.uninverted_optic.radius_inner) annFPM_fft_psf = fftcoron_annFPM_osys.calcPSF(wavelen) annFPM_mft_psf = matrixFTcoron_annFPM_osys.calcPSF(wavelen) diff_img = annFPM_mft_psf[0].data - annFPM_fft_psf[0].data abs_diff_img = np.abs(diff_img) if display: plt.figure(figsize=(16, 3)) plt.subplot(131) poppy.display_PSF(annFPM_fft_psf, vmin=1e-10, vmax=1e-6, title='Annular FPM Lyot coronagraph, FFT') plt.subplot(132) poppy.display_PSF(annFPM_mft_psf, vmin=1e-10, vmax=1e-6, title='Annular FPM Lyot coronagraph, Matrix FT') plt.subplot(133) plt.imshow((annFPM_mft_psf[0].data - annFPM_fft_psf[0].data), cmap='gist_heat') plt.colorbar() plt.title('Difference (MatrixFT - FFT)') plt.show() print("Max of absolute difference: %.10g" % np.max(abs_diff_img)) assert (np.all(abs_diff_img < 2e-7))