Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/navigate/controller/sub_controllers/stages.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@

# Local Imports
from navigate.controller.sub_controllers.gui import GUIController
from navigate.model.devices import log_initialization
from navigate.tools.decorators import log_initialization

# Logger Setup
p = __name__.split(".")[1]
logger = logging.getLogger(p)


@log_initialization
class StageController(GUIController):
"""StageController
Expand Down
7 changes: 0 additions & 7 deletions src/navigate/log_files/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,3 @@ def filter(self, record):
if record.getMessage().startswith("Spec"):
return False
return True

class DebugFilter(logging.Filter):
"""
A custom logging filter to include only DEBUG level messages.
"""
def filter(self, record):
return record.levelno == logging.DEBUG
14 changes: 1 addition & 13 deletions src/navigate/log_files/logging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ filters:
(): ext://navigate.log_files.filters.PerformanceFilter
not_performance:
(): ext://navigate.log_files.filters.NonPerfFilter
only_debug:
(): ext://navigate.log_files.filters.DebugFilter
handlers:
console:
class: logging.StreamHandler
Expand All @@ -30,29 +28,19 @@ handlers:
level: DEBUG
formatter: base
filename: view_controller_debug.log
filters: [not_performance, only_debug]
filters: [not_performance]
mode: a
# performance:
# class: logging.handlers.RotatingFileHandler
# level: DEBUG
# formatter: base
# filename: view_controller_performance.log
# filters: [performance_specs]
# mode: a
loggers:
view:
level: DEBUG
# handlers: [console, vc_info, vc_debug, performance]
handlers: [console, vc_info, vc_debug]
propagate: no
controller:
level: DEBUG
# handlers: [console, vc_info, vc_debug, performance]
handlers: [console, vc_info, vc_debug]
propagate: no
config:
level: DEBUG
# handlers: [console, vc_info, vc_debug, performance]
handlers: [console, vc_info, vc_debug]
propagate: no

Expand Down
11 changes: 1 addition & 10 deletions src/navigate/log_files/model_logging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ filters:
(): ext://navigate.log_files.filters.PerformanceFilter
not_performance:
(): ext://navigate.log_files.filters.NonPerfFilter
only_debug:
(): ext://navigate.log_files.filters.DebugFilter
handlers:
console:
class: logging.StreamHandler
Expand All @@ -30,7 +28,7 @@ handlers:
level: DEBUG
formatter: base
filename: model_debug.log
filters: [not_performance, only_debug]
filters: [not_performance]
mode: a
model_error:
class: logging.handlers.RotatingFileHandler
Expand All @@ -39,13 +37,6 @@ handlers:
filename: model_error.log
filters: [not_performance]
mode: a
# model_performance:
# class: logging.handlers.RotatingFileHandler
# level: DEBUG
# formatter: base
# filename: model_performance.log
# filters: [performance_specs]
# mode: a
loggers:
model:
level: DEBUG
Expand Down
65 changes: 10 additions & 55 deletions src/navigate/model/devices/__init__.py
Original file line number Diff line number Diff line change
@@ -1,62 +1,17 @@
""" Hardware devices. """

# Standard library imports
from functools import wraps
import logging
import reprlib

# Third party imports

# Local imports
# from .daq.synthetic import SyntheticDAQ # noqa
# from .camera.synthetic import SyntheticCamera # noqa
# from .filter_wheel.synthetic import SyntheticFilterWheel # noqa
# from .galvo.synthetic import SyntheticGalvo # noqa
# from .remote_focus.synthetic import SyntheticRemoteFocus # noqa
# from .shutter.synthetic import SyntheticShutter # noqa
# from .stages.synthetic import SyntheticStage # noqa
# from .zoom.synthetic import SyntheticZoom # noqa
# from .lasers.synthetic import SyntheticLaser # noqa
# from .mirrors.synthetic import SyntheticMirror # noqa

def log_initialization(cls):
"""Decorator for logging the initialization of a device class.

Parameters
----------
cls : class
The class to be logged.

