Commit 4d5160d0 authored by Médéric Boquien's avatar Médéric Boquien

Remove the dh2002 models which have been surperseded by the dale2014 ones.

parent 3cdb39f2
......@@ -289,45 +289,11 @@ def build_bc2003(base):
))
def build_dh2002(base):
dh2002_dir = os.path.join(os.path.dirname(__file__), 'dh2002/')
# Getting the alpha grid for the templates
dhcal = np.genfromtxt(dh2002_dir + 'dhcal.dat')
alpha_grid = dhcal[:, 1]
# Getting the lambda grid for the templates (we checked that all share the
# same grid).
first_template = np.genfromtxt(dh2002_dir + 'irdh01.spec', skip_header=1)
lambda_grid = first_template[:, 0] * 0.1 # Convert Å to nm
templates = []
for i in range(len(alpha_grid)):
filename = dh2002_dir + 'irdh' + ("%02d" % (i + 1)) + '.spec'
print("Importing %s..." % filename)
table = np.genfromtxt(filename, skip_header=1)[:, 1] # Luminosity
# column
# The table give the luminosity density in Lsun/Å normalised to 1 Lsun
# over the full spectrum. As we converted the wavelengths to nm, we
# must multiply the density per 10 to keep the normalisation.
table = table * 10
templates.append(table)
templates = np.array(templates)
data = (alpha_grid, lambda_grid, templates)
base.add_dh2002(data)
def build_dale2014(base):
dh2002_dir = os.path.join(os.path.dirname(__file__), 'dh2002/')
dale2014_dir = os.path.join(os.path.dirname(__file__), 'dale2014/')
# Getting the alpha grid for the templates
d14cal = np.genfromtxt(dh2002_dir + 'dhcal.dat')
d14cal = np.genfromtxt(dale2014_dir + 'dhcal.dat')
alpha_grid = d14cal[:, 1]
# Getting the lambda grid for the templates and convert from microns to nm.
......@@ -667,32 +633,27 @@ def build_base():
print("\nDONE\n")
print('#' * 78)
print("4- Importing Dale and Helou (2002) templates\n")
build_dh2002(base)
print("\nDONE\n")
print('#' * 78)
print("5- Importing Draine and Li (2007) models\n")
print("4- Importing Draine and Li (2007) models\n")
build_dl2007(base)
print("\nDONE\n")
print('#' * 78)
print("6- Importing the updated Draine and Li (2007 models)\n")
print("5- Importing the updated Draine and Li (2007 models)\n")
build_dl2014(base)
print("\nDONE\n")
print('#' * 78)
print("7- Importing Fritz et al. (2006) models\n")
print("6- Importing Fritz et al. (2006) models\n")
build_fritz2006(base)
print("\nDONE\n")
print('#' * 78)
print("8- Importing Dale et al (2014) templates\n")
print("7- Importing Dale et al (2014) templates\n")
build_dale2014(base)
print("\nDONE\n")
print('#' * 78)
print("9- Importing nebular lines and continuum\n")
print("8- Importing nebular lines and continuum\n")
build_nebular(base)
print("\nDONE\n")
print('#' * 78)
......
......@@ -167,8 +167,8 @@ def get_module(name, **kwargs):
module_name: string
The name of the module we want to get the class. This name can be
prefixed by anything using a dot, then the part before the dot is
used to determine the module to load (e.g. 'dh2002.1' will return
the 'dh2002' module).
used to determine the module to load (e.g. 'dl2014.1' will return
the 'dl2014' module).
Returns
-------
......
# -*- coding: utf-8 -*-
# Copyright (C) 2012, 2013 Centre de données Astrophysiques de Marseille
# Licensed under the CeCILL-v2 licence - see Licence_CeCILL_V2-en.txt
# Author: Yannick Roehlly
"""
Dale and Helou (2002) IR models module
======================================
This module implements the Dale and Helou (2002) infra-red models.
"""
from collections import OrderedDict
from . import CreationModule
from ..data import Database
class DH2002(CreationModule):
"""Dale and Helou (2002) templates IR re-emission module
Given an amount of attenuation (e.g. resulting from the action of a dust
attenuation module) this module normalises the Dale and Helou (2002)
template corresponding to a given α to this amount of energy and add it
to the SED.
Information added to the SED: NAME_alpha.
"""
parameter_list = OrderedDict([
('alpha', (
'float',
"Alpha slope. Possible values between 0.0625 and 4.000.",
2.
))
])
out_parameter_list = OrderedDict([('alpha', 'Alpha slope.')])
def _init_code(self):
"""Get the template set out of the database"""
with Database() as database:
self.dh2002 = database.get_dh2002()
def process(self, sed):
"""Add the IR re-emission contributions
Parameters
----------
sed: pcigale.sed.SED object
"""
alpha = float(self.parameters["alpha"])
if 'dust.luminosity' not in sed.info.keys():
sed.add_info('dust.luminosity', 1., True)
luminosity = sed.info['dust.luminosity']
ir_template = self.dh2002.get_template(alpha)
sed.add_module(self.name, self.parameters)
sed.add_info("dust.alpha", alpha)
sed.add_contribution('dust', self.dh2002.wavelength_grid,
luminosity * ir_template)
# CreationModule to be returned by get_module
Module = DH2002
......@@ -24,7 +24,6 @@ import numpy as np
from .filters import Filter
from .m2005 import M2005
from .bc03 import BC03
from .dh2002 import DH2002
from .dale2014 import Dale2014
from .dl2007 import DL2007
from .dl2014 import DL2014
......@@ -118,26 +117,6 @@ class _BC03(BASE):
self.lumin_table = ssp.lumin_table
class _DH2002(BASE):
"""Storage for Dale and Helou (2002) infra-red templates
The Dale and Helou (2002) template are gathered in a unique numpy array,
nevertheless, they are stored in their own table with a unique row.
"""
__tablename__ = 'dh2002_templates'
name = Column(String, primary_key=True)
description = Column(Text)
data = Column(PickleType)
def __init__(self, name, description, data):
self.name = name
self.description = description
self.data = data
class _Dale2014(BASE):
"""Storage for Dale et al (2014) infra-red templates
"""
......@@ -426,71 +405,6 @@ class Database(object):
"""
return self._get_parameters(_BC03)
def add_dh2002(self, data):
"""
Add Dale and Helou (2002) templates the collection.
Parameters
----------
data: array
Array containing the templates data.
"""
name = 'dh2002'
description = ("These are the Dale & Helou (2002) infra-red "
"templates to which the stellar emission was "
"subtracted (Nohl et al., 2009). The data is a "
"tuple composed of the alpha grid, the lambda grid "
"and a 2D array of luminosity density (normalised "
"over the full spectrum) with the alpha in the first "
"axis and the lambda in the second.")
if self.is_writable:
template = _DH2002(name, description, data)
self.session.add(template)
try:
self.session.commit()
except exc.IntegrityError:
self.session.rollback()
raise DatabaseInsertError(
'The template is already in the base.')
else:
raise Exception('The database is not writable.')
def get_dh2002(self):
"""
Get the Dale and Helou infrared templates from the database
Returns
-------
template: pcigale.base.DH2002
The Dale and Helou (2002) infrared templates.
Raises
------
DatabaseLookupError: if the templates are not in the database.
"""
result = (self.session.query(_DH2002).
filter(_DH2002.name == 'dh2002').
first())
if result:
return DH2002(result.data[0], result.data[1], result.data[2])
else:
raise DatabaseLookupError(
"The DH2002 templates are not in the database.")
def get_dh2002_parameters(self):
"""Get parameters for the Dale 2014 models.
Returns
-------
paramaters: dictionary
dictionary of parameters and their values
"""
return self._get_parameters(_DH2002)
def add_dl2007(self, model):
"""
Add a Draine and Li (2007) model to the database.
......
# -*- coding: utf-8 -*-
# Copyright (C) 2012 Centre de données Astrophysiques de Marseille
# Licensed under the CeCILL-v2 licence - see Licence_CeCILL_V2-en.txt
# Author: Yannick Roehlly
import numpy as np
from scipy import interpolate
class DH2002(object):
"""Dale an Helou 2002 infra-red templates
This class holds the data associated with the Dale and Helou (2002)
infra red templates.
"""
def __init__(self, alpha_grid, wavelength_grid, templates):
"""Create a new IR template set
Parameters
----------
alpha_grid: array
Vector of the various values for the α slope in the templates.
wavelength_grid: array
Vector of the λ grid used in the templates [nm]
templates: array
Template data in a 2D array containing the luminosity density
(normalised over the full spectrum) with α in the first axis and
λ in the second.
"""
self.alpha_grid = alpha_grid
self.wavelength_grid = wavelength_grid
self.templates = templates
def get_template(self, alpha):
"""Get the IR template corresponding to the given alpha
The template for the given α is interpolated from the Dale and Helou
(2002) template set. The new template is normalised in case of errors
in the interpolation.
Parameters
----------
alpha: float
α slope of the IR.
Returns
-------
luminosity: array
The luminosity density vector base on the template set λ grid.
"""
result = interpolate.interp1d(self.alpha_grid, self.templates,
axis=0)(alpha)
# Return the normalised result
return result / np.trapz(result, x=self.wavelength_grid)
......@@ -131,7 +131,7 @@ class Configuration(object):
"SSP: bc03, m2005 ; "
"Nebular: nebular ; "
"Attenuation: dustatt_calzleit, dustatt_powerlaw ; "
"Dust model: casey2012, dh2002, dl2007, dl2014 ; "
"Dust model: casey2012, dale2014, dl2007, dl2014 ; "
"AGN: dale2014, fritz2006 ; "
"redshift: redshifting (mandatory!).")
......
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