Advertisement
Guest User

Star formation for Gadget

a guest
Oct 18th, 2015
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.55 KB | None | 0 0
  1. from pylab import *
  2. from scipy import integrate
  3. from yt.mods import *
  4. import yt.visualization.eps_writer as eps
  5. from yt.analysis_modules.star_analysis.api import StarFormationRate
  6.  
  7. #
  8. # Cosmology Stuff
  9. #
  10.  
  11. # Standard cosmology params
  12. # Comes from Planck 2015. Table 4  last column of:
  13. # http://arxiv.org/pdf/1502.01589v2.pdf
  14. Omega_m = 0.3089
  15. Omega_L = 0.6911
  16. H_0 = 67.74
  17. c = 3.0e5  # km/s
  18. h = H_0/100.
  19. Omega_r = 4.165e-5/(h*h)
  20.  
  21. # Calculate E(z)
  22. def E(z):
  23.     return sqrt(Omega_r*(1.0+z)**4+Omega_m*(1.0+z)**3+Omega_L)
  24.  
  25. # Get t from z(t)
  26. # Eq. 3 & 30 of http://arxiv.org/pdf/astro-ph/9905116v4.pdf
  27. # Return value in years
  28. def tl(z):
  29.     f = lambda x: 1.0/((1.0+x)*E(x))
  30.     return integrate.quad(f,z,inf,full_output=1)[0]*9.78e9/h/1.0e6
  31. vtl = vectorize(tl)                             # Vectorized version
  32.  
  33. #
  34. # YT Stuff
  35. #
  36.  
  37. # Load in Gadget snapshot
  38. ds = load('snapshot_024.hdf5')
  39. sp = ds.all_data()
  40.  
  41. # Get star masses in Msun
  42. mass = sp[('PartType4', 'Masses')].in_units('Msun')
  43.  
  44. #  Get creation time of each star particle in Myr
  45. act = sp[('PartType4','StellarFormationTime')]  # Gadget creation time in terms of a(t)
  46. zct = array(1.0/act - 1.0)                      # Convert a(t) to z(t)
  47. ct = vtl(zct)                                   # Convert z(t) to t in Myr
  48. ct = YTArray(ct,'Myr')                          # Assign to YTArray with proper units
  49.  
  50. # Get star formation rate with known masses and creation time
  51. sfr = StarFormationRate(ds, data_source=sp,star_mass=mass,star_creation_time=ct)
  52. sfr.write_out(name="StarFormationRate.out")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement