From 22c3c7a6077cb2a670500e7afd0ab7547bb9517d Mon Sep 17 00:00:00 2001 From: Mike S Wang <32841762+MikeSWang@users.noreply.github.com> Date: Wed, 6 Nov 2024 16:03:11 +0000 Subject: [PATCH] ENH(py): Align Python logger behaviour with C++'s --- src/triumvirate/logger.py | 23 ++- src/triumvirate/parameters.pyx | 4 +- src/triumvirate/threept.py | 320 ++++++++++++++++++++++++--------- src/triumvirate/twopt.py | 225 ++++++++++++++++------- 4 files changed, 416 insertions(+), 156 deletions(-) diff --git a/src/triumvirate/logger.py b/src/triumvirate/logger.py index 35a2385b..be6efce2 100644 --- a/src/triumvirate/logger.py +++ b/src/triumvirate/logger.py @@ -14,6 +14,7 @@ import time import warnings from copy import copy +from functools import partialmethod class _ElapsedColourLogFormatter(logging.Formatter): @@ -25,7 +26,8 @@ class _ElapsedColourLogFormatter(logging.Formatter): _COLOURS = { 'NOTSET': "\033[0m", # reset 'DEBUG': f"\033[{_IN_BOLD};36m", # cyan - 'INFO': f"\033[{_IN_BOLD};32m", # green (blue) + 'STAT': f"\033[{_IN_BOLD};34m", # blue + 'INFO': f"\033[{_IN_BOLD};32m", # green 'WARNING': f"\033[{_IN_BOLD};33m", # yellow 'ERROR': f"\033[{_IN_BOLD};31m", # red 'CRITICAL': f"\033[{_IN_BOLD};37;41m", # white on red @@ -141,14 +143,14 @@ def _format_warning(message, category, filename, lineno, line=None): return msg_txt -def setup_logger(log_level=logging.INFO): +def setup_logger(log_level=15): """Set up and return a customised logger with elapsed time, C++ runtime indication and formatted warning messages. Parameters ---------- log_level : int, optional - Logging devel (default is `logging.INFO`). + Logging devel (default is 15, i.e. ``STAT`` for status). Returns ------- @@ -161,6 +163,10 @@ def setup_logger(log_level=logging.INFO): For more details of the Python logging facility. """ + # Add custom log levels. + logging.STAT = 15 + logging.addLevelName(logging.STAT, 'STAT') + # Set formatter. formatter = _ElapsedColourLogFormatter( fmt='[%(asctime)s %(elapsed)s %(levelname)s] %(message)s', @@ -180,11 +186,16 @@ def setup_logger(log_level=logging.INFO): logger_.setLevel(log_level) - # Adapt logger for C++ code indication. - logger = _CppLogAdapter(logger_, {'cpp_state': False}) - # Adapt logger to capture warnings. warnings.formatwarning = _format_warning logging.captureWarnings(True) + # Adapt logger for custom log levels. + logging.LoggerAdapter.stat = partialmethod( + logging.LoggerAdapter.log, logging.STAT + ) + + # Adapt logger for C++ code indication. + logger = _CppLogAdapter(logger_, {'cpp_state': False}) + return logger diff --git a/src/triumvirate/parameters.pyx b/src/triumvirate/parameters.pyx index 4f7af7ce..1ae1b64a 100644 --- a/src/triumvirate/parameters.pyx +++ b/src/triumvirate/parameters.pyx @@ -550,7 +550,7 @@ cdef class ParameterSet: """ try: - self._logger.info("Validating parameters...", cpp_state='start') + self._logger.stat("Validating parameters...", cpp_state='start') except (AttributeError, TypeError): pass @@ -603,7 +603,7 @@ cdef class ParameterSet: self._validity = True try: - self._logger.info("... validated parameters.", cpp_state='end') + self._logger.stat("... validated parameters.", cpp_state='end') except (AttributeError, TypeError): pass diff --git a/src/triumvirate/threept.py b/src/triumvirate/threept.py index f164e55b..b8e2e3e1 100644 --- a/src/triumvirate/threept.py +++ b/src/triumvirate/threept.py @@ -486,7 +486,10 @@ def _compute_3pt_stats_survey_like(threept_algofunc, paramset = ParameterSet(param_dict=paramset, logger=logger) if logger: - logger.info("Parameter set have been initialised.") + try: + logger.stat("Parameter set have been initialised.") + except AttributeError: + logger.info("Parameter set have been initialised.") if paramset['catalogue_type'] != 'survey': raise ValueError( @@ -513,7 +516,10 @@ def _compute_3pt_stats_survey_like(threept_algofunc, binning = Binning.from_parameter_set(paramset) if logger: - logger.info("Binning has been initialised.") + try: + logger.stat("Binning has been initialised.") + except AttributeError: + logger.info("Binning has been initialised.") # Set up lines of sight. if los_data is None: @@ -525,7 +531,10 @@ def _compute_3pt_stats_survey_like(threept_algofunc, los_rand = np.ascontiguousarray(los_rand) if logger: - logger.info("Lines of sight have been initialised.") + try: + logger.stat("Lines of sight have been initialised.") + except AttributeError: + logger.info("Lines of sight have been initialised.") # Set up box alignment. if None in paramset['boxsize'].values(): @@ -573,7 +582,10 @@ def _compute_3pt_stats_survey_like(threept_algofunc, ) if logger: - logger.info("Catalogues have been aligned.") + try: + logger.stat("Catalogues have been aligned.") + except AttributeError: + logger.info("Catalogues have been aligned.") # -------------------------------------------------------------------- # Measurements @@ -581,10 +593,16 @@ def _compute_3pt_stats_survey_like(threept_algofunc, # Prepare catalogues. if logger: - logger.info( - "Preparing catalogue for clustering algorithm...", - cpp_state='start' - ) + try: + logger.stat( + "Preparing catalogue for clustering algorithm...", + cpp_state='start' + ) + except AttributeError: + logger.info( + "Preparing catalogue for clustering algorithm...", + cpp_state='start' + ) particles_data = \ catalogue_data._convert_to_cpp_catalogue(verbose=paramset['verbose']) @@ -592,10 +610,16 @@ def _compute_3pt_stats_survey_like(threept_algofunc, catalogue_rand._convert_to_cpp_catalogue(verbose=paramset['verbose']) if logger: - logger.info( - "... prepared catalogue for clustering algorithm.", - cpp_state='end' - ) + try: + logger.stat( + "... prepared catalogue for clustering algorithm.", + cpp_state='end' + ) + except AttributeError: + logger.info( + "... prepared catalogue for clustering algorithm.", + cpp_state='end' + ) # Set up constants. alpha = catalogue_data.wstotal / catalogue_rand.wstotal @@ -644,12 +668,20 @@ def _compute_3pt_stats_survey_like(threept_algofunc, # Perform measurement. if logger: - logger.info( - "Measuring %s from paired survey-type catalogues " - "in the local plane-parallel approximation...", - statistic_name, - cpp_state='start' - ) + try: + logger.stat( + "Measuring %s from paired survey-type catalogues " + "in the local plane-parallel approximation...", + statistic_name, + cpp_state='start' + ) + except AttributeError: + logger.info( + "Measuring %s from paired survey-type catalogues " + "in the local plane-parallel approximation...", + statistic_name, + cpp_state='start' + ) results = threept_algofunc( particles_data, particles_rand, los_data, los_rand, @@ -657,12 +689,20 @@ def _compute_3pt_stats_survey_like(threept_algofunc, ) if logger: - logger.info( - "... measured %s from paired survey-type catalogues " - "in the local plane-parallel approximation.", - statistic_name, - cpp_state='end' - ) + try: + logger.stat( + "... measured %s from paired survey-type catalogues " + "in the local plane-parallel approximation.", + statistic_name, + cpp_state='end' + ) + except AttributeError: + logger.info( + "... measured %s from paired survey-type catalogues " + "in the local plane-parallel approximation.", + statistic_name, + cpp_state='end' + ) if save: odirpath = paramset['directories']['measurements'] or "" @@ -1049,7 +1089,10 @@ def compute_3pcf(catalogue_data, catalogue_rand, # paramset = ParameterSet(param_dict=paramset, logger=logger) # if logger: -# logger.info("Parameter set have been initialised.") +# try: +# logger.stat("Parameter set have been initialised.") +# except AttributeError: +# logger.info("Parameter set have been initialised.") # # -- Data ------------------------------------------------------------ @@ -1058,7 +1101,10 @@ def compute_3pcf(catalogue_data, catalogue_rand, # binning = Binning.from_parameter_set(paramset) # if logger: -# logger.info("Binning has been initialised.") +# try: +# logger.stat("Binning has been initialised.") +# except AttributeError: +# logger.info("Binning has been initialised.") # # Set up lines of sight. # if los_data is None: @@ -1070,7 +1116,10 @@ def compute_3pcf(catalogue_data, catalogue_rand, # los_rand = np.ascontiguousarray(los_rand) # if logger: -# logger.info("Lines of sight have been initialised.") +# try: +# logger.stat("Lines of sight have been initialised.") +# except AttributeError: +# logger.info("Lines of sight have been initialised.") # # Set up box alignment. # if paramset['alignment'] == 'centre': @@ -1092,7 +1141,10 @@ def compute_3pcf(catalogue_data, catalogue_rand, # ) # if logger: -# logger.info("Catalogues have been aligned.") +# try: +# logger.stat("Catalogues have been aligned.") +# except AttributeError: +# logger.info("Catalogues have been aligned.") # # -------------------------------------------------------------------- # # Measurements @@ -1100,10 +1152,16 @@ def compute_3pcf(catalogue_data, catalogue_rand, # # Prepare catalogues. # if logger: -# logger.info( -# "Preparing catalogue for clustering algorithm...", -# cpp_state='start' -# ) +# try: +# logger.stat( +# "Preparing catalogue for clustering algorithm...", +# cpp_state='start' +# ) +# except AttributeError: +# logger.info( +# "Preparing catalogue for clustering algorithm...", +# cpp_state='start' +# ) # particles_data = \ # catalogue_data._convert_to_cpp_catalogue(verbose=paramset['verbose']) @@ -1111,10 +1169,16 @@ def compute_3pcf(catalogue_data, catalogue_rand, # catalogue_rand._convert_to_cpp_catalogue(verbose=paramset['verbose']) # if logger: -# logger.info( -# "... prepared catalogue for clustering algorithm.", -# cpp_state='end' -# ) +# try: +# logger.stat( +# "... prepared catalogue for clustering algorithm.", +# cpp_state='end' +# ) +# except AttributeError: +# logger.info( +# "... prepared catalogue for clustering algorithm.", +# cpp_state='end' +# ) # # Set up constants. # alpha = catalogue_data.wstotal / catalogue_rand.wstotal @@ -1163,13 +1227,23 @@ def compute_3pcf(catalogue_data, catalogue_rand, # # Perform measurement. # if logger: -# logger.info( -# "Measuring bispectrum from paired survey-type catalogues " -# "with line-of-sight end-point choice %d " -# "in the local plane-parallel approximation...", -# los_choice, -# cpp_state='start' -# ) +# try: +# logger.stat( +# "Measuring bispectrum from paired survey-type catalogues " +# "with line-of-sight end-point choice %d " +# "in the local plane-parallel approximation...", +# los_choice, +# cpp_state='start' +# ) +# except AttributeError: +# logger.info( +# "Measuring bispectrum from paired survey-type catalogues " +# "with line-of-sight end-point choice %d " +# "in the local plane-parallel approximation...", +# los_choice, +# cpp_state='start' +# ) + # results = _compute_bispec_for_los_choice( # particles_data, particles_rand, los_data, los_rand, los_choice, @@ -1177,13 +1251,22 @@ def compute_3pcf(catalogue_data, catalogue_rand, # ) # if logger: -# logger.info( -# "... measured bispctrum from paired survey-type catalogues " -# "with line-of-sight end-point choice %d " -# "in the local plane-parallel approximation.", -# los_choice, -# cpp_state='end' -# ) +# try: +# logger.stat( +# "... measured bispctrum from paired survey-type catalogues " +# "with line-of-sight end-point choice %d " +# "in the local plane-parallel approximation.", +# los_choice, +# cpp_state='end' +# ) +# except AttributeError: +# logger.info( +# "... measured bispctrum from paired survey-type catalogues " +# "with line-of-sight end-point choice %d " +# "in the local plane-parallel approximation.", +# los_choice, +# cpp_state='end' +# ) # if save: # odirpath = paramset['directories']['measurements'] or "" @@ -1319,7 +1402,10 @@ def _compute_3pt_stats_sim_like(threept_algofunc, catalogue_data, paramset = ParameterSet(param_dict=paramset, logger=logger) if logger: - logger.info("Parameter set have been initialised.") + try: + logger.stat("Parameter set have been initialised.") + except AttributeError: + logger.info("Parameter set have been initialised.") if paramset['catalogue_type'] != 'sim': raise ValueError( @@ -1346,7 +1432,10 @@ def _compute_3pt_stats_sim_like(threept_algofunc, catalogue_data, binning = Binning.from_parameter_set(paramset) if logger: - logger.info("Binning has been initialised.") + try: + logger.stat("Binning has been initialised.") + except AttributeError: + logger.info("Binning has been initialised.") # Set up box alignment. if None in paramset['boxsize'].values(): @@ -1380,7 +1469,10 @@ def _compute_3pt_stats_sim_like(threept_algofunc, catalogue_data, ) if logger: - logger.info("Catalogue box has been periodised.") + try: + logger.stat("Catalogue box has been periodised.") + except AttributeError: + logger.info("Catalogue box has been periodised.") # -------------------------------------------------------------------- # Measurements @@ -1398,19 +1490,31 @@ def _compute_3pt_stats_sim_like(threept_algofunc, catalogue_data, ) if logger: - logger.info( - "Preparing catalogue for clustering algorithm...", - cpp_state='start' - ) + try: + logger.stat( + "Preparing catalogue for clustering algorithm...", + cpp_state='start' + ) + except AttributeError: + logger.info( + "Preparing catalogue for clustering algorithm...", + cpp_state='start' + ) particles_data = \ catalogue_data._convert_to_cpp_catalogue(verbose=paramset['verbose']) if logger: - logger.info( - "... prepared catalogue for clustering algorithm.", - cpp_state='end' - ) + try: + logger.stat( + "... prepared catalogue for clustering algorithm.", + cpp_state='end' + ) + except AttributeError: + logger.info( + "... prepared catalogue for clustering algorithm.", + cpp_state='end' + ) # Set up constants. norm_factor_part = _calc_bispec_normalisation_from_particles( @@ -1448,22 +1552,38 @@ def _compute_3pt_stats_sim_like(threept_algofunc, catalogue_data, # Perform measurement. if logger: - logger.info( - "Measuring %s from a simulation-box catalogue " - "in the global plane-parallel approximation...", - statistic_name, - cpp_state='start' - ) + try: + logger.stat( + "Measuring %s from a simulation-box catalogue " + "in the global plane-parallel approximation...", + statistic_name, + cpp_state='start' + ) + except AttributeError: + logger.info( + "Measuring %s from a simulation-box catalogue " + "in the global plane-parallel approximation...", + statistic_name, + cpp_state='start' + ) results = threept_algofunc(particles_data, paramset, binning, norm_factor) if logger: - logger.info( - "... measured %s from a simulation-box catalogue " - "in the global plane-parallel approximation.", - statistic_name, - cpp_state='end' - ) + try: + logger.stat( + "... measured %s from a simulation-box catalogue " + "in the global plane-parallel approximation.", + statistic_name, + cpp_state='end' + ) + except AttributeError: + logger.info( + "... measured %s from a simulation-box catalogue " + "in the global plane-parallel approximation.", + statistic_name, + cpp_state='end' + ) if save: odirpath = paramset['directories']['measurements'] or "" @@ -1829,7 +1949,10 @@ def compute_3pcf_window(catalogue_rand, los_rand=None, paramset = ParameterSet(param_dict=paramset, logger=logger) if logger: - logger.info("Parameter set have been initialised.") + try: + logger.stat("Parameter set have been initialised.") + except AttributeError: + logger.info("Parameter set have been initialised.") # -- Data ------------------------------------------------------------ @@ -1838,7 +1961,10 @@ def compute_3pcf_window(catalogue_rand, los_rand=None, binning = Binning.from_parameter_set(paramset) if logger: - logger.info("Binning has been initialised.") + try: + logger.stat("Binning has been initialised.") + except AttributeError: + logger.info("Binning has been initialised.") # Set up lines of sight. if los_rand is None: @@ -1846,7 +1972,10 @@ def compute_3pcf_window(catalogue_rand, los_rand=None, los_rand = np.ascontiguousarray(los_rand) if logger: - logger.info("Lines of sight have been initialised.") + try: + logger.stat("Lines of sight have been initialised.") + except AttributeError: + logger.info("Lines of sight have been initialised.") # Set up box alignment. catalogue_rand.centre( @@ -1858,7 +1987,10 @@ def compute_3pcf_window(catalogue_rand, los_rand=None, ) if logger: - logger.info("Catalogues have been aligned.") + try: + logger.stat("Catalogues have been aligned.") + except AttributeError: + logger.info("Catalogues have been aligned.") # -------------------------------------------------------------------- # Measurements @@ -1904,11 +2036,18 @@ def compute_3pcf_window(catalogue_rand, los_rand=None, # Perform measurement. if logger: - logger.info( - "Measuring three-point correlation function window " - "from a random catalogue...", - cpp_state='start' - ) + try: + logger.stat( + "Measuring three-point correlation function window " + "from a random catalogue...", + cpp_state='start' + ) + except AttributeError: + logger.info( + "Measuring three-point correlation function window " + "from a random catalogue...", + cpp_state='start' + ) results = _compute_3pcf_window( particles_rand, los_rand, @@ -1917,11 +2056,18 @@ def compute_3pcf_window(catalogue_rand, los_rand=None, ) if logger: - logger.info( - "... measured three-point correlation function window " - "from a random catalogue.", - cpp_state='end' - ) + try: + logger.stat( + "... measured three-point correlation function window " + "from a random catalogue.", + cpp_state='end' + ) + except AttributeError: + logger.info( + "... measured three-point correlation function window " + "from a random catalogue.", + cpp_state='end' + ) if save: odirpath = paramset['directories']['measurements'] or "" diff --git a/src/triumvirate/twopt.py b/src/triumvirate/twopt.py index 02704f4b..1d03c07a 100644 --- a/src/triumvirate/twopt.py +++ b/src/triumvirate/twopt.py @@ -409,7 +409,10 @@ def _compute_2pt_stats_survey_like(twopt_algofunc, paramset = ParameterSet(param_dict=paramset, logger=logger) if logger: - logger.info("Parameter set have been initialised.") + try: + logger.stat("Parameter set have been initialised.") + except AttributeError: + logger.info("Parameter set have been initialised.") if paramset['catalogue_type'] != 'survey': raise ValueError( @@ -436,7 +439,10 @@ def _compute_2pt_stats_survey_like(twopt_algofunc, binning = Binning.from_parameter_set(paramset) if logger: - logger.info("Binning has been initialised.") + try: + logger.stat("Binning has been initialised.") + except AttributeError: + logger.info("Binning has been initialised.") # Set up lines of sight. if los_data is None: @@ -448,7 +454,10 @@ def _compute_2pt_stats_survey_like(twopt_algofunc, los_rand = np.ascontiguousarray(los_rand) if logger: - logger.info("Lines of sight have been initialised.") + try: + logger.stat("Lines of sight have been initialised.") + except AttributeError: + logger.info("Lines of sight have been initialised.") # Set up box alignment. if None in paramset['boxsize'].values(): @@ -496,7 +505,10 @@ def _compute_2pt_stats_survey_like(twopt_algofunc, ) if logger: - logger.info("Catalogues have been aligned.") + try: + logger.stat("Catalogues have been aligned.") + except AttributeError: + logger.info("Catalogues have been aligned.") # -------------------------------------------------------------------- # Measurements @@ -504,10 +516,16 @@ def _compute_2pt_stats_survey_like(twopt_algofunc, # Prepare catalogues. if logger: - logger.info( - "Preparing catalogue for clustering algorithm...", - cpp_state='start' - ) + try: + logger.stat( + "Preparing catalogue for clustering algorithm...", + cpp_state='start' + ) + except AttributeError: + logger.info( + "Preparing catalogue for clustering algorithm...", + cpp_state='start' + ) particles_data = \ catalogue_data._convert_to_cpp_catalogue(verbose=paramset['verbose']) @@ -515,10 +533,16 @@ def _compute_2pt_stats_survey_like(twopt_algofunc, catalogue_rand._convert_to_cpp_catalogue(verbose=paramset['verbose']) if logger: - logger.info( - "... prepared catalogue for clustering algorithm.", - cpp_state='end' - ) + try: + logger.stat( + "... prepared catalogue for clustering algorithm.", + cpp_state='end' + ) + except AttributeError: + logger.info( + "... prepared catalogue for clustering algorithm.", + cpp_state='end' + ) # Set up constants. alpha = catalogue_data.wstotal / catalogue_rand.wstotal @@ -570,12 +594,20 @@ def _compute_2pt_stats_survey_like(twopt_algofunc, # Perform measurement. if logger: - logger.info( - "Measuring %s from paired survey-type catalogues " - "in the local plane-parallel approximation...", - statistic_name, - cpp_state='start' - ) + try: + logger.stat( + "Measuring %s from paired survey-type catalogues " + "in the local plane-parallel approximation...", + statistic_name, + cpp_state='start' + ) + except AttributeError: + logger.info( + "Measuring %s from paired survey-type catalogues " + "in the local plane-parallel approximation...", + statistic_name, + cpp_state='start' + ) results = twopt_algofunc( particles_data, particles_rand, los_data, los_rand, @@ -583,12 +615,20 @@ def _compute_2pt_stats_survey_like(twopt_algofunc, ) if logger: - logger.info( - "... measured %s from paired survey-type catalogues " - "in the local plane-parallel approximation.", - statistic_name, - cpp_state='end' - ) + try: + logger.stat( + "... measured %s from paired survey-type catalogues " + "in the local plane-parallel approximation.", + statistic_name, + cpp_state='end' + ) + except AttributeError: + logger.info( + "... measured %s from paired survey-type catalogues " + "in the local plane-parallel approximation.", + statistic_name, + cpp_state='end' + ) if save: odirpath = paramset['directories']['measurements'] or "" @@ -918,7 +958,10 @@ def _compute_2pt_stats_sim_like(twopt_algofunc, catalogue_data, paramset = ParameterSet(param_dict=paramset, logger=logger) if logger: - logger.info("Parameter set have been initialised.") + try: + logger.stat("Parameter set have been initialised.") + except AttributeError: + logger.info("Parameter set have been initialised.") if paramset['catalogue_type'] != 'sim': raise ValueError( @@ -945,7 +988,10 @@ def _compute_2pt_stats_sim_like(twopt_algofunc, catalogue_data, binning = Binning.from_parameter_set(paramset) if logger: - logger.info("Binning has been initialised.") + try: + logger.stat("Binning has been initialised.") + except AttributeError: + logger.info("Binning has been initialised.") # Set up box alignment. if None in paramset['boxsize'].values(): @@ -979,7 +1025,10 @@ def _compute_2pt_stats_sim_like(twopt_algofunc, catalogue_data, ) if logger: - logger.info("Catalogue box has been periodised.") + try: + logger.stat("Catalogue box has been periodised.") + except AttributeError: + logger.info("Catalogue box has been periodised.") # -------------------------------------------------------------------- # Measurements @@ -997,19 +1046,31 @@ def _compute_2pt_stats_sim_like(twopt_algofunc, catalogue_data, ) if logger: - logger.info( - "Preparing catalogue for clustering algorithm...", - cpp_state='start' - ) + try: + logger.stat( + "Preparing catalogue for clustering algorithm...", + cpp_state='start' + ) + except AttributeError: + logger.info( + "Preparing catalogue for clustering algorithm...", + cpp_state='start' + ) particles_data = \ catalogue_data._convert_to_cpp_catalogue(verbose=paramset['verbose']) if logger: - logger.info( - "... prepared catalogue for clustering algorithm.", - cpp_state='end' - ) + try: + logger.stat( + "... prepared catalogue for clustering algorithm.", + cpp_state='end' + ) + except AttributeError: + logger.info( + "... prepared catalogue for clustering algorithm.", + cpp_state='end' + ) # Set up constants. norm_factor_part = _calc_powspec_normalisation_from_particles( @@ -1047,22 +1108,38 @@ def _compute_2pt_stats_sim_like(twopt_algofunc, catalogue_data, # Perform measurement. if logger: - logger.info( - "Measuring %s from a simulation-box catalogue " - "in the global plane-parallel approximation...", - statistic_name, - cpp_state='start' - ) + try: + logger.stat( + "Measuring %s from a simulation-box catalogue " + "in the global plane-parallel approximation...", + statistic_name, + cpp_state='start' + ) + except AttributeError: + logger.info( + "Measuring %s from a simulation-box catalogue " + "in the global plane-parallel approximation...", + statistic_name, + cpp_state='start' + ) results = twopt_algofunc(particles_data, paramset, binning, norm_factor) if logger: - logger.info( - "... measured %s from a simulation-box catalogue " - "in the global plane-parallel approximation.", - statistic_name, - cpp_state='end' - ) + try: + logger.stat( + "... measured %s from a simulation-box catalogue " + "in the global plane-parallel approximation.", + statistic_name, + cpp_state='end' + ) + except AttributeError: + logger.info( + "... measured %s from a simulation-box catalogue " + "in the global plane-parallel approximation.", + statistic_name, + cpp_state='end' + ) if save: odirpath = paramset['directories']['measurements'] or "" @@ -1356,7 +1433,10 @@ def compute_corrfunc_window(catalogue_rand, los_rand=None, paramset = ParameterSet(param_dict=paramset, logger=logger) if logger: - logger.info("Parameter set have been initialised.") + try: + logger.stat("Parameter set have been initialised.") + except AttributeError: + logger.info("Parameter set have been initialised.") # -- Data ------------------------------------------------------------ @@ -1365,7 +1445,10 @@ def compute_corrfunc_window(catalogue_rand, los_rand=None, binning = Binning.from_parameter_set(paramset) if logger: - logger.info("Binning has been initialised.") + try: + logger.stat("Binning has been initialised.") + except AttributeError: + logger.info("Binning has been initialised.") # Set up lines of sight. if los_rand is None: @@ -1373,7 +1456,10 @@ def compute_corrfunc_window(catalogue_rand, los_rand=None, los_rand = np.ascontiguousarray(los_rand) if logger: - logger.info("Lines of sight have been initialised.") + try: + logger.stat("Lines of sight have been initialised.") + except AttributeError: + logger.info("Lines of sight have been initialised.") # Set up box alignment. catalogue_rand.centre( @@ -1385,7 +1471,10 @@ def compute_corrfunc_window(catalogue_rand, los_rand=None, ) if logger: - logger.info("Catalogues have been aligned.") + try: + logger.stat("Catalogues have been aligned.") + except AttributeError: + logger.info("Catalogues have been aligned.") # -------------------------------------------------------------------- # Measurements @@ -1431,11 +1520,18 @@ def compute_corrfunc_window(catalogue_rand, los_rand=None, # Perform measurement. if logger: - logger.info( - "Measuring two-point correlation function window " - "from a random catalogue...", - cpp_state='start' - ) + try: + logger.stat( + "Measuring two-point correlation function window " + "from a random catalogue...", + cpp_state='start' + ) + except AttributeError: + logger.info( + "Measuring two-point correlation function window " + "from a random catalogue...", + cpp_state='start' + ) results = _compute_corrfunc_window( particles_rand, los_rand, paramset, binning, @@ -1443,11 +1539,18 @@ def compute_corrfunc_window(catalogue_rand, los_rand=None, ) if logger: - logger.info( - "... measured two-point correlation function window " - "from a random catalogue.", - cpp_state='end' - ) + try: + logger.stat( + "... measured two-point correlation function window " + "from a random catalogue.", + cpp_state='end' + ) + except AttributeError: + logger.info( + "... measured two-point correlation function window " + "from a random catalogue.", + cpp_state='end' + ) if save: odirpath = paramset['directories']['measurements']