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

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 @@ ...@@ -5,7 +5,6 @@
# Author: Yannick Roehlly & Denis Burgarella # Author: Yannick Roehlly & Denis Burgarella
from importlib import import_module from importlib import import_module
from collections import OrderedDict
import numpy as np import numpy as np
from scipy import stats from scipy import stats
from astropy.table import Column from astropy.table import Column
...@@ -15,13 +14,13 @@ class AnalysisModule(object): ...@@ -15,13 +14,13 @@ class AnalysisModule(object):
"""Abstract class, the pCigale analysis modules are based on. """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 # used by the module. Each parameter name is associate to a tuple
# (variable type, description [string], default value). Each module must # (variable type, description [string], default value). Each module must
# define its parameter list, unless it does not use any parameter. Using # 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 # None means that there is no description, unit or default value. If None
# should be the default value, use the 'None' string instead. # should be the default value, use the 'None' string instead.
parameter_list = OrderedDict() parameter_list = dict()
def __init__(self, **kwargs): def __init__(self, **kwargs):
"""Instantiate a analysis module """Instantiate a analysis module
......
...@@ -25,7 +25,6 @@ reduced χ²) is given for each observation. ...@@ -25,7 +25,6 @@ reduced χ²) is given for each observation.
""" """
from collections import OrderedDict
import ctypes import ctypes
import multiprocessing as mp import multiprocessing as mp
from multiprocessing.sharedctypes import RawArray from multiprocessing.sharedctypes import RawArray
...@@ -54,7 +53,7 @@ REDSHIFT_DECIMALS = 2 ...@@ -54,7 +53,7 @@ REDSHIFT_DECIMALS = 2
class PdfAnalysis(AnalysisModule): class PdfAnalysis(AnalysisModule):
"""PDF analysis module""" """PDF analysis module"""
parameter_list = OrderedDict([ parameter_list = dict([
("analysed_variables", ( ("analysed_variables", (
"array of strings", "array of strings",
"List of the variables (in the SEDs info dictionaries) for which " "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, ...@@ -149,7 +149,7 @@ def save_table_best(filename, obsid, chi2, chi2_red, variables, fluxes,
All variables corresponding to a SED All variables corresponding to a SED
fluxes: RawArray fluxes: RawArray
Fluxes in all bands for each object Fluxes in all bands for each object
filters: OrderedDict filters: list
Filters used to compute the fluxes Filters used to compute the fluxes
info_keys: list info_keys: list
Parameters names Parameters names
......
...@@ -84,7 +84,7 @@ def init_analysis(params, filters, analysed, redshifts, fluxes, variables, ...@@ -84,7 +84,7 @@ def init_analysis(params, filters, analysed, redshifts, fluxes, variables,
---------- ----------
params: ParametersHandler params: ParametersHandler
Handles the parameters from a 1D index. Handles the parameters from a 1D index.
filters: OrderedDict filters: list
Contains filters to compute the fluxes. Contains filters to compute the fluxes.
analysed: list analysed: list
Variable names to be analysed Variable names to be analysed
......
...@@ -14,7 +14,6 @@ parameters. ...@@ -14,7 +14,6 @@ parameters.
The data file is used only to get the list of fluxes to be computed. The data file is used only to get the list of fluxes to be computed.
""" """
from collections import OrderedDict
import ctypes import ctypes
from datetime import datetime from datetime import datetime
from itertools import product, repeat from itertools import product, repeat
...@@ -44,7 +43,7 @@ class SaveFluxes(AnalysisModule): ...@@ -44,7 +43,7 @@ class SaveFluxes(AnalysisModule):
""" """
parameter_list = OrderedDict([ parameter_list = dict([
("output_file", ( ("output_file", (
"string", "string",
"Name of the output file that contains the parameters of the " "Name of the output file that contains the parameters of the "
......
...@@ -34,8 +34,8 @@ class ParametersHandler(object): ...@@ -34,8 +34,8 @@ class ParametersHandler(object):
---------- ----------
modules: list modules: list
Contains the modules in the order they are called Contains the modules in the order they are called
params: OrderedDict params: list of dictionaries
Contains a list of parameters for each module Contains a dictionary of parameters for each module
""" """
self.modules = modules self.modules = modules
...@@ -61,7 +61,7 @@ class ParametersHandler(object): ...@@ -61,7 +61,7 @@ class ParametersHandler(object):
""" """
# We make a copy of the dictionary as we are modifying it. # 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 # First, we must ensure that all values are lists; when a value is a
# single element, we put it in a list. # single element, we put it in a list.
...@@ -76,7 +76,7 @@ class ParametersHandler(object): ...@@ -76,7 +76,7 @@ class ParametersHandler(object):
# the value lists. # the value lists.
key_list = dictionary.keys() key_list = dictionary.keys()
value_array_list = [dictionary[key] for key in key_list] 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 for combination in
itertools.product(*value_array_list)] itertools.product(*value_array_list)]
...@@ -151,8 +151,8 @@ def save_fluxes(model_fluxes, model_parameters, filters, names, filename, ...@@ -151,8 +151,8 @@ def save_fluxes(model_fluxes, model_parameters, filters, names, filename,
Contains the fluxes of each model. Contains the fluxes of each model.
model_parameters: RawArray model_parameters: RawArray
Contains the parameters associated to each model. Contains the parameters associated to each model.
filters: OrderedDict filters: list
Contains the filters. Contains the filter names.
names: List names: List
Contains the parameters names. Contains the parameters names.
filename: str filename: str
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
import os import os
import inspect import inspect
from importlib import import_module from importlib import import_module
from collections import OrderedDict
def complete_parameters(given_parameters, parameter_list): def complete_parameters(given_parameters, parameter_list):
...@@ -24,12 +23,12 @@ def complete_parameters(given_parameters, parameter_list): ...@@ -24,12 +23,12 @@ def complete_parameters(given_parameters, parameter_list):
---------- ----------
given_parameters: dictionary given_parameters: dictionary
Parameter dictionary used to configure the module. Parameter dictionary used to configure the module.
parameter_list: OrderedDict parameter_list: dictionary
Parameter list from the module. Parameter list from the module.
Returns Returns
------- -------
parameters: OrderedDict parameters: dict
Ordered dictionary combining the given parameters with the default Ordered dictionary combining the given parameters with the default
values for the missing ones. values for the missing ones.
...@@ -61,7 +60,7 @@ def complete_parameters(given_parameters, parameter_list): ...@@ -61,7 +60,7 @@ def complete_parameters(given_parameters, parameter_list):
"expected one. " + message) "expected one. " + message)
# We want the result to be ordered as the parameter_list of the module is. # We want the result to be ordered as the parameter_list of the module is.
result = OrderedDict() result = dict()
for key in parameter_list: for key in parameter_list:
result[key] = given_parameters[key] result[key] = given_parameters[key]
...@@ -72,21 +71,21 @@ class CreationModule(object): ...@@ -72,21 +71,21 @@ class CreationModule(object):
"""Abstract class, the pCigale SED creation modules are based on. """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 # used by the module. Each parameter name is associate to a tuple
# (variable type, description [string], default value). Each module must # (variable type, description [string], default value). Each module must
# define its parameter list, unless it does not use any parameter. Using # 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 # None means that there is no description or default value. If None should
# be the default value, use the 'None' string instead. # 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 # parameters that are added to the SED info dictionary and for which a
# statistical analysis may be done. Each parameter name is associated with # statistical analysis may be done. Each parameter name is associated with
# its description. In the SED info dictionary, the parameter name in # its description. In the SED info dictionary, the parameter name in
# is postfixed with a same postfix used in the module name, to allow # is postfixed with a same postfix used in the module name, to allow
# the use of repeated modules. # 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 # 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 # the configuration file. For instance, it can be used to give special
......
...@@ -13,7 +13,6 @@ Populations. ...@@ -13,7 +13,6 @@ Populations.
""" """
import numpy as np import numpy as np
from collections import OrderedDict
from . import CreationModule from . import CreationModule
from ..data import Database from ..data import Database
...@@ -26,7 +25,7 @@ class BC03(CreationModule): ...@@ -26,7 +25,7 @@ class BC03(CreationModule):
component to the SED. component to the SED.
""" """
parameter_list = OrderedDict([ parameter_list = dict([
("imf", ( ("imf", (
"int", "int",
"Initial mass function: 0 (Salpeter) or 1 (Chabrier).", "Initial mass function: 0 (Salpeter) or 1 (Chabrier).",
...@@ -47,7 +46,7 @@ class BC03(CreationModule): ...@@ -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, " ("sfr", "Instantaneous Star Formation Rate in solar mass per year, "
"at the age of the galaxy."), "at the age of the galaxy."),
('sfr10Myrs', 'Average SFR in the last 10 Myr (default) of the ' ('sfr10Myrs', 'Average SFR in the last 10 Myr (default) of the '
......
...@@ -14,7 +14,6 @@ This module implements the Casey (2012) infra-red models. ...@@ -14,7 +14,6 @@ This module implements the Casey (2012) infra-red models.
import numpy as np import numpy as np
import scipy.constants as cst import scipy.constants as cst
from collections import OrderedDict
from . import CreationModule from . import CreationModule
...@@ -27,7 +26,7 @@ class Casey2012(CreationModule): ...@@ -27,7 +26,7 @@ class Casey2012(CreationModule):
""" """
parameter_list = OrderedDict([ parameter_list = dict([
("temperature", ( ("temperature", (
"float", "float",
"Temperature of the dust in K.", "Temperature of the dust in K.",
...@@ -45,7 +44,7 @@ class Casey2012(CreationModule): ...@@ -45,7 +44,7 @@ class Casey2012(CreationModule):
)) ))
]) ])
out_parameter_list = OrderedDict([ out_parameter_list = dict([
("temperature", "Temperature of the dust in K."), ("temperature", "Temperature of the dust in K."),
("beta", "Emissivity index of the dust."), ("beta", "Emissivity index of the dust."),
("alpha", "Mid-infrared powerlaw slope.") ("alpha", "Mid-infrared powerlaw slope.")
......
...@@ -11,7 +11,6 @@ This module implements the Dale (2014) infra-red models. ...@@ -11,7 +11,6 @@ This module implements the Dale (2014) infra-red models.
""" """
from collections import OrderedDict
from pcigale.data import Database from pcigale.data import Database
from . import CreationModule from . import CreationModule
...@@ -28,7 +27,7 @@ class Dale2014(CreationModule): ...@@ -28,7 +27,7 @@ class Dale2014(CreationModule):
""" """
parameter_list = OrderedDict([ parameter_list = dict([
('fracAGN', ( ('fracAGN', (
'float', 'float',
"AGN fraction. It is not recommended to combine this AGN emission " "AGN fraction. It is not recommended to combine this AGN emission "
...@@ -50,7 +49,7 @@ class Dale2014(CreationModule): ...@@ -50,7 +49,7 @@ class Dale2014(CreationModule):
)) ))
]) ])
out_parameter_list = OrderedDict([ out_parameter_list = dict([
('fracAGN', 'Contribution of the AGN'), ('fracAGN', 'Contribution of the AGN'),
('alpha', 'Alpha slope'), ('alpha', 'Alpha slope'),
('lir', 'Total IR luminosity between 8 and 1000 microns (AGN + SB)') ('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. ...@@ -12,7 +12,6 @@ This module implements the Draine and Li (2007) infra-red models.
""" """
from collections import OrderedDict
import numpy as np import numpy as np
from pcigale.data import Database from pcigale.data import Database
from . import CreationModule from . import CreationModule
...@@ -30,7 +29,7 @@ class DL2007(CreationModule): ...@@ -30,7 +29,7 @@ class DL2007(CreationModule):
""" """
parameter_list = OrderedDict([ parameter_list = dict([
('qpah', ( ('qpah', (
'float', 'float',
"Mass fraction of PAH. Possible values are: 0.47, 1.12, 1.77, " "Mass fraction of PAH. Possible values are: 0.47, 1.12, 1.77, "
...@@ -58,7 +57,7 @@ class DL2007(CreationModule): ...@@ -58,7 +57,7 @@ class DL2007(CreationModule):
)) ))
]) ])
out_parameter_list = OrderedDict([ out_parameter_list = dict([
('qpah', 'Mass fraction of PAH'), ('qpah', 'Mass fraction of PAH'),
('umin', 'Minimum radiation field'), ('umin', 'Minimum radiation field'),
('umax', 'Maximum radiation field'), ('umax', 'Maximum radiation field'),
......
...@@ -12,7 +12,6 @@ This module implements the updated Draine and Li (2007) infrared models. ...@@ -12,7 +12,6 @@ This module implements the updated Draine and Li (2007) infrared models.
""" """
from collections import OrderedDict
import numpy as np import numpy as np
from pcigale.data import Database from pcigale.data import Database
from . import CreationModule from . import CreationModule
...@@ -30,7 +29,7 @@ class DL2014(CreationModule): ...@@ -30,7 +29,7 @@ class DL2014(CreationModule):
""" """
parameter_list = OrderedDict([ parameter_list = dict([
('qpah', ( ('qpah', (
'float', 'float',
"Mass fraction of PAH. Possible values are: 0.47, 1.12, 1.77, " "Mass fraction of PAH. Possible values are: 0.47, 1.12, 1.77, "
...@@ -61,7 +60,7 @@ class DL2014(CreationModule): ...@@ -61,7 +60,7 @@ class DL2014(CreationModule):
)) ))
]) ])
out_parameter_list = OrderedDict([ out_parameter_list = dict([
('qpah', 'Mass fraction of PAH'), ('qpah', 'Mass fraction of PAH'),
('umin', 'Minimum radiation field'), ('umin', 'Minimum radiation field'),
('alpha', 'Power law slope dU/dM∝U¯ᵅ'), ('alpha', 'Power law slope dU/dM∝U¯ᵅ'),
......
...@@ -14,7 +14,6 @@ attenuation formulae, adding an UV-bump and a power law. ...@@ -14,7 +14,6 @@ attenuation formulae, adding an UV-bump and a power law.
""" """
import numpy as np import numpy as np
from collections import OrderedDict
from . import CreationModule from . import CreationModule
...@@ -179,7 +178,7 @@ class CalzLeit(CreationModule): ...@@ -179,7 +178,7 @@ class CalzLeit(CreationModule):
""" """
parameter_list = OrderedDict([ parameter_list = dict([
("E_BVs_young", ( ("E_BVs_young", (
"float", "float",
"E(B-V)*, the colour excess of the stellar continuum light for " "E(B-V)*, the colour excess of the stellar continuum light for "
...@@ -221,7 +220,7 @@ class CalzLeit(CreationModule): ...@@ -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 " ("E_BVs", "E(B-V), the colour excess of the stellar continuum "
"light for each population."), "light for each population."),
("E_BVs_old_factor", "Ratio of the old population E(B-V) to the " ("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. ...@@ -14,7 +14,6 @@ in Charlot and Fall (2000) with a UV bump added.
""" """
import numpy as np import numpy as np
from collections import OrderedDict
from . import CreationModule from . import CreationModule
...@@ -105,7 +104,7 @@ class PowerLawAtt(CreationModule): ...@@ -105,7 +104,7 @@ class PowerLawAtt(CreationModule):
""" """
parameter_list = OrderedDict([ parameter_list = dict([
("Av_young", ( ("Av_young", (
"float", "float",
"V-band attenuation of the young population.", "V-band attenuation of the young population.",
...@@ -146,7 +145,7 @@ class PowerLawAtt(CreationModule): ...@@ -146,7 +145,7 @@ class PowerLawAtt(CreationModule):
)) ))
]) ])
out_parameter_list = OrderedDict([ out_parameter_list = dict([
("Av", "V-band attenuation."), ("Av", "V-band attenuation."),
("Av_old_factor", "Reduction factor for the V-band attenuation " ("Av_old_factor", "Reduction factor for the V-band attenuation "
"of the old population compared to the young " "of the old population compared to the young "
......
...@@ -11,7 +11,6 @@ This module implements the Fritz et al. (2006) models. ...@@ -11,7 +11,6 @@ This module implements the Fritz et al. (2006) models.
""" """
import numpy as np import numpy as np
from collections import OrderedDict
from pcigale.data import Database from pcigale.data import Database
from . import CreationModule from . import CreationModule
from pcigale.sed.cosmology import cosmology from pcigale.sed.cosmology import cosmology
...@@ -39,7 +38,7 @@ class Fritz2006(CreationModule): ...@@ -39,7 +38,7 @@ class Fritz2006(CreationModule):
""" """
parameter_list = OrderedDict([ parameter_list = dict([
('r_ratio', ( ('r_ratio', (
'float', 'float',
"Ratio of the maximum to minimum radii of the dust torus. " "Ratio of the maximum to minimum radii of the dust torus. "
...@@ -83,7 +82,7 @@ class Fritz2006(CreationModule): ...@@ -83,7 +82,7 @@ class Fritz2006(CreationModule):
)) ))
]) ])
out_parameter_list = OrderedDict([ out_parameter_list = dict([
('fracAGN', 'Contribution of the AGN'), ('fracAGN', 'Contribution of the AGN'),
('agn.therm_luminosity', 'Luminosity of the AGN contribution due to ' ('agn.therm_luminosity', 'Luminosity of the AGN contribution due to '
'the dust torus'), 'the dust torus'),
......
...@@ -12,7 +12,6 @@ This module reads a SED spectrum from a file. ...@@ -12,7 +12,6 @@ This module reads a SED spectrum from a file.
""" """
from astropy.table import Table from astropy.table import Table
from collections import OrderedDict
from ..utils import read_table from ..utils import read_table
from . import CreationModule from . import CreationModule
...@@ -22,7 +21,7 @@ class LoadSpecFile(CreationModule): ...@@ -22,7 +21,7 @@ class LoadSpecFile(CreationModule):
""" """
parameter_list = OrderedDict([ parameter_list = dict([
("filename", ( ("filename", (
'str', 'str',
"Name of the file to load and to add to the SED table. This " "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. ...@@ -12,7 +12,6 @@ This module implements the Maraston (2005) Single Stellar Populations.
""" """
import numpy as np import numpy as np
from collections import OrderedDict
from . import CreationModule from . import CreationModule
from ..data import Database from ..data import Database