Commit eabdd39f authored by Médéric Boquien's avatar Médéric Boquien

When the redshifts are not indicated in pcigale.ini, compute them from the...

When the redshifts are not indicated in pcigale.ini, compute them from the input flux file when the configuration dictionary is returned rather than in the analysis module, which should not have to change the configuration.
parent e0e09b8c
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
- The pcigale-mock tool has been merged into pcigale-plots; the mock plots can be obtained with the "mock" command. - The pcigale-mock tool has been merged into pcigale-plots; the mock plots can be obtained with the "mock" command.
- The sfhdelayed module is now initialised with _init_code() to be consistent with the way things are done in other modules. This should give a slight speedup under some sircumstances too. (Médéric Boquien) - The sfhdelayed module is now initialised with _init_code() to be consistent with the way things are done in other modules. This should give a slight speedup under some sircumstances too. (Médéric Boquien)
- In sfhfromfile, the specification of the time grid was vague and therefore could lead to incorrect results if it was not properly formatted by the end user. The description has been clarified and we now check that the time starts from 0 and that the time step is always 1 Myr. If it is not the case we raise an exception. (Médéric Boquien) - In sfhfromfile, the specification of the time grid was vague and therefore could lead to incorrect results if it was not properly formatted by the end user. The description has been clarified and we now check that the time starts from 0 and that the time step is always 1 Myr. If it is not the case we raise an exception. (Médéric Boquien)
- When the redshift is not indicated in pcigale.ini, the analysis module fills the list of redshifts from the redshifts indicated in the input flux file. This is inefficient as analysis modules should have have to modify the configuration. Now this is done when interpreting pcigale.ini before calling the relevant analysis module. As a side effect, "pigale check" now returns the total number of models that cigale will compute rather than the number of models per redshift bin. (Médéric Boquien)
### Fixed ### Fixed
- To estimate parameters in log, pcigale determines which variables end with the "_log" string and removed it to compute the models. However in some circumstances, it was overzealous. This has been fixed. (Médéric Boquien) - To estimate parameters in log, pcigale determines which variables end with the "_log" string and removed it to compute the models. However in some circumstances, it was overzealous. This has been fixed. (Médéric Boquien)
......
...@@ -36,18 +36,19 @@ def check(config): ...@@ -36,18 +36,19 @@ def check(config):
""" """
# TODO: Check if all the parameters that don't have default values are # TODO: Check if all the parameters that don't have default values are
# given for each module. # given for each module.
print("With this configuration, pcigale must compute {} " configuration = config.configuration
"SEDs.".format(ParametersHandler( print("With this configuration cigale will compute {} "
config.configuration['creation_modules'], "models.".format(ParametersHandler(
config.configuration['creation_modules_params'] configuration['creation_modules'],
).size)) configuration['creation_modules_params']).size))
def run(config): def run(config):
"""Run the analysis. """Run the analysis.
""" """
analysis_module = get_module(config.configuration['analysis_method']) configuration = config.configuration
analysis_module.process(config.configuration) analysis_module = get_module(configuration['analysis_method'])
analysis_module.process(configuration)
def main(): def main():
......
...@@ -45,8 +45,6 @@ from ..utils import ParametersHandler, backup_dir ...@@ -45,8 +45,6 @@ from ..utils import ParametersHandler, backup_dir
# Tolerance threshold under which any flux or error is considered as 0. # Tolerance threshold under which any flux or error is considered as 0.
TOLERANCE = 1e-12 TOLERANCE = 1e-12
# Limit the redshift to this number of decimals
REDSHIFT_DECIMALS = 2
class PdfAnalysis(AnalysisModule): class PdfAnalysis(AnalysisModule):
...@@ -137,12 +135,7 @@ class PdfAnalysis(AnalysisModule): ...@@ -137,12 +135,7 @@ class PdfAnalysis(AnalysisModule):
n_obs = len(obs_table) n_obs = len(obs_table)
w_redshifting = creation_modules.index('redshifting') w_redshifting = creation_modules.index('redshifting')
if list(creation_modules_params[w_redshifting]['redshift']) == ['']: z = np.array(creation_modules_params[w_redshifting]['redshift'])
z = np.unique(np.around(obs_table['redshift'],
decimals=REDSHIFT_DECIMALS))
creation_modules_params[w_redshifting]['redshift'] = z
else:
z = np.array(creation_modules_params[w_redshifting]['redshift'])
# The parameters handler allows us to retrieve the models parameters # 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 # from a 1D index. This is useful in that we do not have to create
......
...@@ -29,10 +29,6 @@ from .workers import init_fluxes as init_worker_fluxes ...@@ -29,10 +29,6 @@ from .workers import init_fluxes as init_worker_fluxes
from .workers import fluxes as worker_fluxes from .workers import fluxes as worker_fluxes
# Limit the redshift to this number of decimals
REDSHIFT_DECIMALS = 2
class SaveFluxes(AnalysisModule): class SaveFluxes(AnalysisModule):
"""Save fluxes analysis module """Save fluxes analysis module
...@@ -92,14 +88,6 @@ class SaveFluxes(AnalysisModule): ...@@ -92,14 +88,6 @@ class SaveFluxes(AnalysisModule):
name.endswith('_err')] name.endswith('_err')]
n_filters = len(filters) n_filters = len(filters)
w_redshifting = creation_modules.index('redshifting')
if list(creation_modules_params[w_redshifting]['redshift']) == ['']:
obs_table = read_table(conf['data_file'])
z = np.unique(np.around(obs_table['redshift'],
decimals=REDSHIFT_DECIMALS))
creation_modules_params[w_redshifting]['redshift'] = z
del obs_table, z
# The parameters handler allows us to retrieve the models parameters # 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 # from a 1D index. This is useful in that we do not have to create
# a list of parameters as they are computed on-the-fly. It also has # a list of parameters as they are computed on-the-fly. It also has
......
...@@ -18,6 +18,9 @@ from ..utils import read_table ...@@ -18,6 +18,9 @@ from ..utils import read_table
from .. import creation_modules from .. import creation_modules
from .. import analysis_modules from .. import analysis_modules
# Limit the redshift to this number of decimals
REDSHIFT_DECIMALS = 2
def list_modules(package_name): def list_modules(package_name):
"""Lists the modules available in a package """Lists the modules available in a package
...@@ -259,6 +262,10 @@ class Configuration(object): ...@@ -259,6 +262,10 @@ class Configuration(object):
""" """
configuration = {} configuration = {}
# Before building the configuration dictionary, we ensure that all the
# fields are filled
self.complete_conf()
for section in ['data_file', 'column_list', 'creation_modules', for section in ['data_file', 'column_list', 'creation_modules',
'analysis_method']: 'analysis_method']:
configuration[section] = self.config[section] configuration[section] = self.config[section]
...@@ -314,3 +321,20 @@ class Configuration(object): ...@@ -314,3 +321,20 @@ class Configuration(object):
self.config['creation_modules']]): self.config['creation_modules']]):
print("{} Options are: {}.". print("{} Options are: {}.".
format(comments[module], ', '.join(modules[module]))) format(comments[module], ', '.join(modules[module])))
def complete_conf(self):
"""Complete the configuration when there is missing information that is
to be extracted from other sources such as the input file (redshifts)
or the output parameters (single run)
"""
z_mod = self.config['sed_creation_modules']['redshifting']['redshift']
if type(z_mod) is str and not z_mod:
if self.config['data_file']:
obs_table = read_table(self.config['data_file'])
z = np.unique(np.around(obs_table['redshift'],
decimals=REDSHIFT_DECIMALS))
self.config['sed_creation_modules']['redshifting']['redshift'] = z
else:
raise Exception("No flux file and no redshift indicated. "
"The spectra cannot be computed. Aborting.")
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