Commit 2f29f425 authored by Yannick Roehlly's avatar Yannick Roehlly
Browse files

Change how redshit and fluxes are managed

Now the redshift is an attribute of the SED.

The SED.compute_fnu() no longuer takes redshift and apply_redshift
arguments as the SED is supposed to be redshifted.

The SED.lambda_fnu() method was converted to the SED.fnu property
returning th Fν flux density at each wavelength of the wavelength grid.
parent 0c2ec58d
......@@ -239,8 +239,7 @@ class Psum(AnalysisModule):
# Theoretical fluxes
theor_fluxes = [red_sed.compute_fnu(transmission[name],
effective_wavelength[name],
obs_redshift)
effective_wavelength[name])
for name in filter_list]
reduced_chi2, galaxy_mass, probability = compute_chi2(
......@@ -305,16 +304,14 @@ class Psum(AnalysisModule):
# we develop a way to serialise the SED, we should save the
# complete SED object.
if save_best_sed:
best_sed_lambda_fnu = best_sed.lambda_fnu(
redshift=obs_table['redshift'][obs_index])
best_sed_table = atpy.Table()
best_sed_table.table_name = "Best SED"
best_sed_table.add_column("wavelength",
best_sed_lambda_fnu[0],
best_sed.wavelength_grid,
"nm")
best_sed_table.add_column("fnu",
best_norm_factor
* best_sed_lambda_fnu[1],
* best_sed.fnu,
"mJy")
best_sed_table.write(OUT_DIR + obs_name + 'bestSED.fits',
verbose=False)
......@@ -326,11 +323,9 @@ class Psum(AnalysisModule):
# Plot the best SED
if plot_best_sed:
best_sed_lambda_fnu = best_sed.lambda_fnu(
redshift=obs_table['redshift'][obs_index])
figure = plt.figure()
ax = figure.add_subplot(111)
plot_x, plot_y = best_sed_lambda_fnu
plot_x, plot_y = best_sed.wavelength_grid, best_sed.fnu
plot_mask = (
(plot_x >= PLOT_L_MIN * (1 + obs_redshift)) &
(plot_x <= PLOT_L_MAX * (1 + obs_redshift))
......
......@@ -133,10 +133,9 @@ class SaveFluxes(AnalysisModule):
row.append(value)
# Add the flux in each filter to the row
row += [sed.compute_fnu(filter.trans_table,
filter.effective_wavelength,
0)
for filter in filter_list]
row += [sed.compute_fnu(filter_.trans_table,
filter_.effective_wavelength)
for filter_ in filter_list]
out_rows.append(row)
......
......@@ -103,5 +103,7 @@ class IGMAtt(CreationModule):
igm_effect
)
sed.redshift = redshift
# CreationModule to be returned by get_module
Module = IGMAtt
......@@ -63,6 +63,7 @@ class SED(object):
"""
self.sfh = sfh
self.redshift = 0.
self.modules = []
self.wavelength_grid = None
self.contribution_names = []
......@@ -131,40 +132,21 @@ class SED(object):
else:
return self._luminosities.sum(0)
def lambda_fnu(self, redshift=0, apply_redshift=False):
"""
Return the (redshifted if asked) total Fν flux density vs wavelength
spectrum of the SED.
Parameters
----------
redshift : float, default = 0
If 0 (the default), the flux at 10 pc is computed.
apply_redshift : boolean, default = None
If true, the spectrum will be redshifted before computing the
flux. The default is False because we generally use a specific
module to apply the redshift.
Returns
-------
wavelength, f_nu : tuple of array of floats
The wavelength is in nm and the Fν is in mJy.
@property
def fnu(self):
"""Total Fν flux density of the SED
Return the total Fν density vector, i.e the total luminosity converted
to Fν flux in mJy.
"""
wavelength = self.wavelength_grid
luminosity = self.luminosity
if apply_redshift:
wavelength, luminosity = utils.redshift_spectrum(
wavelength, luminosity, redshift)
# Fλ flux density in W/m²/nm
f_lambda = utils.luminosity_to_flux(luminosity, redshift)
f_lambda = utils.luminosity_to_flux(self.luminosity, self.redshift)
# Fν flux density in Jy
f_nu = utils.lambda_flambda_to_fnu(wavelength, f_lambda)
# Fν flux density in mJy
f_nu = utils.lambda_flambda_to_fnu(self.wavelength_grid, f_lambda)
return wavelength, f_nu
return f_nu
def add_info(self, key, value, mass_proportional=False, force=False):
"""
......@@ -319,7 +301,6 @@ class SED(object):
return self.luminosities[idx]
def compute_fnu(self, transmission, lambda_eff,
redshift=0, apply_redshift=False,
add_line_fluxes=True):
"""
Compute the Fν flux density corresponding the filter which
......@@ -352,14 +333,6 @@ class SED(object):
lambda_eff : float
Effective wavelength of the filter in nm.
redshift : float
The redshift of the galaxy. If 0, the flux is computed at 10 pc.
apply_redshift : boolean
If true, the spectrum will be redshifted before computing the
flux. The default is False because we generally use a specific
module to apply the redshift.
add_line_flux : boolean
If true (default), the flux coming from the spectral lines will be
taken into account.
......@@ -376,9 +349,6 @@ class SED(object):
wavelength = self.wavelength_grid
l_lambda = self.luminosity
if apply_redshift:
wavelength, l_lambda = utils.redshift_lambda_l_lambda(
(wavelength, l_lambda), redshift)
# Test if the spectrum cover all the filter extend
if ((min(self.wavelength_grid) > lambda_min) or
......@@ -409,7 +379,7 @@ class SED(object):
f_lambda = utils.luminosity_to_flux(
(np.trapz(transmission_r * l_lambda_r, wavelength_r) /
np.trapz(transmission_r, wavelength_r)),
redshift
self.redshift
)
# Add the Fλ fluxes from the spectral lines.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment