Commit b9c8b782 authored by Médéric Boquien's avatar Médéric Boquien

Merge branch 'SSP' into SSP_mag

parents 55485070 3d4218fe
......@@ -459,9 +459,10 @@ def build_yggdrasil_ssp(base):
# Metallicities associated to each key
metallicities = ["0.004", "0.008", "0.02"]
fcovs = ["0", "0.5"]
for Z in metallicities:
filename = f"{yggdrasil_dir}Z={Z}_kroupa_IMF_fcov_0.5_SFR_inst_Spectra"
for Z, fcov in itertools.product(metallicities, fcovs):
filename = f"{yggdrasil_dir}Z={Z}_kroupa_IMF_fcov_{fcov}_SFR_inst_Spectra"
print(f"Importing {filename}...")
with open(filename) as f:
......@@ -487,8 +488,8 @@ def build_yggdrasil_ssp(base):
# Conversion from erg/s/Å/10⁶ Msun to W/nm/Msun
ssp_lumin *= 1e-7 * 10 * 1e-6
base.add_yggdrasil_ssp(Yggdrasil_SSP(float(Z), ssp_time, ssp_wave,
ssp_info, ssp_lumin))
base.add_yggdrasil_ssp(Yggdrasil_SSP(float(Z), float(fcov), ssp_time,
ssp_wave, ssp_info, ssp_lumin))
def build_dale2014(base):
models = []
......@@ -979,7 +980,11 @@ def build_base(bc03res='lr'):
print("\nDONE\n")
print('#' * 78)
print("11- Importing the Yggdrasil SSP")
build_yggdrasil_ssp(base)
print("\nDONE\n")
print('#' * 78)
base.session.close_all()
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -147,6 +147,7 @@ class _Yggdrasil_SSP(BASE):
__tablename__ = "yggdrasil_ssp"
metallicity = Column(Float, primary_key=True)
fcov = Column(Float, primary_key=True)
time_grid = Column(PickleType)
wavelength_grid = Column(PickleType)
info_table = Column(PickleType)
......@@ -154,6 +155,7 @@ class _Yggdrasil_SSP(BASE):
def __init__(self, ssp):
self.metallicity = ssp.metallicity
self.fcov = ssp.fcov
self.time_grid = ssp.time_grid
self.wavelength_grid = ssp.wavelength_grid
self.info_table = ssp.info_table
......@@ -573,18 +575,19 @@ class Database(object):
else:
raise Exception('The database is not writable.')
def get_yggdrasil_ssp(self, metallicity):
def get_yggdrasil_ssp(self, metallicity, fcov):
result = self.session.query(_Yggdrasil_SSP)\
.filter(_Yggdrasil_SSP.metallicity == metallicity)\
.filter(_Yggdrasil_SSP.fcov == fcov)\
.first()
if result:
return Yggdrasil_SSP(result.metallicity, result.time_grid,
result.wavelength_grid, result.info_table,
result.spec_table)
return Yggdrasil_SSP(result.metallicity, result.fcov,
result.time_grid, result.wavelength_grid,
result.info_table, result.spec_table)
else:
raise DatabaseLookupError(
"The Yggdrasil SSP for metallicity <{}> is not in the "
"database.".format(metallicity))
"The Yggdrasil SSP for metallicity <{}> and fcov <{}> is not in"
" the database.".format(metallicity, fcov))
def get_yggdrasil_ssp_parameters(self):
return self._get_parameters(_Yggdrasil_SSP)
......
......@@ -4,10 +4,11 @@ import numpy as np
class Yggdrasil_SSP(object):
def __init__(self, metallicity, time_grid, wavelength_grid,
def __init__(self, metallicity, fcov, time_grid, wavelength_grid,
info_table, spec_table):
self.metallicity = metallicity
self.fcov = fcov
self.time_grid = time_grid
self.wavelength_grid = wavelength_grid
self.info_table = info_table
......
......@@ -20,9 +20,14 @@ class YggdrasilSSP(SedModule):
parameter_list = OrderedDict([
("metallicity", (
"cigale_list(options=0.004 & 0.008 & 0.02)",
"Metalicity. Possible values are: 0.004, 0.008, and 0.02.",
"Metallicity. Possible values are: 0.004, 0.008, and 0.02.",
0.02
)),
("fcov", (
"cigale_list(options=0 & 0.5)",
"Coverting fraction. Possible values are 0 and 0.5.",
0.5
)),
("separation_age", (
"cigale_list(dtype=int, minvalue=0)",
"Age [Myr] of the separation between the young and the old star "
......@@ -35,10 +40,12 @@ class YggdrasilSSP(SedModule):
def _init_code(self):
"""Read the SSP from the database."""
self.metallicity = float(self.parameters["metallicity"])
self.fcov = float(self.parameters["fcov"])
self.separation_age = int(self.parameters["separation_age"])
with Database() as database:
self.ssp = database.get_yggdrasil_ssp(self.metallicity)
self.ssp = database.get_yggdrasil_ssp(self.metallicity,
self.fcov)
def process(self, sed):
"""Add the convolution of a Bruzual and Charlot SSP to the SED
......@@ -72,6 +79,7 @@ class YggdrasilSSP(SedModule):
sed.add_module(self.name, self.parameters)
sed.add_info("stellar.metallicity", self.metallicity)
sed.add_info("stellar.fcov", self.fcov)
sed.add_info("stellar.old_young_separation_age", self.separation_age)
sed.add_info("stellar.age", self.ssp.time_grid[index])
......
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