diff --git a/src/nectarchain/makers/component/spe/spe_algorithm.py b/src/nectarchain/makers/component/spe/spe_algorithm.py index ed4f4b6e..36f633e9 100644 --- a/src/nectarchain/makers/component/spe/spe_algorithm.py +++ b/src/nectarchain/makers/component/spe/spe_algorithm.py @@ -111,6 +111,12 @@ class SPEalgorithm(Component): help="The order of the polynome used in the savgol filter algorithm", ).tag(config=True) + display_toggle = Bool( + False, + read_only=False, + help="Enable/disable display of SPE fit results", + ) + def __init__( self, pixels_id: np.ndarray, config=None, parent=None, **kwargs ) -> None: @@ -207,7 +213,10 @@ def read_param_from_yaml(self, parameters_file, only_update=False) -> None: @staticmethod def _update_parameters( - parameters: Parameters, charge: np.ndarray, counts: np.ndarray, **kwargs + parameters: Parameters, + charge: np.ndarray, + counts: np.ndarray, + **kwargs, ) -> Parameters: """Update the parameters of the FlatFieldSPEMaker class based on the input charge and counts data. @@ -694,7 +703,7 @@ def _make_minuitParameters_array_from_parameters( self._charge[index].data[~self._charge[index].mask], self._counts[index].data[~self._charge[index].mask], pixel_id=_id, - **kwargs, + **dict(kwargs, display=self.display_toggle), ) index_parameter = Parameter(name="index", value=index, frozen=True) parameters.append(index_parameter) @@ -765,7 +774,6 @@ def run_fit(i: int, tol: float) -> dict: def run( self, pixels_id: np.ndarray = None, - display: bool = True, **kwargs, ) -> np.ndarray: self.log.info("running maker") @@ -790,7 +798,7 @@ def run( else: self.log.info("creation of the minuit parameters array") minuitParameters_array = self._make_minuitParameters_array_from_parameters( - pixels_id=pixels_id, display=display, **kwargs + pixels_id=pixels_id, **kwargs ) self.log.info("running fits") @@ -855,7 +863,7 @@ def run( res, pixels_id, return_fit_array=True ) - if display: + if self.display_toggle: self.log.info("plotting") t = time.time() self.display(pixels_id, **kwargs) @@ -1343,7 +1351,6 @@ def _update_parameters( def run( self, pixels_id: np.ndarray = None, - display: bool = True, **kwargs, ) -> np.ndarray: if pixels_id is None: @@ -1359,4 +1366,4 @@ def run( ], ) ] - return super().run(pixels_id=pixels_id, display=display, **kwargs) + return super().run(pixels_id=pixels_id, **kwargs) diff --git a/src/nectarchain/user_scripts/ggrolleron/gain_SPEfit_combined_computation.py b/src/nectarchain/user_scripts/ggrolleron/gain_SPEfit_combined_computation.py index 41bb1b08..166ffcd4 100644 --- a/src/nectarchain/user_scripts/ggrolleron/gain_SPEfit_combined_computation.py +++ b/src/nectarchain/user_scripts/ggrolleron/gain_SPEfit_combined_computation.py @@ -138,6 +138,7 @@ def main( ): run_number = kwargs.pop("run_number") max_events = kwargs.pop("max_events", [None for i in range(len(run_number))]) + display = kwargs.pop("display") if max_events is None: max_events = [None for i in range(len(run_number))] @@ -173,6 +174,7 @@ def main( run_number=_run_number, max_events=_max_events, SPE_result=path[0], + display_toggle=display, **kwargs, ) tool.setup() @@ -181,7 +183,7 @@ def main( _figpath = f"{figpath}/{tool.name}_run{tool.run_number}_maxevents{_max_events}_{tool.method}_{str_extractor_kwargs}" else: _figpath = f"{figpath}/{tool.name}_run{tool.run_number}_{tool.method}_{str_extractor_kwargs}" - tool.finish(figpath=_figpath, display=args.display) + tool.finish(figpath=_figpath) except Exception as e: log.warning(e, exc_info=True) @@ -220,7 +222,6 @@ def main( kwargs.pop("verbosity") kwargs.pop("figpath") - kwargs.pop("display") kwargs.pop("HHV_run_number") # args.HHV_run_number = 3942 # kwargs['run_number'] = [3936] diff --git a/src/nectarchain/user_scripts/ggrolleron/gain_SPEfit_computation.py b/src/nectarchain/user_scripts/ggrolleron/gain_SPEfit_computation.py index d4980929..759a142b 100644 --- a/src/nectarchain/user_scripts/ggrolleron/gain_SPEfit_computation.py +++ b/src/nectarchain/user_scripts/ggrolleron/gain_SPEfit_computation.py @@ -138,6 +138,7 @@ def main( ): run_number = kwargs.pop("run_number") max_events = kwargs.pop("max_events", [None for i in range(len(run_number))]) + display = kwargs.pop("display") if max_events is None: max_events = [None for i in range(len(run_number))] @@ -162,6 +163,7 @@ def main( progress_bar=True, run_number=_run_number, max_events=_max_events, + display_toggle=display, **kwargs, ) tool.setup() @@ -169,8 +171,8 @@ def main( _figpath = f"{figpath}/{tool.name}_run{tool.run_number}_maxevents{_max_events}_{tool.method}_{CtapipeExtractor.get_extractor_kwargs_str(tool.method,tool.extractor_kwargs)}" else: _figpath = f"{figpath}/{tool.name}_run{tool.run_number}_{tool.method}_{CtapipeExtractor.get_extractor_kwargs_str(tool.method,tool.extractor_kwargs)}" - tool.start(figpath=_figpath, display=args.display) - tool.finish(figpath=_figpath, display=args.display) + tool.start(figpath=_figpath) + tool.finish(figpath=_figpath) except Exception as e: log.warning(e, exc_info=True) @@ -221,7 +223,6 @@ def main( kwargs.pop("verbosity") kwargs.pop("figpath") - kwargs.pop("display") kwargs.pop("HHV") kwargs.pop("free_pp_n")