Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cigale
CIGALE
Commits
4fcb6311
Commit
4fcb6311
authored
Sep 17, 2013
by
Yannick Roehlly
Browse files
Use ordered dictionaries for parameters
So that the configuration files and the serialized data have a logical order.
parent
325f5cd7
Changes
16
Hide whitespace changes
Inline
Side-by-side
pcigale/analysis_modules/common.py
View file @
4fcb6311
...
...
@@ -4,19 +4,20 @@
# Author: Yannick Roehlly <yannick.roehlly@oamp.fr>
from
importlib
import
import_module
from
collections
import
OrderedDict
class
AnalysisModule
(
object
):
"""Abstract class, the pCigale analysis modules are based on.
"""
# parameter_list is a dictionary containing all the parameters
used by the
# module. Each parameter name is associate to a tuple
(variable type,
# description [string], default value). Each module must
define its
# parameter list, unless it does not use any parameter. Using
None means
# that there is no description, unit or default value. If None
should be
# the default value, use the 'None' string instead.
parameter_list
=
{}
# parameter_list is a
ordered
dictionary containing all the parameters
#
used by the
module. Each parameter name is associate to a tuple
#
(variable type,
description [string], default value). Each module must
#
define its
parameter list, unless it does not use any parameter. Using
#
None means
that there is no description, unit or default value. If None
#
should be
the default value, use the 'None' string instead.
parameter_list
=
OrderedDict
()
def
__init__
(
self
,
**
kwargs
):
"""Instantiate a analysis module
...
...
pcigale/analysis_modules/psum.py
View file @
4fcb6311
...
...
@@ -21,6 +21,7 @@ import sys
import
atpy
import
json
import
numpy
as
np
from
collections
import
OrderedDict
from
copy
import
deepcopy
from
scipy
import
stats
from
progressbar
import
ProgressBar
...
...
@@ -48,56 +49,56 @@ class Module(common.AnalysisModule):
TODO: Description of the PSUM method.
"""
parameter_list
=
{
"analysed_variables"
:
(
parameter_list
=
OrderedDict
([
(
"analysed_variables"
,
(
"array of strings"
,
"List of the variables (in the SEDs info dictionaries) for which "
"the statistical analysis will be done."
,
[
"sfr"
,
"average_sfr"
]
),
"save_best_sed"
:
(
)
),
(
"save_best_sed"
,
(
"boolean"
,
"If true, save the best SED for each observation to a file."
,
False
),
"plot_best_sed"
:
(
)
),
(
"plot_best_sed"
,
(
"boolean"
,
"If true, for each observation save a plot of the best SED "
"and the observed fluxes."
,
False
),
"plot_chi2_distribution"
:
(
)
),
(
"plot_chi2_distribution"
,
(
"boolean"
,
"If true, for each observation and each analysed variable "
"plot the value vs reduced chi-square distribution."
,
False
),
"save_pdf"
:
(
)
),
(
"save_pdf"
,
(
"boolean"
,
"If true, for each observation and each analysed variable "
"save the probability density function."
,
False
),
"plot_pdf"
:
(
)
),
(
"plot_pdf"
,
(
"boolean"
,
"If true, for each observation and each analysed variable "
"plot the probability density function."
,
False
),
"pdf_max_bin_number"
:
(
)
),
(
"pdf_max_bin_number"
,
(
"integer"
,
"Maximum number of bins used to compute the probability density "
"function. This is only used when saving or printing the PDF. "
"If there are less values, the probability is given for each "
"one."
,
50
),
"storage_type"
:
(
)
),
(
"storage_type"
,
(
"string"
,
"Type of storage used to cache the generate SED."
,
"memory"
)
}
)
)
])
def
process
(
self
,
data_file
,
column_list
,
sed_modules
,
sed_modules_params
,
redshift_module_name
,
...
...
pcigale/analysis_modules/savefluxes.py
View file @
4fcb6311
...
...
@@ -14,6 +14,7 @@ The data file is used only to get the list of fluxes to be computed.
import
os
from
itertools
import
product
from
collections
import
OrderedDict
from
datetime
import
datetime
from
astropy.table
import
Table
from
progressbar
import
ProgressBar
...
...
@@ -29,24 +30,24 @@ class Module(common.AnalysisModule):
"""
parameter_list
=
{
"output_file"
:
(
parameter_list
=
OrderedDict
([
(
"output_file"
,
(
"string"
,
"Name of the output file."
,
"computed_fluxes.xml"
),
"output_format"
:
(
)
),
(
"output_format"
,
(
"string"
,
"Format of the output file. Any format supported by astropy.table "
"e.g. votable or ascii."
,
"votable"
),
"storage_type"
:
(
)
),
(
"storage_type"
,
(
"string"
,
"Type of storage used to cache the generate SED."
,
"memory"
)
}
)
)
])
def
process
(
self
,
data_file
,
column_list
,
sed_modules
,
sed_modules_params
,
redshift_module
,
...
...
pcigale/sed/modules/bc03.py
View file @
4fcb6311
...
...
@@ -4,6 +4,7 @@
# Author: Yannick Roehlly <yannick.roehlly@oamp.fr>
import
numpy
as
np
from
collections
import
OrderedDict
from
.
import
common
from
...data
import
Database
...
...
@@ -18,40 +19,40 @@ class Module(common.SEDCreationModule):
Bruzual and Charlot (2003) models.
"""
parameter_list
=
{
"imf"
:
(
parameter_list
=
OrderedDict
([
(
"imf"
,
(
"string"
,
"Initial mass function: salp (Salpeter) or chab (Chabrier)"
,
None
),
"metallicity"
:
(
)
),
(
"metallicity"
,
(
"float"
,
"Mettalicity, 0.02 for Solar metallicity."
,
None
),
"separation_age"
:
(
"int
eger
"
,
)
),
(
"separation_age"
,
(
"int"
,
"Age [Myr] of the separation between the young and the old star "
"populations. The default value in 10^7 years (10 Myr). Set "
"to 0 not to differentiate ages (only an old population)."
,
10
)
}
out_parameter_list
=
{
"sfr"
:
"Instantaneous Star Formation Rate in solar mass per year, "
"at the age of the galaxy."
,
"average_sfr"
:
"Average SFR in the last 100 Myr (default) of the "
"galaxy history."
,
"m_star"
:
"Total mass in stars in Solar mass."
,
"m_gas"
:
"Mass returned to the ISM by evolved stars in Solar mass."
,
"n_ly"
:
"rate of H-ionizing photons in s^-1, per Solar mass "
"of galaxy."
,
"b_4000"
:
"Amplitude of 4000 Å break (Bruzual 2003)"
,
"b4_vn"
:
"Amplitude of 4000 Å narrow break (Balogh et al. 1999)"
,
"b4_sdss"
:
"Amplitude of 4000 Å break (Stoughton et al. 2002)"
,
"b_912"
:
"Amplitude of Lyman discontinuity"
}
)
)
])
out_parameter_list
=
OrderedDict
([
(
"sfr"
,
"Instantaneous Star Formation Rate in solar mass per year, "
"at the age of the galaxy."
)
,
(
"average_sfr"
,
"Average SFR in the last 100 Myr (default) of the "
"galaxy history."
)
,
(
"m_star"
,
"Total mass in stars in Solar mass."
)
,
(
"m_gas"
,
"Mass returned to the ISM by evolved stars in Solar mass."
)
,
(
"n_ly"
,
"rate of H-ionizing photons in s^-1, per Solar mass "
"of galaxy."
)
,
(
"b_4000"
,
"Amplitude of 4000 Å break (Bruzual 2003)"
)
,
(
"b4_vn"
,
"Amplitude of 4000 Å narrow break (Balogh et al. 1999)"
)
,
(
"b4_sdss"
,
"Amplitude of 4000 Å break (Stoughton et al. 2002)"
)
,
(
"b_912"
,
"Amplitude of Lyman discontinuity"
)
])
def
_init_code
(
self
):
"""Read the SSP from the database."""
...
...
pcigale/sed/modules/casey2012.py
View file @
4fcb6311
...
...
@@ -5,6 +5,7 @@
import
numpy
as
np
import
scipy.constants
as
cst
from
collections
import
OrderedDict
from
.
import
common
...
...
@@ -19,35 +20,35 @@ class Module(common.SEDCreationModule):
"""
parameter_list
=
{
"temperature"
:
(
parameter_list
=
OrderedDict
([
(
"temperature"
,
(
"float"
,
"Temperature of the dust in K."
,
None
),
"beta"
:
(
)
),
(
"beta"
,
(
"float"
,
"Emissivity index of the dust."
,
None
),
"alpha"
:
(
)
),
(
"alpha"
,
(
"float"
,
"Mid-infrared powerlaw slope."
,
None
),
"attenuation_value_names"
:
(
)
),
(
"attenuation_value_names"
,
(
"list of strings"
,
"List of attenuation value names (in the SED's info dictionary)."
"A new re-emission contribution will be added for each one."
,
None
)
}
out_parameter_list
=
{
"temperature"
:
"Temperature of the dust in K."
,
"beta"
:
"Emissivity index of the dust."
,
"alpha"
:
"Mid-infrared powerlaw slope."
}
)
)
])
out_parameter_list
=
OrderedDict
([
(
"temperature"
,
"Temperature of the dust in K."
)
,
(
"beta"
,
"Emissivity index of the dust."
)
,
(
"alpha"
,
"Mid-infrared powerlaw slope."
)
])
def
_init_code
(
self
):
...
...
pcigale/sed/modules/common.py
View file @
4fcb6311
...
...
@@ -4,6 +4,7 @@
# Author: Yannick Roehlly <yannick.roehlly@oamp.fr>
from
importlib
import
import_module
from
collections
import
OrderedDict
def
complete_parameters
(
given_parameters
,
parameter_list
):
...
...
@@ -14,36 +15,34 @@ def complete_parameters(given_parameters, parameter_list):
have no default value and is not present in given_parameters, raises an
error. If a parameter is present in given_parameters and not in
parameter_list, an exception is also raised.
Returns an ordered dictionary with the same key order as the parameter
list.
Parameters
----------
given_parameters : dictionary
Parameter dictionary used to configure the module.
parameter_list :
dictionary
parameter_list :
OrderedDict
Parameter list from the module.
Returns
-------
parameters :
dictionary
D
ictionary combining the given parameters with the default
values for
the missing ones.
parameters :
OrderedDict
Ordered d
ictionary combining the given parameters with the default
values for
the missing ones.
Raises
------
KeyError when the given parameters are different from the expected ones.
"""
# For parameters that are present on the parameter_list with a default
# value and that are not in the giver_parameters dictionary, we add them
# with their default value.
# Complete the given parameters with default values when needed.
for
key
in
parameter_list
:
if
(
not
key
in
given_parameters
)
and
(
parameter_list
[
key
][
2
]
is
not
None
):
given_parameters
[
key
]
=
parameter_list
[
key
][
2
]
# If the keys of the parameters dictionary are different from the one
# of the parameter_list dictionary, we raises a KeyError. That means
# that a parameter is missing (and has no default value) or that an
# unexpected one was given.
# Check parameter consistency between the parameter list and the given
# parameters.
if
not
set
(
given_parameters
.
keys
())
==
set
(
parameter_list
.
keys
()):
missing_parameters
=
(
set
(
parameter_list
.
keys
())
-
set
(
given_parameters
.
keys
()))
...
...
@@ -61,29 +60,34 @@ def complete_parameters(given_parameters, parameter_list):
raise
KeyError
(
"The parameters passed are different from the "
"expected one. "
+
message
)
return
given_parameters
# We want the result to be ordered as the parameter_list of the module is.
result
=
OrderedDict
()
for
key
in
parameter_list
.
keys
():
result
[
key
]
=
given_parameters
[
key
]
return
result
class
SEDCreationModule
(
object
):
"""Abstract class, the pCigale SED creation modules are based on.
"""
# parameter_list is a dictionary containing all the parameters
used by
# the module. Each parameter name is associate to a tuple
(variable type,
# description [string], default value). Each module must
define its
# parameter list, unless it does not use any parameter. Using
None means
# that there is no description or default value. If None should
be the
# default value, use the 'None' string instead.
parameter_list
=
{}
# out_parameter_list is a dictionary containing all the SED
parameters
# that are added to the SED info dictionary and for which a
statistical
# analysis may be done. Each parameter name is associated with
its
# description. In the SED info dictionary, the parameter name in
prefixed
# with the name of the module plus an underscore (to allow
several
# modules to add a parameter with the same name, for instance a
repeated
# module.)
out_parameter_list
=
{}
# parameter_list is a
n ordered
dictionary containing all the parameters
#
used by
the module. Each parameter name is associate to a tuple
#
(variable type,
description [string], default value). Each module must
#
define its
parameter list, unless it does not use any parameter. Using
#
None means
that there is no description or default value. If None should
#
be the
default value, use the 'None' string instead.
parameter_list
=
OrderedDict
()
# out_parameter_list is a
n ordered
dictionary containing all the SED
#
parameters
that are added to the SED info dictionary and for which a
#
statistical
analysis may be done. Each parameter name is associated with
#
its
description. In the SED info dictionary, the parameter name in
#
prefixed
with the name of the module plus an underscore (to allow
#
several
modules to add a parameter with the same name, for instance a
#
repeated
module.)
out_parameter_list
=
OrderedDict
()
# comments is the text that is used to comment the module section in
# the configuration file. For instance, it can be used to give special
...
...
pcigale/sed/modules/dh2002.py
View file @
4fcb6311
...
...
@@ -3,6 +3,7 @@
# Licensed under the CeCILL-v2 licence - see Licence_CeCILL_V2-en.txt
# Author: Yannick Roehlly <yannick.roehlly@oamp.fr>
from
collections
import
OrderedDict
from
.
import
common
from
...data
import
Database
...
...
@@ -21,21 +22,21 @@ class Module(common.SEDCreationModule):
"""
parameter_list
=
{
'alpha'
:
(
parameter_list
=
OrderedDict
([
(
'alpha'
,
(
'float'
,
"Alpha slope."
,
None
),
'attenuation_value_names'
:
(
)
),
(
'attenuation_value_names'
,
(
'array of strings'
,
"List of attenuation value names (in the SED's info dictionary). "
"A new re-emission contribution will be added for each one."
,
None
)
}
)
)
])
out_parameter_list
=
{
'alpha'
:
'Alpha slope.'
}
out_parameter_list
=
OrderedDict
([(
'alpha'
,
'Alpha slope.'
)])
def
_init_code
(
self
):
"""Get the template set out of the database"""
...
...
pcigale/sed/modules/dl2007.py
View file @
4fcb6311
...
...
@@ -4,6 +4,7 @@
# Author: Médéric Boquien <mederic.boquien@oamp.fr>
from
.
import
common
from
collections
import
OrderedDict
import
numpy
as
np
from
pcigale.data
import
Database
...
...
@@ -22,39 +23,41 @@ class Module(common.SEDCreationModule):
"""
parameter_list
=
{
'qpah'
:
(
parameter_list
=
OrderedDict
([
(
'qpah'
,
(
'float'
,
"Mass fraction of PAH"
,
None
),
'umin'
:
(
)
),
(
'umin'
,
(
'float'
,
"Minimum radiation field"
,
None
),
'umax'
:
(
)
),
(
'umax'
,
(
'float'
,
"Maximum radiation field"
,
None
),
'gamma'
:
(
)
),
(
'gamma'
,
(
'float'
,
"Fraction illuminated from Umin to Umax"
,
None
),
'attenuation_value_names'
:
(
)
),
(
'attenuation_value_names'
,
(
'list of strings'
,
"List of attenuation value names (in the SED's info dictionary). "
"A new re-emission contribution will be added for each one."
,
None
)
}
out_parameter_list
=
{
'qpah'
:
'Mass fraction of PAH'
,
'umin'
:
'Minimum radiation field'
,
'umax'
:
'Maximum radiation field'
,
'gamma'
:
'Fraction illuminated from Umin to Umax'
}
))
])
out_parameter_list
=
OrderedDict
([
(
'qpah'
,
'Mass fraction of PAH'
),
(
'umin'
,
'Minimum radiation field'
),
(
'umax'
,
'Maximum radiation field'
),
(
'gamma'
,
'Fraction illuminated from Umin to Umax'
)
])
def
_init_code
(
self
):
"""Get the model out of the database"""
...
...
pcigale/sed/modules/dustatt_calzleit.py
View file @
4fcb6311
...
...
@@ -4,6 +4,7 @@
# Author: Yannick Roehlly <yannick.roehlly@oamp.fr>
import
numpy
as
np
from
collections
import
OrderedDict
from
.
import
common
from
...data
import
Database
...
...
@@ -167,77 +168,77 @@ class Module(common.SEDCreationModule):
"""
parameter_list
=
{
"E_BVs_young"
:
(
parameter_list
=
OrderedDict
([
(
"E_BVs_young"
,
(
"float"
,
"E(B-V)*, the colour excess of the stellar continuum light for "
"the young population."
,
None
),
"E_BVs_old_factor"
:
(
)
),
(
"E_BVs_old_factor"
,
(
"float"
,
"Reduction factor for the E(B-V)* of the old population compared "
"to the young one (<1)."
,
None
),
"young_contribution_name"
:
(
)
),
(
"young_contribution_name"
,
(
"string"
,
"Name of the contribution containing the spectrum of the "
"young population."
,
"m2005_young"
),
"old_contribution_name"
:
(
)
),
(
"old_contribution_name"
,
(
"string"
,
"Name of the contribution containing the spectrum of the "
"old population. If it is set to 'None', only one population "
"is considered."
,
"m2005_old"
),
"uv_bump_wavelength"
:
(
)
),
(
"uv_bump_wavelength"
,
(
"float"
,
"Central wavelength of the UV bump in nm."
,
217.5
),
"uv_bump_width"
:
(
)
),
(
"uv_bump_width"
,
(
"float"
,
"Width (FWHM) of the UV bump in nm."
,
None
),
"uv_bump_amplitude"
:
(
)
),
(
"uv_bump_amplitude"
,
(
"float"
,
"Amplitude of the UV bump in nm."
,
None
),
"powerlaw_slope"
:
(
)
),
(
"powerlaw_slope"
,
(
"float"
,
"Slope delta of the power law modifying the attenuation curve."
,
None
),
"filters"
:
(
)
),
(
"filters"
,
(
"list of strings"
,
"List of the filters for which the attenuation will be computed."
,
[
'V_B90'
,
'FUV'
]
)
}
out_parameter_list
=
{
"
NAME_
E_BVs_young"
:
"E(B-V)*, the colour excess of the stellar "
"continuum
light for the young population."
,
"
NAME_
E_BVs_old"
:
"E(B-V)*, the colour excess of the stellar "
"continuum light for the old population."
,
"
NAME_
attenuation_young"
:
"Amount of luminosity attenuated from the "
"young population in W."
,
"
NAME_
E_BVs_old_factor"
:
"Ratio of the old population E(B-V)* to the "
"young one."
,
"
NAME_
attenuation_old"
:
"Amount of luminosity attenuated from the "
"old population in W."
,
"
NAME_
attenuation"
:
"Total amount of luminosity attenuated in W."
,
"
NAME_
uv_bump_wavelength"
:
"Central wavelength of UV bump in nm."
,
"
NAME_
uv_bump_width"
:
"Width of the UV bump in nm."
,
"
NAME_
uv_bump_amplitude"
:
"Amplitude of the UV bump in nm."
,
"
NAME_
powerlaw_slope"
:
"Slope of the power law."
,
"
NAME_
FILTER"
:
"Attenuation in the FILTER filter."
,
}
)
)
])
out_parameter_list
=
OrderedDict
([
(
"E_BVs_young"
,
"E(B-V)*, the colour excess of the stellar
continuum
"
"
light for the young population."
)
,
(
"E_BVs_old"
,
"E(B-V)*, the colour excess of the stellar "
"continuum light for the old population."
)
,
(
"attenuation_young"
,
"Amount of luminosity attenuated from the "
"young population in W."
)
,
(
"E_BVs_old_factor"
,
"Ratio of the old population E(B-V)* to the "
"young one."
)
,
(
"attenuation_old"
,
"Amount of luminosity attenuated from the "
"old population in W."
)
,
(
"attenuation"
,
"Total amount of luminosity attenuated in W."
)
,
(
"uv_bump_wavelength"
,
"Central wavelength of UV bump in nm."
)
,
(
"uv_bump_width"
,
"Width of the UV bump in nm."
)
,
(
"uv_bump_amplitude"
,
"Amplitude of the UV bump in nm."
)
,
(
"powerlaw_slope"
,
"Slope of the power law."
)
,
(
"FILTER"
,
"Attenuation in the FILTER filter."
)
])
def
_init_code
(
self
):