Commit b517d0bb authored by Yannick Roehlly's avatar Yannick Roehlly
Browse files

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):
......
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