Advertisement
Guest User

Untitled

a guest
Jul 25th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.50 KB | None | 0 0
  1. import numpy as np
  2. from halotools.empirical_models import PrebuiltSubhaloModelFactory
  3. model = PrebuiltSubhaloModelFactory('smhm_binary_sfr')
  4. from halotools.sim_manager import CachedHaloCatalog
  5. halocat = CachedHaloCatalog(simname = 'zheng07', redshift = 0, halo_finder = 'rockstar')
  6. model.populate_mock(halocat)
  7.  
  8. sample_mask = model.mock.galaxy_table['stellar_mass'] > 1e10
  9. gals = model.mock.galaxy_table[sample_mask]
  10.  
  11. #Compute total stellar mass
  12. from halotools.utils import group_member_generator
  13. gals.sort('halo_hostid')
  14. grouping_key = 'halo_hostid'
  15. requested_columns = ['stellar_mass']
  16. group_gen = group_member_generator(gals, grouping_key, requested_columns)
  17.  
  18. total_stellar_mass = np.zeros(len(gals))
  19. for first, last, member_props in group_gen:
  20.     stellar_mass_of_members = member_props[0]
  21.     total_stellar_mass[first:last] = sum(stellar_mass_of_members)
  22.  
  23. gals['halo_total_stellar_mass'] = total_stellar_mass
  24.  
  25. #Compute host halo mass
  26. gals.sort(['halo_hostid', 'halo_upid'])
  27. grouping_key = 'halo_hostid'
  28. requested_columns = ['halo_mvir']
  29. group_gen = group_member_generator(gals, grouping_key, requested_columns)
  30.  
  31. host_mass = np.zeros(len(gals))
  32. for first, last, member_props in group_gen:
  33.     mvir_members = member_props[0]
  34.     mvir_host = mvir_members[0]
  35.     host_mass[first:last] = mvir_host
  36.  
  37. gals['halo_mhost'] = host_mass
  38.  
  39. #Compare total vs host mass and plot
  40. from halotools.mock_observables import mean_y_vs_x
  41.  
  42. bins = np.logspace(12, 15, 25)
  43. result = mean_y_vs_x(gals['halo_mhost'].data,
  44.                      gals['halo_total_stellar_mass'].data,
  45.                      bins = bins,
  46.                      error_estimator = 'variance')
  47.  
  48. host_mass, mean_stellar_mass, mean_stellar_mass_err = result
  49. print host_mass, mean_stellar_mass, mean_stellar_mass_err
  50.  
  51. from seaborn import plt
  52.  
  53. plt.errorbar(host_mass, mean_stellar_mass, yerr=mean_stellar_mass_err,
  54.              fmt = "none", ecolor='gray')
  55. plt.plot(host_mass, mean_stellar_mass, 'D', color='k')
  56.  
  57. plt.loglog()
  58. plt.xticks(size=18)
  59. plt.yticks(size=18)
  60. plt.xlabel(r'$M_{\rm halo}/M_{\odot}$', fontsize=25)
  61. plt.ylabel(r'$\langle M_{\ast}^{\rm tot}/M_{\odot}\rangle$', fontsize=25)
  62. plt.ylim(ymax=5e12)
  63.  
  64.  
  65. #Compute velocities
  66. from halotools import mock_observables
  67. x = halocat.halo_table['halo_x']
  68. y = halocat.halo_table['halo_y']
  69. z = halocat.halo_table['halo_z']
  70. sample = np.vstack((x,y,z)).T
  71. vx = halocat.halo_table['halo_vx']
  72. vy = halocat.halo_table['halo_vy']
  73. vz = halocat.halo_table['halo_vz']
  74. velocities = np.vstack((vx,vy,vz)).T
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement