def multi_prop(n,lam, prefix, beam_ratio, RAVC=True, LS=True): diam = 37. print("lam: ", lam) print("beam_ratio: ", beam_ratio) npupil = math.ceil(n*beam_ratio) # compute the pupil size --> has to be ODD (proper puts the center in the up right pixel next to the grid center) if npupil % 2 == 0: npupil = npupil +1 ## Non coronagraphic PSF --> simulate a non-coronagraphic psf (wfo_noCoro, sampling) = proper.prop_run_multi('simple_telescope', lam, n, PASSVALUE={'prefix':prefix, 'charge':0, 'diam':diam,'beam_ratio':beam_ratio, 'RAVC':False, 'LS':False}, QUIET=True) #(wfo_noCoro, sampling) = proper.prop_run('simple_telescope', lam, n, PASSVALUE={'prefix':prefix, 'charge':0, 'diam':37., 'RAVC':False, 'LS':False}, QUIET=True) NoCoro_psf = (abs(wfo_noCoro))**2 fits.writeto(prefix+'psf_noCoro_nonorm.fits', NoCoro_psf, overwrite=True)#[int(n/2)-math.ceil(50./beam_ratio):int(n/2)+math.ceil(50./beam_ratio),int(n/2)-math.ceil(50./beam_ratio):int(n/2)+math.ceil(50./beam_ratio)], overwrite=True) psf_noCoro_maxnorm = NoCoro_psf/np.max(NoCoro_psf) fits.writeto(prefix+'_psf_noCoro_maxnorm.fits', psf_noCoro_maxnorm, overwrite=True)#[int(n/2)-math.ceil(50./beam_ratio):int(n/2)+math.ceil(50./beam_ratio),int(n/2)-math.ceil(50./beam_ratio):int(n/2)+math.ceil(50./beam_ratio)], overwrite=True) psf_noCoro_flux1norm = NoCoro_psf/sum(sum(NoCoro_psf)) fits.writeto(prefix+'_psf_noCoro_flux1norm.fits', psf_noCoro_flux1norm, overwrite=True)#[int(n/2)-math.ceil(50./beam_ratio):int(n/2)+math.ceil(50./beam_ratio),int(n/2)-math.ceil(50./beam_ratio):int(n/2)+math.ceil(50./beam_ratio)], overwrite=True) ## No Vortex Si Mask --> simulate a non-coronagraphic-apodized psf: apodizer and Lyot Stop are present, but not the vortex --> as an off-axis psf (wfo_offaxis, sampling) = proper.prop_run_multi('simple_telescope', lam, n, PASSVALUE={'prefix':prefix, 'charge':0, 'diam':diam,'beam_ratio':beam_ratio, 'RAVC':RAVC, 'LS':LS}, QUIET=True) #(wfo_offaxis, sampling) = proper.prop_run('simple_telescope', lam, n, PASSVALUE={'prefix':prefix, 'charge':0, 'diam':37., 'RAVC':RAVC, 'LS':LS}, QUIET=True) Offaxis_psf = (abs(wfo_offaxis))**2 fits.writeto(prefix+'psf_offaxis_nonorm.fits', Offaxis_psf, overwrite=True)#[int(n/2)-math.ceil(50./beam_ratio):int(n/2)+math.ceil(50./beam_ratio),int(n/2)-math.ceil(50./beam_ratio):int(n/2)+math.ceil(50./beam_ratio)], overwrite=True) psf_noVortex_Mask_maxnorm = Offaxis_psf/np.max(NoCoro_psf) fits.writeto(prefix+'psf_offaxis_maxnorm.fits', psf_noVortex_Mask_maxnorm, overwrite=True)#[int(n/2)-math.ceil(50./beam_ratio):int(n/2)+math.ceil(50./beam_ratio),int(n/2)-math.ceil(50./beam_ratio):int(n/2)+math.ceil(50./beam_ratio)], overwrite=True) psf_noVortex_Mask_flux1norm = Offaxis_psf/sum(sum(NoCoro_psf)) fits.writeto(prefix+'psf_offaxis_flux1norm.fits', psf_noVortex_Mask_flux1norm, overwrite=True)#[int(n/2)-math.ceil(50./beam_ratio):int(n/2)+math.ceil(50./beam_ratio),int(n/2)-math.ceil(50./beam_ratio):int(n/2)+math.ceil(50./beam_ratio)], overwrite=True) (wfo_Coro, sampling) = proper.prop_run_multi('simple_telescope', lam, n, PASSVALUE={'prefix':prefix, 'charge':2, 'diam':diam,'beam_ratio':beam_ratio, 'RAVC':RAVC, 'LS':LS}, QUIET=True) #(wfo_Coro, sampling) = proper.prop_run('simple_telescope', lam, n, PASSVALUE={'prefix':prefix, 'charge':2, 'diam':37., 'RAVC':RAVC, 'LS':LS}, QUIET=True) psf_Coro = (abs(wfo_Coro))**2 fits.writeto(prefix+'_psf_Coro_nonorm.fits', psf_Coro, overwrite=True)#[int(n/2)-math.ceil(50./beam_ratio):int(n/2)+math.ceil(50./beam_ratio),int(n/2)-math.ceil(50./beam_ratio):int(n/2)+math.ceil(50./beam_ratio)], overwrite=True) psf_Coro_maxnorm = psf_Coro/np.max(Offaxis_psf) fits.writeto(prefix+'_psf_Coro_maxnorm.fits', psf_Coro_maxnorm, overwrite=True)#[int(n/2)-math.ceil(50./beam_ratio):int(n/2)+math.ceil(50./beam_ratio),int(n/2)-math.ceil(50./beam_ratio):int(n/2)+math.ceil(50./beam_ratio)], overwrite=True) psf_Coro_flux1norm = psf_Coro/sum(sum(NoCoro_psf)) fits.writeto(prefix+'_psf_Coro_flux1norm.fits', psf_Coro_flux1norm, overwrite=True)#[int(n/2)-math.ceil(50./beam_ratio):int(n/2)+math.ceil(50./beam_ratio),int(n/2)-math.ceil(50./beam_ratio):int(n/2)+math.ceil(50./beam_ratio)], overwrite=True) return
def run_hlc_erkin(): nlam = 7 lam0 = 0.575 bandwidth = 0.1 minlam = lam0 * (1 - bandwidth/2) maxlam = lam0 * (1 + bandwidth/2) lam_array = np.linspace( minlam, maxlam, nlam ) n = 256 # output image dimension final_sampling = 0.1 # output sampling in lam0/D # compute coronagraphic field print( "Computing coronagraphic field..." ) (fields, sampling) = proper.prop_run_multi('wfirst_phaseb', lam_array, n, QUIET=True, \ PASSVALUE={'cor_type':'hlc_erkin','use_errors':0,'zindex':[4],'zval_m':[0.19e-9], 'use_hlc_dm_patterns':1, 'final_sampling_lam0':final_sampling} ) images = np.abs(fields)**2 image = np.sum( images, 0 ) / nlam # move source to 7 lam/D print( "Computing offset source to compute NI..." ) (fields, sampling) = proper.prop_run_multi('wfirst_phaseb_compact', lam_array, n, QUIET=True, \ PASSVALUE={'cor_type':'hlc_erkin','source_x_offset':7.0,'final_sampling_lam0':final_sampling, 'use_hlc_dm_patterns':1} ) psfs = np.abs(fields)**2 psf = np.sum( psfs, 0 ) / nlam ni = image / np.max(psf) fig, ax = plt.subplots( figsize=(8,8) ) im = ax.imshow(ni, norm=LogNorm(vmin=1e-10,vmax=1e-7), cmap=plt.get_cmap('jet')) circ = Circle((n/2,n/2),3/final_sampling,edgecolor='white', facecolor='none') ax.add_patch(circ) circ = Circle((n/2,n/2),9/final_sampling,edgecolor='white', facecolor='none') ax.add_patch(circ) fig.colorbar(im, shrink=0.5) plt.show()
def form_multi_psf(prescription, sources, gridsize, common_sampling, npsf, multi=True): source_psfs = [] for source in sources: settings = source['settings'] wavelengths = source['wavelengths'] wl_weights = source['weights'] if multi is True: (wavefronts, samplings) = proper.prop_run_multi(prescription, wavelengths, gridsize=gridsize, QUIET=True, PRINT_INTENSITY=False, PASSVALUE=settings) # prop_run_multi returns complex arrays, even when PSFs are intensity, so make real with abs psfs = normalise_sampling(np.abs(wavefronts), samplings, common_sampling, npsf) else: wavefronts = [] samplings = [] for wl in wavelengths: (wavefront, sampling) = proper.prop_run(prescription, wl, gridsize=gridsize, QUIET=True, PRINT_INTENSITY=False, PASSVALUE=settings) wavefronts.append(wavefront) samplings.append(sampling) psfs = normalise_sampling(wavefronts, samplings, common_sampling, npsf) source_psfs.append(combine_psfs(psfs, wl_weights)) psf_all = combine_psfs(np.stack(source_psfs), [1. for i in range(len(source_psfs))]) return psf_all
def run_hlc(): nlam = 7 lam0 = 0.575 bandwidth = 0.1 minlam = lam0 * (1 - bandwidth / 2) maxlam = lam0 * (1 + bandwidth / 2) lam_array = np.linspace(minlam, maxlam, nlam) n = 256 # output image dimension (must be power of 2) final_sampling = 0.1 # output sampling in lam0/D # compute unaberrated coronagraphic field using Dwight's DM wavefront maps print( "Computing unaberrated coronagraphic field using DM wavefront map...") (fields, sampling) = proper.prop_run_multi('wfirst_phaseb', lam_array, n, QUIET=True, \ PASSVALUE={'cor_type':'hlc','use_errors':0,'zindex':[4],'zval_m':[0.19e-9], 'use_hlc_dm_patterns':1,'final_sampling_lam0':final_sampling} ) images = np.abs(fields)**2 image = np.sum(images, 0) / nlam # compute unaberrated coronagraphic field using DM actuator settings print( "Computing unaberrated coronagraphic field using DM actuator pistons..." ) dm1 = proper.prop_fits_read(wfirst_phaseb_proper.lib_dir + '/examples/hlc_dm1.fits') dm2 = proper.prop_fits_read(wfirst_phaseb_proper.lib_dir + '/examples/hlc_dm2.fits') (fields, sampling) = proper.prop_run_multi('wfirst_phaseb', lam_array, n, QUIET=True, \ PASSVALUE={'cor_type':'hlc','use_errors':0,'zindex':[4],'zval_m':[0.19e-9], 'use_hlc_dm_patterns':0,'final_sampling_lam0':final_sampling, 'use_dm1':1, 'dm1_m':dm1, 'use_dm2':1, 'dm2_m':dm2} ) images = np.abs(fields)**2 image_dm = np.sum(images, 0) / nlam # compute aberrated coronagraphic field using DM actuator settings print( "Computing aberrated coronagraphic field using DM actuator pistons...") dm1 = proper.prop_fits_read(wfirst_phaseb_proper.lib_dir + '/examples/hlc_with_aberrations_dm1.fits') dm2 = proper.prop_fits_read(wfirst_phaseb_proper.lib_dir + '/examples/hlc_with_aberrations_dm2.fits') (fields, sampling) = proper.prop_run_multi('wfirst_phaseb', lam_array, n, QUIET=True, \ PASSVALUE={'cor_type':'hlc', 'use_errors':1, 'polaxis':10, 'use_hlc_dm_patterns':0, 'final_sampling_lam0':final_sampling, 'use_dm1':1, 'dm1_m':dm1, 'use_dm2':1, 'dm2_m':dm2} ) images = np.abs(fields)**2 image_ab = np.sum(images, 0) / nlam # move source to 7 lam/D print("Computing offset source to compute NI...") (fields, sampling) = proper.prop_run_multi('wfirst_phaseb_compact', lam_array, n, QUIET=True, \ PASSVALUE={'cor_type':'hlc','source_x_offset':7.0,'use_hlc_dm_patterns':1,'final_sampling_lam0':final_sampling} ) psfs = np.abs(fields)**2 psf = np.sum(psfs, 0) / nlam max_psf = np.max(psf) ni = image / max_psf ni_dm = image_dm / max_psf ni_ab = image_ab / max_psf fig, ax = plt.subplots(nrows=1, ncols=3, figsize=(11, 4)) im = ax[0].imshow(ni, norm=LogNorm(vmin=1e-10, vmax=1e-7), cmap=plt.get_cmap('jet')) circ_in = Circle((n / 2, n / 2), 3 / final_sampling, edgecolor='white', facecolor='none') circ_out = Circle((n / 2, n / 2), 9 / final_sampling, edgecolor='white', facecolor='none') ax[0].add_patch(circ_in) ax[0].add_patch(circ_out) ax[0].set_title('Unaberrated,\nUsing wavefront maps') fig.colorbar(im, ax=ax[0], shrink=0.5) im = ax[1].imshow(ni_dm, norm=LogNorm(vmin=1e-10, vmax=1e-7), cmap=plt.get_cmap('jet')) circ_in = Circle((n / 2, n / 2), 3 / final_sampling, edgecolor='white', facecolor='none') circ_out = Circle((n / 2, n / 2), 9 / final_sampling, edgecolor='white', facecolor='none') ax[1].add_patch(circ_in) ax[1].add_patch(circ_out) ax[1].set_title('Unaberrated,\nUsing DM piston maps') fig.colorbar(im, ax=ax[1], shrink=0.5) im = ax[2].imshow(ni_ab, norm=LogNorm(vmin=1e-10, vmax=1e-7), cmap=plt.get_cmap('jet')) circ_in = Circle((n / 2, n / 2), 3 / final_sampling, edgecolor='white', facecolor='none') circ_out = Circle((n / 2, n / 2), 9 / final_sampling, edgecolor='white', facecolor='none') ax[2].add_patch(circ_in) ax[2].add_patch(circ_out) ax[2].set_title('Aberrated,\nUsing DM piston maps') fig.colorbar(im, ax=ax[2], shrink=0.5) plt.show()
def run_flatten(): nlam = 7 lam0 = 0.575 bandwidth = 0.1 minlam = lam0 * (1 - bandwidth / 2) maxlam = lam0 * (1 + bandwidth / 2) lam_array = np.linspace(minlam, maxlam, nlam) n = 256 final_sampling = 0.1 # compute field before flattening (use HLC DM WFE maps) print("Computing field before flattening...") fields, sampling = proper.prop_run_multi( 'wfirst_phaseb', lam_array, n, QUIET=True, \ PASSVALUE={'final_sampling_lam0':final_sampling, 'use_hlc_dm_patterns':1, 'use_errors':1, 'polaxis':10} ) images = np.abs(fields)**2 image_before = np.sum(images, 0) / nlam # compute field after flattening dm1 = proper.prop_fits_read(wfirst_phaseb_proper.lib_dir + '/examples/errors_polaxis10_dm.fits') print("Computing field after flattening...") fields, sampling = proper.prop_run_multi( 'wfirst_phaseb', lam_array, n, QUIET=True, \ PASSVALUE={'final_sampling_lam0':final_sampling, 'use_dm1':1, 'dm1_m':dm1, 'use_hlc_dm_patterns':1, 'use_errors':1, 'polaxis':10} ) images = np.abs(fields)**2 image_after = np.sum(images, 0) / nlam # move source by 7.0 lam/D print("Computing offset source to compute NI...") fields, sampling = proper.prop_run_multi( 'wfirst_phaseb_compact', lam_array, n, QUIET=True, \ PASSVALUE={'source_x_offset':7.0,'final_sampling_lam0':final_sampling,'use_hlc_dm_patterns':1} ) images = np.abs(fields)**2 psf = np.sum(images, 0) / nlam max_psf = np.max(psf) ni_before = image_before / max_psf ni_after = image_after / max_psf fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(9, 4)) im = ax[0].imshow(ni_before, norm=LogNorm(vmin=1e-7, vmax=1e-2), cmap=plt.get_cmap('jet')) circ = Circle((n / 2, n / 2), 3 / final_sampling, edgecolor='white', facecolor='none') ax[0].add_patch(circ) circ = Circle((n / 2, n / 2), 9 / final_sampling, edgecolor='white', facecolor='none') ax[0].add_patch(circ) ax[0].set_title('Before') fig.colorbar(im, ax=ax[0], shrink=0.5) im = ax[1].imshow(ni_after, norm=LogNorm(vmin=1e-7, vmax=1e-2), cmap=plt.get_cmap('jet')) circ = Circle((n / 2, n / 2), 3 / final_sampling, edgecolor='white', facecolor='none') ax[1].add_patch(circ) circ = Circle((n / 2, n / 2), 9 / final_sampling, edgecolor='white', facecolor='none') ax[1].add_patch(circ) ax[1].set_title('After') fig.colorbar(im, ax=ax[1], shrink=0.5) plt.show()
def run_spc_wide_new(): nlam = 7 lam0 = 0.825 bandwidth = 0.1 minlam = lam0 * (1 - bandwidth / 2) maxlam = lam0 * (1 + bandwidth / 2) lam_array = np.linspace(minlam, maxlam, nlam) n = 512 # output image dimension (must be power of 2) final_sampling = 0.1 # output sampling in lam0/D # compute unaberrated coronagraphic field print("Computing unaberrated coronagraphic field using compact model...") (fields, sampling) = proper.prop_run_multi('wfirst_phaseb_compact', lam_array, n, QUIET=True, \ PASSVALUE={'cor_type':'spc-wide','final_sampling_lam0':final_sampling} ) images = np.abs(fields)**2 image_noab = np.sum(images, 0) / nlam # compute aberrated coronagraphic field using EFC-derived DM actuator settings print( "Computing aberrated coronagraphic field using DM actuator pistons...") dm1 = proper.prop_fits_read(wfirst_phaseb_proper.lib_dir + '/examples/spc-wide_with_aberrations_dm1.fits') dm2 = proper.prop_fits_read(wfirst_phaseb_proper.lib_dir + '/examples/spc-wide_with_aberrations_dm2.fits') (fields, sampling) = proper.prop_run_multi('wfirst_phaseb', lam_array, n, QUIET=True, \ PASSVALUE={'cor_type':'spc-wide', 'use_errors':1, 'polaxis':10, 'final_sampling_lam0':final_sampling, 'use_dm1':1, 'dm1_m':dm1, 'use_dm2':1, 'dm2_m':dm2} ) images = np.abs(fields)**2 image_ab = np.sum(images, 0) / nlam # move source to 10 lam/D print("Computing offset source to compute NI...") (fields, sampling) = proper.prop_run_multi('wfirst_phaseb_compact', lam_array, n, QUIET=True, \ PASSVALUE={'cor_type':'spc-wide','source_x_offset':10.0,'final_sampling_lam0':final_sampling} ) psfs = np.abs(fields)**2 psf = np.sum(psfs, 0) / nlam max_psf = np.max(psf) ni_noab = image_noab / max_psf ni_ab = image_ab / max_psf fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(8, 4)) im = ax[0].imshow(ni_noab, norm=LogNorm(vmin=1e-10, vmax=1e-7), cmap=plt.get_cmap('jet')) circ_in = Circle((n / 2, n / 2), 5.4 / final_sampling, edgecolor='white', facecolor='none') circ_out = Circle((n / 2, n / 2), 20 / final_sampling, edgecolor='white', facecolor='none') ax[0].add_patch(circ_in) ax[0].add_patch(circ_out) ax[0].set_title('Unaberrated') fig.colorbar(im, ax=ax[0], shrink=0.5) im = ax[1].imshow(ni_ab, norm=LogNorm(vmin=1e-10, vmax=1e-7), cmap=plt.get_cmap('jet')) circ_in = Circle((n / 2, n / 2), 5.4 / final_sampling, edgecolor='white', facecolor='none') circ_out = Circle((n / 2, n / 2), 20 / final_sampling, edgecolor='white', facecolor='none') ax[1].add_patch(circ_in) ax[1].add_patch(circ_out) ax[1].set_title('Aberrated,\nUsing DM piston maps') fig.colorbar(im, ax=ax[1], shrink=0.5) plt.show()
def run_hlc_input_fields(): nlam = 7 lam0 = 0.575 bandwidth = 0.1 minlam = lam0 * (1 - bandwidth / 2) maxlam = lam0 * (1 + bandwidth / 2) lam_array = np.linspace(minlam, maxlam, nlam) n = 256 # output image dimension final_sampling = 0.1 # output sampling in lam0/D # compute coronagraphic field with full prescription print('Computing field with full prescription') t1 = time.time() (fields, sampling) = proper.prop_run_multi('wfirst_phaseb', lam_array, n, QUIET=True, \ PASSVALUE={'use_errors':1,'polaxis':-2,'zindex':[4],'zval_m':[0.19e-9],'final_sampling_lam0':final_sampling} ) t2 = time.time() print('Time (sec) for full prescription = ' + str(t2 - t1)) images = np.abs(fields)**2 image_full = np.sum(images, 0) / nlam # write FPM exit pupil fields with full prescription print('Writing FPM exit pupil fields using full prescription') (fields, sampling) = proper.prop_run_multi('wfirst_phaseb', lam_array, n, QUIET=True, \ PASSVALUE={'use_errors':1,'polaxis':-2,'zindex':[4],'zval_m':[0.19e-9],'use_hlc_dm_patterns':0,'use_fpm':0,'end_at_fpm_exit_pupil':1, \ 'output_field_rootname':'hlc_input_field'} ) # compute coronagraphic field with compact prescription and input fields print( 'Computing field with compact prescription and pre-computed input fields' ) t1 = time.time() (fields, sampling) = proper.prop_run_multi('wfirst_phaseb_compact', lam_array, n, QUIET=True, \ PASSVALUE={'input_field_rootname':'hlc_input_field','polaxis':-2,'final_sampling_lam0':final_sampling} ) t2 = time.time() print('Time (sec) for compact prescription with input fields = ' + str(t2 - t1)) images = np.abs(fields)**2 image = np.sum(images, 0) / nlam # move source to 7 lam/D print('Computing offset source to compute NI') (fields, sampling) = proper.prop_run_multi('wfirst_phaseb_compact', lam_array, n, QUIET=True, \ PASSVALUE={'source_x_offset':7.0,'final_sampling_lam0':final_sampling} ) psfs = np.abs(fields)**2 psf = np.sum(psfs, 0) / nlam max_psf = np.max(psf) ni_full = image_full / max_psf ni = image / max_psf fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(9, 4)) im = ax[0].imshow(ni_full, norm=LogNorm(vmin=1e-7, vmax=1e-2), cmap=plt.get_cmap('jet')) circ = Circle((n / 2, n / 2), 3 / final_sampling, edgecolor='white', facecolor='none') ax[0].add_patch(circ) circ = Circle((n / 2, n / 2), 9 / final_sampling, edgecolor='white', facecolor='none') ax[0].add_patch(circ) ax[0].set_title('Full prescription') fig.colorbar(im, ax=ax[0], shrink=0.5) im = ax[1].imshow(ni, norm=LogNorm(vmin=1e-7, vmax=1e-2), cmap=plt.get_cmap('jet')) circ = Circle((n / 2, n / 2), 3 / final_sampling, edgecolor='white', facecolor='none') ax[1].add_patch(circ) circ = Circle((n / 2, n / 2), 9 / final_sampling, edgecolor='white', facecolor='none') ax[1].add_patch(circ) ax[1].set_title('Compact prescription') fig.colorbar(im, ax=ax[1], shrink=0.5) plt.show()