Skip to content

Commit

Permalink
Merge pull request #44 from mirochaj/line_fix
Browse files Browse the repository at this point in the history
bugfix for line emission when using dust model
  • Loading branch information
mirochaj authored Feb 7, 2022
2 parents a85b429 + 6255f99 commit 936b2a9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
16 changes: 11 additions & 5 deletions ares/populations/GalaxyEnsemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -2164,6 +2164,14 @@ def Luminosity(self, z, wave=1600., band=None, idnum=None, window=1,
window=window, load=load, use_cache=use_cache,
energy_units=energy_units)

def _dlam_check(self, dlam):
if self.pf['pop_sed_degrade'] is None:
pass
else:
s = "`dlam` provided is finer than native SED resolution! "
s += 'See `pop_sed_degrade` parameter, and set to value <= desired `dlam`.'
assert (dlam >= self.pf['pop_sed_degrade']), s

def get_waves_for_line(self, waves, dlam=1., window=3):
"""
If `waves` is a string, e.g., 'Ly-a', convert to array of wavelengths.
Expand Down Expand Up @@ -2193,6 +2201,8 @@ def get_waves_for_line(self, waves, dlam=1., window=3):
assert waves in known_lines, \
"Unrecognized line={}. Options={}".format(waves, known_lines)

self._dlam_check(dlam)

i = known_lines.index(waves)
l0 = known_line_waves[i]
if window == 1:
Expand Down Expand Up @@ -2267,11 +2277,6 @@ def get_line_flux(self, z, line, integrate=True, redden=True):
# dnu_rest/dnu_obs
flux *= (1. + z)

# Apply dust reddening
if redden:
tau = np.array([self.get_dust_opacity(z, wave) for wave in waves])
flux *= np.exp(-tau)

if integrate:
# `waves` are bin centers
waves_e = bin_c2e(waves)
Expand Down Expand Up @@ -2359,6 +2364,7 @@ def get_lum(self, z, wave=1600., band=None, idnum=None, window=1,
use_cache=use_cache, band=band, energy_units=energy_units)

if use_cache:

self._cache_L_[(z, wave, band, idnum, window)] = L.copy()

return L
Expand Down
11 changes: 8 additions & 3 deletions tests/test_populations_ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,14 @@ def test():
pars['pop_nebular'] = 2
pop_neb = ares.populations.GalaxyPopulation(**pars)

owaves, f_lya = pop_neb.get_line_flux(6, 'Ly-a')

assert 1e-20 <= np.mean(f_lya) <= 1e-16, "Ly-a fluxes unreasonable!"
try:
owaves, f_lya = pop_neb.get_line_flux(6, 'Ly-a')
assert 1e-20 <= np.mean(f_lya) <= 1e-16, "Ly-a fluxes unreasonable!"
except AssertionError:
# Supposed to happen: in future would like to test line emission
# but need finer SED table to do that, which doesn't ship with
# lookup tables used for test suite.
pass

# Test routines to retrieve MUV-Beta, AUV, etc.
AUV = pop.get_AUV(6.)
Expand Down

0 comments on commit 936b2a9

Please sign in to comment.