From c76b486e22309714cd709b7d095e7ad31f3229a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9d=C3=A9ric=20Boquien?= Date: Mon, 7 Dec 2015 15:35:45 -0300 Subject: [PATCH] When estimating a parameter in log, these were not scaled appropriately and taken in log when saving the related PDF --- CHANGELOG.md | 2 +- .../analysis_modules/pdf_analysis/utils.py | 35 ++++++++++++++++++- .../analysis_modules/pdf_analysis/workers.py | 11 ++---- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a1b4942..beac5a49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ ### Changed ### 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 χ². (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) ### Optimised - Prior to version 0.7.0, we needed to maintain the list of redshifts for all the computed models. Past 0.7.0 we just infer the redshift from a list unique redshifts. This means that we can now discard the list of redshifts for all the models and only keep the list of unique redshifts. This saves ~8 MB of memory for every 10⁶ models. the models should be computed slightly faster but it is in the measurement noise. (Médéric Boquien) diff --git a/pcigale/analysis_modules/pdf_analysis/utils.py b/pcigale/analysis_modules/pdf_analysis/utils.py index 01c738b4..8de02054 100644 --- a/pcigale/analysis_modules/pdf_analysis/utils.py +++ b/pcigale/analysis_modules/pdf_analysis/utils.py @@ -32,7 +32,7 @@ def save_best_sed(obsid, sed, norm): sed.to_votable(OUT_DIR + "{}_best_model.xml".format(obsid), mass=norm) -def save_pdf(obsid, name, model_variable, likelihood): +def _save_pdf(obsid, name, model_variable, likelihood): """Compute and save the PDF to a FITS file We estimate the probability density functions (PDF) of the parameter from @@ -83,6 +83,39 @@ def save_pdf(obsid, name, model_variable, likelihood): table.write(OUT_DIR + "{}_{}_pdf.fits".format(obsid, name)) +def save_pdf(obsid, names, mass_proportional, model_variables, scaling, + likelihood, wlikely): + """Compute and save the PDF of analysed variables + + Parameters + ---------- + obsid: string + Name of the object. Used to prepend the output file name + names: list of strings + Analysed variables names + model_variables: array + Values of the model variables + likelihood: 1D array + Likelihood of the "likely" models + + """ + for i, name in enumerate(names): + if name.endswith('_log'): + if name[:-4] in mass_proportional: + model_variable = np.log10(model_variables[:, i][wlikely] * + scaling[wlikely]) + else: + model_variable = np.log10(model_variables[:, i][wlikely]) + else: + if name in mass_proportional: + model_variable = (model_variables[:, i][wlikely] * + scaling[wlikely]) + else: + model_variable = model_variables[:, i][wlikely] + + _save_pdf(obsid, name, model_variable, likelihood) + + def _save_chi2(obsid, name, model_variable, chi2): """Save the best reduced χ² versus an analysed variable diff --git a/pcigale/analysis_modules/pdf_analysis/workers.py b/pcigale/analysis_modules/pdf_analysis/workers.py index c8ec0cd3..103944a2 100644 --- a/pcigale/analysis_modules/pdf_analysis/workers.py +++ b/pcigale/analysis_modules/pdf_analysis/workers.py @@ -291,14 +291,9 @@ def analysis(idx, obs): sed.mass_proportional_info, gbl_model_variables[wz, :], scaling, chi2 / (nobs - 1)) if gbl_save['pdf']: - for i, variable in enumerate(gbl_analysed_variables): - if variable in sed.mass_proportional_info: - save_pdf(obs['id'], variable, - gbl_model_variables[wz, i][wlikely] * - scaling[wlikely], likelihood) - else: - save_pdf(obs['id'], variable, - gbl_model_variables[wz, i][wlikely], likelihood) + save_pdf(obs['id'], gbl_analysed_variables, + sed.mass_proportional_info, gbl_model_variables[wz, :], + scaling, likelihood, wlikely) with gbl_n_computed.get_lock(): gbl_n_computed.value += 1 -- GitLab