Commit f4f8275d authored by Médéric Boquien's avatar Médéric Boquien
Browse files

Allow pcigale to run without stellar populations so we can carry out SED...

Allow pcigale to run without stellar populations so we can carry out SED modelling of dust only for instance.
parent 8c85aeba
......@@ -337,8 +337,9 @@ class PdfAnalysis(AnalysisModule):
model_variables[:, :, index] *= normalisation_factors
# We also add the galaxy mass to the analysed variables
analysed_variables.insert(0, "galaxy_mass")
model_variables = np.dstack((normalisation_factors, model_variables))
if any(module in creation_modules for module in ('bc03', 'm2005')):
analysed_variables.insert(0, "galaxy_mass")
model_variables = np.dstack((normalisation_factors, model_variables))
##################################################################
# Variable analysis #
......@@ -411,12 +412,13 @@ class PdfAnalysis(AnalysisModule):
reduced_chi_squares[best_model_index, range(len(best_model_index))],
name="reduced_chi_square"
))
best_model_table.add_column(Column(
normalisation_factors[best_model_index,
range(len(best_model_index))],
name="galaxy_mass",
unit="Msun"
))
if any(module in creation_modules for module in ('bc03', 'm2005')):
best_model_table.add_column(Column(
normalisation_factors[best_model_index,
range(len(best_model_index))],
name="galaxy_mass",
unit="Msun"
))
for index, name in enumerate(model_info_names):
column = Column([list(model_info[model_idx])[index] for model_idx
......
......@@ -77,7 +77,7 @@ def gen_compute_fluxes_at_redshift(sed, filters, redshifting_module,
except AttributeError:
age_at_redshift = cosmology.age(redshift) * 1000
if sed.info["age"] > age_at_redshift:
if "age" in sed.info.keys() and sed.info["age"] > age_at_redshift:
cache[redshift] = -99 * np.ones(len(filters))
else:
......
......@@ -95,7 +95,9 @@ class Casey2012(CreationModule):
sed : pcigale.sed.SED object
"""
luminosity = sed.info['attenuation.total']
if 'dust.luminosity' not in sed.info.keys():
sed.add_info('dust.luminosity', 1., True)
luminosity = 1.
sed.add_module(self.name, self.parameters)
sed.add_info("dust.temperature", self.parameters["temperature"])
......
......@@ -79,7 +79,9 @@ class Dale2014(CreationModule):
parameters : dictionary containing the parameters
"""
luminosity = sed.info['attenuation.total']
if 'dust.luminosity' not in sed.info.keys():
sed.add_info('dust.luminosity', 1., True)
luminosity = 1.
frac_agn = self.parameters["fracAGN"]
......
......@@ -61,7 +61,9 @@ class DH2002(CreationModule):
"""
alpha = float(self.parameters["alpha"])
luminosity = sed.info['attenuation.total']
if 'dust.luminosity' not in sed.info.keys():
sed.add_info('dust.luminosity', 1., True)
luminosity = 1.
ir_template = self.dh2002.get_template(alpha)
......
......@@ -96,7 +96,9 @@ class DL2007(CreationModule):
parameters : dictionary containing the parameters
"""
luminosity = sed.info['attenuation.total']
if 'dust.luminosity' not in sed.info.keys():
sed.add_info('dust.luminosity', 1., True)
luminosity = 1.
sed.add_module(self.name, self.parameters)
sed.add_info('dust.qpah', self.parameters["qpah"])
......
......@@ -294,7 +294,7 @@ class CalzLeit(CreationModule):
attenuation_spectrum)
# Total attenuation
sed.add_info("attenuation.total", attenuation_total, True)
sed.add_info("dust.luminosity", attenuation_total, True)
# Fλ fluxes (only from continuum) in each filter after attenuation.
flux_att = {}
......
......@@ -219,7 +219,7 @@ class PowerLawAtt(CreationModule):
attenuation_spectrum)
# Total attenuation
sed.add_info("attenuation.total", attenuation_total, True)
sed.add_info("dust.luminosity", attenuation_total, True)
# Fλ fluxes (only in continuum) in each filter after attenuation.
flux_att = {}
......
......@@ -6,7 +6,7 @@
from astropy.io.votable.tree import VOTableFile, Resource, Table, Field, Info
def save_sed_to_vo(sed, filename, mass=1.):
def save_sed_to_vo(sed, filename, norm=1.):
"""
Save a SED object to a VO-Table file
......@@ -16,8 +16,8 @@ def save_sed_to_vo(sed, filename, mass=1.):
The SED to save.
filename : string
Name of the file to save the SED to.
mass : float
Mass of the galaxy in solar mass.
norm : float
Normalisation factor of the SED
"""
votable = VOTableFile()
......@@ -36,7 +36,7 @@ def save_sed_to_vo(sed, filename, mass=1.):
])
fnu_table.create_arrays(len(sed.wavelength_grid))
fnu_table.array["wavelength"] = sed.wavelength_grid
fnu_table.array["F_nu"] = mass * sed.fnu
fnu_table.array["F_nu"] = norm * sed.fnu
# F_lambda contributions and total
flambda_table = Table(votable, name="Flambda", id="Flambda")
......@@ -52,31 +52,35 @@ def save_sed_to_vo(sed, filename, mass=1.):
flambda_table.fields.extend(flambda_fields)
flambda_table.create_arrays(len(sed.wavelength_grid))
flambda_table.array["wavelength"] = sed.wavelength_grid
flambda_table.array["F_lambda_total"] = mass * sed.luminosity
flambda_table.array["F_lambda_total"] = norm * sed.luminosity
for name in sed.contribution_names:
flambda_table.array[name] = mass * sed.get_lumin_contribution(name)
flambda_table.array[name] = norm * sed.get_lumin_contribution(name)
# SFH
sfh_resource = Resource(id="Star_Formation_History")
votable.resources.append(sfh_resource)
sfh_table = Table(votable, name="SFH", id="SFH")
sfh_resource.tables.append(sfh_table)
sfh_table.fields.extend([
Field(votable, name="time", datatype="double", unit="Myr",
ucd="time.age"),
Field(votable, name="SFR", datatype="double", unit="Msun/yr",
ucd="phys.SFR")
])
sfh_table.create_arrays(len(sed.sfh[0]))
sfh_table.array["time"] = sed.sfh[0]
sfh_table.array["SFR"] = mass * sed.sfh[1]
if sed.sfh is not None:
sfh_resource = Resource(id="Star_Formation_History")
votable.resources.append(sfh_resource)
sfh_table = Table(votable, name="SFH", id="SFH")
sfh_resource.tables.append(sfh_table)
sfh_table.fields.extend([
Field(votable, name="time", datatype="double", unit="Myr",
ucd="time.age"),
Field(votable, name="SFR", datatype="double", unit="Msun/yr",
ucd="phys.SFR")
])
sfh_table.create_arrays(len(sed.sfh[0]))
sfh_table.array["time"] = sed.sfh[0]
sfh_table.array["SFR"] = norm * sed.sfh[1]
# SED information to keywords
votable.infos.append(Info(name="Galaxy mass in Msun", value=mass))
if sed.sfh is not None:
# If there is a stellar population then the norm factor is the stellar
# mass.
votable.infos.append(Info(name="Galaxy mass in Msun", value=norm))
votable.infos.append(Info(name="Redshift", value=sed.redshift))
for name, value in sed.info.items():
if name in sed.mass_proportional_info:
votable.infos.append(Info(name=name, value=mass * value))
votable.infos.append(Info(name=name, value=norm * value))
else:
votable.infos.append(Info(name=name, value=value))
......
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