From 1b3d70373ad666bb506de0c15490512ae47033a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9d=C3=A9ric=20Boquien?= Date: Tue, 8 Dec 2015 11:11:52 -0300 Subject: [PATCH] Merge the output files into one. The parameters estimated from the PDF are prefixed with 'bayes' and those from the best fit with 'best'. --- CHANGELOG.md | 4 + .../analysis_modules/pdf_analysis/__init__.py | 21 ++-- .../analysis_modules/pdf_analysis/utils.py | 98 ++++++++----------- 3 files changed, 52 insertions(+), 71 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a75686b..64e42778 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) ### 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 - 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) diff --git a/pcigale/analysis_modules/pdf_analysis/__init__.py b/pcigale/analysis_modules/pdf_analysis/__init__.py index 936c56e0..0a28fbe9 100644 --- a/pcigale/analysis_modules/pdf_analysis/__init__.py +++ b/pcigale/analysis_modules/pdf_analysis/__init__.py @@ -34,7 +34,7 @@ import numpy as np from ...utils import read_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 .workers import sed as worker_sed from .workers import init_sed as init_worker_sed @@ -224,12 +224,9 @@ class PdfAnalysis(AnalysisModule): print("\nSaving results...") - save_table_analysis('analysis_results.txt', obs_table['id'], - analysed_variables, analysed_averages, - analysed_std) - save_table_best('best_models.txt', obs_table['id'], best_chi2, - best_chi2_red, best_parameters, best_fluxes, filters, - info) + save_results("results", obs_table['id'], analysed_variables, + analysed_averages, analysed_std, best_chi2, best_chi2_red, + best_parameters, best_fluxes, filters, info) if mock_flag is True: @@ -270,12 +267,10 @@ class PdfAnalysis(AnalysisModule): print("\nSaving results...") - save_table_analysis('analysis_mock_results.txt', mock_table['id'], - analysed_variables, analysed_averages, - analysed_std) - save_table_best('best_mock_models.txt', mock_table['id'], - best_chi2, best_chi2_red, best_parameters, - best_fluxes, filters, info) + save_results("results_mock", mock_table['id'], analysed_variables, + analysed_averages, analysed_std, best_chi2, + best_chi2_red, best_parameters, best_fluxes, filters, + info) print("Run completed!") diff --git a/pcigale/analysis_modules/pdf_analysis/utils.py b/pcigale/analysis_modules/pdf_analysis/utils.py index 5a914c24..dd3afb1f 100644 --- a/pcigale/analysis_modules/pdf_analysis/utils.py +++ b/pcigale/analysis_modules/pdf_analysis/utils.py @@ -167,94 +167,76 @@ def save_chi2(obsid, names, mass_proportional, model_variables, scaling, chi2): _save_chi2(obsid, name, model_variable, chi2) -def save_table_analysis(filename, obsid, analysed_variables, analysed_averages, - analysed_std): - """Save the estimated values derived from the analysis of the PDF +def save_results(filename, obsid, bayes_variables, bayes_mean, bayes_std, chi2, + chi2_red, best, fluxes, filters, info_keys): + """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 ---------- - filename: name of the file to save - Name of the output file + filename: string + Name of the output file without the extension obsid: table column Names of the objects - analysed_variables: list + bayes_variables: list Analysed variable names - analysed_averages: RawArray + bayes_mean: RawArray Analysed variables values estimates - analysed_std: RawArray + bayes_std: RawArray 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 Best χ² for each object chi2_red: RawArray Best reduced χ² for each object - variables: RawArray - All variables corresponding to a SED + best: RawArray + All variables corresponding to the best SED fluxes: RawArray - Fluxes in all bands for each object + Fluxes in all bands for the best SED filters: list Filters used to compute the fluxes info_keys: list 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_fluxes.reshape(fluxes[1]) - np_variables = np.ctypeslib.as_array(variables[0]) - np_variables = np_variables.reshape(variables[1]) + np_best = np.ctypeslib.as_array(best[0]) + np_best = np_best.reshape(best[1]) np_chi2 = np.ctypeslib.as_array(chi2[0]) np_chi2_red = np.ctypeslib.as_array(chi2_red[0]) - best_model_table = Table() - best_model_table.add_column(Column(obsid.data, name="observation_id")) - best_model_table.add_column(Column(np_chi2, name="chi_square")) - best_model_table.add_column(Column(np_chi2_red, name="reduced_chi_square")) + table = Table() + + table.add_column(Column(obsid.data, name="id")) + + 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): - column = Column(np_variables[:, index], name=name) - best_model_table.add_column(column) + for idx, name in enumerate(info_keys): + table.add_column(Column(np_best[:, idx], name="best."+name)) - for index, name in enumerate(filters): - column = Column(np_fluxes[:, index], name=name, unit='mJy') - best_model_table.add_column(column) + for idx, name in enumerate(filters): + table.add_column(Column(np_fluxes[:, idx], name="best."+name, + unit='mJy')) - best_model_table.write(OUT_DIR + filename, format='ascii.fixed_width', - delimiter=None) + table.write(OUT_DIR+filename+".txt", format='ascii.fixed_width', + delimiter=None) + table.write(OUT_DIR+filename+".fits", format='fits') def dchi2_over_ds2(s, obs_fluxes, obs_errors, mod_fluxes): -- GitLab