From b8eacdbcf62fe0420c34641532af601d5a8dde6a Mon Sep 17 00:00:00 2001 From: Robin Savonet Date: Tue, 22 Apr 2025 10:43:51 +0200 Subject: [PATCH 1/2] Addition of ncomp in contrast curve verbose print --- vip_hci/metrics/contrcurve.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/vip_hci/metrics/contrcurve.py b/vip_hci/metrics/contrcurve.py index b87711ff..0da14a75 100644 --- a/vip_hci/metrics/contrcurve.py +++ b/vip_hci/metrics/contrcurve.py @@ -207,16 +207,20 @@ def contrast_curve( else: fwhm_med = fwhm + # Retrieve ncomp info + ncomp = algo_dict["ncomp"] + if verbose: start_time = time_ini() if isinstance(starphot, float) or isinstance(starphot, int): - msg0 = "ALGO : {}, FWHM = {}, # BRANCHES = {}, SIGMA = {}," - msg0 += " STARPHOT = {}" - print(msg0.format(algo.__name__, fwhm_med, nbranch, sigma, - starphot)) + msg0 = "ALGO : {}, ncomp = {}, FWHM = {}, \n" + msg0 += "# BRANCHES = {}, SIGMA = {}, STARPHOT = {}" + print(msg0.format(algo.__name__, ncomp, fwhm_med, nbranch, + sigma, starphot)) else: - msg0 = "ALGO : {}, FWHM = {}, # BRANCHES = {}, SIGMA = {}" - print(msg0.format(algo.__name__, fwhm_med, nbranch, sigma)) + msg0 = "ALGO : {}, ncomp = {}, FWHM = {}, \n" + msg0 += "# BRANCHES = {}, SIGMA = {}, " + print(msg0.format(algo.__name__, ncomp, fwhm_med, nbranch, sigma)) # throughput verbose_thru = False @@ -496,8 +500,7 @@ def contrast_curve( # Give a title to the contrast curve plot if object_name is not None and frame_size is not None: - # Retrieve ncomp and pca_type info to use in title - ncomp = algo_dict["ncomp"] + # Retrieve pca_type info to use in title if algo_dict["cube_ref"] is None: pca_type = "ADI" else: From a49c527a3f4db8af58aecdcdb1131031058f104a Mon Sep 17 00:00:00 2001 From: Robin Savonet Date: Thu, 15 May 2025 15:45:16 +0200 Subject: [PATCH 2/2] Added opt_SNR as returned variable in pca_grid --- vip_hci/objects/pppca.py | 1 + vip_hci/psfsub/pca_fullfr.py | 2 +- vip_hci/psfsub/utils_pca.py | 8 ++++++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/vip_hci/objects/pppca.py b/vip_hci/objects/pppca.py index 27fbca6b..0095f242 100644 --- a/vip_hci/objects/pppca.py +++ b/vip_hci/objects/pppca.py @@ -243,6 +243,7 @@ def run( self.frame_final, self.dataframe, self.opt_number_pc, + self.opt_SNR, ) = res if self.results is not None: self.results.register_session( diff --git a/vip_hci/psfsub/pca_fullfr.py b/vip_hci/psfsub/pca_fullfr.py index 2ddc29a3..656464c7 100644 --- a/vip_hci/psfsub/pca_fullfr.py +++ b/vip_hci/psfsub/pca_fullfr.py @@ -643,7 +643,7 @@ def pca(*all_args: List, **all_kwargs: dict): # PCA grid, computing S/Ns if isinstance(algo_params.ncomp, (tuple, list)): if algo_params.full_output: - final_residuals_cube, frame, table, _ = res_pca + final_residuals_cube, frame, table, _, _ = res_pca else: # returning only the optimal residual final_residuals_cube = res_pca[1] diff --git a/vip_hci/psfsub/utils_pca.py b/vip_hci/psfsub/utils_pca.py index f01446a1..e5e2dd1d 100644 --- a/vip_hci/psfsub/utils_pca.py +++ b/vip_hci/psfsub/utils_pca.py @@ -185,6 +185,9 @@ def pca_grid(cube, angle_list, fwhm=None, range_pcs=None, source_xy=None, S/Ns for ``source_xy``. opt_npc : int [source_xy is not None] Optimal number of PCs for ``source_xy``. + opt_SNR : float + [source_xy is not None] Optimal signal-to-noise ratio for ``source_xy`` + at opt_npc """ from ..metrics import snr, frame_report @@ -371,6 +374,7 @@ def get_snr(frame, y, x, fwhm, fmerit): if x is not None and y is not None and fwhm is not None: argmax = np.argmax(snrlist) opt_npc = pclist[argmax] + opt_SNR = snrlist[argmax] df = DataFrame({'PCs': pclist, 'S/Ns': snrlist, 'fluxes': fluxlist}) if debug: print(df, '\n') @@ -378,7 +382,7 @@ def get_snr(frame, y, x, fwhm, fmerit): if verbose: print('Number of steps', len(pclist)) msg = 'Optimal number of PCs = {}, for S/N={:.3f}' - print(msg.format(opt_npc, snrlist[argmax])) + print(msg.format(opt_npc, opt_SNR)) # Plot of SNR and flux as function of PCs if plot: @@ -411,7 +415,7 @@ def get_snr(frame, y, x, fwhm, fmerit): finalfr = cubeout[argmax] _ = frame_report(finalfr, fwhm, (x, y), verbose=verbose) - return cubeout, finalfr, df, opt_npc + return cubeout, finalfr, df, opt_npc, opt_SNR else: if verbose: