Commit 1b3d7037 authored by Médéric Boquien's avatar Médéric Boquien

Merge the output files into one. The parameters estimated from the PDF are...

Merge the output files into one. The parameters estimated from the PDF are prefixed with 'bayes' and those from the best fit with 'best'.
parent 11384661
...@@ -5,6 +5,10 @@ ...@@ -5,6 +5,10 @@
- When using the savefluxes module, all the output parameters were saved. This is not efficient when the user is only interested in some of the output parameters but not all. We introduce the "variables" configuration parameter for savefluxes to list the output parameters the user wants to save. If the list is left empty, all parameters are saved, preserving the current behaviour. This should increase the speed substantially when saving memory. (Médéric Boquien) - When using the savefluxes module, all the output parameters were saved. This is not efficient when the user is only interested in some of the output parameters but not all. We introduce the "variables" configuration parameter for savefluxes to list the output parameters the user wants to save. If the list is left empty, all parameters are saved, preserving the current behaviour. This should increase the speed substantially when saving memory. (Médéric Boquien)
### Changed ### 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)
- To homogenize input and output files, the "observation_id" has been changed to "id" in the output files. (Médéric Boquien)
- The output files providing estimates of the physical properties are now generated both in the form of text and FITS files. (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)
- When estimating a parameter in log, these were not scaled appropriately and taken in log when saving the related χ² and PDF. (Médéric Boquien) - When estimating a parameter in log, these were not scaled appropriately and taken in log when saving the related χ² and PDF. (Médéric Boquien)
......
...@@ -34,7 +34,7 @@ import numpy as np ...@@ -34,7 +34,7 @@ import numpy as np
from ...utils import read_table from ...utils import read_table
from .. import AnalysisModule, complete_obs_table from .. import AnalysisModule, complete_obs_table
from .utils import save_table_analysis, save_table_best, analyse_chi2 from .utils import save_results, analyse_chi2
from ...warehouse import SedWarehouse from ...warehouse import SedWarehouse
from .workers import sed as worker_sed from .workers import sed as worker_sed
from .workers import init_sed as init_worker_sed from .workers import init_sed as init_worker_sed
...@@ -224,12 +224,9 @@ class PdfAnalysis(AnalysisModule): ...@@ -224,12 +224,9 @@ class PdfAnalysis(AnalysisModule):
print("\nSaving results...") print("\nSaving results...")
save_table_analysis('analysis_results.txt', obs_table['id'], save_results("results", obs_table['id'], analysed_variables,
analysed_variables, analysed_averages, analysed_averages, analysed_std, best_chi2, best_chi2_red,
analysed_std) best_parameters, best_fluxes, filters, info)
save_table_best('best_models.txt', obs_table['id'], best_chi2,
best_chi2_red, best_parameters, best_fluxes, filters,
info)
if mock_flag is True: if mock_flag is True:
...@@ -270,12 +267,10 @@ class PdfAnalysis(AnalysisModule): ...@@ -270,12 +267,10 @@ class PdfAnalysis(AnalysisModule):
print("\nSaving results...") print("\nSaving results...")
save_table_analysis('analysis_mock_results.txt', mock_table['id'], save_results("results_mock", mock_table['id'], analysed_variables,
analysed_variables, analysed_averages, analysed_averages, analysed_std, best_chi2,
analysed_std) best_chi2_red, best_parameters, best_fluxes, filters,
save_table_best('best_mock_models.txt', mock_table['id'], info)
best_chi2, best_chi2_red, best_parameters,
best_fluxes, filters, info)
print("Run completed!") print("Run completed!")
......
...@@ -167,94 +167,76 @@ def save_chi2(obsid, names, mass_proportional, model_variables, scaling, chi2): ...@@ -167,94 +167,76 @@ def save_chi2(obsid, names, mass_proportional, model_variables, scaling, chi2):
_save_chi2(obsid, name, model_variable, chi2) _save_chi2(obsid, name, model_variable, chi2)
def save_table_analysis(filename, obsid, analysed_variables, analysed_averages, def save_results(filename, obsid, bayes_variables, bayes_mean, bayes_std, chi2,
analysed_std): chi2_red, best, fluxes, filters, info_keys):
"""Save the estimated values derived from the analysis of the PDF """Save the estimated values derived from the analysis of the PDF and the
parameters associated with the best fit. An simple text file and a FITS
file are generated.
Parameters Parameters
---------- ----------
filename: name of the file to save filename: string
Name of the output file Name of the output file without the extension
obsid: table column obsid: table column
Names of the objects Names of the objects
analysed_variables: list bayes_variables: list
Analysed variable names Analysed variable names
analysed_averages: RawArray bayes_mean: RawArray
Analysed variables values estimates Analysed variables values estimates
analysed_std: RawArray bayes_std: RawArray
Analysed variables errors estimates Analysed variables errors estimates
"""
np_analysed_averages = np.ctypeslib.as_array(analysed_averages[0])
np_analysed_averages = np_analysed_averages.reshape(analysed_averages[1])
np_analysed_std = np.ctypeslib.as_array(analysed_std[0])
np_analysed_std = np_analysed_std.reshape(analysed_std[1])
result_table = Table()
result_table.add_column(Column(obsid.data, name="observation_id"))
for index, variable in enumerate(analysed_variables):
result_table.add_column(Column(
np_analysed_averages[:, index],
name=variable
))
result_table.add_column(Column(
np_analysed_std[:, index],
name=variable+"_err"
))
result_table.write(OUT_DIR + filename, format='ascii.fixed_width',
delimiter=None)
def save_table_best(filename, obsid, chi2, chi2_red, variables, fluxes,
filters, info_keys):
"""Save the values corresponding to the best fit
Parameters
----------
filename: name of the file to save
Name of the output file
obsid: table column
Names of the objects
chi2: RawArray chi2: RawArray
Best χ² for each object Best χ² for each object
chi2_red: RawArray chi2_red: RawArray
Best reduced χ² for each object Best reduced χ² for each object
variables: RawArray best: RawArray
All variables corresponding to a SED All variables corresponding to the best SED
fluxes: RawArray fluxes: RawArray
Fluxes in all bands for each object Fluxes in all bands for the best SED
filters: list filters: list
Filters used to compute the fluxes Filters used to compute the fluxes
info_keys: list info_keys: list
Parameters names Parameters names
""" """
np_bayes_mean = np.ctypeslib.as_array(bayes_mean[0])
np_bayes_mean = np_bayes_mean.reshape(bayes_mean[1])
np_bayes_std = np.ctypeslib.as_array(bayes_std[0])
np_bayes_std = np_bayes_std.reshape(bayes_std[1])
np_fluxes = np.ctypeslib.as_array(fluxes[0]) np_fluxes = np.ctypeslib.as_array(fluxes[0])
np_fluxes = np_fluxes.reshape(fluxes[1]) np_fluxes = np_fluxes.reshape(fluxes[1])
np_variables = np.ctypeslib.as_array(variables[0]) np_best = np.ctypeslib.as_array(best[0])
np_variables = np_variables.reshape(variables[1]) np_best = np_best.reshape(best[1])
np_chi2 = np.ctypeslib.as_array(chi2[0]) np_chi2 = np.ctypeslib.as_array(chi2[0])
np_chi2_red = np.ctypeslib.as_array(chi2_red[0]) np_chi2_red = np.ctypeslib.as_array(chi2_red[0])
best_model_table = Table() table = Table()
best_model_table.add_column(Column(obsid.data, name="observation_id"))
best_model_table.add_column(Column(np_chi2, name="chi_square")) table.add_column(Column(obsid.data, name="id"))
best_model_table.add_column(Column(np_chi2_red, name="reduced_chi_square"))
for idx, name in enumerate(bayes_variables):
table.add_column(Column(np_bayes_mean[:, idx], name="bayes."+name))
table.add_column(Column(np_bayes_std[:, idx],
name="bayes."+name+"_err"))
table.add_column(Column(np_chi2, name="best.chi_square"))
table.add_column(Column(np_chi2_red, name="best.reduced_chi_square"))
for index, name in enumerate(info_keys): for idx, name in enumerate(info_keys):
column = Column(np_variables[:, index], name=name) table.add_column(Column(np_best[:, idx], name="best."+name))
best_model_table.add_column(column)
for index, name in enumerate(filters): for idx, name in enumerate(filters):
column = Column(np_fluxes[:, index], name=name, unit='mJy') table.add_column(Column(np_fluxes[:, idx], name="best."+name,
best_model_table.add_column(column) unit='mJy'))
best_model_table.write(OUT_DIR + filename, format='ascii.fixed_width', table.write(OUT_DIR+filename+".txt", format='ascii.fixed_width',
delimiter=None) delimiter=None)
table.write(OUT_DIR+filename+".fits", format='fits')
def dchi2_over_ds2(s, obs_fluxes, obs_errors, mod_fluxes): def dchi2_over_ds2(s, obs_fluxes, obs_errors, mod_fluxes):
......
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