def star_throughput(): ap.companion = False thru_tot = np.zeros((3, 4)) for p in range(2, 3): # for p in range(0,1): if p == 0: tp.aber_params['CPA'] = False tp.aber_params['NCPA'] = False tp.use_atmos = False tp.use_ao = False if p == 1: tp.aber_params['CPA'] = True tp.aber_params['NCPA'] = False tp.use_atmos = True tp.use_ao = True if p == 2: tp.aber_params['CPA'] = True tp.aber_params['NCPA'] = True tp.use_atmos = True tp.use_ao = True # tp.band[0] = 860 tp.occulter_type = 'None' ref = gpd.run()[0, 0] # ref_phot = phot.aper_phot(ref, 0, lods[0]) ref_tot = np.sum(ref) # # mask = np.int_(phot.aperture(76, 52, 6)) # print ref_phot # datacube = [] # # tp.use_ao = False rad_int = np.zeros((4, 64)) for i in range(1, 4): #range(4): tp.occulter_type = occulter_types[i] # 'Gaussian' occult = gpd.run()[0, 0] # datacube[i]/ref_phot # phot.coron_4_VIP(datacube[i],ref) for r in range(64): print i, r, occult.shape, r + 1 rad_int[i, r] = phot.aper_phot(occult, r * 1, (r + 1) * 1) # plt.plot(rad_int[i]) # plt.show() occult_tot = np.sum(occult) dprint(occult_tot / ref_tot) thru_tot[p, i] = occult_tot / ref_tot # datacube = np.array(datacube) # throughput = np.zeros((3)) return thru_tot
mp.respons_var = True mp.bad_pix = True mp.hot_pix = 1 mp.R_mean = 8 mp.g_mean = 0.2 mp.g_sig = 0.04 mp.bg_mean = -10 mp.bg_sig = 40 mp.pix_yield = 0.7 # check dis if __name__ == '__main__': if os.path.exists(iop.int_maps): os.remove(iop.int_maps) ideal = gpd.run()[0, :] # compare_images(ideal, logAmp=True, vmax = 0.01, vmin=1e-6, annos = ['Ideal 800 nm', '1033 nm', '1267 nm', '1500 nm'], title=r'$I$') with open(iop.int_maps, 'rb') as handle: int_maps = pickle.load(handle) int_maps = np.array(int_maps) dprint(int_maps[0].shape) # view_datacube(int_maps, logAmp=True) grid(int_maps[::-1][:4], titles=r'$\phi$', annos=['Entrance Pupil', 'After CPA', 'After AO', 'After NCPA']) grid(int_maps[::-1][4:], nrows=2, width=1, titles=r'$I$',
def exo_through(): ap.companion = True ap.lods = [[0, 0], [0.5, -0.5], [1, 1], [-1.5, 1.5], [-2, -2], [2.5, -2.5], [3, 3], [-3.5, 3.5], [-4, -4]] # ap.lods = [] # for io in range(9): # ap.lods.append(np.array([0.5,0.5])) ap.contrast = np.ones((len(ap.lods))) * 10 #00 thru_matrix = np.zeros((3, 4, 8)) colors = ['#1F77b4', '#ff7f0e', '#2ca02c', '#d62728'] fwhm = 12 def get_xy(lod): x = tp.grid_size / 2 - lod[0] * fwhm y = tp.grid_size / 2 - lod[1] * fwhm return x, y for p in range(2, 3): # for p in range(0,1): if p == 0: tp.aber_params['CPA'] = False tp.aber_params['NCPA'] = False tp.use_atmos = False tp.use_ao = False if p == 1: tp.aber_params['CPA'] = True tp.aber_params['NCPA'] = False tp.use_atmos = True tp.use_ao = True if p == 2: tp.aber_params['CPA'] = True tp.aber_params['NCPA'] = True tp.use_atmos = True tp.use_ao = True # if ap.companion == True: tp.occulter_type = 'None' ref = gpd.run()[0, 0] # ref = np.transpose(ref) injected = np.zeros((len(ap.contrast))) for io in range(len(ap.contrast)): x, y = get_xy(ap.lods[io]) print io, x, y, mask = phot.aperture(x, y, 4) # quicklook_im(ref, logAmp=True) # quicklook_im(ref * mask) injected[io] = np.sum(ref * mask) / np.sum(mask) print injected[io] for i in range(0, 4): tp.occulter_type = occulter_types[i] # 'Gaussian' occult = gpd.run()[0, 0] recovered = np.zeros((len(ap.contrast))) for io in range(len(ap.contrast)): x, y = get_xy(ap.lods[io]) print io, x, y, mask = phot.aperture(x, y, 4) # quicklook_im(ref, logAmp=True) # quicklook_im(ref * mask) recovered[io] = np.sum(occult * mask) / np.sum(mask) print recovered[io] # plt.plot(injected) # plt.plot(recovered) # plt.show() # plt.figure() vector_radd = range(0, 9) thruput_mean = recovered / injected # plt.plot(thruput_mean, marker='o', c=colors[i]) rad_samp = np.arange(0, 9, 0.5) from scipy.interpolate import InterpolatedUnivariateSpline print len(vector_radd), len(thruput_mean) f = InterpolatedUnivariateSpline(vector_radd, thruput_mean, k=2) thruput_interp = f(rad_samp) plt.plot(rad_samp, thruput_interp, c=colors[i]) # plt.show() plt.show() plt.figure() # Isource = np.sum(ref * mask) / np.sum(mask) # , 'sum' # # plt.imshow(ref * mask, origin='lower') # # plt.show() # # mask = np.int_(phot.aperture(76, 52, 6)) # # plt.imshow(datacube[i]*mask, origin='lower') # throughput[0] = (np.sum(datacube[0] * mask) / np.sum(mask)) / Isource # , 'sum' # # plt.show() # # mask = np.int_(phot.aperture(76, 52, 10)) # # plt.imshow(datacube[i]*mask, origin='lower') # throughput[1] = (np.sum(datacube[1] * mask) / np.sum(mask)) / Isource # , 'sum' # # plt.show() # # mask = np.int_(phot.aperture(76, 52, 8)) # # plt.imshow(datacube[i]*mask, origin='lower') # throughput[2] = (np.sum(datacube[2] * mask) / np.sum(mask)) / Isource # , 'sum' # # plt.show() # print throughput # # # throughput = [ 0.68996802, 0.12175953, 0.27923381] # MEDIUM_SIZE = 16 # plt.rc('font', size=MEDIUM_SIZE) # controls default text sizes # # plt.rc('axes', linewidth=2) # from matplotlib import rcParams # rcParams['font.family'] = 'STIXGeneral' # 'Times New Roman' # rcParams['mathtext.fontset'] = 'custom' # rcParams['mathtext.fontset'] = 'stix' # # fig, ax = plt.subplots(figsize=(4.3, 3.8)) # labels = ['a', 'b', 'c'] # for i, int in enumerate(rad_int): # # int/=throughput[i] # ax.plot(np.linspace(0, 0.8, 64), int, label=occulter_types[i]) # ax.text(0.05, 0.9, labels[p], transform=ax.transAxes, fontweight='bold', color='k', fontsize=17, # family='serif') # ax.tick_params(direction='in', which='both', right=True, top=True) # ax.set_xlabel('Radial Separation') # # ax.set_yscale('log') # if p == 0: # ax.set_ylabel('Intensity Ratio') # ax.legend() # plt.subplots_adjust(left=0.19, right=0.98, top=0.99, bottom=0.15) # # plt.savefig(str(p)+'.pdf') # print thru_data # plt.show() return
ax.set_ylabel('SR') ax1 = ax.twinx() # ax1.set_ylim(ax.get_ylim()) ax1.set_ylabel('$\phi$ (nm)') from matplotlib.ticker import FormatStrFormatter for i in range(3): tp.aber_params['NCPA'] = NCPAs[i] tp.aber_params['Amp'] = Amps[i] SRs = [] phis = [] for act in acts: tp.servo_error[0] = act num_exp = 3 + act # 20 #5000 ap.numframes = int(num_exp * ap.exposure_time / cp.frame_time) hypercube = gpd.run() peak_meas = hypercube[-1, 0, tp.grid_size / 2, tp.grid_size / 2] SR = peak_meas / peak_perf dprint(SR) SRs.append(SR) phi = np.sqrt((1 - SR)) * tp.band[0] / (2 * np.pi) phis.append(phi) ax.plot(acts, SRs) dprint(acts) # ax1.plot(acts, phis) phi_lab = np.int_( np.sqrt((1 - ax.get_yticks())) * tp.band[0] / (2 * np.pi)) # phi_lab[-2:] = [0, 0] dprint(phi_lab) ax1.set(yticks=ax.get_yticks(),
from Utils.plot_tools import view_datacube import numpy as np import matplotlib.pyplot as plt tp.detector = 'ideal' # tp.show_wframe = False cp.numframes = 1 mp.frame_time = 0.1 num_frames = [1, 10, 100] tp.use_ao = True tp.occulter_type = 'GAUSSIAN' cp.vary_r0 = False # turn off the automatic variation sp.show_wframe = False if sp.show_wframe == 'continuous': sp.fig = plt.figure() if __name__ == '__main__': datacube = [] for nf in num_frames: # image = np.zeros((tp.grid_size,tp.grid_size)) # for f in range(nf): # image += run()[0] cp.numframes = nf hypercube = run() # hypercube = np.array(hypercube) image = np.sum(hypercube, axis=0) / nf datacube.append(image[0]) datacube = np.array(datacube) view_datacube(datacube)
tp.use_atmos = True tp.use_ao = True tp.CPA_type = None#'Static'#'Quasi'# None tp.NCPA_type = None#'Static' #None tp.active_null = False tp.satelite_speck = True tp.speck_locs = [[40,60], [40,70],[50,50]]#[[20,20],[40,30], [40,40]] tp.speck_phases = [np.pi, np.pi/2, np.pi] tp.speck_peakIs = np.ones((len(tp.speck_locs)))*0.05#*(1.1*len(tp.speck_locs)) mp.frame_time = 0.1 measured = [] for phase in np.linspace(0,6*np.pi,150): # tp.speck_phases = [-np.pi/2]#[phase]# run() measured.append(tp.variable) # with open('test.pkl', 'wb') as handle: # pickle.dump(measured, handle, protocol=pickle.HIGHEST_PROTOCOL) # with open('test.pkl', 'rb') as handle: # measured =pickle.load(handle) # speck_phase = np.array(measured)#+1.9377 # # exceed = np.where(speck_phase >= 3.14)[0] # # speck_phase[exceed] = speck_phase[exceed]-2*3.14 # plt.plot(np.linspace(-2*np.pi,6*np.pi,150) - speck_phase) # # plt.xlabel('DM phase') # # plt.xlim([0,2*np.pi]) # # plt.ylim([0,np.pi])