datatau = dl_tr.nu2tau(datnu) data2.append(datatau.transpose()) #print tauchan, datatau[tauchan] #print "data shapes", data1.shape, data2.shape print "Average over %d time points" % len(data1) data1, data2 = n.ma.array(data1), n.ma.array(data2) data = n.multiply(n.conjugate(data1), data2) * norm #data is shaped [timesample, channel] P = n.ma.array([]) for ind in n.arange(len(taulist)): P = n.append(P, n.mean(data.T[ind])) print P #print len(taulist), len(P) #kz = taulist*2*n.pi/Y kz = cosmo_units.eta2kparr(taulist * 1.E-9, z) #This function needs tau in Hz^-1 #print "shapes of arrays:", data1.shape, data2.shape #Bootstrap resampling B = 10 bootmean, booterr = boot_simple.bootstrap(B, data) #plotting fig = p.figure() ax = fig.add_subplot(311) #plotp.P_v_Eta(ax,kz,P) ax.set_xlabel('kz') ax.set_ylabel(r'$P(k) mK^{2} (h^{-1} Mpc)^{3}$') p.plot(kz, P, 'bo') ax.set_yscale('log') ax = fig.add_subplot(312)
def plot_eor_summary(files=None, title='Input Files', k_mag=.2, models=True, verbose=False, capsize=3.5, **kwargs): """Create summary plot of known EoR results. All inputs are optional. files: capo formated pspec k3pk files title: legend handle for input files k_mag: the k value to take the limits near (find limits close to k_mag) modles: boolean, plot fiducal 21cmfast models (included in capo) capsize: defines the size of the upper limits caps. verbose: print info while plotting """ fig = p.figure(figsize=(10, 5)) ax = fig.add_subplot(111) # plot the GMRT paciga 2014 data GMRT = GMRT_2014_all() GMRT_results = {} if verbose: print('GMRT') for i, z in enumerate(GMRT.keys()): # index = n.argwhere(GMRT[z][:,0] - .2 < 0.1).squeeze() freq = pspec.z2f(z) k_horizon = n.sqrt(cosmo_units.eta2kparr(30./c, z)**2 + cosmo_units.u2kperp(15*freq*1e6/cosmo_units.c, z)**2) index = n.argwhere(abs(GMRT[z][:, 0] - k_mag)).squeeze() GMRT_results[z] = n.min(GMRT[z][index, 2]) if verbose: print('results: {0},\t{1}'.format(z, n.sqrt(GMRT_results[z]))) ax.errorbar(float(z), GMRT_results[z], GMRT_results[z]/1.5, fmt='p', ecolor='gray', color='gray', uplims=True, label='Paciga, 2013' if i == 0 else "", capsize=capsize) # Get MWA 32 data MWA_results = {} MWA = MWA_32T_all() if verbose: print('Results: Z,\t Upper Limits') print('MWA 32') for i, z in enumerate(MWA.keys()): # index = n.argwhere(MWA[z][:,0] - .2 < .01).squeeze() freq = pspec.z2f(z) k_horizon = n.sqrt(cosmo_units.eta2kparr(30./c, z)**2 + cosmo_units.u2kperp(15*freq*1e6/cosmo_units.c, z)**2) index = n.argwhere(abs(MWA[z][:, 0] > k_horizon)).squeeze() MWA_results[z] = n.min(MWA[z][index, 2]) if verbose: print('results: {0},\t{1}'.format(z, n.sqrt(MWA_results[z]))) ax.errorbar(float(z), MWA_results[z], MWA_results[z]/1.5, fmt='r*', uplims=True, label='Dillon, 2014' if i == 0 else "", capsize=capsize) MWA128_results = {} MWA128 = MWA_128_all() if verbose: print('MWA 128') for i, z in enumerate(MWA128.keys()): index = n.argmin(abs(MWA128[z][:, 0] - k_mag)).squeeze() MWA128_results[z] = n.min(MWA128[z][index, 2]) if verbose: print('results: {0},\t{1}'.format(z, n.sqrt(MWA128_results[z]))) ax.errorbar(float(z), MWA128_results[z], MWA128_results[z]/1.5, fmt='y*', uplims=True, alpha=.5, label='Dillon, 2015' if i == 0 else "", capsize=capsize) MWA_beards = MWA_128_beards() MWA_beards_results = {} if verbose: print('MWA Beardsley') for i, z in enumerate(MWA_beards.keys()): index = n.argmin(abs(MWA_beards[z][:, 0] - k_mag).squeeze()) MWA_beards_results[z] = n.min(MWA_beards[z][index, 2]) if verbose: print('results: {0},\t{1}'.format(z, n.sqrt(MWA_beards_results[z]))) ax.errorbar(float(z), MWA_beards_results[z], MWA_beards_results[z]/1.5, fmt='g*', uplims=True, label='Beardsley, 2016' if i == 0 else "", capsize=capsize) # Get Paper-32 data PSA32 = PAPER_32_all() PSA32_results = {} Jacobs_et_al = [0, 1, 2, 4] if verbose: print('PSA32') for i, z in enumerate(PSA32.keys()): index = n.argmin(abs(PSA32[z][:, 0] - k_mag)).squeeze() PSA32_results[z] = n.min(PSA32[z][index, 2]) if verbose: print('results: {0},\t{1}'.format(z, n.sqrt(PSA32_results[z]))) if i in Jacobs_et_al: ax.errorbar(float(z), PSA32_results[z], PSA32_results[z]/1.5, fmt='md', uplims=True, label='Jacobs, 2015' if i == 0 else "", capsize=capsize) else: ax.errorbar(float(z), PSA32_results[z], PSA32_results[z]/1.5, fmt='cv', uplims=True, label='Parsons, 2014', capsize=capsize) # Get PAPER-64 results PSA64 = PAPER_64_all() PSA64_results = {} if verbose: print('PSA64') for z in PSA64.keys(): index = n.argmin(abs(PSA64[z][:, 0] - k_mag)).squeeze() PSA64_results[z] = n.min(abs(PSA64[z][index, 2])) if verbose: print('results: {0},\t{1}'.format(z, n.sqrt(PSA64_results[z]))) ax.errorbar(float(z), PSA64_results[z], PSA64_results[z]/1.5, fmt='bs', uplims=True, label='Ali, 2015', capsize=capsize) # zs = [10.87,8.37] results = {} if verbose: print('Input files') zs, ks, k3pk, k3err = get_k3pk_from_npz(files) for i, z in enumerate(zs): results_array = n.array([ks[i], k3pk[i], k3pk[i] + k3err[i], k3pk[i] - k3err[i]]).T negs = n.argwhere(k3pk[i] < 0).squeeze() try: len(negs) except: negs = n.array([negs.item()]) if len(negs) > 0: results_array[negs, -2], results_array[negs, -1] = abs(results_array[negs, -1]), -1 * results_array[negs, -2] index = n.argmin(abs(results_array[:, 0] - k_mag)).squeeze() results[z] = n.min(abs(results_array[index, 2])) if verbose: print('results: {0},\t{1}'.format(z, n.sqrt(results[z]))) ax.errorbar(float(z), results[z], results[z]/1.5, fmt='ko', uplims=True, label=title if i == 0 else "", capsize=capsize) ax.set_yscale('log') ax.set_ylabel('$\Delta^{2} (mK)^{2}$') ax.set_ylim([1e0, 1e7]) ax.set_xlabel('z') ax.grid(axis='y') # Add model data. if models: if verbose: print 'Plotting 21cmFAST Model' simk = 0.2 xlim = ax.get_xlim() # save the data xlimits parm_array, k_array, delta2_array, delta2_err_array = load_andre_models() k_index = n.abs(k_array[0]-simk).argmin() alphaXs = n.sort(list(set(parm_array[:, 3]))) Mmins = n.sort(list(set(parm_array[:, 4]))) Nxs = n.sort(list(set(parm_array[:, 2]))) for Nx in Nxs: for alphaX in alphaXs: for Mmin in Mmins: _slice = n.argwhere(all_and([ parm_array[:, 2] == Nx, parm_array[:, 3] == alphaX, parm_array[:, 4] == Mmin] )) ax.plot(parm_array[_slice, 0], delta2_array[_slice, k_index], '-k', label='Fiducal 21cmFAST model') ax.set_xlim(xlim) # reset to the data xlimits handles, labels = ax.get_legend_handles_labels() handles = [h[0] if cnt > 0 else h for cnt, h in enumerate(handles)] num_hands = len(handles) handles.insert(num_hands, handles.pop(0)) labels.insert(num_hands, labels.pop(0)) box = ax.get_position() ax.set_position([box.x0, box.height * .2 + box.y0, box.width, box.height*.8]) # fig.subplots_adjust(bottom=.275,top=.8) ax.legend(handles, labels, loc='lower center', bbox_to_anchor=(.5, -.425), ncol=3, **kwargs) # ax.legend(loc='bottom',ncol=3) return fig
#print "data lenth", len(datnu) datatau = dl_tr.nu2tau(datnu) data2.append(n.array(datatau).transpose()) #print tauchan, datatau[tauchan] #print "data shapes", data1.shape, data2.shape print "Average over %d time points" % len(data1) data1, data2 = n.array(data1), n.array(data2) data = n.multiply(n.conjugate(data1), data2)*norm #data is shaped [timesample, channel] P=[] for ind in n.arange(len(taulist)): P.append(n.mean(data.T[ind])) #print len(taulist), len(P) #kz = taulist*2*n.pi/Y kz = cosmo_units.eta2kparr(taulist*1.E-9,z) #This function needs tau in Hz^-1 #print "shapes of arrays:", data1.shape, data2.shape #Bootstrap resampling B = 100 bootmean, booterr = boot_simple.bootstrap(B, data) #plotting fig = p.figure() ax = fig.add_subplot(311) #plotp.P_v_Eta(ax,kz,P) ax.set_xlabel('kz') ax.set_ylabel(r'$P(k) K^{2} (h^{-1} Mpc)^{3}$') p.plot(kz,P,'bo')
print k3err[i][j], print 2*POBER_NOISE(kmags [i][j],freqs[i]).squeeze() print "%%%"*10 #make a nice big 2x4 plot of all the new pspectra # with Pk on top # and Delta^2 on the bottom figure(10,figsize=(17,10)) clf() Nzs = len(z)-1#all points except P14 print Nzs j = 0 for i,redshift in enumerate(z):#gotta index z to get the right data if n.abs(redshift-7.67)<0.01:continue #skip the P14 point k_horizon = n.sqrt(cosmo_units.eta2kparr(30./3e8,redshift)**2 + \ cosmo_units.u2kperp(15*freqs[i]*1e6/3e8,redshift)**2) print "cutting %d points below k= %4.3f"%(n.sum(kmags[i]<k_horizon),k_horizon) window_points = n.argwhere(kmags[i]>k_horizon).squeeze() j += 1 ax_pk = subplot(2,Nzs,j) ax_delta = subplot(2,Nzs,Nzs+j) #plot PAPER # PAPER Pk ax_pk.errorbar(kpars[i],n.abs(Pks[i]),yerr=Pkerr[i],fmt='k+') # PAPER Delta^2 ax_delta.errorbar(kmags[i][window_points],k3Pk[i][window_points],yerr=k3err[i][window_points],fmt='k.', capsize=0) #plot PAPER sensitivity
freqs = n.array(freqs) zs = pspec.f2z(freqs*1e-3) fig = p.figure(figsize=(10,5)) ax = fig.add_subplot(111) #plot the GMRT paciga 2014 data GMRT = eor_results.GMRT_2014_all() GMRT_results = {} print('GMRT') for i,z in enumerate(GMRT.keys()): #index = n.argwhere(GMRT[z][:,0] - .2 < 0.1).squeeze() freq= pspec.z2f(z) k_horizon = n.sqrt(cosmo_units.eta2kparr(30./c,z)**2 + \ cosmo_units.u2kperp(15*freq*1e6/c,z)**2) if np.min(abs(GMRT[z][:,0] -myk))>.07:continue index = n.argwhere( abs(GMRT[z][:,0] -myk) ).squeeze() GMRT_results[z] = n.min(GMRT[z][2:,2]) print('results: {0},\t{1}'.format(z,n.sqrt(GMRT_results[z]))) ax.errorbar(float(z), GMRT_results[z], GMRT_results[z]/1.5, fmt='p',ecolor='gray',color='gray', uplims=True, label='Paciga, 2013' if i ==0 else "",capsize = capsize) #Get MWA 32 data MWA_results = {} MWA = eor_results.MWA_32T_all() print('Results: Z,\t Upper Limits') print('MWA 32') for i,z in enumerate(MWA.keys()): #index = n.argwhere(MWA[z][:,0] - .2 < .01).squeeze() freq= pspec.z2f(z)
print('Skipping') continue freqs = n.array(freqs) zs = pspec.f2z(freqs * 1e-3) fig = p.figure(figsize=(10, 5)) ax = fig.add_subplot(111) #plot the GMRT paciga 2014 data GMRT = eor_results.GMRT_2014_all() GMRT_results = {} print('GMRT') for i, z in enumerate(GMRT.keys()): #index = n.argwhere(GMRT[z][:,0] - .2 < 0.1).squeeze() freq = pspec.z2f(z) k_horizon = n.sqrt(cosmo_units.eta2kparr(30./c,z)**2 + \ cosmo_units.u2kperp(15*freq*1e6/c,z)**2) if np.min(abs(GMRT[z][:, 0] - myk)) > .07: continue index = n.argwhere(abs(GMRT[z][:, 0] - myk)).squeeze() GMRT_results[z] = n.min(GMRT[z][2:, 2]) print('results: {0},\t{1}'.format(z, n.sqrt(GMRT_results[z]))) ax.errorbar(float(z), GMRT_results[z], GMRT_results[z] / 1.5, fmt='p', ecolor='gray', color='gray', uplims=True, label='Paciga, 2013' if i == 0 else "", capsize=capsize)
def plot_eor_summary(files=None, title='Input Files', k_mag=.2, models=True, verbose=False, capsize=3.5, **kwargs): """Create summary plot of known EoR results. All inputs are optional. files: capo formated pspec k3pk files title: legend handle for input files k_mag: the k value to take the limits near (find limits close to k_mag) modles: boolean, plot fiducal 21cmfast models (included in capo) capsize: defines the size of the upper limits caps. verbose: print info while plotting """ fig = p.figure(figsize=(10, 5)) ax = fig.add_subplot(111) # plot the GMRT paciga 2014 data GMRT = GMRT_2014_all() GMRT_results = {} if verbose: print('GMRT') for i, z in enumerate(GMRT.keys()): # index = n.argwhere(GMRT[z][:,0] - .2 < 0.1).squeeze() freq = pspec.z2f(z) k_horizon = n.sqrt( cosmo_units.eta2kparr(30. / c, z)**2 + cosmo_units.u2kperp(15 * freq * 1e6 / cosmo_units.c, z)**2) index = n.argwhere(abs(GMRT[z][:, 0] - k_mag)).squeeze() GMRT_results[z] = n.min(GMRT[z][index, 2]) if verbose: print('results: {0},\t{1}'.format(z, n.sqrt(GMRT_results[z]))) ax.errorbar(float(z), GMRT_results[z], GMRT_results[z] / 1.5, fmt='p', ecolor='gray', color='gray', uplims=True, label='Paciga, 2013' if i == 0 else "", capsize=capsize) # Get MWA 32 data MWA_results = {} MWA = MWA_32T_all() if verbose: print('Results: Z,\t Upper Limits') print('MWA 32') for i, z in enumerate(MWA.keys()): # index = n.argwhere(MWA[z][:,0] - .2 < .01).squeeze() freq = pspec.z2f(z) k_horizon = n.sqrt( cosmo_units.eta2kparr(30. / c, z)**2 + cosmo_units.u2kperp(15 * freq * 1e6 / cosmo_units.c, z)**2) index = n.argwhere(abs(MWA[z][:, 0] > k_horizon)).squeeze() MWA_results[z] = n.min(MWA[z][index, 2]) if verbose: print('results: {0},\t{1}'.format(z, n.sqrt(MWA_results[z]))) ax.errorbar(float(z), MWA_results[z], MWA_results[z] / 1.5, fmt='r*', uplims=True, label='Dillon, 2014' if i == 0 else "", capsize=capsize) MWA128_results = {} MWA128 = MWA_128_all() if verbose: print('MWA 128') for i, z in enumerate(MWA128.keys()): index = n.argmin(abs(MWA128[z][:, 0] - k_mag)).squeeze() MWA128_results[z] = n.min(MWA128[z][index, 2]) if verbose: print('results: {0},\t{1}'.format(z, n.sqrt(MWA128_results[z]))) ax.errorbar(float(z), MWA128_results[z], MWA128_results[z] / 1.5, fmt='y*', uplims=True, alpha=.5, label='Dillon, 2015' if i == 0 else "", capsize=capsize) MWA_beards = MWA_128_beards() MWA_beards_results = {} if verbose: print('MWA Beardsley') for i, z in enumerate(MWA_beards.keys()): index = n.argmin(abs(MWA_beards[z][:, 0] - k_mag).squeeze()) MWA_beards_results[z] = n.min(MWA_beards[z][index, 2]) if verbose: print('results: {0},\t{1}'.format(z, n.sqrt(MWA_beards_results[z]))) ax.errorbar(float(z), MWA_beards_results[z], MWA_beards_results[z] / 1.5, fmt='g*', uplims=True, label='Beardsley, 2016' if i == 0 else "", capsize=capsize) # Get Paper-32 data PSA32 = PAPER_32_all() PSA32_results = {} Jacobs_et_al = [0, 1, 2, 4] if verbose: print('PSA32') for i, z in enumerate(PSA32.keys()): index = n.argmin(abs(PSA32[z][:, 0] - k_mag)).squeeze() PSA32_results[z] = n.min(PSA32[z][index, 2]) if verbose: print('results: {0},\t{1}'.format(z, n.sqrt(PSA32_results[z]))) if i in Jacobs_et_al: ax.errorbar(float(z), PSA32_results[z], PSA32_results[z] / 1.5, fmt='md', uplims=True, label='Jacobs, 2015' if i == 0 else "", capsize=capsize) else: ax.errorbar(float(z), PSA32_results[z], PSA32_results[z] / 1.5, fmt='cv', uplims=True, label='Parsons, 2014', capsize=capsize) # Get PAPER-64 results PSA64 = PAPER_64_all() PSA64_results = {} if verbose: print('PSA64') for z in PSA64.keys(): index = n.argmin(abs(PSA64[z][:, 0] - k_mag)).squeeze() PSA64_results[z] = n.min(abs(PSA64[z][index, 2])) if verbose: print('results: {0},\t{1}'.format(z, n.sqrt(PSA64_results[z]))) ax.errorbar(float(z), PSA64_results[z], PSA64_results[z] / 1.5, fmt='bs', uplims=True, label='Ali, 2015', capsize=capsize) # zs = [10.87,8.37] results = {} if verbose: print('Input files') zs, ks, k3pk, k3err = get_k3pk_from_npz(files) for i, z in enumerate(zs): results_array = n.array( [ks[i], k3pk[i], k3pk[i] + k3err[i], k3pk[i] - k3err[i]]).T negs = n.argwhere(k3pk[i] < 0).squeeze() try: len(negs) except: negs = n.array([negs.item()]) if len(negs) > 0: results_array[negs, -2], results_array[negs, -1] = abs( results_array[negs, -1]), -1 * results_array[negs, -2] index = n.argmin(abs(results_array[:, 0] - k_mag)).squeeze() results[z] = n.min(abs(results_array[index, 2])) if verbose: print('results: {0},\t{1}'.format(z, n.sqrt(results[z]))) ax.errorbar(float(z), results[z], results[z] / 1.5, fmt='ko', uplims=True, label=title if i == 0 else "", capsize=capsize) ax.set_yscale('log') ax.set_ylabel('$\Delta^{2} (mK)^{2}$') ax.set_ylim([1e0, 1e7]) ax.set_xlabel('z') ax.grid(axis='y') # Add model data. if models: if verbose: print 'Plotting 21cmFAST Model' simk = 0.2 xlim = ax.get_xlim() # save the data xlimits parm_array, k_array, delta2_array, delta2_err_array = load_andre_models( ) k_index = n.abs(k_array[0] - simk).argmin() alphaXs = n.sort(list(set(parm_array[:, 3]))) Mmins = n.sort(list(set(parm_array[:, 4]))) Nxs = n.sort(list(set(parm_array[:, 2]))) for Nx in Nxs: for alphaX in alphaXs: for Mmin in Mmins: _slice = n.argwhere( all_and([ parm_array[:, 2] == Nx, parm_array[:, 3] == alphaX, parm_array[:, 4] == Mmin ])) ax.plot(parm_array[_slice, 0], delta2_array[_slice, k_index], '-k', label='Fiducal 21cmFAST model') ax.set_xlim(xlim) # reset to the data xlimits handles, labels = ax.get_legend_handles_labels() handles = [h[0] if cnt > 0 else h for cnt, h in enumerate(handles)] num_hands = len(handles) handles.insert(num_hands, handles.pop(0)) labels.insert(num_hands, labels.pop(0)) box = ax.get_position() ax.set_position( [box.x0, box.height * .2 + box.y0, box.width, box.height * .8]) # fig.subplots_adjust(bottom=.275,top=.8) ax.legend(handles, labels, loc='lower center', bbox_to_anchor=(.5, -.425), ncol=3, **kwargs) # ax.legend(loc='bottom',ncol=3) return fig
print "%%%" * 10 # make a nice big 2x4 plot of all the new pspectra # with Pk on top # and Delta^2 on the bottom figure(10, figsize=(17, 10)) clf() Nzs = len(z) - 1 # all points except P14 print Nzs j = 0 for i, redshift in enumerate(z): # gotta index z to get the right data if n.abs(redshift - 7.67) < 0.01: continue # skip the P14 point k_horizon = n.sqrt( cosmo_units.eta2kparr(30.0 / 3e8, redshift) ** 2 + cosmo_units.u2kperp(15 * freqs[i] * 1e6 / 3e8, redshift) ** 2 ) print "cutting %d points below k= %4.3f" % (n.sum(kmags[i] < k_horizon), k_horizon) window_points = n.argwhere(kmags[i] > k_horizon).squeeze() j += 1 ax_pk = subplot(2, Nzs, j) ax_delta = subplot(2, Nzs, Nzs + j) # plot PAPER # PAPER Pk ax_pk.errorbar(kpars[i], n.abs(Pks[i]), yerr=Pkerr[i], fmt="k+") # PAPER Delta^2 ax_delta.errorbar( kmags[i][window_points], k3Pk[i][window_points], yerr=k3err[i][window_points], fmt="k.", capsize=0 )
print k3err[i][j], print 2 * POBER_NOISE(kmags[i][j], freqs[i]).squeeze() print "%%%" * 10 #make a nice big 2x4 plot of all the new pspectra # with Pk on top # and Delta^2 on the bottom figure(10, figsize=(17, 10)) clf() Nzs = len(z) - 1 #all points except P14 print Nzs j = 0 for i, redshift in enumerate(z): #gotta index z to get the right data if n.abs(redshift - 7.67) < 0.01: continue #skip the P14 point k_horizon = n.sqrt(cosmo_units.eta2kparr(30./3e8,redshift)**2 + \ cosmo_units.u2kperp(15*freqs[i]*1e6/3e8,redshift)**2) print "cutting %d points below k= %4.3f" % (n.sum(kmags[i] < k_horizon), k_horizon) window_points = n.argwhere(kmags[i] > k_horizon).squeeze() j += 1 ax_pk = subplot(2, Nzs, j) ax_delta = subplot(2, Nzs, Nzs + j) #plot PAPER # PAPER Pk ax_pk.errorbar(kpars[i], n.abs(Pks[i]), yerr=Pkerr[i], fmt='k+') # PAPER Delta^2 ax_delta.errorbar(kmags[i][window_points], k3Pk[i][window_points],