@@ -76,6 +76,7 @@ def __dict__(self, name):
76
76
def tab_z (self ):
77
77
if not hasattr (self , '_tab_z' ):
78
78
h = self ._gen_halo_histories ()
79
+ self ._tab_z = h ['z' ]
79
80
return self ._tab_z
80
81
81
82
@tab_z .setter
@@ -89,16 +90,6 @@ def tab_t(self):
89
90
self ._tab_t = self .cosm .t_of_z (self .tab_z ) / s_per_yr
90
91
return self ._tab_t
91
92
92
- @property
93
- def tab_dz (self ):
94
- if not hasattr (self , '_tab_dz' ):
95
- dz = np .diff (self .tab_z )
96
- if np .allclose (np .diff (dz ), 0 ):
97
- dz = dz [0 ]
98
- self ._tab_dz = dz
99
-
100
- return self ._tab_dz
101
-
102
93
@property
103
94
def _b14 (self ):
104
95
if not hasattr (self , '_b14_' ):
@@ -132,7 +123,7 @@ def _roman(self): # pragma: no cover
132
123
def run (self ):
133
124
return
134
125
135
- def cSFRD (self , z , Mh ):
126
+ def get_sfrd_in_mass_range (self , z , Mlo , Mhi = None ):
136
127
"""
137
128
Compute cumulative SFRD as a function of lower-mass bound.
138
129
@@ -141,26 +132,23 @@ def cSFRD(self, z, Mh):
141
132
Cumulative *FRACTION* of SFRD in halos above Mh.
142
133
"""
143
134
144
- if type (Mh ) not in [list , np .ndarray ]:
145
- Mh = np .array ([Mh ])
146
-
147
135
iz = np .argmin (np .abs (z - self .histories ['z' ]))
148
136
_Mh = self .histories ['Mh' ][:,iz ]
149
137
_sfr = self .histories ['SFR' ][:,iz ]
150
138
_w = self .histories ['nh' ][:,iz ]
151
139
152
- # Really this is the number of galaxies that formed in a given
153
- # differential redshift slice.
154
- SFRD = np .zeros_like (Mh )
155
- for i , _mass in enumerate (Mh ):
156
- ok = _Mh >= _mass
157
- SFRD [i ] = np .sum (_sfr [ok == 1 ] * _w [ok == 1 ]) / rhodot_cgs
140
+ if Mhi is None :
141
+ Mhi = _Mh .max ()
158
142
159
- SFRD_tot = self .SFRD (z )
143
+ ok = np .logical_and (_Mh >= Mlo , _Mh <= Mhi )
144
+ SFRD = np .sum (_sfr [ok == 1 ] * _w [ok == 1 ]) / rhodot_cgs
160
145
161
- return SFRD / SFRD_tot
146
+ return SFRD
162
147
163
148
def SFRD (self , z , Mmin = None ):
149
+ return self .get_sfrd (z , Mmin = Mmin )
150
+
151
+ def get_sfrd (self , z , Mmin = None ):
164
152
"""
165
153
Will convert to internal cgs units.
166
154
"""
@@ -241,11 +229,11 @@ def tile(self, arr, thin, renorm=False):
241
229
else :
242
230
return new
243
231
244
- def noise_normal (self , arr , sigma ):
232
+ def get_noise_normal (self , arr , sigma ):
245
233
noise = np .random .normal (scale = sigma , size = arr .size )
246
234
return np .reshape (noise , arr .shape )
247
235
248
- def noise_lognormal (self , arr , sigma ):
236
+ def get_noise_lognormal (self , arr , sigma ):
249
237
lognoise = np .random .normal (scale = sigma , size = arr .size )
250
238
#noise = 10**(np.log10(arr) + np.reshape(lognoise, arr.shape)) - arr
251
239
noise = np .power (10 , np .log10 (arr ) + np .reshape (lognoise , arr .shape )) \
@@ -409,11 +397,11 @@ def _gen_halo_histories(self):
409
397
# Two potential kinds of scatter in MAR
410
398
mar = self .tile (mar_raw , thin )
411
399
if sigma_env > 0 :
412
- mar *= (1. + self .noise_normal (mar , sigma_env ))
400
+ mar *= (1. + self .get_noise_normal (mar , sigma_env ))
413
401
414
402
if sigma_mar > 0 :
415
403
np .random .seed (self .pf ['pop_scatter_mar_seed' ])
416
- noise = self .noise_lognormal (mar , sigma_mar )
404
+ noise = self .get_noise_lognormal (mar , sigma_mar )
417
405
mar += noise
418
406
# Normalize by mean of log-normal to preserve mean MAR?
419
407
mar /= np .exp (0.5 * sigma_mar ** 2 )
@@ -668,18 +656,23 @@ def _TabulateEmissivity(self, E=None, Emin=None, Emax=None, wave=None):
668
656
669
657
return zarr , tab / cm_per_mpc ** 3
670
658
671
- def Emissivity (self , z , E = None , Emin = None , Emax = None ):
659
+ def get_emissivity (self , z , E = None , Emin = None , Emax = None ):
672
660
"""
673
661
Compute the emissivity of this population as a function of redshift
674
- and rest-frame photon energy [eV].
662
+ and (potentially) rest-frame photon energy [eV].
663
+
664
+ .. note :: If Emin and Emax are supplied, this is a luminosity density,
665
+ and will have units of erg/s/(co-moving cm)^3. If `E` is supplied,
666
+ will also carry units of eV^-1.
675
667
676
668
Parameters
677
669
----------
678
670
z : int, float
671
+ Redshift.
679
672
680
673
Returns
681
674
-------
682
- Emissivity in units of erg / s / c-cm**3 [/ eV]
675
+ Emissivity in units of erg / s / c-cm**3 [/ eV].
683
676
684
677
"""
685
678
@@ -707,9 +700,9 @@ def Emissivity(self, z, E=None, Emin=None, Emax=None):
707
700
return 10 ** func (z )
708
701
#return self._cache_ehat_[(E, Emin, Emax)](z)
709
702
710
- def PhotonLuminosityDensity (self , z , E = None , Emin = None , Emax = None ):
703
+ def get_photon_density (self , z , E = None , Emin = None , Emax = None ):
711
704
# erg / s / cm**3
712
- rhoL = self .Emissivity (z , E = E , Emin = Emin , Emax = Emax )
705
+ rhoL = self .get_emissivity (z , E = E , Emin = Emin , Emax = Emax )
713
706
erg_per_phot = self ._get_energy_per_photon (Emin , Emax ) * erg_per_ev
714
707
715
708
return rhoL / np .mean (erg_per_phot )
@@ -1243,7 +1236,7 @@ def _gen_prescribed_galaxy_histories(self, zstop=0):
1243
1236
noise = np .zeros_like (Sd )
1244
1237
np .random .seed (self .pf ['pop_dust_scatter_seed' ])
1245
1238
for _i , _z in enumerate (z ):
1246
- noise [:,_i ] = self .noise_lognormal (Sd [:,_i ], sigma [:,_i ])
1239
+ noise [:,_i ] = self .get_noise_lognormal (Sd [:,_i ], sigma [:,_i ])
1247
1240
1248
1241
Sd += noise
1249
1242
@@ -1578,32 +1571,6 @@ def _gen_active_galaxy_histories(self):
1578
1571
1579
1572
return results
1580
1573
1581
-
1582
- def Slice (self , z , slc ):
1583
- """
1584
- slice format = {'field': (lo, hi)}
1585
- """
1586
-
1587
- iz = np .argmin (np .abs (z - self .tab_z ))
1588
- hist = self .histories
1589
-
1590
- c = np .ones (hist ['Mh' ].shape [0 ], dtype = int )
1591
- for key in slc :
1592
- lo , hi = slc [key ]
1593
-
1594
- ok = np .logical_and (hist [key ][:,iz ] >= lo , hist [key ][:,iz ] <= hi )
1595
- c *= ok
1596
-
1597
- # Build output
1598
- to_return = {}
1599
- for key in self .histories :
1600
- if self .histories [key ].ndim == 1 :
1601
- to_return [key ] = self .histories [key ][c == 1 ]
1602
- else :
1603
- to_return [key ] = self .histories [key ][c == 1 ,iz ]
1604
-
1605
- return to_return
1606
-
1607
1574
def get_field (self , z , field ):
1608
1575
iz = np .argmin (np .abs (z - self .histories ['z' ]))
1609
1576
return self .histories [field ][:,iz ]
0 commit comments