from ramses_pp.modules import Simulation sim = Simulation.load("grid_n08_halo_1") #sim.run_ahf() #sim.run_ahf_merger() #sim.run_ahf_tracker(snaptime=125,halos=[1]) sim.run_ahf_tracker() # in this case, run the tracker on all halos
arr = np.zeros(len(data['particle_mass'])) return arr == 0.0 def setup_ds(ds): #Return only dark matter particles, and assert that the filter holds print 'Here' assert (ds.add_particle_filter("dark_matter")) #from yt.data_objects.particle_filters import add_particle_filter #add_particle_filter("dark_matter", function=dark_matter, filtered_type='all', requires=["page"]) #Load the simulation simname = sys.argv[1] sim = Simulation.load(simname) #cd to the simulation directory print 'Changing directory to: %s' % sim.path() os.chdir(sim.path()) #Check if a rockstar/ directory exists. If it doesn't, make it if not os.path.exists('%s/rockstar/' % sim.path()): os.mkdir('%s/rockstar/' % sim.path()) #cd to rockstar/ os.chdir('rockstar/') print 'In dir: %s' % os.getcwd() print 'Starting rockstar...' outputs = np.arange(1, sim.num_snapshots() + 1) dirs = []
#!/usr/bin/env python from ramses_pp.modules import Simulation import sys sim = Simulation.load(sys.argv[1]) snap = sim.snapshot(int(sys.argv[2])) halos = snap.halos() for halo in halos: print halo.sphere()
def lazy_load_galaxy(sim_name, sim_patch="normal", snap_no=None, halo_id=None, return_snap=True, return_halos=True, filter_stars=True, filter_dark=True, disk_h=10, disk_w=50, disk_units="kpccm"): """ reads in the simulation and returns the galaxy, halo_sphere the ytsnapshot and the snap object since you find yourself doing this a lot, I figured it would make sense as a function in it'w own right """ sim = Simulation.load(sim_name) # super lazy mode activated if snap_no == None: snap = sim.snapshot(sim.num_snapshots(), module="yt", patch=sim_patch) else: snap = sim.snapshot(snap_no, module="yt", patch=sim_patch) if halo_id == None: halo_id = 0 ytsnap = snap.raw_snapshot() all_data = ytsnap.all_data() halos = snap.halos() print halos print halos[0]["pos"], halos[0]["Rvir"] galaxy_halo = halos[halo_id] print galaxy_halo print "getting halo sphere" halo_sphere = ytsnap.sphere(galaxy_halo["pos"], galaxy_halo["Rvir"]) add_particle_filter("stars", function=star_filter, filtered_type="all", requires=["particle_age"]) halo_sphere.ds.add_particle_filter("stars") add_particle_filter("dark", function=dark_filter, filtered_type="all", requires=["particle_age"]) halo_sphere.ds.add_particle_filter("dark") disk_height = ytsnap.arr(disk_h, disk_units) disk_width = ytsnap.arr(disk_w, disk_units) cylinder, disks = load_disk_data(snap, sim_name, sim_patch, halo_id=halo_id, snapno=None, n_disks=1, disk_h=disk_height, disk_w=disk_width, cylinder_w=disk_width, cylinder_h=disk_height, extra=None, overwrite=True, save=False, center=None, normal=None) add_particle_filter("stars", function=star_filter, filtered_type="all", requires=["particle_age"]) cylinder.ds.add_particle_filter("stars") add_particle_filter("dark", function=dark_filter, filtered_type="all", requires=["particle_age"]) cylinder.ds.add_particle_filter("dark") return cylinder, halo_sphere, ytsnap, snap
def main(name, z): fig, ax0 = plt.subplots(nrows=1, sharex=True) plt.xlabel(r'Lookback Time [Gyr]') plt.ylabel(r'Star Formation Rate [M$_{\odot}$/yr]') sim = Simulation.load(name) idx = sim.redshift(z) snapshot = sim.snapshot(idx) pf = snapshot.raw_snapshot() z = pf.current_redshift aexp = 1 / (1 + z) cosmology = snapshot.cosmology() h0 = cosmology['h'] * 100 friedman = snapshot.integrate_friedman(store=True) print friedman age_simu = friedman['age_simu'] time_simu = friedman['time_simu'] halos = snapshot.halos() sorted_halos = sorted(halos, key=lambda x: x.total_mass(), reverse=True) for i in range(0, 8): halo = sorted_halos[i**3] try: sphere = halo.get_sphere() ct = sphere.particles.source['particle_age'] stars = (ct != 0) gas_mass, particle_mass = sphere.quantities["TotalQuantity"]( ["CellMassMsun", "ParticleMassMsun"]) total_mass = gas_mass + particle_mass ct_stars = ct[stars] age = snapshot.tform(ct_stars) # Gyr s = sim.snapshot(idx, module='pynbody').raw_snapshot() mass = sphere.particles.source['ParticleMassMsun'][stars] print 'Total stellar mass %e' % np.sum(mass) print 'Total halo mass %e' % total_mass print 'Min age = %f, Max age = %f, Mean age = %f' % ( min(age), max(age), np.mean(age)) sfh, sfhtimes = find_sfh(ax0, age, mass, total_mass, bins=50) print 'Min SFR = %f, Max SFR = %f' % (min(sfh), max(sfh)) #plt.xlim(0, age_simu) if i == 0: make_twin(s, ax0, age_simu - sfhtimes, age_simu - age) #plt.semilogx(sfhtimes, sfh) except yt.utilities.exceptions.YTSphereTooSmall as e: print 'Sphere too small: ', e except ValueError as ve: print 'ValueError: ', ve #t = plt.title(r'Star Formation Rate. z=%10.5f, M$_{H}$=%e'%(z, total_mass)) #t.set_y(1.09) box = ax0.get_position() ax0.set_position( [box.x0, box.y0 + box.height * 0.1, box.width, box.height * 0.9]) # Put a legend below current axis ax0.legend(loc='upper center', bbox_to_anchor=(0.5, -0.12), fancybox=True, shadow=True, ncol=5, prop={'size': 7.5}) #plt.ylim(0, 0.2) #plt.semilogy() plt.savefig('%s_sfr_%05d.png' % (name, idx))
import numpy as np from ramses_pp.fortran import test from ramses_pp.modules import Simulation sim = Simulation.load('4Mpc_aton_256') snapshot = sim.snapshot(215) cosmo = snapshot.cosmology() omega_m_0 = cosmo['omega_m_0'] omega_l_0 = cosmo['omega_l_0'] omega_k_0 = cosmo['omega_k_0'] aexp = cosmo['aexp'] h0 = cosmo['h'] * 100 alpha = 1e-6 axpmin = 1e-3 ntable = 1000 age_tot = 0 axp_out, hexp_out, tau_out, t_out, age_tot = test.friedman( omega_m_0, omega_l_0, omega_k_0, alpha, axpmin, ntable) print age_tot #Find neighbouring expansion factor i = 1 while ((axp_out[i] > aexp) and (i < ntable)): i += 1 #Interpolate time time_simu = t_out[i] * (aexp - axp_out[i-1])/(axp_out[i]-axp_out[i-1]) + \