Commit b517d0bb authored by Yannick Roehlly's avatar Yannick Roehlly

Move pcigale.sed.modules to pcigale.creation_modules

Move the SED creation modules to pcigale.creation_modules to be more
consistent with the analysis module location.
parent 9058940d
......@@ -12,7 +12,7 @@ Contents:
:maxdepth: 2
usage/index
sed_modules/index
creation_modules/index
stat_modules/index
database/index
programmer/index
......
......@@ -25,7 +25,7 @@ directory with that content:
# Order of the modules use for SED creation. Available modules : bc03,
# dh2002, dl2007, dustatt_calzleit, dustatt_powerlaw, igmattenuation,
# lines, loadfile, m2005, sfh2exp, sfhfromfile.
sed_modules = ,
creation_modules = ,
# Module used to redshift the SED before the integration in the filters.
# This is a SED creation module that accepts a 'redshift' parameter (see
......@@ -45,7 +45,7 @@ You need to edit this file to complete:
in the pcigale database. When a column is the error associated with a
filter, its name must prefix the filter name with *_err*.
* *sed_modules* is the list of pcigale SED creation modules, **in the right
* *creation_modules* is the list of pcigale SED creation modules, **in the right
order**, that will be used to create the theoretical SED (see the various
module documentations). The comments above the entry list the available
modules.
......@@ -69,7 +69,7 @@ Here is a sample completed minimal configuration file:
# Order of the modules use for SED creation. Available modules : bc03,
# dh2002, dl2007, dustatt_calzleit, dustatt_powerlaw, igmattenuation,
# lines, loadfile, m2005, sfh2exp, sfhfromfile.
sed_modules = sfh2exp, m2005, dustatt_calzleit, dh2002
creation_modules = sfh2exp, m2005, dustatt_calzleit, dh2002
# Module used to redshift the SED before the integration in the filters.
# This is a SED creation module that accepts a 'redshift' parameter (see
......@@ -97,7 +97,7 @@ will become something like this:
# Order of the modules use for SED creation. Available modules : bc03,
# dh2002, dl2007, dustatt_calzleit, dustatt_powerlaw, igmattenuation,
# lines, loadfile, m2005, sfh2exp, sfhfromfile.
sed_modules = sfh2exp, m2005, dustatt_calzleit, dh2002
creation_modules = sfh2exp, m2005, dustatt_calzleit, dh2002
# Module used to redshift the SED before the integration in the filters.
# This is a SED creation module that accepts a 'redshift' parameter (see
......@@ -216,7 +216,7 @@ if you want to use some filters but not the error, delete the error column
names.
To each module is associated a set of parameters (see
:doc:`/sed_modules/index`). You may give a list of possible values for each
:doc:`/creation_modules/index`). You may give a list of possible values for each
one, separated by commas. pcigale will compute all the possible combination of
parameter values and create the corresponding SED that will be compared to
your observations.
......
......@@ -30,23 +30,23 @@ def check(config):
# TODO : Check if all the parameters that don't have default values are
# given for each module.
print ("With this configuration, pcigale must compute {} "
"SEDs.".format(len(config.sed_modules_conf_array)))
"SEDs.".format(len(config.creation_modules_conf_array)))
def run(config):
"Run the analysis."
data_file = config.configuration['data_file']
column_list = config.configuration['column_list']
sed_modules = config.configuration['sed_modules']
sed_modules_params = config.sed_modules_conf_array
creation_modules = config.configuration['creation_modules']
creation_modules_params = config.creation_modules_conf_array
redshift_module = config.configuration['redshift_module']
redshift_configuration = config.configuration['redshift_configuration']
analysis_module = get_analysis_module(config.configuration[
'analysis_method'])
analysis_module_params = config.configuration['analysis_method_params']
analysis_module.process(data_file, column_list, sed_modules,
sed_modules_params, redshift_module,
analysis_module.process(data_file, column_list, creation_modules,
creation_modules_params, redshift_module,
redshift_configuration, analysis_module_params)
......
......@@ -28,8 +28,8 @@ class AnalysisModule(object):
# module parameter.
self.parameters = kwargs
def _process(self, data_file, column_list, sed_modules,
sed_modules_params, redshift_module,
def _process(self, data_file, column_list, creation_modules,
creation_modules_params, redshift_module,
redshift_configuration, parameters):
"""Do the actual analysis
......@@ -42,13 +42,13 @@ class AnalysisModule(object):
Name of the file containing the observations to be fitted.
column_list : array of strings
Names of the columns from the data file to use in the analysis.
sed_modules : array of strings
creation_modules : array of strings
Names (in the right order) of the modules to use to build the SED.
sed_modules_params : array of array of dictionaries
creation_modules_params : array of array of dictionaries
Array containing all the possible combinations of configurations
for the sed_modules. Each 'inner' array has the same length as the
sed_modules array and contains the configuration dictionary for
the corresponding module.
for the creation_modules. Each 'inner' array has the same length as
the creation_modules array and contains the configuration dictionary
for the corresponding module.
redshift_module : string
Name of the module used to redshift the SED.
redshift_configuration : dictionary
......@@ -63,8 +63,8 @@ class AnalysisModule(object):
"""
raise NotImplementedError()
def process(self, data_file, column_list, sed_modules,
sed_modules_params, redshift_module,
def process(self, data_file, column_list, creation_modules,
creation_modules_params, redshift_module,
redshift_configuration, parameters):
"""Process with the analysis
......@@ -79,13 +79,13 @@ class AnalysisModule(object):
Name of the file containing the observations to be fitted.
column_list : array of strings
Names of the columns from the data file to use in the analysis.
sed_modules : array of strings
creation_modules : array of strings
Names (in the right order) of the modules to use to build the SED.
sed_modules_params : array of array of dictionaries
creation_modules_params : array of array of dictionaries
Array containing all the possible combinations of configurations
for the sed_modules. Each 'inner' array has the same length as the
sed_modules array and contains the configuration dictionary for
the corresponding module.
for the creation_modules. Each 'inner' array has the same length as
the creation_modules array and contains the configuration
dictionary for the corresponding module.
redshift_module : string
Name of the module used to redshift the SED.
redshift_configuration : dictionary
......@@ -132,8 +132,8 @@ class AnalysisModule(object):
"expected one." + message)
#We do the actual processing
self._process(data_file, column_list, sed_modules,
sed_modules_params, redshift_module,
self._process(data_file, column_list, creation_modules,
creation_modules_params, redshift_module,
redshift_configuration, parameters)
......
......@@ -30,7 +30,7 @@ from progressbar import ProgressBar
from matplotlib import pyplot as plt
from . import common
from ..warehouse import SedWarehouse
from ..sed.modules.common import get_module
from ..creation_modules.common import get_module
from ..data import Database
......@@ -102,8 +102,8 @@ class Module(common.AnalysisModule):
))
])
def process(self, data_file, column_list, sed_modules,
sed_modules_params, redshift_module_name,
def process(self, data_file, column_list, creation_modules,
creation_modules_params, redshift_module_name,
redshift_configuration, parameters):
"""Process with the psum analysis.
......@@ -117,10 +117,10 @@ class Module(common.AnalysisModule):
Name of the file containing the observations to fit.
column_list: list of strings
Name of the columns from the data file to use for the analysis.
sed_modules: list of strings
creation_modules: list of strings
List of the module names (in the right order) to use for creating
the SEDs.
sed_modules_params: list of dictionaries
creation_modules_params: list of dictionaries
List of the parameter dictionaries for each module.
redshift_module_name : string
Name of the module used to redshift the SED.
......@@ -163,7 +163,8 @@ class Module(common.AnalysisModule):
# observation. This table contains the parameters of the SED as well as
# the value for the analysed variables.
out_bestsed_columns = ["id"]
for module_param_list in zip(sed_modules, sed_modules_params[0]):
for module_param_list in zip(creation_modules,
creation_modules_params[0]):
for module_param in product([module_param_list[0]],
module_param_list[1].keys()):
out_bestsed_columns.append(".".join(module_param))
......@@ -211,15 +212,15 @@ class Module(common.AnalysisModule):
# data table row index) and axis 3 is the considered variable (based
# on the analysed variables list + reduced_chi2, probability and
# galaxy_mass at the beginning).
comp_table = np.zeros((len(sed_modules_params),
comp_table = np.zeros((len(creation_modules_params),
obs_table.data.shape[0],
len(analysed_variables) + 3), dtype=float)
comp_table[:, :, :] = np.nan
# We loop over all the possible theoretical SEDs
progress_bar = ProgressBar(maxval=len(sed_modules_params)).start()
for model_index, parameters in enumerate(sed_modules_params):
sed = sed_warehouse.get_sed(sed_modules, parameters)
progress_bar = ProgressBar(maxval=len(creation_modules_params)).start()
for model_index, parameters in enumerate(creation_modules_params):
sed = sed_warehouse.get_sed(creation_modules, parameters)
# Compute the reduced Chi-square, the galaxy mass (normalisation
# factor) and probability for each observed SEDs. Add these and
......@@ -281,8 +282,8 @@ class Module(common.AnalysisModule):
best_index = comp_table[:, obs_index, 0].argmin()
best_chi2 = comp_table[best_index, obs_index, 0]
best_norm_factor = comp_table[best_index, obs_index, 2]
best_params = sed_modules_params[best_index]
best_sed = sed_warehouse.get_sed(sed_modules, best_params)
best_params = creation_modules_params[best_index]
best_sed = sed_warehouse.get_sed(creation_modules, best_params)
# We need to pass the SED through the redshit/IGM module before
# plotting it.
obs_redshift = obs_table['redshift'][obs_index]
......@@ -319,7 +320,7 @@ class Module(common.AnalysisModule):
verbose=False)
# Write the SED modules parameters to a file
with open(OUT_DIR + obs_name + "bestSED.params", "w") as f:
f.write(json.dumps(zip(sed_modules, best_params),
f.write(json.dumps(zip(creation_modules, best_params),
indent=2,
separators=(',', ': ')))
......
......@@ -49,8 +49,8 @@ class Module(common.AnalysisModule):
))
])
def process(self, data_file, column_list, sed_modules,
sed_modules_params, redshift_module,
def process(self, data_file, column_list, creation_modules,
creation_modules_params, redshift_module,
redshift_configuration, parameters):
"""Process with the savedfluxes analysis.
......@@ -64,10 +64,10 @@ class Module(common.AnalysisModule):
Name of the file containing the observations to fit.
column_list: list of strings
Name of the columns from the data file to use for the analysis.
sed_modules: list of strings
creation_modules: list of strings
List of the module names (in the right order) to use for creating
the SEDs.
sed_modules_params: list of dictionaries
creation_modules_params: list of dictionaries
List of the parameter dictionaries for each module.
redshift_module_name : string
Name of the module used to redshift the SED.
......@@ -99,7 +99,8 @@ class Module(common.AnalysisModule):
# Columns of the output table
out_columns = []
for module_param_list in zip(sed_modules, sed_modules_params[0]):
for module_param_list in zip(creation_modules,
creation_modules_params[0]):
for module_param in product([module_param_list[0]],
module_param_list[1].keys()):
out_columns.append(".".join(module_param))
......@@ -113,9 +114,9 @@ class Module(common.AnalysisModule):
cache_type=parameters["storage_type"])
# We loop over all the possible theoretical SEDs
progress_bar = ProgressBar(maxval=len(sed_modules_params)).start()
for model_index, parameters in enumerate(sed_modules_params):
sed = sed_warehouse.get_sed(sed_modules, parameters)
progress_bar = ProgressBar(maxval=len(creation_modules_params)).start()
for model_index, parameters in enumerate(creation_modules_params):
sed = sed_warehouse.get_sed(creation_modules, parameters)
row = []
......
......@@ -6,7 +6,7 @@
import numpy as np
from collections import OrderedDict
from . import common
from ...data import Database
from ..data import Database
class Module(common.SEDCreationModule):
......
......@@ -181,13 +181,13 @@ def get_module(name, **kwargs):
Returns
-------
a pcigale.sed.modules.Module instance
a pcigale.creation_modules.Module instance
"""
# Determine the real module name by removing the dotted prefix.
module_name = name.split('.')[0]
try:
module = import_module("." + module_name, 'pcigale.sed.modules')
module = import_module("." + module_name, 'pcigale.creation_modules')
return module.Module(name=name, **kwargs)
except ImportError:
print('Module ' + module_name + ' does not exists!')
......
......@@ -5,7 +5,7 @@
from collections import OrderedDict
from . import common
from ...data import Database
from ..data import Database
class Module(common.SEDCreationModule):
......
......@@ -6,7 +6,7 @@
import numpy as np
from collections import OrderedDict
from . import common
from ...data import Database
from ..data import Database
def k_calzetti2000(wavelength):
......
......@@ -12,7 +12,7 @@ in Charlot and Fall (2000) with a UV bump added.
import numpy as np
from collections import OrderedDict
from . import common
from ...data import Database
from ..data import Database
def power_law(wavelength, delta):
......
......@@ -6,8 +6,8 @@
import numpy as np
from collections import OrderedDict
from . import common
from .. import utils
from ...extern.lsst import Sed as lsst
from ..sed import utils
from ..extern.lsst import Sed as lsst
class Module(common.SEDCreationModule):
......
......@@ -6,7 +6,7 @@
import numpy as np
from collections import OrderedDict
from . import common
from ...data import Database
from ..data import Database
class Module(common.SEDCreationModule):
......
......@@ -13,7 +13,7 @@ import numpy as np
from textwrap import wrap
from .tools import param_dict_combine
from ..data import Database
from ..sed.modules import common as modules
from ..creation_modules import common as modules
from ..analysis_modules import common as analysis
......@@ -23,7 +23,7 @@ def list_modules(package_name):
Parameters
----------
package_name : string
Name of the package (e.g. pcigale.sed.modules).
Name of the package (e.g. pcigale.creation_modules).
Returns
-------
......@@ -124,10 +124,10 @@ class Configuration(object):
"error columns are suffixed with '_err'. The values must be "
"in mJy.")
self.config['sed_modules'] = []
self.config.comments['sed_modules'] = [""] + wrap(
self.config['creation_modules'] = []
self.config.comments['creation_modules'] = [""] + wrap(
"Order of the modules use for SED creation. Available modules : "
+ ', '.join(list_modules('pcigale.sed.modules')) + ".")
+ ', '.join(list_modules('pcigale.creation_modules')) + ".")
self.config['redshift_module'] = ""
self.config.comments['redshift_module'] = [""] + wrap(
......@@ -182,7 +182,7 @@ class Configuration(object):
self.config.comments['sed_creation_modules'] = ["", ""] + wrap(
"Configuration of the SED creation modules.")
for module_name in self.config['sed_modules']:
for module_name in self.config['creation_modules']:
self.config["sed_creation_modules"][module_name] = {}
sub_config = self.config["sed_creation_modules"][module_name]
......@@ -236,9 +236,9 @@ class Configuration(object):
File containing the observations to fit.
configuration['column_list'] : list of strings
List of the columns of data_file to use in the fitting.
configuration['sed_modules'] : list of strings
configuration['creation_modules'] : list of strings
List of the modules (in the right order) used to create the SEDs.
configuration['sed_modules_params'] : list of dictionaries
configuration['creation_modules_params'] : list of dictionaries
Configuration parameters for each module. To each parameter, the
dictionary associates a list of possible values (possibly only
one).
......@@ -253,18 +253,18 @@ class Configuration(object):
"""
configuration = {}
for section in ['data_file', 'column_list', 'sed_modules',
for section in ['data_file', 'column_list', 'creation_modules',
'redshift_module', 'analysis_method']:
configuration[section] = self.config[section]
# Parsing the SED modules parameters
configuration['sed_modules_params'] = []
for module in self.config['sed_modules']:
configuration['creation_modules_params'] = []
for module in self.config['creation_modules']:
module_params = {}
for key, value in \
self.config['sed_creation_modules'][module].items():
module_params[key] = evaluate_description(value)
configuration['sed_modules_params'].append(module_params)
configuration['creation_modules_params'].append(module_params)
# We don't need to "evaluate" the configuration values for the
# redshit and analysis modules as we don't expect multiple values here.
configuration['redshift_configuration'] = \
......@@ -275,7 +275,7 @@ class Configuration(object):
return configuration
@property
def sed_modules_conf_array(self):
def creation_modules_conf_array(self):
"""Return the array of all the possible parameter sets from the
SED creation modules.
......@@ -287,7 +287,7 @@ class Configuration(object):
-------
result : array of arrays of dictionaries
The inner arrays contains the various parameter dictionaries
for the modules listed in configuration['sed_modules'].
for the modules listed in configuration['creation_modules'].
"""
......@@ -296,7 +296,7 @@ class Configuration(object):
# containing one value for each parameter. We put this list in a list
# corresponding to the SED modules one.
tmp_list = [param_dict_combine(dictionary) for dictionary in
self.configuration['sed_modules_params']]
self.configuration['creation_modules_params']]
# The we use itertools to create an array of all possible
# combinations.
......
......@@ -5,7 +5,7 @@
from json import JSONEncoder
from ..sed import SED
from ..sed.modules import common as sed_modules
from ..creation_modules import common as creation_modules
class SedWarehouse(object):
......@@ -45,7 +45,7 @@ class SedWarehouse(object):
Returns
-------
a pcigale.sed.modules.Module instance
a pcigale.creation_modules.Module instance
"""
# JSon representation of the tuple (name, parameters) used as a key
......@@ -56,7 +56,7 @@ class SedWarehouse(object):
if module_key in self.module_cache:
module = self.module_cache[module_key]
else:
module = sed_modules.get_module(name, **kwargs)
module = creation_modules.get_module(name, **kwargs)
self.module_cache[module_key] = module
return module
......
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