Commit 0d883320 authored by Médéric Boquien's avatar Médéric Boquien

Pratical implementation of the validation of the parameters. The patch is...

Pratical implementation of the validation of the parameters. The patch is quite long as it has a direct effect on the structure of the configuration dictionary. The validation has the advantage of automatically convert the parameters to the right type. Therefore rather than building a dictionary ourselves, we rather use the ready-made dictionary from ConfigObj. Because the names of the sections are not the same, quite a bit of code had to be adapted. Finally, note that the validation file containing the specification of each variable, pcigale.ini.spec, is created while building the pcigale.ini file. Also because it is needed to convert the data to the right type, one cannot run cigale without a correct validation file.
parent 784a1690
......@@ -6,6 +6,7 @@
- Similarly to the savefluxes module, in the pdf_analysis module if the list of physical properties is left empty, all physical parameters are now analysed. (Médéric Boquien)
- It is now possible to pass the parameters of the models to be computed from a file rather than having to indicate them in pcigale.ini. This means that the models do not necessarily need to be computed on a systematic grid of parameters. The name of the file is passed as an argument to the parameters\_file keyword in pcigale.ini. If this is done, the creation\_modules argument is ignored. Finally, the file must be formatted as following: each row is a different model and each column a different parameter. They must follow the naming scheme: module\_name.parameter\_name, that is "bc03.imf" for instance. (Médéric Boquien)
- Addition of the schreiber2016 SED creation module implementing the Schreiber et al. (2016) dust models. (Laure Ciesla)
- The physical parameters provided in pcigale.ini were not checked at startup against what the modules could accept. This could lead to a runtime crash if an unexpected value was passed to the module. Now the parameters are checked at startup. If an issue is found, it is indicated and the user is asked to fix it before launching cigale again. The validation file is build at the same time as pcigale.ini. (Médéric Boquien)
### Changed
- The estimates of the physical parameters from the analysis of the PDF and from the best fit were recorded in separate files. This can be bothersome when trying to compare quantities from different files. Rather, we generate a single file containing all quantities. The ones estimated from the analysis of the PDF are prefixed with "bayes" and the ones from the best fit with "best". (Médéric Boquien)
......
......@@ -37,16 +37,20 @@ def check(config):
# TODO: Check if all the parameters that don't have default values are
# given for each module.
configuration = config.configuration
print("With this configuration cigale will compute {} "
"models.".format(ParametersHandler(configuration).size))
if configuration:
print("With this configuration cigale will compute {} "
"models.".format(ParametersHandler(configuration).size))
def run(config):
"""Run the analysis.
"""
configuration = config.configuration
analysis_module = get_module(configuration['analysis_method'])
analysis_module.process(configuration)
if configuration:
analysis_module = get_module(configuration['analysis_method'])
analysis_module.process(configuration)
def main():
......
......@@ -71,7 +71,7 @@ class AnalysisModule(object):
KeyError: when not all the needed parameters are given.
"""
parameters = configuration['analysis_method_params']
parameters = configuration['analysis_params']
# For parameters that are present on the parameter_list with a default
# value and that are not in the parameters dictionary, we add them
# with their default value.
......
......@@ -66,13 +66,13 @@ class PdfAnalysis(AnalysisModule):
False
)),
("save_chi2", (
"boolean{}",
"boolean()",
"If true, for each observation and each analysed variable save "
"the reduced chi2.",
False
)),
("save_pdf", (
"boolean{}",
"boolean()",
"If true, for each observation and each analysed variable save "
"the probability density function.",
False
......@@ -115,16 +115,16 @@ class PdfAnalysis(AnalysisModule):
# Initalise variables from input arguments.
creation_modules = conf['creation_modules']
creation_modules_params = conf['creation_modules_params']
analysed_variables = conf['analysis_method_params']["analysed_variables"]
creation_modules_params = conf['sed_modules_params']
analysed_variables = conf['analysis_params']["analysed_variables"]
analysed_variables_nolog = [variable[:-4] if variable.endswith('_log')
else variable for variable in
analysed_variables]
n_variables = len(analysed_variables)
save = {key: conf['analysis_method_params']["save_{}".format(key)].lower() == "true"
for key in ["best_sed", "chi2", "pdf"]}
lim_flag = conf['analysis_method_params']["lim_flag"].lower() == "true"
mock_flag = conf['analysis_method_params']["mock_flag"].lower() == "true"
save = {key: conf['analysis_params']["save_{}".format(key)] for key in
["best_sed", "chi2", "pdf"]}
lim_flag = conf['analysis_params']["lim_flag"]
mock_flag = conf['analysis_params']["mock_flag"]
filters = [name for name in conf['column_list'] if not
name.endswith('_err')]
......@@ -137,8 +137,7 @@ class PdfAnalysis(AnalysisModule):
lim_flag)
n_obs = len(obs_table)
w_redshifting = creation_modules.index('redshifting')
z = np.array(creation_modules_params[w_redshifting]['redshift'])
z = np.array(creation_modules_params['redshifting']['redshift'])
# The parameters handler allows us to retrieve the models parameters
# from a 1D index. This is useful in that we do not have to create
......
......@@ -81,9 +81,9 @@ class SaveFluxes(AnalysisModule):
# Rename the output directory if it exists
backup_dir()
out_file = conf['analysis_method_params']['output_file']
out_format = conf['analysis_method_params']['output_format']
save_sed = conf['analysis_method_params']['save_sed'].lower() == "true"
out_file = conf['analysis_params']['output_file']
out_format = conf['analysis_params']['output_format']
save_sed = conf['analysis_params']['save_sed']
filters = [name for name in conf['column_list'] if not
name.endswith('_err')]
......@@ -97,7 +97,7 @@ class SaveFluxes(AnalysisModule):
params = ParametersHandler(conf)
n_params = params.size
info = conf['analysis_method_params']['variables']
info = conf['analysis_params']['variables']
n_info = len(info)
model_fluxes = (RawArray(ctypes.c_double, n_params * n_filters),
......
......@@ -33,6 +33,7 @@ def backup_dir(directory=OUT_DIR):
))
os.mkdir(directory)
shutil.copyfile('pcigale.ini', directory + 'pcigale.ini')
shutil.copyfile('pcigale.ini.spec', directory + 'pcigale.ini.spec')
def save_fluxes(model_fluxes, model_parameters, filters, names, filename,
......
......@@ -46,8 +46,8 @@ class ParametersHandlerGrid(object):
"""
self.modules = configuration['creation_modules']
self.parameters = [self._param_dict_combine(dictionary) for dictionary
in configuration['creation_modules_params']]
self.parameters = [self._param_dict_combine(configuration['sed_modules_params'][module])
for module in self.modules]
self.shape = tuple(len(parameter) for parameter in self.parameters)
self.size = int(np.product(self.shape))
......
This diff is collapsed.
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