Returns
-------
cls : class
The class with the logging decorator.
"""
# Set up the reprlib object
mod_repr = reprlib.Repr()
mod_repr.indent = 4
mod_repr.maxstring = 50
mod_repr.maxother = 50

# Get the original __init__ method
original_init = cls.__init__

@wraps(original_init)
def new_init(self, *args, **kwargs):
module_location = cls.__module__
logger = logging.getLogger(module_location.split(".")[1])
try:
original_init(self, *args, **kwargs)
logger.info(f"{mod_repr.repr(cls.__name__)}, "
f"{mod_repr.repr(args)}, "
f"{mod_repr.repr(kwargs)}"
)
except Exception as e:
logger.error(f"{mod_repr.repr(cls.__name__)} Initialization Failed")
logger.error(f"Input args & kwargs: {args}, {kwargs}")
logger.error(f"Error: {e}")
raise e

# Replace the original __init__ method with the new one
cls.__init__ = new_init
return cls
from .daq.synthetic import SyntheticDAQ # noqa
from .camera.synthetic import SyntheticCamera # noqa
from .filter_wheel.synthetic import SyntheticFilterWheel # noqa
from .galvo.synthetic import SyntheticGalvo # noqa
from .remote_focus.synthetic import SyntheticRemoteFocus # noqa
from .shutter.synthetic import SyntheticShutter # noqa
from .stages.synthetic import SyntheticStage # noqa
from .zoom.synthetic import SyntheticZoom # noqa
from .lasers.synthetic import SyntheticLaser # noqa
from .mirrors.synthetic import SyntheticMirror # noqa
8 changes: 5 additions & 3 deletions src/navigate/model/devices/camera/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@

# Local Imports
from navigate.config import get_navigate_path
from navigate.model.devices import log_initialization
from navigate.tools.decorators import log_initialization

# Logger Setup
p = __name__.split(".")[1]
logger = logging.getLogger(p)


@log_initialization
class CameraBase:
"""CameraBase - Parent camera class."""
Expand Down Expand Up @@ -163,8 +164,9 @@ def get_offset_variance_maps(self):
os.path.join(map_path, f"{serial_number}_var.tiff")
)
except FileNotFoundError:
logger.info(f"{str(self)}, Offset or variance map not found in"
f" {map_path}")
logger.info(
f"{str(self)}, Offset or variance map not found in {map_path}"
)
self._offset, self._variance = None, None
return self._offset, self._variance

Expand Down
3 changes: 2 additions & 1 deletion src/navigate/model/devices/camera/hamamatsu.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@

# Local Imports
from navigate.model.devices.camera.base import CameraBase
from navigate.model.devices import log_initialization
from navigate.tools.decorators import log_initialization

# Logger Setup
p = __name__.split(".")[1]
logger = logging.getLogger(p)
Expand Down
2 changes: 1 addition & 1 deletion src/navigate/model/devices/camera/photometrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

# Local Imports
from navigate.model.devices.camera.base import CameraBase
from navigate.model.devices import log_initialization
from navigate.tools.decorators import log_initialization

# Logger Setup
p = __name__.split(".")[1]
Expand Down
2 changes: 1 addition & 1 deletion src/navigate/model/devices/camera/synthetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
# Local Imports
from navigate.model.analysis import camera
from navigate.model.devices.camera.base import CameraBase
from navigate.model.devices import log_initialization
from navigate.tools.decorators import log_initialization

# Logger Setup
p = __name__.split(".")[1]
Expand Down
3 changes: 2 additions & 1 deletion src/navigate/model/devices/daq/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@

# Local Imports
from navigate.model.waveforms import camera_exposure
from navigate.model.devices import log_initialization
from navigate.tools.decorators import log_initialization

# Logger Setup
p = __name__.split(".")[1]
logger = logging.getLogger(p)


@log_initialization
class DAQBase:
"""DAQBase - Parent class for Data Acquisition (DAQ) classes."""
Expand Down
21 changes: 7 additions & 14 deletions src/navigate/model/devices/daq/ni.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@
# Local Imports
from navigate.model.devices.daq.base import DAQBase
from navigate.tools.waveform_template_funcs import get_waveform_template_parameters
from navigate.model.devices import log_initialization
from navigate.tools.decorators import log_initialization

# Logger Setup
p = __name__.split(".")[1]
logger = logging.getLogger(p)


@log_initialization
class NIDAQ(DAQBase):
"""NIDAQ class for Control of NI Data Acquisition Cards."""
Expand Down Expand Up @@ -159,8 +160,7 @@ def set_external_trigger(self, external_trigger=None):
self.analog_output_tasks[board_name].register_done_event(None)
except Exception:
logger.debug(
f"Error Registering Done Event: "
f"{traceback.format_exc()}"
f"Error Registering Done Event: {traceback.format_exc()}"
)
else:
# close master trigger task
Expand Down Expand Up @@ -259,9 +259,7 @@ def callback_func(task_handle, status, callback_data):
task.stop()
task.start()
except Exception:
logger.debug(
f"Analog task restart failed {traceback.format_exc()}"
)
logger.debug(f"Analog task restart failed {traceback.format_exc()}")
return status

return callback_func
Expand Down Expand Up @@ -456,9 +454,7 @@ def run_acquisition(self):
except Exception:
# when triggered from external triggers, sometimes the camera trigger task
# is done but not actually done, there will a DAQ WARNING message
logger.debug(
f"Wait until tasks done failed - {traceback.format_exc()}"
)
logger.debug(f"Wait until tasks done failed - {traceback.format_exc()}")
pass
try:
self.camera_trigger_task.stop()
Expand Down Expand Up @@ -575,17 +571,14 @@ def update_analog_task(self, board_name):
).squeeze()
self.analog_output_tasks[board_name].write(waveforms)
except Exception:
logger.debug(
f"Could not update analog task: {traceback.format_exc()}"
)
logger.debug(f"Could not update analog task: {traceback.format_exc()}")
for board in self.analog_output_tasks.keys():
try:
self.analog_output_tasks[board].stop()
self.analog_output_tasks[board].close()
except Exception:
logger.debug(
f"Could not stop analog tasks: "
f"{traceback.format_exc()}"
f"Could not stop analog tasks: {traceback.format_exc()}"
)

self.create_analog_output_tasks(self.current_channel_key)
Expand Down
3 changes: 2 additions & 1 deletion src/navigate/model/devices/daq/synthetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@

# Local Imports
from navigate.model.devices.daq.base import DAQBase
from navigate.model.devices import log_initialization
from navigate.tools.decorators import log_initialization

# Logger Setup
p = __name__.split(".")[1]
logger = logging.getLogger(p)


@log_initialization
class SyntheticDAQ(DAQBase):
"""SyntheticDAQ class for Data Acquisition (DAQ)."""
Expand Down
3 changes: 2 additions & 1 deletion src/navigate/model/devices/filter_wheel/asi.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
# Local Imports
from navigate.model.devices.filter_wheel.base import FilterWheelBase
from navigate.model.devices.APIs.asi.asi_tiger_controller import TigerController
from navigate.model.devices import log_initialization
from navigate.tools.decorators import log_initialization

# Logger Setup
p = __name__.split(".")[1]
Expand Down Expand Up @@ -170,6 +170,7 @@ def close(self):
logger.debug("ASI Filter Wheel - Closing Device.")
self.filter_wheel.disconnect_from_serial()


@log_initialization
class ASICubeSlider(FilterWheelBase):
"""ASICubeSlider - Class for controlling the C60 Cube Slider from ASI.
Expand Down
2 changes: 1 addition & 1 deletion src/navigate/model/devices/filter_wheel/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
# Third Party Imports

