Base Class
PhysioMotion4DBase provides the shared logging behavior used by workflow,
segmentation, registration, transform, contour, and USD helper classes.
Class Reference
- class physiomotion4d.PhysioMotion4DBase(class_name=None, log_level=20, log_to_file=None)[source]
Bases:
objectBase class providing standardized logging and debug settings.
This class provides a consistent logging interface for all PhysioMotion4D classes. All classes share a common logger called “PhysioMotion4D” but include their class name in log messages for identification.
- Class Attributes:
_shared_logger (logging.Logger): Shared logger for all PhysioMotion4D classes _class_filter (ClassNameFilter): Filter for controlling which classes show logs _logger_initialized (bool): Whether the shared logger has been set up
- Instance Attributes:
class_name (str): Name of the class for log message prefixing log_level (int): Current logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
Example
>>> import logging >>> class MyRegistration(PhysioMotion4DBase): ... def __init__(self): ... super().__init__(class_name='MyRegistration', log_level=logging.INFO) ... ... def register(self): ... self.log_info('Starting registration...') ... self.log_debug('Using parameters: ...') >>> >>> # Filter to show only specific classes >>> PhysioMotion4DBase.set_log_classes(['MyRegistration']) >>> >>> # Show all classes again >>> PhysioMotion4DBase.set_log_all_classes()
- __init__(class_name=None, log_level=20, log_to_file=None)[source]
Initialize the base class with logging configuration.
- Parameters:
class_name (
Optional[str]) – Name for the class (used in log messages). If None, uses the class name. Default: Nonelog_level (
int|str) – Logging level. Can be an integer (logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR, logging.CRITICAL) or a string (‘DEBUG’, ‘INFO’, ‘WARNING’, ‘ERROR’, ‘CRITICAL’). Default: logging.INFOlog_to_file (
Optional[str]) – Optional file path to write logs to in addition to console output. Default: None
- classmethod set_log_level(log_level)[source]
Set the logging level for all PhysioMotion4D classes.
- Parameters:
log_level (
int|str) – Logging level. Can be an integer (logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR, logging.CRITICAL) or a string (‘DEBUG’, ‘INFO’, ‘WARNING’, ‘ERROR’, ‘CRITICAL’).- Return type:
Example
>>> import logging >>> PhysioMotion4DBase.set_log_level(logging.DEBUG) >>> # or >>> PhysioMotion4DBase.set_log_level('DEBUG')
- classmethod set_log_classes(class_names)[source]
Set which classes should show their logging output.
Only log messages from the specified classes will be displayed. All other classes will have their logs hidden.
- Parameters:
class_names (
list[str]) – List of class names to show logs from. Example: [“RegisterModelsPCA”, “WorkflowFitStatisticalModelToPatient”]- Return type:
Example
>>> PhysioMotion4DBase.set_log_classes(['RegisterModelsPCA']) >>> # Now only RegisterModelsPCA logs will be shown
- classmethod set_log_all_classes()[source]
Enable logging output from all PhysioMotion4D classes.
Disables the class filter so all classes show their logs.
Example
>>> PhysioMotion4DBase.set_log_all_classes() >>> # Now all classes will show their logs
- Return type:
- classmethod get_log_classes()[source]
Get the list of classes currently showing logs.
- Return type:
- Returns:
List of class names that are allowed to show logs. Empty list if filter is disabled (all classes shown).
Example
>>> classes = PhysioMotion4DBase.get_log_classes() >>> print(classes) ['RegisterModelsPCA', 'WorkflowFitStatisticalModelToPatient']
- log_debug(message, *args)[source]
Log a debug message with optional %-style formatting.
- Parameters:
- Return type:
Example
>>> self.log_debug('Processing %s with %d items', filename, count) >>> self.log_debug('Value is %(value)d', {'value': 42})
- log_info(message, *args)[source]
Log an info message with optional %-style formatting.
- Parameters:
- Return type:
Example
>>> self.log_info('Loading file: %s', filepath) >>> self.log_info('Iteration %(iter)d of %(total)d', {'iter': 5, 'total': 10})
- log_warning(message, *args)[source]
Log a warning message with optional %-style formatting.
- Parameters:
- Return type:
Example
>>> self.log_warning('Memory usage at %d%%', usage_percent) >>> self.log_warning('Parameter %(name)s out of range', {'name': 'threshold'})
- log_error(message, *args)[source]
Log an error message with optional %-style formatting.
- Parameters:
- Return type:
Example
>>> self.log_error('Failed to load %s: %s', filename, error_msg) >>> self.log_error('Error code: %(code)d', {'code': 404})
- log_critical(message, *args)[source]
Log a critical message with optional %-style formatting.
- Parameters:
- Return type:
Example
>>> self.log_critical('System failure at %s', timestamp) >>> self.log_critical('Critical error: %(msg)s', {'msg': 'Out of memory'})
- log_section(title, *args, width=70, char='=')[source]
Log a formatted section header with optional %-style formatting.
Useful for visually separating major sections of output.
- Parameters:
- Return type:
Example
>>> self.log_section('Stage 1: Initialization') >>> self.log_section('Processing file: %s', filename) >>> self.log_section('Stage %(num)d: %(name)s', {'num': 2, 'name': 'Analysis'}) # Outputs: # ====================================================================== # Stage 2: Analysis # ======================================================================
- log_progress(current, total, prefix='Progress')[source]
Log progress information.
- Parameters:
- Return type:
Example
>>> for i in range(100): ... self.log_progress(i + 1, 100) >>> self.log_progress(5, 10, prefix='Processing')
Note
For custom formatted progress messages, use log_info() directly: >>> self.log_info(‘Loading %s: %d/%d’, filename, current, total)
Logging
Runtime classes should call log_info(), log_debug(), and
log_warning() instead of printing directly. The base class also supports
global log filtering by class name.
import logging
from physiomotion4d import PhysioMotion4DBase
class MyProcessor(PhysioMotion4DBase):
def __init__(self) -> None:
super().__init__(class_name="MyProcessor", log_level=logging.INFO)
def process(self) -> None:
self.log_info("Starting processing")
self.log_debug("Detailed diagnostic state")
self.log_warning("Recoverable issue")
processor = MyProcessor()
processor.process()
PhysioMotion4DBase.set_log_classes(["MyProcessor"])
PhysioMotion4DBase.set_log_all_classes()
Extension Notes
New runtime classes should inherit from PhysioMotion4DBase and pass a
class_name plus log_level to super().__init__. Standalone scripts,
data containers, and small pure utility functions do not need to inherit from
the base class.