Commit 06ee0d5f authored by Yannick Roehlly's avatar Yannick Roehlly
Browse files

Separate the redshift module from the main workflow

The redshifting module must be separated from the main modules producing
the restframe SED, because the redshift parameter is taken directly from
the observation list.
Nevertheless, it is still a SED creation module because one may want to
use it for testing various redshifts.
parent 998e408e
...@@ -41,11 +41,14 @@ def run(config): ...@@ -41,11 +41,14 @@ def run(config):
column_list = config.configuration['column_list'] column_list = config.configuration['column_list']
sed_modules = config.configuration['sed_modules'] sed_modules = config.configuration['sed_modules']
sed_modules_params = config.sed_modules_conf_array sed_modules_params = config.sed_modules_conf_array
redshift_module = config.configuration['redshift_module']
redshift_configuration = config.configuration['redshift_configuration']
stat_module = get_stats_module(config.configuration['analysis_method']) stat_module = get_stats_module(config.configuration['analysis_method'])
stat_module_params = config.configuration['analysis_method_params'] stat_module_params = config.configuration['analysis_method_params']
stat_module.process(data_file, column_list, sed_modules, stat_module.process(data_file, column_list, sed_modules,
sed_modules_params, stat_module_params) sed_modules_params, redshift_module,
redshift_configuration, stat_module_params)
def main(): def main():
......
...@@ -130,6 +130,12 @@ class Configuration(object): ...@@ -130,6 +130,12 @@ class Configuration(object):
"Order of the modules use for SED creation. Available modules : " "Order of the modules use for SED creation. Available modules : "
+ ', '.join(list_modules('pcigale.sed.modules')) + ".") + ', '.join(list_modules('pcigale.sed.modules')) + ".")
self.config['redshift_module'] = ""
self.config.comments['redshift_module'] = [""] + wrap(
"Module used to redshift the SED before the integration in the "
"filters. This is a SED creation module that accepts a 'redshift' "
"parameter (see the documentation).")
self.config['analysis_method'] = "" self.config['analysis_method'] = ""
self.config.comments['analysis_method'] = [""] + wrap( self.config.comments['analysis_method'] = [""] + wrap(
"Method used for statistical analysis. Available methods: " "Method used for statistical analysis. Available methods: "
...@@ -191,6 +197,20 @@ class Configuration(object): ...@@ -191,6 +197,20 @@ class Configuration(object):
self.config['sed_creation_modules'].comments[module_name] = [ self.config['sed_creation_modules'].comments[module_name] = [
modules.get_module(module_name).comments] modules.get_module(module_name).comments]
# Configuration for the redshift module
self.config['redshift_configuration'] = {}
self.config.comments['redshift_configuration'] = ["", ""] + wrap(
"Set the 'redshift' parameter to None (or delete the line). If "
"there are other parameters, you must give only one value for "
"each.")
module_name = self.config['redshift_module']
for name, (typ, desc, default) in \
modules.get_module(module_name).parameter_list.items():
if default is None:
default = ''
self.config['redshift_configuration'][name] = default
self.config['redshift_configuration'].comments[name] = wrap(desc)
# Configuration for the analysis method # Configuration for the analysis method
self.config['analysis_configuration'] = {} self.config['analysis_configuration'] = {}
self.config.comments['analysis_configuration'] = ["", ""] + wrap( self.config.comments['analysis_configuration'] = ["", ""] + wrap(
...@@ -221,6 +241,9 @@ class Configuration(object): ...@@ -221,6 +241,9 @@ class Configuration(object):
Configuration parameters for each module. To each parameter, the Configuration parameters for each module. To each parameter, the
dictionary associates a list of possible values (possibly only dictionary associates a list of possible values (possibly only
one). one).
configuration['redshift_module'] : string
configuration['redshift_configuration'] : dictionary
Parameters for the redshift module.
configuration['analysis_method'] : string configuration['analysis_method'] : string
Statistical analysis module used to fit the data. Statistical analysis module used to fit the data.
configuration['analysis_method_params'] : dictionary configuration['analysis_method_params'] : dictionary
...@@ -230,7 +253,7 @@ class Configuration(object): ...@@ -230,7 +253,7 @@ class Configuration(object):
configuration = {} configuration = {}
for section in ['data_file', 'column_list', 'sed_modules', for section in ['data_file', 'column_list', 'sed_modules',
'analysis_method']: 'redshift_module', 'analysis_method']:
configuration[section] = self.config[section] configuration[section] = self.config[section]
# Parsing the SED modules parameters # Parsing the SED modules parameters
...@@ -241,7 +264,11 @@ class Configuration(object): ...@@ -241,7 +264,11 @@ class Configuration(object):
self.config['sed_creation_modules'][module].items(): self.config['sed_creation_modules'][module].items():
module_params[key] = evaluate_description(value) module_params[key] = evaluate_description(value)
configuration['sed_modules_params'].append(module_params) configuration['sed_modules_params'].append(module_params)
# Parsing the redshift module parameters
configuration['redshift_configuration'] = {}
for key, value in self.config['redshift_configuration'].items():
configuration['redshift_configuration'][key] = \
evaluate_description(value)
# Parsing the statistical analysis parameters # Parsing the statistical analysis parameters
configuration['analysis_method_params'] = {} configuration['analysis_method_params'] = {}
for key, value in self.config['analysis_configuration'].items(): for key, value in self.config['analysis_configuration'].items():
......
...@@ -30,7 +30,8 @@ class AnalysisModule(object): ...@@ -30,7 +30,8 @@ class AnalysisModule(object):
self.parameters = kwargs self.parameters = kwargs
def _process(self, data_file, column_list, sed_modules, def _process(self, data_file, column_list, sed_modules,
sed_modules_params, parameters): sed_modules_params, redshift_module,
redshift_configuration, parameters):
"""Do the actual analysis """Do the actual analysis
This method is responsible for the fitting / analysis process This method is responsible for the fitting / analysis process
...@@ -49,6 +50,10 @@ class AnalysisModule(object): ...@@ -49,6 +50,10 @@ class AnalysisModule(object):
for the sed_modules. Each 'inner' array has the same length as the for the sed_modules. Each 'inner' array has the same length as the
sed_modules array and contains the configuration dictionary for sed_modules array and contains the configuration dictionary for
the corresponding module. the corresponding module.
redshift_module : string
Name of the module used to redshift the SED.
redshift_configuration : dictionary
Configuration dictionary for the module used to redshift the SED.
parameters : dictionary parameters : dictionary
Configuration for the module. Configuration for the module.
...@@ -60,7 +65,8 @@ class AnalysisModule(object): ...@@ -60,7 +65,8 @@ class AnalysisModule(object):
raise NotImplementedError() raise NotImplementedError()
def process(self, data_file, column_list, sed_modules, def process(self, data_file, column_list, sed_modules,
sed_modules_params, parameters): sed_modules_params, redshift_module,
redshift_configuration, parameters):
"""Process with the analysis """Process with the analysis
This method is responsible for checking the module parameters before This method is responsible for checking the module parameters before
...@@ -81,6 +87,10 @@ class AnalysisModule(object): ...@@ -81,6 +87,10 @@ class AnalysisModule(object):
for the sed_modules. Each 'inner' array has the same length as the for the sed_modules. Each 'inner' array has the same length as the
sed_modules array and contains the configuration dictionary for sed_modules array and contains the configuration dictionary for
the corresponding module. the corresponding module.
redshift_module : string
Name of the module used to redshift the SED.
redshift_configuration : dictionary
Configuration dictionary for the module used to redshift the SED.
parameters : dictionary parameters : dictionary
Configuration for the module. Configuration for the module.
...@@ -124,7 +134,8 @@ class AnalysisModule(object): ...@@ -124,7 +134,8 @@ class AnalysisModule(object):
#We do the actual processing #We do the actual processing
self._process(data_file, column_list, sed_modules, self._process(data_file, column_list, sed_modules,
sed_modules_params, parameters) sed_modules_params, redshift_module,
redshift_configuration, parameters)
def get_module(module_name): def get_module(module_name):
......
...@@ -21,11 +21,13 @@ import os ...@@ -21,11 +21,13 @@ import os
import sys import sys
import atpy import atpy
import numpy as np import numpy as np
from copy import deepcopy
from scipy import stats from scipy import stats
from progressbar import ProgressBar from progressbar import ProgressBar
from matplotlib import pyplot as plt from matplotlib import pyplot as plt
from . import common from . import common
from ..sed.warehouse import create_sed from ..sed.warehouse import create_sed
from ..sed.modules.common import get_module
from ..data import Database from ..data import Database
...@@ -90,7 +92,8 @@ class Module(common.AnalysisModule): ...@@ -90,7 +92,8 @@ class Module(common.AnalysisModule):
} }
def process(self, data_file, column_list, sed_modules, def process(self, data_file, column_list, sed_modules,
sed_modules_params, parameters): sed_modules_params, redshift_module_name,
redshift_configuration, parameters):
"""Process with the psum analysis. """Process with the psum analysis.
The analysis is done in two nested loops: over each observation and The analysis is done in two nested loops: over each observation and
...@@ -108,25 +111,13 @@ class Module(common.AnalysisModule): ...@@ -108,25 +111,13 @@ class Module(common.AnalysisModule):
the SEDs. the SEDs.
sed_modules_params: list of dictionaries sed_modules_params: list of dictionaries
List of the parameter dictionaries for each module. List of the parameter dictionaries for each module.
redshift_module_name : string
Name of the module used to redshift the SED.
redshift_configuration : dictionary
Configuration dictionary for the module used to redshift the SED.
parameters: dictionary parameters: dictionary
Dictionnary containing the parameters. Dictionnary containing the parameters.
Returns
-------
best_sed: list of tuples (pcigale.sed object, dict, float, float)
There is one tuple per observed object: the first element is the
best fitting SED for this object, the second dictionary of
parameter used to produce it, the third is the reduced Chi-square
of the fit and the fourth is the normalisation factor to be
applied to the SED to fit the observation.
results: dictionary
Dictionary associating to NAME and NAME_err the weighted average
and standard deviation lists, where name is galaxy_mass or the
content of the analysed variables list. Each key is associated
to an array which index corresponds to the rows in the observation
data file. This dictionary is also saved as a FITS file to the
disk.
""" """
# Create the output directory and stop it exists. # Create the output directory and stop it exists.
...@@ -164,6 +155,10 @@ class Module(common.AnalysisModule): ...@@ -164,6 +155,10 @@ class Module(common.AnalysisModule):
effective_wavelength[name] = filt.effective_wavelength effective_wavelength[name] = filt.effective_wavelength
base.close() base.close()
# We get the redshift module.
redshift_module = get_module(redshift_module_name)
redshift_module.parameters = redshift_configuration
# Read the observation table and complete it by adding error where # Read the observation table and complete it by adding error where
# none is provided and by adding the systematic deviation. # none is provided and by adding the systematic deviation.
obs_table = atpy.Table(data_file, verbose=False) obs_table = atpy.Table(data_file, verbose=False)
...@@ -208,10 +203,15 @@ class Module(common.AnalysisModule): ...@@ -208,10 +203,15 @@ class Module(common.AnalysisModule):
obs_errors = [obs_table[name + '_err'][obs_index] obs_errors = [obs_table[name + '_err'][obs_index]
for name in filter_list] for name in filter_list]
# We copy the SED before redshifting it.
red_sed = deepcopy(sed)
redshift_module.parameters["redshift"] = obs_redshift
redshift_module.process(red_sed)
# Theoretical fluxes # Theoretical fluxes
theor_fluxes = [sed.compute_fnu(transmission[name], theor_fluxes = [red_sed.compute_fnu(transmission[name],
effective_wavelength[name], effective_wavelength[name],
obs_redshift) obs_redshift)
for name in filter_list] for name in filter_list]
reduced_chi2, galaxy_mass, probability = compute_chi2( reduced_chi2, galaxy_mass, probability = compute_chi2(
......
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