Skip to content

Commit

Permalink
Make verbose a private property, and add getter and setters for it, t…
Browse files Browse the repository at this point in the history
…o propagate verbosity
  • Loading branch information
rettigl committed Sep 19, 2024
1 parent 79a181d commit 8716dc0
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 19 deletions.
23 changes: 21 additions & 2 deletions sed/calibrator/delay.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def __init__(
else:
self._config = {}

self.verbose = verbose
set_verbosity(logger, self.verbose)
self._verbose = verbose
set_verbosity(logger, self._verbose)

self.adc_column: str = self._config["dataframe"].get("adc_column", None)
self.delay_column: str = self._config["dataframe"]["delay_column"]
Expand All @@ -60,6 +60,25 @@ def __init__(
self.calibration: dict[str, Any] = self._config["delay"].get("calibration", {})
self.offsets: dict[str, Any] = self._config["delay"].get("offsets", {})

@property
def verbose(self) -> bool:
"""Accessor to the verbosity flag.
Returns:
bool: Verbosity flag.
"""
return self._verbose

@verbose.setter
def verbose(self, verbose: bool):
"""Setter for the verbosity.
Args:
verbose (bool): Option to turn on verbose output. Sets loglevel to INFO.
"""
self._verbose = verbose
set_verbosity(logger, self._verbose)

def append_delay_axis(
self,
df: pd.DataFrame | dask.dataframe.DataFrame,
Expand Down
23 changes: 21 additions & 2 deletions sed/calibrator/energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ def __init__(

self._config = config

self.verbose = verbose
set_verbosity(logger, self.verbose)
self._verbose = verbose
set_verbosity(logger, self._verbose)

self.loader = loader
self.biases: np.ndarray = None
Expand Down Expand Up @@ -125,6 +125,25 @@ def __init__(
self.offsets: dict[str, Any] = self._config["energy"].get("offsets", {})
self.correction: dict[str, Any] = self._config["energy"].get("correction", {})

@property
def verbose(self) -> bool:
"""Accessor to the verbosity flag.
Returns:
bool: Verbosity flag.
"""
return self._verbose

@verbose.setter
def verbose(self, verbose: bool):
"""Setter for the verbosity.
Args:
verbose (bool): Option to turn on verbose output. Sets loglevel to INFO.
"""
self._verbose = verbose
set_verbosity(logger, self._verbose)

@property
def ntraces(self) -> int:
"""Property returning the number of traces.
Expand Down
25 changes: 22 additions & 3 deletions sed/calibrator/momentum.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ def __init__(

self._config = config

self.verbose = verbose
set_verbosity(logger, self.verbose)
self._verbose = verbose
set_verbosity(logger, self._verbose)

self.image: np.ndarray = None
self.img_ndim: int = None
Expand Down Expand Up @@ -132,6 +132,25 @@ def __init__(

self._state: int = 0

@property
def verbose(self) -> bool:
"""Accessor to the verbosity flag.
Returns:
bool: Verbosity flag.
"""
return self._verbose

@verbose.setter
def verbose(self, verbose: bool):
"""Setter for the verbosity.
Args:
verbose (bool): Option to turn on verbose output. Sets loglevel to INFO.
"""
self._verbose = verbose
set_verbosity(logger, self._verbose)

@property
def features(self) -> dict:
"""Dictionary of detected features for the symmetrization process.
Expand Down Expand Up @@ -1241,7 +1260,7 @@ def apply_func(apply: bool): # noqa: ARG001
transformations["creation_date"] = datetime.now().timestamp()
self.transformations = transformations

if self.verbose:
if self._verbose:
plt.figure()
subs = 20
plt.title("Final Deformation field")
Expand Down
39 changes: 31 additions & 8 deletions sed/core/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ def __init__(
logger.debug(f"Use {num_cores} cores for processing.")

if verbose is None:
self.verbose = self._config["core"].get("verbose", True)
self._verbose = self._config["core"].get("verbose", True)
else:
self.verbose = verbose
set_verbosity(logger, self.verbose)
self._verbose = verbose
set_verbosity(logger, self._verbose)

self._dataframe: pd.DataFrame | ddf.DataFrame = None
self._timed_dataframe: pd.DataFrame | ddf.DataFrame = None
Expand Down Expand Up @@ -148,17 +148,17 @@ def __init__(
verbose=verbose,
),
config=self._config,
verbose=self.verbose,
verbose=self._verbose,
)

self.mc = MomentumCorrector(
config=self._config,
verbose=self.verbose,
verbose=self._verbose,
)

self.dc = DelayCalibrator(
config=self._config,
verbose=self.verbose,
verbose=self._verbose,
)

self.use_copy_tool = self._config.get("core", {}).get(
Expand Down Expand Up @@ -227,6 +227,29 @@ def _repr_html_(self):
# """Provides an overview panel with plots of different data attributes."""
# self.view_event_histogram(dfpid=2, backend="matplotlib")

@property
def verbose(self) -> bool:
"""Accessor to the verbosity flag.
Returns:
bool: Verbosity flag.
"""
return self._verbose

@verbose.setter
def verbose(self, verbose: bool):
"""Setter for the verbosity.
Args:
verbose (bool): Option to turn on verbose output. Sets loglevel to INFO.
"""
self._verbose = verbose
set_verbosity(logger, self._verbose)
self.mc.verbose = verbose
self.ec.verbose = verbose
self.dc.verbose = verbose
self.loader.verbose = verbose

@property
def dataframe(self) -> pd.DataFrame | ddf.DataFrame:
"""Accessor to the underlying dataframe.
Expand Down Expand Up @@ -629,7 +652,7 @@ def generate_splinewarp(

self.mc.spline_warp_estimate(use_center=use_center, **kwds)

if self.mc.slice is not None and self.verbose:
if self.mc.slice is not None and self._verbose:
print("Original slice with reference features")
self.mc.view(annotated=True, backend="bokeh", crosshair=True)

Expand Down Expand Up @@ -1334,7 +1357,7 @@ def calibrate_energy_axis(
energy_scale=energy_scale,
**kwds,
)
if self.verbose:
if self._verbose:
self.ec.view(
traces=self.ec.traces_normed,
xaxis=self.ec.calibration["axis"],
Expand Down
20 changes: 19 additions & 1 deletion sed/loader/base/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,25 @@ def __init__(
self.files: list[str] = []
self.runs: list[str] = []
self.metadata: dict[Any, Any] = {}
self.verbose = verbose
self._verbose = verbose

@property
def verbose(self) -> bool:
"""Accessor to the verbosity flag.
Returns:
bool: Verbosity flag.
"""
return self._verbose

@verbose.setter
def verbose(self, verbose: bool):
"""Setter for the verbosity.
Args:
verbose (bool): Option to turn on verbose output. Sets loglevel to INFO.
"""
self._verbose = verbose

@abstractmethod
def read_dataframe(
Expand Down
21 changes: 20 additions & 1 deletion sed/loader/flash/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,31 @@ def __init__(self, config: dict, verbose: bool = True) -> None:
"""
super().__init__(config=config, verbose=verbose)

set_verbosity(logger, self.verbose)
set_verbosity(logger, self._verbose)

self.instrument: str = self._config["core"].get("instrument", "hextof") # default is hextof
self.raw_dir: str = None
self.processed_dir: str = None

@property
def verbose(self) -> bool:
"""Accessor to the verbosity flag.
Returns:
bool: Verbosity flag.
"""
return self._verbose

@verbose.setter
def verbose(self, verbose: bool):
"""Setter for the verbosity.
Args:
verbose (bool): Option to turn on verbose output. Sets loglevel to INFO.
"""
self._verbose = verbose
set_verbosity(logger, self._verbose)

def _initialize_dirs(self) -> None:
"""
Initializes the directories on Maxwell based on configuration. If paths is provided in
Expand Down
21 changes: 20 additions & 1 deletion sed/loader/mpes/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,13 +570,32 @@ def __init__(
):
super().__init__(config=config, verbose=verbose)

set_verbosity(logger, self.verbose)
set_verbosity(logger, self._verbose)

self.read_timestamps = self._config.get("dataframe", {}).get(
"read_timestamps",
False,
)

@property
def verbose(self) -> bool:
"""Accessor to the verbosity flag.
Returns:
bool: Verbosity flag.
"""
return self._verbose

@verbose.setter
def verbose(self, verbose: bool):
"""Setter for the verbosity.
Args:
verbose (bool): Option to turn on verbose output. Sets loglevel to INFO.
"""
self._verbose = verbose
set_verbosity(logger, self._verbose)

def read_dataframe(
self,
files: str | Sequence[str] = None,
Expand Down
21 changes: 20 additions & 1 deletion sed/loader/sxp/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class SXPLoader(BaseLoader):
def __init__(self, config: dict, verbose: bool = True) -> None:
super().__init__(config=config, verbose=verbose)

set_verbosity(logger, self.verbose)
set_verbosity(logger, self._verbose)

self.multi_index = ["trainId", "pulseId", "electronId"]
self.index_per_electron: MultiIndex = None
Expand All @@ -66,6 +66,25 @@ def __init__(self, config: dict, verbose: bool = True) -> None:
self.raw_dir: str = None
self.processed_dir: str = None

@property
def verbose(self) -> bool:
"""Accessor to the verbosity flag.
Returns:
bool: Verbosity flag.
"""
return self._verbose

@verbose.setter
def verbose(self, verbose: bool):
"""Setter for the verbosity.
Args:
verbose (bool): Option to turn on verbose output. Sets loglevel to INFO.
"""
self._verbose = verbose
set_verbosity(logger, self._verbose)

def _initialize_dirs(self):
"""
Initializes the paths based on the configuration.
Expand Down

0 comments on commit 8716dc0

Please sign in to comment.