Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce Abstract #137

Merged
merged 8 commits into from
Apr 6, 2022
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
15 changes: 14 additions & 1 deletion sashimi/hardware/cameras/interface.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from enum import Enum
from abc import ABC, abstractmethod


class CameraException(Exception):
Expand All @@ -14,24 +15,27 @@ class TriggerMode(Enum):
EXTERNAL_TRIGGER = 2


class AbstractCamera:
class AbstractCamera(ABC):
def __init__(self, camera_id, max_sensor_resolution=None):
self.camera_id = camera_id
self.max_sensor_resolution = max_sensor_resolution

@abstractmethod
def get_frames(self):
"""
Returns a list of arrays, each of which corresponds to an available frame. If no frames where found returns an
empty list.
"""
pass

@abstractmethod
def start_acquisition(self):
"""
Allocate as many frames as will fit in 2GB of memory and start data acquisition.
"""
pass

@abstractmethod
def stop_acquisition(self):
"""
Stop data acquisition and release the memory allocated for frames.
Expand All @@ -45,38 +49,47 @@ def shutdown(self):
self.stop_acquisition()

@property
@abstractmethod
def exposure_time(self):
return None

@exposure_time.setter
@abstractmethod
def exposure_time(self, exp_val):
pass

@property
@abstractmethod
def binning(self):
return None

@binning.setter
@abstractmethod
def binning(self, exp_val):
pass

@property
@abstractmethod
def roi(self):
return None

@roi.setter
@abstractmethod
def roi(self, exp_val: tuple):
pass

@property
@abstractmethod
def trigger_mode(self):
return None

@trigger_mode.setter
@abstractmethod
def trigger_mode(self, exp_val):
pass

@property
@abstractmethod
def frame_rate(self):
return None

Expand Down
20 changes: 20 additions & 0 deletions sashimi/hardware/cameras/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ def roi(self, exp_val: tuple):
self._roi = exp_val
self.prepare_mock_image()

@property
def trigger_mode(self):
return None

@trigger_mode.setter
def trigger_mode(self, exp_val):
pass

def prepare_mock_image(self):
self.current_mock_image = block_reduce(
self.full_mock_image, (self._binning, self._binning), func=np.max
Expand All @@ -76,3 +84,15 @@ def get_frames(self):
else:
self.previous_frame_time = self.current_time
return frames

def start_acquisition(self):
"""
Allocate as many frames as will fit in 2GB of memory and start data acquisition.
"""
pass

def stop_acquisition(self):
"""
Stop data acquisition and release the memory allocated for frames.
"""
pass
4 changes: 3 additions & 1 deletion sashimi/hardware/external_trigger/interface.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from typing import Optional
from abc import ABC, abstractmethod


class AbstractComm:
class AbstractComm(ABC):
def __init__(self, address):
self.address = address

@abstractmethod
def trigger_and_receive_duration(self, config) -> Optional[float]:
return None
4 changes: 4 additions & 0 deletions sashimi/hardware/light_source/cobolt.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ def get_info(self):
def close(self):
self.socket.close()

def set_power(self, current):
"""Sets power of laser based on self.intensity and self.intensity_units"""
pass

@property
def intensity(self):
return self._current
Expand Down
9 changes: 8 additions & 1 deletion sashimi/hardware/light_source/interface.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from enum import Enum
from abc import ABC, abstractmethod


class LaserState(Enum):
Expand All @@ -14,7 +15,7 @@ class LaserWarning(Warning):
pass


class AbstractLightSource:
class AbstractLightSource(ABC):
def __init__(self, port):
self.port = port
self._status = LaserState.OFF
Expand All @@ -23,25 +24,31 @@ def __init__(self, port):
def start(self):
pass

@abstractmethod
def set_power(self, current):
"""Sets power of laser based on self.intensity and self.intensity_units"""
pass
fedem-p marked this conversation as resolved.
Show resolved Hide resolved

@abstractmethod
def close(self):
pass

@property
@abstractmethod
def intensity(self):
return None

@intensity.setter
@abstractmethod
def intensity(self, exp_val):
pass
fedem-p marked this conversation as resolved.
Show resolved Hide resolved

@property
@abstractmethod
def status(self):
return self._status

@status.setter
@abstractmethod
def status(self, exp_val):
pass
7 changes: 7 additions & 0 deletions sashimi/hardware/light_source/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ def __init__(self, port=None):
self._current = 0
self.intensity_units = "mocks"

def set_power(self, current):
"""Sets power of laser based on self.intensity and self.intensity_units"""
pass

def close(self):
pass

@property
def intensity(self):
return self._current
Expand Down
30 changes: 23 additions & 7 deletions sashimi/hardware/scanning/__init__.py
Original file line number Diff line number Diff line change
@@ -1,73 +1,89 @@
from contextlib import contextmanager
from abc import ABC, abstractmethod


class ScanningError(Exception):
pass


class AbstractScanInterface:
class AbstractScanInterface(ABC):
def __init__(self, sample_rate, n_samples, conf, *args, **kwargs):
self.sample_rate = sample_rate
self.n_samples = n_samples
self.conf = conf

@abstractmethod
def start(self):
pass

@abstractmethod
def write(self):
pass

@abstractmethod
def read(self):
pass

@property
@abstractmethod
def z_piezo(self):
return None

@z_piezo.setter
@abstractmethod
def z_piezo(self, waveform):
pass

@property
@abstractmethod
def z_frontal(self):
return None

@z_frontal.setter
@abstractmethod
def z_frontal(self, waveform):
pass

@property
@abstractmethod
def z_lateral(self):
return None

@z_lateral.setter
@abstractmethod
def z_lateral(self, waveform):
pass

@property
@abstractmethod
def camera_trigger(self):
return None

@camera_trigger.setter
@abstractmethod
def camera_trigger(self, waveform):
pass

@property
@abstractmethod
def xy_frontal(self):
return None

@xy_frontal.setter
@abstractmethod
def xy_frontal(self, waveform):
pass

@property
@abstractmethod
def xy_lateral(self):
return None

@xy_lateral.setter
@abstractmethod
def xy_lateral(self, waveform):
pass

def write(self):
pass

def read(self):
pass


@contextmanager
def open_abstract_interface(sample_rate, n_samples, conf) -> AbstractScanInterface:
Expand Down
51 changes: 47 additions & 4 deletions sashimi/hardware/scanning/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ def __init__(self, sample_rate, n_samples, conf):
super().__init__(sample_rate, n_samples, conf)
self.piezo_array = np.zeros(n_samples)

def start(self):
pass

def read(self):
sleep(0.05)

def write(self):
sleep(0.05)

@property
def z_piezo(self):
len_sampling = len(self.piezo_array)
Expand All @@ -18,11 +27,45 @@ def z_piezo(self):
def z_piezo(self, waveform):
self.piezo_array[:] = waveform

def read(self):
sleep(0.05)
@property
def z_frontal(self):
return None

def write(self):
sleep(0.05)
@z_frontal.setter
def z_frontal(self, waveform):
pass

@property
def z_lateral(self):
return None

@z_lateral.setter
def z_lateral(self, waveform):
pass

@property
def camera_trigger(self):
return None

@camera_trigger.setter
def camera_trigger(self, waveform):
pass

@property
def xy_frontal(self):
return None

@xy_frontal.setter
def xy_frontal(self, waveform):
pass

@property
def xy_lateral(self):
return None

@xy_lateral.setter
def xy_lateral(self, waveform):
pass


@contextmanager
Expand Down