def PAPER_64_all(): """ Return results from PAPER 64 Ali et.al 2015. outputs results[z] = n.array([k, Delta^2, 2-sigma upper, 2-sigma lower]) """ PAPER_RESULTS_FILES = (glob.glob(os.path.dirname(__file__) + '/data/psa64_apj/pspec_*.npz')) PAPER_RESULTS_FILES.sort() freqs = [] for filename in PAPER_RESULTS_FILES: try: freqs.append(n.load(filename)['freq'] * 1e3) except(KeyError): try: dchan = (int(filename.split('/')[-1].split('.')[0] .split('_')[2]) - int(filename.split('.')[0].split('_')[1])) chan = (int(filename.split('/')[-1].split('.')[0] .split('_')[1]) + dchan / 2.) # a pretty good apprximation of chan 2 freq for 500kHz channels freqs.append(chan / 2. + 100) except: continue freqs = n.array(freqs) zs = pspec.f2z(freqs * 1e-3) results = {} for files, z in zip(PAPER_RESULTS_FILES, zs): f = n.load(files) results[z] = n.array([f['k'], f['k3pk'], f['k3pk'] + f['k3err'], f['k3pk'] - f['k3err']]).T return results
def gather_metadata(uv, chans, window): M = {} chans = a.scripting.parse_chans(chans, uv['nchan']) freqs = a.cal.get_freqs(uv['sdf'], uv['sfreq'], uv['nchan']) freqs = freqs.take(chans) M['sdf'] = uv['sdf'] M['fq'] = np.average(freqs) M['z'] = pspec.f2z(M['fq']) M['B'] = M['sdf'] * freqs.size / pfb.NOISE_EQUIV_BW[window] M['etas'] = np.fft.fftshift(pspec.f2eta(freqs)) M['kpl'] = M['etas'] * pspec.dk_deta(M['z']) M['bm'] = np.polyval(pspec.DEFAULT_BEAM_POLY, M['fq']) M['scalar'] = pspec.X2Y(M['z']) * M['bm'] * M['B'] return chans, freqs, M
def PAPER_64_all(): ''' Results from PAPER 64 Ali et.al 2015 outputs results[z] = n.array([k, Delta^2, 2-sigma upper, 2-sigma lower]) ''' PAPER_RESULTS_FILES = glob.glob( os.path.dirname(__file__) + '/data/psa64_apj/pspec_*.npz') PAPER_RESULTS_FILES.sort() freqs = [] for filename in PAPER_RESULTS_FILES: try: freqs.append(n.load(filename)['freq'] * 1e3) except (KeyError): try: dchan = int( filename.split('/')[-1].split('.')[0].split('_')[2]) - int( filename.split('.')[0].split('_')[1]) chan = int( filename.split('/')[-1].split('.')[0].split('_') [1]) + dchan / 2. freqs.append( chan / 2. + 100 ) #a pretty good apprximation of chan 2 freq for 500kHz channels except: continue freqs = n.array(freqs) zs = pspec.f2z(freqs * 1e-3) #zs = n.array([8.31]) results = {} for files, z in zip(PAPER_RESULTS_FILES, zs): f = n.load(files) results[z] = n.array([ f['k'], f['k3pk'], f['k3pk'] + f['k3err'], f['k3pk'] - f['k3err'] ]).T return results
def RM_bad(fq, k): _z = pspec.f2z(fq) return k * c * (1.0 + _z) / (4.0 * H(_z) * nu2l2(fq))
windowpad = F['windowpad'] plotres=True PLOTWINDOWCONTOUR=False figsize=(20,25) try: observation_num = int(sys.argv[1].split('.')[0]) observation=MWA_Observation(observation_num,db=db) except(ValueError): gpstime = int(n.round(Time(F['time'],scale='utc',format='jd').gps)) observation_num = find_closest_observation(gpstime,db=db) observation=MWA_Observation(observation_num,db=db) for plotres in [False,True]: z = pspec.f2z(freq/1e9) #windowpad = 0.01 #should match whatever I used in uvfitswedge.py if len(sys.argv[1:])==1 and not sys.argv[1].endswith('.p.npz'): amps = n.ma.masked_invalid(n.log10(n.abs(F['P'].T))) outname = sys.argv[1].replace('.npz','') else: if len(sys.argv[1:])==1:outname = sys.argv[1].replace('.npz','') else:outname = 'mywedge' if plotres: outname += '_res' P=0 P2 = 0 C = 0 for Pfile in sys.argv[1:]: F = n.load(Pfile) if plotres: P += F['P_res']
def posterior(kpl, pk, err, pkfold=None, errfold=None, f0=.151, umag=16., theo_noise=None, verbose=False): """Find posterior of Delta^2.""" import scipy.interpolate as interp k0 = n.abs(kpl).argmin() kpl = kpl[k0:] z = pspec.f2z(f0) kpr = pspec.dk_du(z) * umag k = n.sqrt(kpl**2 + kpr**2) if pkfold is None: if verbose: print 'Folding for posterior' pkfold = pk[k0:].copy() errfold = err[k0:].copy() pkpos, errpos = pk[k0 + 1:].copy(), err[k0 + 1:].copy() pkneg, errneg = pk[k0 - 1:0:-1].copy(), err[k0 - 1:0:-1].copy() pkfold[1:] = ((pkpos / errpos**2 + pkneg / errneg**2) / (1. / errpos**2 + 1. / errneg**2)) errfold[1:] = n.sqrt(1. / (1. / errpos**2 + 1. / errneg**2)) # ind = n.logical_and(kpl>.2, kpl<.5) ind = n.logical_and(k > .15, k < .5) # ind = n.logical_and(kpl>.12, kpl<.5) # print kpl,pk.real,err k = k[ind] pkfold = pkfold[ind] errfold = errfold[ind] # if not theo_noise is None: # theo_noise=theo_noise[ind] pk = pkfold err = errfold err_omit = err.copy() # s = n.logspace(1,3.5,100) s = n.linspace(-5000, 5000, 10000) # print s data = [] data_omit = [] for _k, _pk, _err in zip(k, pk, err): if verbose: print _k, _pk.real, _err # print '%6.3f %9.5f 9.5f'%(_k, _pk.real, _err) for ss in s: data.append(n.exp(-.5 * n.sum((pk.real - ss)**2 / err**2))) data_omit.append(n.exp(-.5 * n.sum((pk.real - ss)**2 / err_omit**2))) # print data[-1] data = n.array(data) data_omit = n.array(data_omit) # print data # print s # data/=n.sum(data) data /= n.max(data) data_omit /= n.max(data_omit) p.figure(5, figsize=(6.5, 5.5)) p.plot(s, data, 'k', linewidth=2) # p.plot(s, data_omit, 'k--', linewidth=1) # use a spline interpolator to get the 1 and 2 sigma limits. # spline = interp.interp1d(data,s) # print spline # print max(data), min(data) # print spline(.68), spline(.95) # p.plot(spline(n.linspace(.0,1,100)),'o') # p.plot(s, n.exp(-.5)*n.ones_like(s)) # p.plot(s, n.exp(-.5*2**2)*n.ones_like(s)) data_c = n.cumsum(data) data_omit_c = n.cumsum(data_omit) data_c /= data_c[-1] data_omit_c /= data_omit_c[-1] mean = s[n.argmax(data)] s1lo, s1hi = s[data_c < 0.1586][-1], s[data_c > 1 - 0.1586][0] s2lo, s2hi = s[data_c < 0.0227][-1], s[data_c > 1 - 0.0227][0] if verbose: print 'Posterior: Mean, (1siglo,1sighi), (2siglo,2sighi)' if verbose: print 'Posterior:', mean, (s1lo, s1hi), (s2lo, s2hi) mean_o = s[n.argmax(data_omit)] s1lo_o, s1hi_o = s[data_omit_c < 0.1586][-1], s[data_omit_c > 1 - 0.1586][0] s2lo_o, s2hi_o = s[data_omit_c < 0.0227][-1], s[data_omit_c > 1 - 0.0227][0] if verbose: print 'Posterior (omit):', mean_o, (s1lo_o, s1hi_o), (s2lo_o, s2hi_o) p.vlines(s1lo, 0, 1, color=(0, 107 / 255., 164 / 255.), linewidth=2) p.vlines(s1hi, 0, 1, color=(0, 107 / 255., 164 / 255.), linewidth=2) # limits for data_omit p.vlines(s2lo, 0, 1, color=(1, 128 / 255., 14 / 255.), linewidth=2) p.vlines(s2hi, 0, 1, color=(1, 128 / 255., 14 / 255.), linewidth=2) if theo_noise is not None: s2l_theo = n.sqrt(1. / n.mean(1. / theo_noise**2)) p.vlines(s2l_theo, 0, 1, color='black', linewidth=2) if verbose: print('Noise level: {0:0>5.3f} mk^2'.format(s2l_theo)) p.xlabel(r'$k^3/2\pi^2\ P(k)\ [{\rm mK}^2]$', fontsize='large') p.ylabel('Posterior Distribution', fontsize='large') p.xlim(0, 700) p.title('z = {0:.2f}'.format(z)) if (s2lo > 700) or (s2hi > 1000): p.xlim(0, 1500) p.grid(1) p.subplots_adjust(left=.15, top=.95, bottom=.15, right=.95) p.savefig('posterior_{0:.2f}.png'.format(z)) f = open('posterior_{0:.2f}.txt'.format(z), 'w') f.write('Posterior: Mean,\t(1siglo,1sighi),\t(2siglo,2sighi)\n') f.write('Posterior: {0:.4f},\t({1:.4f},{2:.4f}),\t({3:.4f},' '{4:.4f})\n'.format(mean, s1lo, s1hi, s2lo, s2hi)) f.write('Posterior (omit): {0:.4f},\t({1:.4f},{2:.4f}),t({3:.4f},' '{4:.4f})\n'.format(mean_o, s1lo_o, s1hi_o, s2lo_o, s2hi_o)) f.write('Noise level: {0:0>5.3f} mk^2\n'.format(s2l_theo)) f.close()
for filename in files: try: freqs.append(n.load(filename)['freq']*1e3) print('Frequency found: {0}'.format(freqs[-1])) except(KeyError): try: dchan = int(filename.split('/')[-1].split('.')[0].split('_')[2])-int(filename.split('.')[0].split('_')[1]) chan = int(filename.split('/')[-1].split('.')[0].split('_')[1]) + dchan/2. freqs.append(chan/2. + 100) #a pretty good apprximation of chan 2 freq for 500kHz channels print('Frequency found: {0}'.format(freqs[-1])) except: print('No frequency found for file: '+filename+'\n') 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)
D = F[0] times = D.data.field('DATE') t_int = n.diff(times).max()*24*3600 print "t_int = ",t_int totalt = n.ceil((times.max() - times.min())*24*3600 + t_int) print "total observing time = ",totalt Ntimes = n.ceil(totalt/t_int) print "ntimes = ",Ntimes bls = D.data.field('BASELINE') ant2 = (bls%256).astype(int) ant1 = ((bls-ant2)/256).astype(int) uvws = n.array(zip(D.data.field('UU'),D.data.field('VV'),D.data.field('WW')))*1e9 #bl vectors in ns Nants = len(set(ant2)) Nmax = ant2.max() freqs = gethdufreqs(D) z = pspec.f2z(n.mean(freqs)/1e9) print "padding the horizon by k_parr = ",windowpad windowpad_delay = windowpad / pspec.dk_deta(z) print "at z=%4.1f this is %7.5f ns"%(z,windowpad_delay) df = n.diff(freqs)[0] delays = n.fft.fftfreq(freqs.shape[0],df/1e9) #delays in ns print "n_ant = ",Nants print n.sum((ant2-ant1)==0) Nblt = D.data.field('DATA').shape[0] Nbl = Nblt/Ntimes MAXBL = n.max(bls) Nfreqs = D.data.field('DATA').shape[3] Npol = D.data.field('DATA').shape[4] #form up a list of baselines, sorted by length bl_lengths = [] bls_sorted = []
def kpr_from_sep(sepstr, fq, grid_spacing=[4., 32.]): kx, ky = uv_from_sep(sepstr, grid_spacing=grid_spacing) scalar = pspec.dk_du(pspec.f2z(fq)) * (fq / 0.3) return scalar * np.sqrt(kx**2 + ky**2)
pIvs.fill_value = 1e-5 pIvs_pk = n.ma.masked_invalid(pIvs_pk) pCvs_pk = n.ma.masked_invalid(pCvs_pk) pIvs_pk_mask, pCvs_pk_mask = pIvs_pk.mask, pCvs_pk.mask pIvs_pk = n.ma.masked_less(pIvs_pk, 0) pCvs_pk = n.ma.masked_less(pCvs_pk, 0) pIvs_pk.mask = n.logical_or(pIvs_pk.mask, pIvs_pk_mask) pCvs_pk.mask = n.logical_or(pCvs_pk.mask, pCvs_pk_mask) pIvs_pk.fill_value = 1e-5 pCvs_pk.fill_value = 1e-5 try: z_bin = f2z(freq) except: print 'frequency not found in boots. Searching in pspec.npz' f_name = ('/home/mkolopanis/psa64/sigloss_verification/' 'Jul6_noise_3Jy_inttime_44/95_115/I/' 'pspec_Jul6_noise_3Jy_inttime_44_95_115_I.npz') npz = n.load(f_name) # matt's data freq = npz['freq'] z_bin = f2z(freq) # load 21cmSense Noise models used to compute Beta # Beta = (P_noise + P_inj)/P_out noise_files = ('/home/mkolopanis/psa64/' '21cmsense_noise/dish_size_1/*drift_mod*.npz') n_fqs, n_ks, noise = py21cm.load_noise_files(glob.glob(noise_files))
def k_bad(fq,RM): _z = pspec.f2z(fq) k = nu2l2(fq) * RM * 4.* H(_z) / ( (1+_z) * c) print k / 0.71 return k / 0.71
def k3pk(T,k,fq,B): z = pspec.f2z(fq) bm = 0.76 scalar = pspec.X2Y(z) * k**3 / (2*np.pi**2* B*1e9 * bm) return scalar * 1e6 *np.abs(T)**2
fig = figure() colors='kcmb' for j,RM in enumerate(RMs): Nann = 3 for i in range(Nann): if i == 0 or i+1 == Nann: continue #if i%4 != 0: continue nchan_i = int(Nchan/Nann) ntaps = 3 ch1,ch2 = i*nchan_i,(i+1)*nchan_i ch_in,ch_out = ch1-nchan_i, ch2+nchan_i freqs_i = freqs[ch_in:ch_out] dnu = freqs_i[1] - freqs_i[0] eta = np.fft.fftshift(np.fft.fftfreq(nchan_i,dnu)) z_mid = np.median(pspec.f2z(freqs_i)) k = np.abs(eta*pspec.dk_deta(z_mid)) V_nu = RMvis(freqs_i,RM) V_nu *= pspec.jy2T(freqs_i) Trms = pfb.pfb(V_nu,taps=ntaps,window=window,fft=np.fft.ifft) Trms = np.fft.fftshift(Trms) DELTA = k3pk(Trms,k=k,fq=np.mean(freqs_i),B=0.1/Nann) valid = k!=0. DELTA = np.extract(valid,DELTA) DELTA /= DELTA.sum() k = np.extract(valid,k)
def posterior(kpl, pk, err, pkfold=None, errfold=None, f0=.151, umag=16., theo_noise=None, verbose=False): import scipy.interpolate as interp k0 = n.abs(kpl).argmin() kpl = kpl[k0:] z = pspec.f2z(f0) kpr = pspec.dk_du(z) * umag k = n.sqrt(kpl**2 + kpr**2) if pkfold is None: if verbose: print 'Folding for posterior' pkfold = pk[k0:].copy() errfold = err[k0:].copy() pkpos, errpos = pk[k0 + 1:].copy(), err[k0 + 1:].copy() pkneg, errneg = pk[k0 - 1:0:-1].copy(), err[k0 - 1:0:-1].copy() pkfold[1:] = (pkpos / errpos**2 + pkneg / errneg**2) / (1. / errpos**2 + 1. / errneg**2) errfold[1:] = n.sqrt(1. / (1. / errpos**2 + 1. / errneg**2)) #ind = n.logical_and(kpl>.2, kpl<.5) ind = n.logical_and(k > .15, k < .5) #ind = n.logical_and(kpl>.12, kpl<.5) #print kpl,pk.real,err k = k[ind] pkfold = pkfold[ind] errfold = errfold[ind] #if not theo_noise is None: # theo_noise=theo_noise[ind] pk = pkfold err = errfold err_omit = err.copy() #s = n.logspace(1,3.5,100) s = n.linspace(-5000, 5000, 10000) # print s data = [] data_omit = [] for _k, _pk, _err in zip(k, pk, err): if verbose: print _k, _pk.real, _err # print '%6.3f %9.5f 9.5f'%(_k, _pk.real, _err) for ss in s: data.append(n.exp(-.5 * n.sum((pk.real - ss)**2 / err**2))) data_omit.append(n.exp(-.5 * n.sum((pk.real - ss)**2 / err_omit**2))) # print data[-1] data = n.array(data) data_omit = n.array(data_omit) #print data #print s #data/=n.sum(data) data /= n.max(data) data_omit /= n.max(data_omit) p.figure(5, figsize=(6.5, 5.5)) p.plot(s, data, 'k', linewidth=2) # p.plot(s, data_omit, 'k--', linewidth=1) #use a spline interpolator to get the 1 and 2 sigma limits. #spline = interp.interp1d(data,s) #print spline #print max(data), min(data) #print spline(.68), spline(.95) #p.plot(spline(n.linspace(.0,1,100)),'o') # p.plot(s, n.exp(-.5)*n.ones_like(s)) # p.plot(s, n.exp(-.5*2**2)*n.ones_like(s)) data_c = n.cumsum(data) data_omit_c = n.cumsum(data_omit) data_c /= data_c[-1] data_omit_c /= data_omit_c[-1] mean = s[n.argmax(data)] s1lo, s1hi = s[data_c < 0.1586][-1], s[data_c > 1 - 0.1586][0] s2lo, s2hi = s[data_c < 0.0227][-1], s[data_c > 1 - 0.0227][0] if verbose: print 'Posterior: Mean, (1siglo,1sighi), (2siglo,2sighi)' if verbose: print 'Posterior:', mean, (s1lo, s1hi), (s2lo, s2hi) mean_o = s[n.argmax(data_omit)] s1lo_o, s1hi_o = s[data_omit_c < 0.1586][-1], s[data_omit_c > 1 - 0.1586][0] s2lo_o, s2hi_o = s[data_omit_c < 0.0227][-1], s[data_omit_c > 1 - 0.0227][0] if verbose: print 'Posterior (omit):', mean_o, (s1lo_o, s1hi_o), (s2lo_o, s2hi_o) p.vlines(s1lo, 0, 1, color=(0, 107 / 255., 164 / 255.), linewidth=2) p.vlines(s1hi, 0, 1, color=(0, 107 / 255., 164 / 255.), linewidth=2) # limits for data_omit p.vlines(s2lo, 0, 1, color=(1, 128 / 255., 14 / 255.), linewidth=2) p.vlines(s2hi, 0, 1, color=(1, 128 / 255., 14 / 255.), linewidth=2) if not theo_noise is None: s2l_theo = n.sqrt(1. / n.mean(1. / theo_noise**2)) p.vlines(s2l_theo, 0, 1, color='black', linewidth=2) if verbose: print('Noise level: {0:0>5.3f} mk^2'.format(s2l_theo)) p.xlabel(r'$k^3/2\pi^2\ P(k)\ [{\rm mK}^2]$', fontsize='large') p.ylabel('Posterior Distribution', fontsize='large') p.xlim(0, 700) p.title('z = {0:.2f}'.format(z)) if (s2lo > 700) or (s2hi > 1000): p.xlim(0, 1500) p.grid(1) p.subplots_adjust(left=.15, top=.95, bottom=.15, right=.95) p.savefig('posterior_{0:.2f}.png'.format(z)) f = open('posterior_{0:.2f}.txt'.format(z), 'w') f.write('Posterior: Mean,\t(1siglo,1sighi),\t(2siglo,2sighi)\n') f.write( 'Posterior: {0:.4f},\t({1:.4f},{2:.4f}),\t({3:.4f},{4:.4f})\n'.format( mean, s1lo, s1hi, s2lo, s2hi)) f.write( 'Posterior (omit): {0:.4f}, ({1:.4f},{2:.4f}),\t({3:.4f},{4:.4f})\n'. format(mean_o, s1lo_o, s1hi_o, s2lo_o, s2hi_o)) f.write('Noise level: {0:0>5.3f} mk^2\n'.format(s2l_theo)) f.close()
p.xlabel(r'$P_{\rm in}(k)\ [{\rm mK}^2\ (h^{-1}\ {\rm Mpc})^3]$', fontsize=14) p.ylabel(r'$P_{\rm out}(k)\ [{\rm mK}^2\ (h^{-1}\ {\rm Mpc})^3]$', fontsize=14) p.grid() #npz = n.load('/home/mkolopanis/psa64/psa64_multiz/data/pspec_Nov18_vanilla_skew_frpad_2_'+chan+'_I.npz') sig_factor_interp = interp1d(pIs, pIs/pCs,kind='linear',bounds_error=False,fill_value=0) npz_file = opts.path+'/pspec_'+opts.pspec+'_'+chan+'_'+opts.pol+'.npz' npz = n.load(npz_file) #npz = n.load('/home/mkolopanis/psa64/pspec_Mar17_vanilla_ali_frf_recon_'+chan+'_I.npz') #print npz.files kpls,pks,errs = npz['kpl'], npz['pk'], npz['err'] freq = npz['freq'] z_bin = f2z(freq) sig_factors= [] for kpl,pk,err in zip(kpls,pks,errs): #p.([pklo,pkhi], [pk,pk], 'r') pkup = max(pk+err,1e-6) pkdn = max(pk-err,1e-6) p.subplot(gs[2]) p.fill_between([pklo,pkhi], [pkdn,pkdn], [pkup,pkup], facecolor='gray', edgecolor='gray') p.subplot(gs[3]) p.fill_between([1e-3,20], [pkdn,pkdn], [pkup,pkup], facecolor='gray', edgecolor='gray') if pkup > 1e-6: sig_factors.append( sig_factor_interp(pkup)) sig_factors = n.array(sig_factors)
freq = F['freq'] windowpad = F['windowpad'] plotres = True PLOTWINDOWCONTOUR = False figsize = (20, 25) try: observation_num = int(sys.argv[1].split('.')[0]) observation = MWA_Observation(observation_num, db=db) except (ValueError): gpstime = int(n.round(Time(F['time'], scale='utc', format='jd').gps)) observation_num = find_closest_observation(gpstime, db=db) observation = MWA_Observation(observation_num, db=db) for plotres in [False, True]: z = pspec.f2z(freq / 1e9) #windowpad = 0.01 #should match whatever I used in uvfitswedge.py if len(sys.argv[1:]) == 1 and not sys.argv[1].endswith('.p.npz'): amps = n.ma.masked_invalid(n.log10(n.abs(F['P'].T))) outname = sys.argv[1].replace('.npz', '') else: if len(sys.argv[1:]) == 1: outname = sys.argv[1].replace('.npz', '') else: outname = 'mywedge' if plotres: outname += '_res' P = 0 P2 = 0 C = 0 for Pfile in sys.argv[1:]: F = n.load(Pfile) if plotres: P += F['P_res']
try: dchan = int( filename.split('/')[-1].split('.')[0].split('_')[2]) - int( filename.split('.')[0].split('_')[1]) chan = int(filename.split('/')[-1].split('.')[0].split('_') [1]) + dchan / 2. freqs.append( chan / 2. + 100 ) #a pretty good apprximation of chan 2 freq for 500kHz channels print('Frequency found: {0}'.format(freqs[-1])) except: print('No frequency found for file: ' + filename + '\n') 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()