# Local Imports
from navigate.model.devices import log_initialization
from navigate.tools.decorators import log_initialization

# Logger Setup
p = __name__.split(".")[1]
Expand Down
2 changes: 1 addition & 1 deletion src/navigate/model/devices/filter_wheel/ni.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

# Local Imports
from navigate.model.devices.filter_wheel.base import FilterWheelBase
from navigate.model.devices import log_initialization
from navigate.tools.decorators import log_initialization

# Logger Setup
p = __name__.split(".")[1]
Expand Down
2 changes: 1 addition & 1 deletion src/navigate/model/devices/filter_wheel/sutter.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

# Local Imports
from navigate.model.devices.filter_wheel.base import FilterWheelBase
from navigate.model.devices import log_initialization
from navigate.tools.decorators import log_initialization

# Logger Setup
p = __name__.split(".")[1]
Expand Down
2 changes: 1 addition & 1 deletion src/navigate/model/devices/filter_wheel/synthetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

# Local Imports
from navigate.model.devices.filter_wheel.base import FilterWheelBase
from navigate.model.devices import log_initialization
from navigate.tools.decorators import log_initialization

# Logger Setup
p = __name__.split(".")[1]
Expand Down
2 changes: 1 addition & 1 deletion src/navigate/model/devices/galvo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

# Local Imports
from navigate.model.waveforms import sawtooth, sine_wave
from navigate.model.devices import log_initialization
from navigate.tools.decorators import log_initialization

# # Logger Setup
p = __name__.split(".")[1]
Expand Down
2 changes: 1 addition & 1 deletion src/navigate/model/devices/galvo/ni.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

# Local Imports
from navigate.model.devices.galvo.base import GalvoBase
from navigate.model.devices import log_initialization
from navigate.tools.decorators import log_initialization

# # Logger Setup
p = __name__.split(".")[1]
Expand Down
Loading
Loading