def update_plot(i): sim = simlist[i] host, subs = load_elvis(sim=sim, processed=True) # subs = subs[subs.nadler2018 > 0.5] bind = -subs.pot_mltr.values - 0.5*(subs.v_r.values**2 + subs.v_t.values**2) z = WMAP7.lookback_time(1/subs.a_acc.values - 1)[bind>0].value r = subs.r[bind>0] bind = bind[bind>0] # calculate linear regression infallcut = z > 2 bindcut = bind > 0 bind_ = bind[infallcut & bindcut] infall_ = z[infallcut & bindcut] slope, intercept, r_value, p_value, std_err = linregress(infall_, np.log10(bind_)) # update plot offset = [[infall, np.log10(E)] for E,infall in zip(bind,z)] scat.set_offsets(offset) # positions scat.set_array(r) # colors line.set_data(z[bindcut], intercept + slope*z[bindcut]) sim_text.set_text(sim) sortprop_text.set_text("Mvir = "'%.2E' % sortprop[i]) return scat,sim_text,sortprop_text,line
def main(datadir='/data', resultsdirs=['results'], plotsdir='plots', labels=['results'], counts_file='galaxy_counts.txt', snapnum_file='snapnum_redshift.csv', dwarf_limit=0.05, plotlabel='', evolution=False): """ Plot results of Millennium Simulation compact group analysis """ if not os.path.isdir(datadir): raise ValueError("{0} not found!".format(datadir)) for resultsdir in resultsdirs: if not os.path.isdir(resultsdir): raise ValueError("{0} not found!".format(resultsdir)) if not os.path.isdir(plotsdir): os.mkdir(plotsdir) if not os.path.exists(snapnum_file): raise ValueError("{0} not found!".format(snapnum_file)) # # Read snapnum file to convert from snapnum to redshift # snap_to_z = pandas.read_csv(snapnum_file, header=0, comment='#', skip_blank_lines=True, index_col=0, skipinitialspace=True) # # Determine number of snapnums we have in datadir # if evolution: data_snapnum_dirs = np.arange(64) else: data_snapnum_dirs = np.sort( glob.glob(os.path.join(datadir, 'snapnum_*'))) print("Found {0} snapnum directories in {1}.".format( len(data_snapnum_dirs), datadir)) if len(data_snapnum_dirs) == 0 and not os.path.exists(counts_file): return # # Count the number and standard devation of non-dwarf galaxies in raw data files # if os.path.exists(counts_file): print("Found {0}".format(counts_file)) else: generate_snapnum_counts(datadir, data_snapnum_dirs, data_file, dwarf_limit, counts_file) # # Read the galaxy counts file # galaxy_counts = pandas.read_csv(counts_file, header=0, comment='#', skip_blank_lines=True, index_col=0, skipinitialspace=True) # # Get results from each resultsdir # if evolution: num_members, num_members_std = data_read_in_evolution( resultsdirs, data_snapnum_dirs) else: members, groups, num_non_dwarf_members, non_dwarf_members, num_members_std, num_non_dwarf_members_std, num_groups_std = data_read_in( resultsdirs, data_snapnum_dirs, datadir) # # Convert snapnums to redshifts and to lookback times # snapnums = [snapnum for snapnum in range(len(data_snapnum_dirs))] redshifts = np.array([snap_to_z['Z'][snapnum] for snapnum in snapnums]) lbtimes = WMAP7.lookback_time(redshifts).value plot_redshifts = [0.0, 0.1, 0.2, 0.3, 0.5, 1, 1.5, 2, 3, 5, 10] plot_lookback_times = WMAP7.lookback_time(plot_redshifts).value # colors = ['#d73027', '#fc8d59', '#fee090'] symbols = ['o', 's', '^', '*', 'p'] # # Make Evolution Plots # if evolution: plot_evolution(plotlabel, galaxy_counts, num_members, num_members_std, resultsdirs, colors, symbols, lbtimes, plot_lookback_times, plot_redshifts, plotsdir, labels) return # # Plot total number of compact groups vs. redshift # figname = os.path.join(plotsdir, '{0}_num_groups.eps'.format(plotlabel)) num_cgs = np.array([[len(df) for df in groups[result_ind]] for result_ind in range(len(resultsdirs))]) fig = plt.figure() ax = fig.add_subplot(111) ax2 = ax.twiny() for ind, (num_cg, num_cg_std) in enumerate(zip(num_cgs, num_groups_std)): ax.plot(lbtimes, num_cg, color=colors[ind], marker=symbols[ind], label=labels[ind]) ax.fill_between(lbtimes, num_cg - num_cg_std, num_cg + num_cg_std, facecolor=colors[ind], edgecolor="none", alpha=0.6) ax.set_xlabel('Lookback Time (Gyr)') ax.set_ylabel('Number of Compact Groups') ax.set_yscale('log') ax.set_xlim(0, WMAP7.age(0).to('Gyr').value) ax.set_ylim(1.e2, 1.e5) ax.legend(loc='best', fontsize=12, numpoints=1) ax2.set_xlim(ax.get_xlim()) ax2.set_xticks(plot_lookback_times) ax2.set_xticklabels(plot_redshifts) ax2.set_xlabel('Redshift') ax2.grid(False) plt.savefig(figname) plt.close() # # Plot total number of galaxies in compact groups vs. redshift # figname = os.path.join(plotsdir, '{0}_num_members.eps'.format(plotlabel)) num_galaxies = np.array([[len(df) for df in non_dwarf_members[result_ind]] for result_ind in range(len(resultsdirs))]) fig = plt.figure() ax = fig.add_subplot(111) ax2 = ax.twiny() for ind, (num_galaxy, num_galaxy_std) in enumerate( zip(num_galaxies, num_non_dwarf_members_std)): ax.plot(lbtimes, num_galaxy, color=colors[ind], marker=symbols[ind], label=labels[ind]) ax.fill_between(lbtimes, num_galaxy - num_galaxy_std, num_galaxy + num_galaxy_std, facecolor=colors[ind], edgecolor='none', alpha=0.6) ax.set_xlabel('Lookback Time (Gyr)') ax.set_ylabel('Number of non-dwarf Compact Group Members') ax.set_yscale('log') ax.legend(loc='best', fontsize=12, numpoints=1) ax.set_xlim(0, WMAP7.age(0).to('Gyr').value) ax.set_ylim(1.e3, 5.e5) ax2.set_xlim(ax.get_xlim()) ax2.set_xticks(plot_lookback_times) ax2.set_xticklabels(plot_redshifts) ax2.set_xlabel('Redshift') ax2.grid(False) plt.savefig(figname) plt.close() # # Plot fractional number of galaxies in compact groups vs. redshift # figname = os.path.join(plotsdir, '{0}_frac_galaxies.eps'.format(plotlabel)) frac_galaxies = np.array([[ len(df) / galaxy_counts['num_galaxies'][snapnum] for snapnum, df in enumerate(non_dwarf_members[result_ind]) ] for result_ind in range(len(resultsdirs))]) frac_galaxies_std = frac_galaxies * np.sqrt( np.array([[(num_galaxy_std / len(df))**2. + (galaxy_counts['std_galaxies'][snapnum] / galaxy_counts['num_galaxies'][snapnum])**2. for snapnum, (df, num_galaxy_std) in enumerate( zip(non_dwarf_members[result_ind], num_non_dwarf_members_std[result_ind]))] for result_ind in range(len(resultsdirs))])) fig = plt.figure() ax = fig.add_subplot(111) ax2 = ax.twiny() for ind, (frac_galaxy, frac_galaxy_std) in enumerate( zip(frac_galaxies, frac_galaxies_std)): ax.plot(lbtimes, 100. * frac_galaxy, color=colors[ind], marker=symbols[ind], label=labels[ind]) ax.fill_between(lbtimes, 100. * (frac_galaxy - frac_galaxy_std), 100. * (frac_galaxy + frac_galaxy_std), facecolor=colors[ind], edgecolor='none', alpha=0.6) ax.set_xlabel('Lookback Time (Gyr)') ax.set_ylabel('Percent of non-dwarf Galaxies in Compact Groups') #ax.set_yscale('log') ax.legend(loc='best', fontsize=12, numpoints=1) ax.set_xlim(0, WMAP7.age(0).to('Gyr').value) ax.set_ylim(0., 1.5) ax2.set_xlim(ax.get_xlim()) ax2.set_xticks(plot_lookback_times) ax2.set_xticklabels(plot_redshifts) ax2.set_xlabel('Redshift') ax2.grid(False) plt.savefig(figname) plt.close() return # # Now with redshift # # # Plot total number of compact groups vs. redshift # num_cgs = [len(df) for df in groups] fig = plt.figure() ax = fig.add_subplot(111) ax2 = ax.twiny() ax.plot(redshifts, num_cgs, 'k-') ax.plot(redshifts, num_cgs, 'ko') ax.set_xlabel('Redshift') ax.set_ylabel('Number of Compact Groups') ax.set_yscale('log') ax.set_xlim(0, 12) ax.set_ylim(1.e2, 1.e5) ax2.set_xlim(ax.get_xlim()) ax2.set_xticks(np.arange(13)) ax2.set_xticklabels(WMAP7.lookback_time(np.arange(13)).value) ax2.set_xlabel('Lookback time (Gyr)') ax2.grid(False) plt.savefig('num_groups_z.eps') plt.close() # # Plot total number of galaxies in compact groups vs. redshift # num_galaxies = [len(df) for df in non_dwarf_members] fig = plt.figure() ax = fig.add_subplot(111) ax2 = ax.twiny() ax.plot(redshifts, num_galaxies, 'k-') ax.plot(redshifts, num_galaxies, 'ko') ax.set_xlabel('Redshift') ax.set_ylabel('Number of non-dwarf Compact Group Members') ax.set_yscale('log') ax.set_xlim(0, 12) ax.set_ylim(1.e2, 1.e5) ax2.set_xlim(ax.get_xlim()) ax2.set_xticks(np.arange(13)) ax2.set_xticklabels(WMAP7.lookback_time(np.arange(13)).value) ax2.set_xlabel('Lookback time (Gyr)') ax2.grid(False) plt.savefig('num_members_z.eps') plt.close() # # Plot fractional number of galaxies in compact groups vs. redshift # frac_galaxies = [ len(df) / galaxy_counts['num_galaxies'][snapnum] for snapnum, df in enumerate(non_dwarf_members) ] fig = plt.figure() ax = fig.add_subplot(111) ax2 = ax.twiny() ax.plot(redshifts, frac_galaxies, 'k-') ax.plot(redshifts, frac_galaxies, 'ko') ax.set_xlabel('Redshift') ax.set_ylabel('Fracion of non-dwarf Galaxies in Compact Groups') ax.set_xlim(0, 12) ax.set_ylim(1.e-4, 1.e-2) ax2.set_xlim(ax.get_xlim()) ax2.set_xticks(np.arange(13)) ax2.set_xticklabels(WMAP7.lookback_time(np.arange(13)).value) ax2.set_xlabel('Lookback time (Gyr)') ax2.grid(False) plt.savefig('frac_galaxies_z.eps') plt.close() return
simlist.append(sim) simlist.append('vl2') slopes, b, Mvir, c, apeak, error, mass_change, Mpeak, Vmax = [[] for i in range(9) ] for sim in simlist: if sim == 'vl2': halos, subs = load_vl2(scale=1.0, processed=True) subs = subs[subs.Vmax > 8] else: halos, subs = load_elvis(sim=sim, processed=True) # subs = subs[subs.nadler2018 > 0.5] pot = subs.pot_mltr bind = -pot - 0.5 * (subs.v_r**2 + subs.v_t**2) infall = WMAP7.lookback_time(1 / subs.a_acc - 1).value infallcut = infall > 2 bindcut = bind > 0 bind_ = bind[infallcut & bindcut] infall_ = infall[infallcut & bindcut] # linear regression slope, intercept, r_value = linregress(infall_, np.log10(bind_))[:3] pred = intercept + slope * infall_ # save the params slopes.append(slope) error.append(MSE(np.log10(bind_), pred)) b.append(intercept) if sim == 'vl2': Mvir.append(1.93596e+12)
if sim[0] == 'i': simlist.append(sim) # grab ALL subhalos that are desired r, v_r, v_t, a_acc = [np.array([]) for i in range(4)] for sim in simlist: subs = pd.read_pickle('derived_props/'+sim) r = np.append(r, subs.r.values) v_r = np.append(v_r, subs.v_r.values) v_t = np.append(v_t, subs.v_t.values) a_acc = np.append(a_acc, subs.a_acc.values) dict = {'r': r, 'v_r': v_r, 'v_t': v_t, 'a_acc': a_acc} subs = pd.DataFrame(dict) # generate PDFs for each satellite for name, sat in sats.iterrows(): rconstraint = (sat.r_lower < subs.r) & (subs.r < sat.r_upper) vconstraint = (subs.v_r < sat.v_r_upper) & (sat.v_r_lower < subs.v_r) subset = subs[rconstraint & vconstraint] subset2 = subset[(sat.v_t_lower < subset.v_t) & (subset.v_t < sat.v_t_upper)] if len(subset) == 0 or len(subset2) == 0: continue plt.hist(WMAP7.lookback_time(1/subset.a_acc - 1).value) plt.hist(WMAP7.lookback_time(1/subset2.a_acc - 1).value) plt.title(name) plt.xlabel('Infall Time [Gyr]') plt.savefig('figures/infall_pdfs/'+name+'.png',bbox_inches='tight') plt.close()
bind, z, r, v_r = [np.array([]) for i in range(4)] for sim in list_of_sims('elvis'): if sim[0] != 'i' or 'HiRes' in sim: continue try: halos, subs = load_elvis(sim=sim, processed=True) subs = subs[subs.nadler2018 > 0.5] pot = subs.pot_mltr except AttributeError: print(sim + " not included") continue bind_sim = -pot - 0.5 * (subs.v_r.values**2 + subs.v_t.values**2) bind = np.append(bind, bind_sim) z = np.append(z, WMAP7.lookback_time(1 / subs.a_acc.values - 1)) r = np.append(r, subs.r) v_r = np.append(v_r, subs.v_r) """ plt.scatter(WMAP7.lookback_time(1/subs.a_acc.values - 1)[bind_sim>0], np.log10(bind_sim[bind_sim>0]), s=2.0, c=subs.r[bind_sim>0], cmap='plasma', vmin=0.0, vmax=max_r) plt.colorbar().set_label(r'Galactocentric Radius [$kpc$]') plt.xlim(0.0, WMAP7.lookback_time(np.inf).value) plt.ylim(3.4,5.2) plt.yticks([3.5,4.0,4.5,5.0]) plt.xlabel(r'Infall time [$Gyr$]') plt.ylabel(r'log(Binding Energy) [$km^2\ s^{-2}$]'); plt.savefig('figures/eachvolume/rocha_fig1_'+sim+'.png', bbox_inches='tight') plt.close() plt.scatter(subs.r[bind_sim>0], subs.v_r[bind_sim>0], s=2.0, c=WMAP7.lookback_time(1/subs.a_acc.values - 1)[bind_sim>0], cmap='plasma') plt.colorbar().set_label(r'Infall time [$Gyr$]')
F.DLA = d.zabs, 10**d.NH2 / (10**d.NHI + 2*10**d.NH2) pl.rc('font', size=14) #pl.rc('legend', fontsize=12) fig = pl.figure(figsize=(3.5, 3.7)) fig.subplots_adjust(top=0.88, right=0.97, left=0.165, bottom=0.12) ax = pl.gca() fvals = np.array(list(np.log10(F.MWplane[1])) + list(np.log10(F.SMC[1])) + \ list(np.log10(F.LMC[1]))) f0,f1,f2 = np.percentile(fvals[fvals > -20], [10,50, 90]) ax.plot(0, f1, 'r^', ms=8, mew=0, label='$\mathrm{Local\ group}$',) ax.errorbar(0, f1, yerr=np.transpose([(f1-f0, f2-f1)]), ecolor='r', capsize=3, mew=1, fmt=None) ax.plot(WMAP7.lookback_time(F.DLA[0]),np.log10(F.DLA[1]), 'ok', ms=5, mfc='none', mew=0.5, label='$z>1.5\ \ \mathrm{DLA/sub\,DLA}$') x = WMAP7.lookback_time(F.C[0]) y = np.log10(F.C[1]) ax.scatter(x,y, marker='o', c='k',s=70, zorder=10,linewidths=0.5,label='$\mathrm{This\ paper}$') plot([x,x], [y-0.36, y+0.36], 'k') ax.set_xlabel('$\mathrm{Lookback\ time\ (Gyr)}$') ax.set_ylabel('$\log_{10}\ f_{\mathrm{H}_2}$') ax.set_xlim(-0.9, 13.5) ax.set_ylim(-8.99, 0.49) leg = ax.legend(loc='lower left', frameon=0, scatterpoints=1) leg.get_frame().set_lw(0.5) ax1 = pl.twiny(ax)