def lf_for_z(z, log10L_bin_centres, models, legend=False): # THIS WILL BE individual LF plot colors = [ 'b', 'r', 'orange', 'g', 'k', 'c', 'y', 'm', 'darkslateblue', 'gray', 'tomato', 'lawngreen', 'teal', 'wheat' ] fig = plt.figure() if type(models) == str: models = [models] for i, model in enumerate(models): m = getattr(lf_parameters, model)() if hasattr(m, 'beta'): s = abs(np.array(m.redshifts) - z) < 0.1 x = 0.4 * (lum_to_M(10**log10L_bin_centres) - np.array(m.M_star)[s][0]) phistar = 10**np.array(m.phi_star)[s][0] alpha = np.array(m.alpha)[s][0] beta = np.array(m.beta)[s][0] phi = phistar / (10**(x * (alpha + 1)) + 10**(x * (beta + 1))) plt.scatter(log10L_bin_centres, np.log10(phi), c=colors[i], label=model) else: s = abs(np.array(m.redshifts) - z) < 0.1 x = 10**(log10L_bin_centres - np.log10(M_to_lum(np.array(m.M_star)[s][0]))) phistar = 10**np.array(m.phi_star)[s][0] alpha = np.array(m.alpha)[s][0] plt.scatter(log10L_bin_centres, np.log10(phistar * (x)**(alpha + 1) * np.exp(-x)), c=colors[i], label=model) plt.ylabel(r'$\rm log_{10}(\phi \; / \; cMpc^{-3} \; dex^{-1})$') plt.xlabel(r"$\rm log_{10}(L_{UV} \; / \; erg\, s^{-1}\, Hz^{-1})$") if legend: plt.legend(loc='best') return fig
def get_data(ii, tag, inp = 'FLARES'): num = str(ii) if inp == 'FLARES': if len(num) == 1: num = '0'+num sim = rF"../flares_pipeline/data/FLARES_{num}_sp_info.hdf5" num = ''#num+'/' else: sim = rF"../flares_pipeline/data/EAGLE_{inp}_sp_info.hdf5" num='' with h5py.File(sim, 'r') as hf: cop = np.array(hf[num+tag+'/Galaxy'].get('COP'), dtype = np.float64) mstar = np.array(hf[num+tag+'/Galaxy'].get('Mstar_30'), dtype = np.float64)*1e10 S_len = np.array(hf[num+tag+'/Galaxy'].get('S_Length'), dtype = np.int64) G_len = np.array(hf[num+tag+'/Galaxy'].get('G_Length'), dtype = np.int64) S_coords = np.array(hf[num+tag+'/Particle'].get('S_Coordinates'), dtype = np.float64) G_coords = np.array(hf[num+tag+'/Particle'].get('G_Coordinates'), dtype = np.float64) S_mass = np.array(hf[num+tag+'/Particle'].get('S_MassInitial'), dtype = np.float64)*1e10 G_mass = np.array(hf[num+tag+'/Particle'].get('G_Mass'), dtype = np.float64)*1e10 S_Z = np.array(hf[num+tag+'/Particle'].get('S_Z_smooth'), dtype = np.float64) S_age = np.array(hf[num+tag+'/Particle'].get('S_Age'), dtype = np.float64)*1e3 S_los = np.array(hf[num+tag+'/Particle'].get('S_los'), dtype = np.float64) S_sml = np.array(hf[num+tag+'/Particle'].get('S_sml'), dtype = np.float64) G_sml = np.array(hf[num+tag+'/Particle'].get('G_sml'), dtype = np.float64) G_Z = np.array(hf[num+tag+'/Particle'].get('G_Z_smooth'), dtype = np.float64) lfuv = lum_to_M(np.array(hf[num+tag+'/Galaxy/BPASS_2.2.1/Chabrier300/Luminosity/DustModelI'].get('FUV'), dtype = np.float64)) begin = np.zeros(len(S_len), dtype = np.int64) end = np.zeros(len(S_len), dtype = np.int64) begin[1:] = np.cumsum(S_len)[:-1] end = np.cumsum(S_len) gbegin = np.zeros(len(G_len), dtype = np.int64) gend = np.zeros(len(G_len), dtype = np.int64) gbegin[1:] = np.cumsum(G_len)[:-1] gend = np.cumsum(G_len) return S_len, cop, mstar, S_coords, G_coords, S_mass, G_mass, S_Z, S_age, S_los, S_sml, G_sml, G_Z, begin, end, gbegin, gend, S_len, lfuv
def get_hist(ii, tag, bins, inp='GEAGLE', filter='FUV', Luminosity='Dustcorr'): if inp == 'GEAGLE': num = str(ii) if len(num) == 1: num = '0' + num filename = '../photometry/out/GEAGLE_{}_sp_info.hdf5'.format(num) with h5py.File(filename, 'r') as hf: lum = np.array(hf[ F"{tag}/Subhalo/BPASS/SalpeterIMF/ModelI/Luminosity/{Luminosity}/{filter}"] ) tmp, edges = np.histogram(lum_to_M(lum), bins=bins) return tmp
def get_line(ii, tag, line='HI6563', inp='FLARES', LF=False, bins=np.arange(42, 46, 0.5), Type='DustModelI'): if inp == 'FLARES': num = str(ii) if len(num) == 1: num = '0' + num filename = './data/flares.hdf5' num = num + '/' else: filename = F'./data/EAGLE_{inp}_sp_info.hdf5' num = '' with h5py.File(filename, 'r') as hf: if LF: lum = np.array(hf[ F"{num}{tag}/Galaxy/BPASS_2.2.1/Chabrier300/Lines/{Type}/{line}/Luminosity"] ) tmp, edges = np.histogram(lum_to_M(lum), bins=bins) return tmp else: lum = np.array(hf[ F"{num}{tag}/Galaxy/BPASS_2.2.1/Chabrier300/Lines/{Type}/{line}/Luminosity"] ) EW = np.array(hf[ F"{num}{tag}/Galaxy/BPASS_2.2.1/Chabrier300/Lines/{Type}/{line}/EW"] ) return lum, EW
def get_lum(ii, tag, bins=np.arange(-26, -16, 0.5), inp='FLARES', filter='FUV', LF=True, Luminosity='DustModelI'): if inp == 'FLARES': num = str(ii) if len(num) == 1: num = '0' + num filename = rF"./data/flares.hdf5" num = num + '/' else: filename = F'./data/EAGLE_{inp}_sp_info.hdf5' num = '' with h5py.File(filename, 'r') as hf: lum = np.array(hf[ F"{num}/{tag}/Galaxy/BPASS_2.2.1/Chabrier300/Luminosity/{Luminosity}/{filter}"] ) if LF == True: tmp, edges = np.histogram(lum_to_M(lum), bins=bins) return tmp else: return lum
Hbeta = np.concatenate(get_line_all(tag, 'HI4861', inp = 'FLARES', LF = False)[:,1]) CIII = np.concatenate(get_line_all(tag, 'CIII1907', inp = 'FLARES', LF = False)[:,1] + get_line_all(tag, 'CIII1909', inp = 'FLARES', LF = False)[:,1]) OII = np.concatenate(get_line_all(tag, 'OII3726', inp = 'FLARES', LF = False)[:,1] + get_line_all(tag, 'OII3729', inp = 'FLARES', LF = False)[:,1]) # NeIII = get_line_all(tag, 'NeIII3869', inp = 'FLARES', LF = False) + get_line_all(tag, 'NeIII3967', inp = 'FLARES', LF = False) OIII = np.concatenate(get_line_all(tag, 'OIII4959', inp = 'FLARES', LF = False)[:,1] + get_line_all(tag, 'OIII5007', inp = 'FLARES', LF = False)[:,1]) if input == plt_options[1]: x_inp = get_data_all(tag, dataset = 'Mstar_30', DF=False)*1e10 for kk in range(len(x_inp)): x_inp[kk] = np.log10(x_inp[kk]) bins = np.arange(7.5, 11.5, 0.5) xlabel=r'log$_{10}$(M$_{\star}$/M$_{\odot}$)' xpos = 0.455 bottom = 0.20 elif input == plt_options[2]: x_inp = get_lum_all(tag, LF=False) for kk in range(len(x_inp)): x_inp[kk] = lum_to_M(x_inp[kk]) bins = -np.arange(17, 25, 1)[::-1] xlabel = r'$\mathrm{M}_{1500}$' xpos = 0.47 bottom = 0.21 for kk in range(5): axs[kk].set_xlim((-17,-23.9)) ws = np.array([]) for jj in sims: ws = np.append(ws, np.ones(np.shape(x_inp[jj]))*weights[jj]) x_inp = np.concatenate(x_inp) create_EW_plot(x_inp, np.log10(Halpha), bins, ws, axs[0], titles[0], s_m.to_rgba(ii+0.5), ii) create_EW_plot(x_inp, np.log10(Hbeta), bins, ws, axs[1], titles[1], s_m.to_rgba(ii+0.5), ii)
LF=False, filter='FUV', Luminosity='Intrinsic') Mstar_30 = get_data_all(tag, inp='FLARES', DF=False) sfr_30 = get_data_all(tag, dataset='SFR_inst_30', inp='FLARES', DF=False) ws = np.array([]) for jj in range(len(weights)): ws = np.append(ws, np.ones(np.shape(L_FUV[jj])) * weights[jj]) L_FUV = np.concatenate(L_FUV) L_FUV_int = np.concatenate(L_FUV_int) L_NUV = np.concatenate(L_NUV) Mstar_30 = np.concatenate(Mstar_30) * 1e10 sfr_30 = np.concatenate(sfr_30) ok = np.where(lum_to_M(L_FUV) < low)[0] L_FUV, L_NUV, L_FUV_int, Mstar_30 = L_FUV[ok], L_NUV[ok], L_FUV_int[ ok], Mstar_30[ok] sfr_30 = sfr_30[ok] / Mstar_30 beta = np.log10(L_FUV / L_NUV) / np.log10(1500. / 2500.) - 2.0 att = -2.5 * np.log10(L_FUV / L_FUV_int) zpos = -17.5 if tag == '010_z005p000': from astropy.cosmology import Planck13 from astropy import units as u tmp = 1 / Planck13.H(5).decompose() print((1.0 / (3 * tmp.to(u.yr))).value) check = np.logical_and(Mstar_30 > 1e10, att < 0.4) print(sfr_30[check])
def m_to_M(m, cosmo, z): flux = photconv.m_to_flux(m) lum = photconv.flux_to_L(flux, cosmo, z) M = photconv.lum_to_M(lum) return M
def lf_multi(zs, log10L_bin_centres, models, binned_lf=False, legend=False): # THIS WILL BE LF PLOT FOR A SELECTION OF MODELS markers = ['D', 's', 'h', '^', 'o', '*', 'v'] cmap = mpl.cm.tab20 cmap_marker = mpl.cm.Dark2_r if len(zs) % 2 == 1: N = int(len(zs) / 2) + 1 else: N = int(len(zs) / 2) fig, axes = plt.subplots(N, 2, figsize=(6, N * 2), sharex=True, sharey=True) plt.subplots_adjust(left=0.10, bottom=0.10, top=0.95, right=0.85, wspace=0., hspace=-0.) if type(models) == str: models = [models] Nxx = len(models) for z, ax in zip(zs, axes.flatten()): if legend: if Nxx > 7: if ax == axes[0, 0]: try: g = [] for i, model in enumerate(models[:7]): label = getattr(lf_parameters, model)().label g.append( Line2D([-99., -98.], [-99., -98.], color=cmap(i / 19), label=label, alpha=0.6)) ax.legend(handles=g, loc='lower left', fontsize=6) except: continue if ax == axes[0, 1]: try: g = [] for i, model in enumerate(models[7:]): i = i + 7 label = getattr(lf_parameters, model)().label g.append( Line2D([-99., -98.], [-99., -98.], color=cmap(i / 19), label=label, alpha=0.6)) ax.legend(handles=g, loc='lower left', fontsize=6) except: continue else: if ax == axes[0, 0]: try: g = [] for i, model in enumerate(models): label = getattr(lf_parameters, model)().label g.append( Line2D([-99., -98.], [-99., -98.], color=cmap(i / 19), label=label, alpha=0.6)) ax.legend(handles=g, loc='lower left', fontsize=6) except: continue if ax == axes[1, 0]: if binned_lf: if type(binned_lf) == list: g = [] for l, lf in enumerate(binned_lf): g.append( plt.errorbar(-99., -99., yerr=1., color=cmap_marker(l / 7), linestyle='', marker=markers[l], mec='k', alpha=0.6, label=lf['label'], markersize=3, elinewidth=1, capsize=1, capthick=1)) ax.legend(handles=g, loc='lower left', fontsize=6) else: g = [] for l in range(1): g.append( plt.errorbar(-99., -99., yerr=1., fmt='kD', alpha=0.6, label=binned_lf['label'], markersize=3, elinewidth=1, capsize=1, capthick=1)) ax.legend(handles=g, loc='lower left', fontsize=6) # except: # continue for i, model in enumerate(models): m = getattr(lf_parameters, model)() if hasattr(m, 'beta'): s = abs(np.array(m.redshifts) - z) < 0.5 try: x = 0.4 * (lum_to_M(10**log10L_bin_centres) - np.array(m.M_star)[s][0]) phistar = 10**np.array(m.phi_star)[s][0] alpha = np.array(m.alpha)[s][0] beta = np.array(m.beta)[s][0] phi = phistar / (10**(x * (alpha + 1)) + 10**(x * (beta + 1))) ax.plot(log10L_bin_centres, np.log10(phi), c=cmap(i / 19), alpha=0.6) except: continue else: s = abs(np.array(m.redshifts) - z) < 0.5 try: x = 10**(log10L_bin_centres - np.log10(M_to_lum(np.array(m.M_star)[s][0]))) phistar = 10**np.array(m.phi_star)[s][0] alpha = np.array(m.alpha)[s][0] ax.plot(log10L_bin_centres, np.log10(phistar * (x)**(alpha + 1) * np.exp(-x)), c=cmap(i / 19), alpha=0.6) except: continue if binned_lf: if type(binned_lf) == list: for l, lf in enumerate(binned_lf): try: q = abs( np.array([float(k) for k in [*lf['LF'].keys()]]) - z) < 0.5 z_key = str( int( np.array([ float(k) for k in [*lf['LF'].keys()] ])[q])) log10L_bin = np.log10( M_to_lum(np.array(lf['LF'][str(int(z_key))]['M']))) phi_bin = np.array(lf['LF'][str(int(z_key))]['phi']) err = np.array(lf['LF'][str(int(z_key))]['phi_err']) uplims = lf['LF'][str(int(z_key))]['uplim'] if lf['both_err']: if lf['log_err']: phi_err = err else: phi_err = [ logerr_lo(phi_bin, err[0], uplims), logerr_hi(phi_bin, err[1]) ] else: if lf['log_err']: phi_err = err else: phi_err = [ logerr_lo(phi_bin, err, uplims), logerr_hi(phi_bin, err) ] ax.errorbar(log10L_bin, np.log10(phi_bin), yerr=phi_err, color=cmap_marker(l / 7), linestyle='', marker=markers[l], mec='k', alpha=0.8, zorder=50 + l, markersize=3, elinewidth=1, capsize=1, capthick=1, uplims=uplims) except: continue else: try: q = abs( np.array([float(k) for k in [*binned_lf['LF'].keys()]]) - z) < 0.5 z_key = str( int( np.array([ float(k) for k in [*binned_lf['LF'].keys()] ])[q])) log10L_bin = np.log10( M_to_lum( np.array(binned_lf['LF'][str(int(z_key))]['M']))) phi_bin = np.array(binned_lf['LF'][str(int(z_key))]['phi']) err = np.array(binned_lf['LF'][str(int(z_key))]['phi_err']) uplims = binned_lf['LF'][str(int(z_key))]['uplim'] if binned_lf['both_err']: if binned_lf['log_err']: phi_err = err else: phi_err = [ logerr_lo(phi_bin, err[0], uplims), logerr_hi(phi_bin, err[1]) ] print(phi_err) else: if binned_lf['log_err']: phi_err = err else: phi_err = [ logerr_lo(phi_bin, err, uplims), logerr_hi(phi_bin, err) ] ax.errorbar(log10L_bin, np.log10(phi_bin), yerr=phi_err, fmt='kD', alpha=0.6, zorder=50, markersize=3, elinewidth=1, capsize=1, capthick=1, uplims=uplims) except: continue ax.text(0.7, 0.9, r'$\rm z=[{0:.1f}, {1:.1f})$'.format(z - 0.5, z + 0.5), fontsize=8, transform=ax.transAxes) ylim = np.array([-8., -4.01]) ax.set_ylim(-8., -1.5) ax.set_xlim([min(log10L_bin_centres), max(log10L_bin_centres)]) fig.text(0.5, 0.05, r'$\rm\log_{10}[L_{FUV} \; / \; (erg \; s^{-1} \; Hz^{-1})]$', horizontalalignment='center', verticalalignment='center') fig.text(0.05, 0.5, r'$\rm\log_{10}[\phi \; / \; Mpc^{-3}]$', horizontalalignment='center', verticalalignment='center', rotation=90) return fig
def lf_params_zs(zs, log10L_bin_centres, models, legend=False): # THIS WILL BE LF PLOT FOR A SELECTION OF MODELS colours = [ 'b', 'r', 'orange', 'g', 'k', 'c', 'y', 'm', 'darkslateblue', 'gray', 'tomato', 'lawngreen', 'teal', 'wheat' ] if len(zs) % 2 == 1: N = int(len(zs) / 2) + 1 else: N = int(len(zs) / 2) fig, axes = plt.subplots(N, 2, figsize=(6, N * 2), sharex=True, sharey=True) plt.subplots_adjust(left=0.10, bottom=0.10, top=0.95, right=0.85, wspace=0., hspace=-0.) if type(models) == str: models = [models] Nxx = len(models) for z, ax in zip(zs, axes.flatten()): if legend: if Nxx > 7: if ax == axes[0, 0]: try: g = [] for i, model in enumerate(models[:7]): colors_plot = colours[:7] g.append( ax.scatter([-99.], [-99.], c=colors_plot[i], s=5, label=model)) ax.legend(handles=g, loc='lower left') except: continue if ax == axes[0, 1]: try: g = [] for i, model in enumerate(models[7:]): colors_plot = colours[7:] g.append( ax.scatter([-99.], [-99.], c=colors_plot[i], s=5, label=model)) ax.legend(handles=g, loc='lower left') except: continue else: if ax == axes[0, 0]: try: g = [] for i, model in enumerate(models): g.append( ax.scatter([-99.], [-99.], c=colours[i], s=5, label=model)) ax.legend(handles=g, loc='lower left') except: continue for i, model in enumerate(models): m = getattr(lf_parameters, model)() if hasattr(m, 'beta'): s = abs(np.array(m.redshifts) - z) < 0.5 try: x = 0.4 * (lum_to_M(10**log10L_bin_centres) - np.array(m.M_star)[s][0]) phistar = 10**np.array(m.phi_star)[s][0] alpha = np.array(m.alpha)[s][0] beta = np.array(m.beta)[s][0] phi = phistar / (10**(x * (alpha + 1)) + 10**(x * (beta + 1))) ax.scatter(log10L_bin_centres, np.log10(phi), s=5, c=colours[i]) except: continue else: s = abs(np.array(m.redshifts) - z) < 0.5 try: x = 10**(log10L_bin_centres - np.log10(M_to_lum(np.array(m.M_star)[s][0]))) phistar = 10**np.array(m.phi_star)[s][0] alpha = np.array(m.alpha)[s][0] ax.scatter(log10L_bin_centres, np.log10(phistar * (x)**(alpha + 1) * np.exp(-x)), s=5, c=colours[i]) except: continue ax.text(0.7, 0.9, r'$\rm z=[{0:.1f}, {1:.1f})$'.format(z - 0.5, z + 0.5), fontsize=8, transform=ax.transAxes) ylim = np.array([-8., -4.01]) ax.set_ylim(-8., -1.5) ax.set_xlim([min(log10L_bin_centres), max(log10L_bin_centres)]) fig.text(0.5, 0.05, r'$\rm\log_{10}[L_{FUV} \; / \; (erg \; s^{-1} \; Hz^{-1})]$', horizontalalignment='center', verticalalignment='center') fig.text(0.05, 0.5, r'$\rm\log_{10}[\phi \; / \; Mpc^{-3}]$', horizontalalignment='center', verticalalignment='center', rotation=90) return fig
bincen = (bins[1:]+bins[:-1])/2. binwidth = bins[1:] - bins[:-1] L = {} for f in ['FUV','NUV']: L[f] = np.array([]) w = np.array([]) with h5py.File(f'./data1/flares.hdf5', 'r') as hf: for sim in hf.keys(): tmp = np.array(hf[f'{sim}/{tag}/Galaxy/BPASS_2.2.1/Chabrier300/Luminosity/DustModelI_{kappa_BC}/{f}']) L[f] = np.hstack((L[f], tmp)) w = np.append(w, np.ones(len(tmp))*weights[int(sim)]) beta = np.log10(L['FUV']/L['NUV'])/np.log10(1500./2500.) - 2.0 x, y = lum_to_M(L['FUV']), beta out = fl.binned_weighted_quantile(x, y, w, bins, quantiles) hist, binedges = np.histogram(x, bins) ok = np.where(hist>0)[0] ok1 = np.where(hist[ok]>3)[0][0] axs.fill_between(bincen[ok][ok1:], out[:,0][ok][ok1:], out[:,2][ok][ok1:], color=s_m.to_rgba(kappa_BC), alpha=0.25) axs.plot(bincen[ok], out[:,1][ok], ls='dashed', color=s_m.to_rgba(kappa_BC), alpha=1, lw=2) axs.plot(bincen[ok][ok1:], out[:,1][ok][ok1:], ls='-', color=s_m.to_rgba(kappa_BC), alpha=1, lw=2, label=r"$\kappa_{\mathrm{BC}}=%s$"%(str(kappa_BC))) plot_beta(5, axs) axs.set_ylim(ylims) axs.set_xlim(xlims) axs.minorticks_on() axs.tick_params(axis='x', which='minor', direction='in')
L[f] = np.array([]) mstar, sfr = np.array([]), np.array([]) w = np.array([]) with h5py.File(f'data/flares.hdf5', 'r') as hf: for sim in hf.keys(): tmp = np.array(hf[ f'{sim}/{tag}/Galaxy/BPASS_2.2.1/Chabrier300/Luminosity/DustModelI/{f}'] ) L[f] = np.hstack((L[f], tmp)) w = np.append(w, np.ones(len(tmp)) * weights[int(sim)]) beta = np.log10(L['FUV'] / L['NUV']) / np.log10(1500. / 2500.) - 2.0 y = beta if input == plt_options[0]: x = lum_to_M(L['FUV']) else: x = np.log10(get_data_all(tag, inp='FLARES', DF=False) * 1e10) axs[ii].hexbin(x, y, gridsize=(35, 13), bins='log', cmap='Greys_r', linewidths=0., mincnt=5, extent=[*[low, -24.5], *ylims], alpha=0.6, zorder=2) quantiles = [0.84, 0.50, 0.16]
def N(self, area=1., cosmo=False, redshift_limits=[8., 15.], log10L_limits=[27.5, 30.], dz=0.05, dlog10L=0.05, per_arcmin=False, return_volumes=False): # calculates the number of galaxies in each bin on a grid defined by redshift_limits, log10L_limits, dz, dlog10L # and area based on a luminosity function evolution model. area_sm = area # Area in square arcmin area_sd = area_sm / 3600. # Area in square degrees area_sr = (np.pi / 180.)**2 * area_sd # Area in steradian if not cosmo: cosmo = FLARE.core.default_cosmo() # Setting the bin edges as well as centres for later operations bin_edges = { 'log10L': np.arange(log10L_limits[0], log10L_limits[-1] + dlog10L, dlog10L), 'z': np.arange(redshift_limits[0], redshift_limits[-1] + dz, dz) } bin_centres = { 'log10L': bin_edges['log10L'][:-1] + dlog10L / 2., 'z': bin_edges['z'][:-1] + dz / 2. } # Using astropy.cosmology to calculate the volume in each redshift bin volumes = np.asarray([ cp.quad(dVc, bin_edges['z'][i - 1], bin_edges['z'][i], args=cosmo)[0] for i in range(1, len(bin_edges['z'])) ]) params = self.parameters(bin_centres['z']) if 'beta' in params.keys(): alphas = params['alpha'] Lstars = M_to_lum(params['M*']) Mstars = params['M*'] phistars = 10**params['log10phi*'] betas = params['beta'] N = phistars[None, :] * np.vectorize(quadfunct2)( _integ_dblpow, 0.4 * (lum_to_M(10**bin_edges['log10L'][1:, None]) - Mstars[None, :]), 0.4 * (lum_to_M(10**bin_edges['log10L'][:-1, None]) - Mstars[None, :]), alphas[None, :], betas[None, :]) * volumes[None, :] * area_sr ''' Left in for possible future implementation #N = phistars[None, :] * np.vectorize(quadfunct2)(_integ_dblpow2, # 10**(bin_edges['log10L'][:-1, None] - Lstars[None, :]), # 10**(bin_edges['log10L'][1:, None] - Lstars[None, :]), # alphas[None, :], betas[None, :] ) * volumes[None, :] * area_sr ''' else: alphas = params['alpha'] Lstars = M_to_lum(params['M*']) phistars = 10**params['log10phi*'] Mstars = params['M*'] N = phistars[None, :] * np.vectorize(quadfunct)( _integ, 10**bin_edges['log10L'][:-1, None] / Lstars[None, :], 10**bin_edges['log10L'][1:, None] / Lstars[None, :], args=(alphas[None, :])) * volumes[None, :] * area_sr ''' Left in for possible future implementation N = phistars[None, :] * np.vectorize(quadfunct)(_integ2, lum_to_M(10**bin_edges['log10L'][1:, None]) - Mstars[None, :], lum_to_M(10**bin_edges['log10L'][:-1, None]) - Mstars[None, :], args=(alphas[None, :])) * volumes[None, :] * area_sr ''' if per_arcmin: N /= area_sm if return_volumes: return bin_edges, bin_centres, volumes, N else: return bin_edges, bin_centres, N
mstars = np.append(mstars, mstar) lfuvs = np.append(lfuvs, lfuv) att_gals = np.append(att_gals, att_gal) else: atts, mstars, lfuvs, att_gals = att, mstar, lfuv, att_gal mstars = np.log10(mstars) mbins = np.arange(9., 11.75, 0.5) mbins_label = np.array( [F'${mbins[ii]}$ - ${mbins[ii+1]}$' for ii in range(len(mbins) - 1)]) lbins = -np.arange(19.5, 25, 1)[::-1] lbins_label = np.array( [F'${lbins[ii+1]}$ - ${lbins[ii]}$' for ii in range(len(lbins) - 1)]) atts = -2.5 * np.log10(atts) lfuvs = lum_to_M(lfuvs) fig, axs = plt.subplots(nrows=1, ncols=2, figsize=(10, 5), sharex=True, sharey=True, facecolor='w', edgecolor='k') axs = axs.ravel() colors = ['red', 'brown', 'magenta', 'orange', 'indigo'] for ii in range(len(mbins) - 1): ok = np.logical_and(mstars >= mbins[ii], mstars < mbins[ii + 1]) if np.sum(ok) >= 1:
ls='solid', marker='o', yerr=[ np.log10(yy[nonzero]) - np.log10(yy[nonzero] - yyerr[nonzero]), np.log10(yy[nonzero] + yyerr[nonzero]) - np.log10(yy[nonzero]) ], color=s_m.to_rgba( (dbins[kk] + dbins[kk + 1]) / 2)) elif input == plt_options[1]: LFUV_this = np.concatenate(LFUV[ok]) LFUV_int_this = np.concatenate(LFUV_int[ok]) y = -2.5 * np.log10(LFUV_this / LFUV_int_this) x = lum_to_M(LFUV_this) quantiles = [0.84, 0.50, 0.16] out = fl.binned_weighted_quantile(x, y, np.ones(len(x)), bins, quantiles) hist, binedges = np.histogram(x, bins) tok = np.where(hist > 0)[0] axs[ii].errorbar(bincen[tok], out[:, 1][tok], lw=2, ls='solid', marker='o', yerr=[ out[:, 1][tok] - out[:, 2][tok], out[:, 0][tok] - out[:, 1][tok] ],
slen = np.append(slen, dat[ii][-1]) num = np.append(num, num[-1]+len(dat[ii][0])) part_num = np.append(part_num, np.arange(0, len(dat[ii][0]))) slen = np.asarray(slen, dtype=np.int) violin_att = np.ones((len(mstar), np.max(slen)))*np.nan for ii in range(len(mstar)): jj = np.where(ii>=num)[0][-1] begin = dat[jj][4][part_num[ii]] end = dat[jj][5][part_num[ii]] violin_att[ii][:slen[ii]] = dat[jj][3][begin:end] att_gal = -2.5*np.log10(lfuv/lfuv_int) lfuv = lum_to_M(lfuv) mstars = np.log10(mstar) mbins = np.arange(9., 11.75, 0.5) mbins_label = np.array([F'${mbins[ii]}$ - ${mbins[ii+1]}$' for ii in range(len(mbins)-1)]) lbins = -np.arange(19, 25, 1)[::-1] lbins_label = np.array([F'${lbins[ii]}$ - ${lbins[ii+1]}$' for ii in range(len(lbins)-1)]) if inp == 0: fig, axs = plt.subplots(nrows = 2, ncols = 5, figsize=(11, 5), sharex=True, sharey=True, facecolor='w', edgecolor='k') axs = axs.ravel() for ii in range(len(mbins)-1): ok = np.logical_and(mstars>=mbins[ii], mstars<mbins[ii+1])
weights = np.array(df['weights']) for ii, jj in enumerate(z): data = get_all(tags[ii], Luminosity='DustModelI', filter=filters) for kk in range(len(weights)): if kk == 0: Mlum = data[kk][0] part = data[kk][1] slen = data[kk][2] w = np.ones(len(data[kk][2])) * weights[kk] else: Mlum = np.append(Mlum, data[kk][0], axis=0) part = np.append(part, data[kk][1]) slen = np.append(slen, data[kk][2]) w = np.append(w, np.ones(len(data[kk][2])) * weights[kk]) ok = np.where(part == 100)[0] percentile[ii] = np.percentile(Mlum[ok], 97, axis=0) for ii, jj in enumerate(filters): df_filter_lims[jj[8:]] = lum_to_M(percentile[:, ii]) print(df_filter_lims) df_filter_lims.to_csv('Magnitude_limits.txt')
tags = [ '010_z005p000', '009_z006p000', '008_z007p000', '007_z008p000', '006_z009p000', '005_z010p000' ] tags_ref = [ '008_z005p037', '006_z005p971', '005_z007p050', '004_z008p075', '003_z008p988', '002_z009p993' ] for ii in range(6): z = ii + 5 df = pd.read_csv('Magnitude_limits.txt') low = lum_to_M(np.array(df[filter])[ii]) bins = -np.arange(-low, 25, 0.3)[::-1] bincen = (bins[1:] + bins[:-1]) / 2. binwidth = bins[1:] - bins[:-1] vol = (4 / 3) * np.pi * (14 / h)**3 out, hist = get_all(tags[ii], bins, Luminosity='Dustcorr') phi = out / (vol * binwidth) xerr = np.ones(len(phi)) * binwidth[0] / 2. yerr = np.sqrt(out) / (vol * binwidth) axs[ii].errorbar(bincen, np.log10(phi), yerr=[ np.log10(phi) - np.log10(phi - yerr), np.log10(phi + yerr) - np.log10(phi)