Commit 7bf6e22b authored by Médéric Boquien's avatar Médéric Boquien

Improve the presentation of the sanity check and only do as at the end of the...

Improve the presentation of the sanity check and only do as at the end of the run so that sporadic messages are not displayed in individual blocks.
parent a2107cb5
...@@ -195,6 +195,7 @@ class PdfAnalysis(AnalysisModule): ...@@ -195,6 +195,7 @@ class PdfAnalysis(AnalysisModule):
obs.save('observations') obs.save('observations')
results = self._compute(conf, obs, params) results = self._compute(conf, obs, params)
print("\nSanity check of the analysis results...")
results.best.analyse_chi2() results.best.analyse_chi2()
print("\nSaving the analysis results...") print("\nSaving the analysis results...")
......
...@@ -207,11 +207,6 @@ def analysis(idx, obs): ...@@ -207,11 +207,6 @@ def analysis(idx, obs):
gbl_results.best.scaling[idx] = scaling[best_idx_z] gbl_results.best.scaling[idx] = scaling[best_idx_z]
gbl_results.best.index[idx] = (wz.start + best_idx_z*wz.step + gbl_results.best.index[idx] = (wz.start + best_idx_z*wz.step +
gbl_models.block.start) gbl_models.block.start)
else:
# It sometimes happens because models are older than the Universe's age
print(f"No suitable model found for the object {obs.id}. It may be that"
f" models are older than the Universe or that your chi² are very "
f"large.")
gbl_counter.inc() gbl_counter.inc()
......
...@@ -308,15 +308,23 @@ class BestResultsManager(object): ...@@ -308,15 +308,23 @@ class BestResultsManager(object):
objects seems to be overconstrainted. objects seems to be overconstrainted.
""" """
# If no best model has been found, it means none could be properly
# fitted. We warn the user in that case
bad = self.obs.table['id'][np.isnan(self.chi2)].tolist()
if len(bad) > 0:
print(f"No suitable model found for {', '.join(bad)}. It may be "
f"that models are older than the universe or that your χ² are"
f" very large.")
obs = [self.obs.table[obs].data for obs in self.obs.tofit] obs = [self.obs.table[obs].data for obs in self.obs.tofit]
nobs = np.count_nonzero(np.isfinite(obs), axis=0) nobs = np.count_nonzero(np.isfinite(obs), axis=0)
chi2_red = self.chi2 / (nobs - 1) chi2_red = self.chi2 / (nobs - 1)
# If low values of reduced chi^2, it means that the data are overfitted # If low values of reduced chi^2, it means that the data are overfitted
# Errors might be under-estimated or not enough valid data. # Errors might be under-estimated or not enough valid data.
print(f"\n{np.round((chi2_red < 1e-12).sum() / chi2_red.size, 1)}% of " print(f"{np.round((chi2_red < 1e-12).sum() / chi2_red.size, 1)}% of "
f"the objects have chi^2_red~0 and " f"the objects have χ²_red~0 and "
f"{np.round((chi2_red < 0.5).sum() / chi2_red.size, 1)}% " f"{np.round((chi2_red < 0.5).sum() / chi2_red.size, 1)}% "
f"chi^2_red<0.5") f"χ²_red<0.5")
class ResultsManager(object): class ResultsManager(object):
......
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