Commit 14b34462 authored by Médéric Boquien's avatar Médéric Boquien

We rely on OrderedDict to keep the order of the parameters. However given the...

We rely on OrderedDict to keep the order of the parameters. However given the way the code is structured currently, there is really no reason for this. So let's just switch to the standard dictionary. This has two advantages. First the standard dictionary is much faster than OrderedDict (implemented in C rather than in pure python). Then, standard dictionaries are marshalable, which makes them usable as keys for other dictionaries.
parent f84db63e
......@@ -5,7 +5,6 @@
# Author: Yannick Roehlly & Denis Burgarella
from importlib import import_module
from collections import OrderedDict
import numpy as np
from scipy import stats
from astropy.table import Column
......@@ -15,13 +14,13 @@ class AnalysisModule(object):
"""Abstract class, the pCigale analysis modules are based on.
"""
# parameter_list is a ordered dictionary containing all the parameters
# 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 = OrderedDict()
parameter_list = dict()
def __init__(self, **kwargs):
"""Instantiate a analysis module
......
......@@ -25,7 +25,6 @@ reduced χ²) is given for each observation.
"""
from collections import OrderedDict
import ctypes
import multiprocessing as mp
from multiprocessing.sharedctypes import RawArray
......@@ -54,7 +53,7 @@ REDSHIFT_DECIMALS = 2
class PdfAnalysis(AnalysisModule):
"""PDF analysis module"""
parameter_list = OrderedDict([
parameter_list = dict([
("analysed_variables", (
"array of strings",
"List of the variables (in the SEDs info dictionaries) for which "
......
......@@ -149,7 +149,7 @@ def save_table_best(filename, obsid, chi2, chi2_red, variables, fluxes,
All variables corresponding to a SED
fluxes: RawArray
Fluxes in all bands for each object
filters: OrderedDict
filters: list
Filters used to compute the fluxes
info_keys: list
Parameters names
......
......@@ -84,7 +84,7 @@ def init_analysis(params, filters, analysed, redshifts, fluxes, variables,
----------
params: ParametersHandler
Handles the parameters from a 1D index.
filters: OrderedDict
filters: list
Contains filters to compute the fluxes.
analysed: list
Variable names to be analysed
......
......@@ -14,7 +14,6 @@ parameters.
The data file is used only to get the list of fluxes to be computed.
"""
from collections import OrderedDict
import ctypes
from datetime import datetime
from itertools import product, repeat
......@@ -44,7 +43,7 @@ class SaveFluxes(AnalysisModule):
"""
parameter_list = OrderedDict([
parameter_list = dict([
("output_file", (
"string",
"Name of the output file that contains the parameters of the "
......
......@@ -34,8 +34,8 @@ class ParametersHandler(object):
----------
modules: list
Contains the modules in the order they are called
params: OrderedDict
Contains a list of parameters for each module
params: list of dictionaries
Contains a dictionary of parameters for each module
"""
self.modules = modules
......@@ -61,7 +61,7 @@ class ParametersHandler(object):
"""
# We make a copy of the dictionary as we are modifying it.
dictionary = collections.OrderedDict(dictionary)
dictionary = dict(dictionary)
# First, we must ensure that all values are lists; when a value is a
# single element, we put it in a list.
......@@ -76,7 +76,7 @@ class ParametersHandler(object):
# the value lists.
key_list = dictionary.keys()
value_array_list = [dictionary[key] for key in key_list]
combination_list = [collections.OrderedDict(zip(key_list, combination))
combination_list = [dict(zip(key_list, combination))
for combination in
itertools.product(*value_array_list)]
......@@ -151,8 +151,8 @@ def save_fluxes(model_fluxes, model_parameters, filters, names, filename,
Contains the fluxes of each model.
model_parameters: RawArray
Contains the parameters associated to each model.
filters: OrderedDict
Contains the filters.
filters: list
Contains the filter names.
names: List
Contains the parameters names.
filename: str
......
......@@ -6,7 +6,6 @@
import os
import inspect
from importlib import import_module
from collections import OrderedDict
def complete_parameters(given_parameters, parameter_list):
......@@ -24,12 +23,12 @@ def complete_parameters(given_parameters, parameter_list):
----------
given_parameters: dictionary
Parameter dictionary used to configure the module.
parameter_list: OrderedDict
parameter_list: dictionary
Parameter list from the module.
Returns
-------
parameters: OrderedDict
parameters: dict
Ordered dictionary combining the given parameters with the default
values for the missing ones.
......@@ -61,7 +60,7 @@ def complete_parameters(given_parameters, parameter_list):
"expected one. " + message)
# We want the result to be ordered as the parameter_list of the module is.
result = OrderedDict()
result = dict()
for key in parameter_list:
result[key] = given_parameters[key]
......@@ -72,21 +71,21 @@ class CreationModule(object):
"""Abstract class, the pCigale SED creation modules are based on.
"""
# parameter_list is an ordered dictionary containing all the parameters
# 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 = OrderedDict()
parameter_list = dict()
# out_parameter_list is an ordered dictionary containing all the SED
# 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
# is postfixed with a same postfix used in the module name, to allow
# the use of repeated modules.
out_parameter_list = OrderedDict()
out_parameter_list = dict()
# 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
......
......@@ -13,7 +13,6 @@ Populations.
"""
import numpy as np
from collections import OrderedDict
from . import CreationModule
from ..data import Database
......@@ -26,7 +25,7 @@ class BC03(CreationModule):
component to the SED.
"""
parameter_list = OrderedDict([
parameter_list = dict([
("imf", (
"int",
"Initial mass function: 0 (Salpeter) or 1 (Chabrier).",
......@@ -47,7 +46,7 @@ class BC03(CreationModule):
))
])
out_parameter_list = OrderedDict([
out_parameter_list = dict([
("sfr", "Instantaneous Star Formation Rate in solar mass per year, "
"at the age of the galaxy."),
('sfr10Myrs', 'Average SFR in the last 10 Myr (default) of the '
......
......@@ -14,7 +14,6 @@ This module implements the Casey (2012) infra-red models.
import numpy as np
import scipy.constants as cst
from collections import OrderedDict
from . import CreationModule
......@@ -27,7 +26,7 @@ class Casey2012(CreationModule):
"""
parameter_list = OrderedDict([
parameter_list = dict([
("temperature", (
"float",
"Temperature of the dust in K.",
......@@ -45,7 +44,7 @@ class Casey2012(CreationModule):
))
])
out_parameter_list = OrderedDict([
out_parameter_list = dict([
("temperature", "Temperature of the dust in K."),
("beta", "Emissivity index of the dust."),
("alpha", "Mid-infrared powerlaw slope.")
......
......@@ -11,7 +11,6 @@ This module implements the Dale (2014) infra-red models.
"""
from collections import OrderedDict
from pcigale.data import Database
from . import CreationModule
......@@ -28,7 +27,7 @@ class Dale2014(CreationModule):
"""
parameter_list = OrderedDict([
parameter_list = dict([
('fracAGN', (
'float',
"AGN fraction. It is not recommended to combine this AGN emission "
......@@ -50,7 +49,7 @@ class Dale2014(CreationModule):
))
])
out_parameter_list = OrderedDict([
out_parameter_list = dict([
('fracAGN', 'Contribution of the AGN'),
('alpha', 'Alpha slope'),
('lir', 'Total IR luminosity between 8 and 1000 microns (AGN + SB)')
......
......@@ -12,7 +12,6 @@ This module implements the Draine and Li (2007) infra-red models.
"""
from collections import OrderedDict
import numpy as np
from pcigale.data import Database
from . import CreationModule
......@@ -30,7 +29,7 @@ class DL2007(CreationModule):
"""
parameter_list = OrderedDict([
parameter_list = dict([
('qpah', (
'float',
"Mass fraction of PAH. Possible values are: 0.47, 1.12, 1.77, "
......@@ -58,7 +57,7 @@ class DL2007(CreationModule):
))
])
out_parameter_list = OrderedDict([
out_parameter_list = dict([
('qpah', 'Mass fraction of PAH'),
('umin', 'Minimum radiation field'),
('umax', 'Maximum radiation field'),
......
......@@ -12,7 +12,6 @@ This module implements the updated Draine and Li (2007) infrared models.
"""
from collections import OrderedDict
import numpy as np
from pcigale.data import Database
from . import CreationModule
......@@ -30,7 +29,7 @@ class DL2014(CreationModule):
"""
parameter_list = OrderedDict([
parameter_list = dict([
('qpah', (
'float',
"Mass fraction of PAH. Possible values are: 0.47, 1.12, 1.77, "
......@@ -61,7 +60,7 @@ class DL2014(CreationModule):
))
])
out_parameter_list = OrderedDict([
out_parameter_list = dict([
('qpah', 'Mass fraction of PAH'),
('umin', 'Minimum radiation field'),
('alpha', 'Power law slope dU/dM∝U¯ᵅ'),
......
......@@ -14,7 +14,6 @@ attenuation formulae, adding an UV-bump and a power law.
"""
import numpy as np
from collections import OrderedDict
from . import CreationModule
......@@ -179,7 +178,7 @@ class CalzLeit(CreationModule):
"""
parameter_list = OrderedDict([
parameter_list = dict([
("E_BVs_young", (
"float",
"E(B-V)*, the colour excess of the stellar continuum light for "
......@@ -221,7 +220,7 @@ class CalzLeit(CreationModule):
))
])
out_parameter_list = OrderedDict([
out_parameter_list = dict([
("E_BVs", "E(B-V), the colour excess of the stellar continuum "
"light for each population."),
("E_BVs_old_factor", "Ratio of the old population E(B-V) to the "
......
......@@ -14,7 +14,6 @@ in Charlot and Fall (2000) with a UV bump added.
"""
import numpy as np
from collections import OrderedDict
from . import CreationModule
......@@ -105,7 +104,7 @@ class PowerLawAtt(CreationModule):
"""
parameter_list = OrderedDict([
parameter_list = dict([
("Av_young", (
"float",
"V-band attenuation of the young population.",
......@@ -146,7 +145,7 @@ class PowerLawAtt(CreationModule):
))
])
out_parameter_list = OrderedDict([
out_parameter_list = dict([
("Av", "V-band attenuation."),
("Av_old_factor", "Reduction factor for the V-band attenuation "
"of the old population compared to the young "
......
......@@ -11,7 +11,6 @@ This module implements the Fritz et al. (2006) models.
"""
import numpy as np
from collections import OrderedDict
from pcigale.data import Database
from . import CreationModule
from pcigale.sed.cosmology import cosmology
......@@ -39,7 +38,7 @@ class Fritz2006(CreationModule):
"""
parameter_list = OrderedDict([
parameter_list = dict([
('r_ratio', (
'float',
"Ratio of the maximum to minimum radii of the dust torus. "
......@@ -83,7 +82,7 @@ class Fritz2006(CreationModule):
))
])
out_parameter_list = OrderedDict([
out_parameter_list = dict([
('fracAGN', 'Contribution of the AGN'),
('agn.therm_luminosity', 'Luminosity of the AGN contribution due to '
'the dust torus'),
......
......@@ -12,7 +12,6 @@ This module reads a SED spectrum from a file.
"""
from astropy.table import Table
from collections import OrderedDict
from ..utils import read_table
from . import CreationModule
......@@ -22,7 +21,7 @@ class LoadSpecFile(CreationModule):
"""
parameter_list = OrderedDict([
parameter_list = dict([
("filename", (
'str',
"Name of the file to load and to add to the SED table. This "
......
......@@ -12,7 +12,6 @@ This module implements the Maraston (2005) Single Stellar Populations.
"""
import numpy as np
from collections import OrderedDict
from . import CreationModule
from ..data import Database
......@@ -39,7 +38,7 @@ class M2005(CreationModule):
"""
parameter_list = OrderedDict([
parameter_list = dict([
('imf', (
'int',
"Initial mass function: 0 (Salpeter) or 1 (Kroupa)",
......@@ -59,7 +58,7 @@ class M2005(CreationModule):
))
])
out_parameter_list = OrderedDict([
out_parameter_list = dict([
('sfr', 'Instantaneous Star Formation Rate in solar mass per year, '
'at the age of the galaxy.'),
('sfr10Myrs', 'Average SFR in the last 10 Myr (default) of the '
......
......@@ -18,7 +18,6 @@ in dust and not visible in the wavelength range.
import numpy as np
import scipy.constants as cst
from collections import OrderedDict
from . import CreationModule
......@@ -32,7 +31,7 @@ class MBB(CreationModule):
"""
parameter_list = OrderedDict([
parameter_list = dict([
("epsilon_mbb", (
"float",
"Fraction [>= Ø] of L_dust(energy balance) in the MBB",
......@@ -56,7 +55,7 @@ class MBB(CreationModule):
)),
])
out_parameter_list = OrderedDict([
out_parameter_list = dict([
("t_mbb", "Temperature of the modified black body in K."),
("beta_mbb", "Emissivity index of the modified black body."),
("epsilon_mbb", "Fraction of L_dust in the modified black body.")
......
......@@ -3,7 +3,6 @@
# Licensed under the CeCILL-v2 licence - see Licence_CeCILL_V2-en.txt
# Author: Médéric Boquien <mboquien@ast.cam.ac.uk>
from collections import OrderedDict
import numpy as np
from pcigale.data import Database
import scipy.constants as cst
......@@ -25,7 +24,7 @@ class NebularEmission(CreationModule):
"""
parameter_list = OrderedDict([
parameter_list = dict([
('logU', (
'float',
"Ionisation parameter",
......@@ -48,7 +47,7 @@ class NebularEmission(CreationModule):
))
])
out_parameter_list = OrderedDict([
out_parameter_list = dict([
('logU', "Ionisation parameter"),
('f_esc', "Fraction of Lyman continuum photons escaping "
"the galaxy"),
......
......@@ -16,7 +16,6 @@ for all the physical processes at play to build the received total emission.
"""
import numpy as np
from collections import OrderedDict
from . import CreationModule
......@@ -29,7 +28,7 @@ class Param(CreationModule):
"""
parameter_list = OrderedDict([
parameter_list = dict([
("OK", (
"boolean",
"Are you here?.",
......@@ -37,7 +36,7 @@ class Param(CreationModule):
))
])
out_parameter_list = OrderedDict([
out_parameter_list = dict([
("beta_calz94", "The UV slope in the range 125-180&240-260nm"),
("FUV_luminosity", "The rest-frame FUV luminosity"),
("D_4000", "The D_4000 index")
......
......@@ -19,7 +19,6 @@ This module implements the radio emission of galaxies, taking into account only
import numpy as np
import scipy.constants as cst
from collections import OrderedDict
from . import CreationModule
......@@ -32,7 +31,7 @@ class Radio(CreationModule):
"""
parameter_list = OrderedDict([
parameter_list = dict([
("qir", (
"float",
"The value of the FIR/radio correlation coefficient.",
......@@ -45,7 +44,7 @@ class Radio(CreationModule):
))
])
out_parameter_list = OrderedDict([
out_parameter_list = dict([
("qir", "The value of the FIR/radio correlation coefficient."),
("alpha", "The slope of the power-law synchrotron emission.")
])
......
......@@ -18,8 +18,6 @@ is changed, this module may need to be adapted.
"""
from collections import OrderedDict
import numpy as np
from scipy.constants import parsec
from scipy.misc import factorial
......@@ -143,7 +141,7 @@ class Redshifting(CreationModule):
"""
parameter_list = OrderedDict([
parameter_list = dict([
("redshift", (
"float",
"Redshift to apply to the galaxy. Leave empty to use the redshifts"
......
......@@ -13,7 +13,6 @@ decreasing exponentials.
"""
import numpy as np
from collections import OrderedDict
from . import CreationModule
# Time lapse used in the age grid in Myr. If should be consistent with the
......@@ -29,7 +28,7 @@ class Sfh2Exp(CreationModule):
"""
parameter_list = OrderedDict([
parameter_list = dict([
("tau_main", (
"float",
"e-folding time of the main stellar population model in Myr.",
......@@ -68,7 +67,7 @@ class Sfh2Exp(CreationModule):
)),
])
out_parameter_list = OrderedDict([
out_parameter_list = dict([
("tau_main", "e-folding time of the main stellar population model "
"in Myr."),
("tau_burst", "e-folding time of the late starburst population model "
......
......@@ -22,7 +22,6 @@ and interpolate the values of a, b and c.
"""
import numpy as np
from collections import OrderedDict
from . import CreationModule
# Time lapse used in the age grid in Myr. If should be consistent with the
......@@ -39,7 +38,7 @@ class SfhBuat08(CreationModule):
"""
parameter_list = OrderedDict([
parameter_list = dict([
("velocity", (
"float",
"Rotational velocity of the galaxy in km/s. Must be between 80 "
......@@ -59,7 +58,7 @@ class SfhBuat08(CreationModule):
))
])
out_parameter_list = OrderedDict([
out_parameter_list = dict([
("sfh.velocity", "Rotational velocity of the galaxy in km/s."),
("galaxy_mass", "Mass of the galaxy in solar mass.")
])
......
......@@ -15,7 +15,6 @@ constant.
"""
import numpy as np
from collections import OrderedDict
from . import CreationModule
# Time lapse used in the age grid in Myr. If should be consistent with the
......@@ -30,7 +29,7 @@ class SfhQuench(CreationModule):
"""
parameter_list = OrderedDict([
parameter_list = dict([
("quenching_age", (
"integer",
"Age of the galaxy at which the quenching happens in Myr.",
......@@ -51,7 +50,7 @@ class SfhQuench(CreationModule):
))
])
out_parameter_list = OrderedDict([
out_parameter_list = dict([
("sfh.quenching_age", "Age of the galaxt when the quenching occurs "
"in Myr."),
("sfh.quenching_factor", "Quenching factor applied.")
......
......@@ -13,7 +13,6 @@ regularly-spaced short constant SF events.
"""
import numpy as np
from collections import OrderedDict
from . import CreationModule
# Time lapse used in the age grid in Myr. If should be consistent with the
......@@ -29,7 +28,7 @@ class SfhComb(CreationModule):
"""
parameter_list = OrderedDict([
parameter_list = dict([
("N_events", (
"integer",
"Number of individual star formation events. ",
......@@ -66,7 +65,7 @@ class SfhComb(CreationModule):
)),
])
out_parameter_list = OrderedDict([
out_parameter_list = dict([
("N_events", "Number of individual star formation events"),
("t_duration", "Length of each individual star formation event "
"in Myr."),
......
......@@ -13,7 +13,6 @@ regularly-spaced short regularly-spaced delayed-SFH SF events.
"""
import numpy as np
from collections import OrderedDict
from . import CreationModule
# Time lapse used in the age grid in Myr. If should be consistent with the
......@@ -29,7 +28,7 @@ class SfhComb(CreationModule):
"""
parameter_list = OrderedDict([
parameter_list = dict([
("N_events", (
"integer",
"Number of individual star formation events. ",
......@@ -65,7 +64,7 @@ class SfhComb(CreationModule):
)),
])
out_parameter_list = OrderedDict([
out_parameter_list = dict([
("N_events", "Number of individual star formation events"),
("tau_events", "e-folding time of all short events in Myr.."),
("age", "Age of the stellar population in the galaxy in Myr."),
......
......@@ -14,7 +14,6 @@ rise of the SFR up to a maximum, followed by an exponential decrease.
"""
import numpy as np
from collections import OrderedDict
from . import CreationModule
# Time lapse used in the age grid in Myr. If should be consistent with the
......@@ -30,7 +29,7 @@ class SFHDelayed(CreationModule):
"""
parameter_list = OrderedDict([
parameter_list = dict([
("tau_main", (
"float",
"e-folding time of the main stellar population model in Myr.",
......@@ -54,7 +53,7 @@ class SFHDelayed(CreationModule):
))
])
out_parameter_list = OrderedDict([
out_parameter_list = dict([
("tau_main", "e-folding time of the main stellar population model "
"in Myr."),
("age", "Age of the oldest stars in the galaxy in Myr."),
......
......@@ -13,7 +13,6 @@ This module reads the star formation history in a file.
from astropy.table import Table
import numpy as np
from collections import OrderedDict
from ..utils import read_table
from . import CreationModule