re-factored common counter code to Counter class
This commit is contained in:
+4
-26
@@ -1,13 +1,9 @@
|
||||
from datetime import datetime, timedelta
|
||||
import os
|
||||
import zmq
|
||||
|
||||
from bsread.h5 import receive
|
||||
from bsread.avail import dispatcher
|
||||
|
||||
from .acquisition import Acquisition
|
||||
from .basecounter import BaseCounter
|
||||
from .utils import can_create_file, fix_hdf5_filename
|
||||
from .counter import Counter
|
||||
|
||||
|
||||
|
||||
@@ -17,28 +13,10 @@ def bsread_to_h5(filename, channels, n_pulses=100, queue_size=100, mode=zmq.SUB)
|
||||
|
||||
|
||||
|
||||
class BSCounter(BaseCounter):
|
||||
class BSCounter(Counter):
|
||||
|
||||
def __init__(self, default_channels=None, default_path="."):
|
||||
self.default_channels = default_channels
|
||||
self.default_path = default_path
|
||||
|
||||
|
||||
def acquire(self, filename=None, channels=None, use_default_path=True, **kwargs):
|
||||
if filename and use_default_path:
|
||||
filename = os.path.join(self.default_path, filename)
|
||||
|
||||
filename = fix_hdf5_filename(filename)
|
||||
|
||||
if not can_create_file(filename):
|
||||
return
|
||||
|
||||
if not channels:
|
||||
print("No channels specified, using default channel list.")
|
||||
channels = self.default_channels
|
||||
|
||||
acq = lambda: bsread_to_h5(filename, channels, **kwargs)
|
||||
return Acquisition(acq, hold=False)
|
||||
def _acquire(self, *args, **kwargs):
|
||||
bsread_to_h5(*args, **kwargs)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import os
|
||||
from abc import abstractmethod
|
||||
|
||||
from .basecounter import BaseCounter
|
||||
from .utils import can_create_file, fix_hdf5_filename
|
||||
|
||||
from .acquisition import Acquisition
|
||||
|
||||
|
||||
|
||||
class Counter(BaseCounter):
|
||||
|
||||
def __init__(self, default_channels=None, default_path="."):
|
||||
self.default_channels = default_channels
|
||||
self.default_path = default_path
|
||||
|
||||
|
||||
def acquire(self, filename=None, channels=None, use_default_path=True, **kwargs):
|
||||
if filename and use_default_path:
|
||||
filename = os.path.join(self.default_path, filename)
|
||||
|
||||
filename = fix_hdf5_filename(filename)
|
||||
|
||||
if not can_create_file(filename):
|
||||
return
|
||||
|
||||
if not channels:
|
||||
print("No channels specified, using default channel list.")
|
||||
channels = self.default_channels
|
||||
|
||||
acq = lambda: self._acquire(filename, channels, **kwargs)
|
||||
return Acquisition(acq, hold=False)
|
||||
|
||||
|
||||
@abstractmethod
|
||||
def _acquire(self):
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
|
||||
+4
-26
@@ -1,12 +1,8 @@
|
||||
from datetime import datetime, timedelta
|
||||
import os
|
||||
import zmq
|
||||
|
||||
import data_api as dapi
|
||||
|
||||
from .acquisition import Acquisition
|
||||
from .basecounter import BaseCounter
|
||||
from .utils import can_create_file, fix_hdf5_filename
|
||||
from .counter import Counter
|
||||
|
||||
|
||||
|
||||
@@ -30,28 +26,10 @@ def dapi_get(channels, start_time_delta=None, end_time_delta=None):
|
||||
|
||||
|
||||
|
||||
class DBCounter(BaseCounter):
|
||||
class DBCounter(Counter):
|
||||
|
||||
def __init__(self, default_channels=None, default_path="."):
|
||||
self.default_channels = default_channels
|
||||
self.default_path = default_path
|
||||
|
||||
|
||||
def acquire(self, filename=None, channels=None, use_default_path=True, **kwargs):
|
||||
if filename and use_default_path:
|
||||
filename = os.path.join(self.default_path, filename)
|
||||
|
||||
filename = fix_hdf5_filename(filename)
|
||||
|
||||
if not can_create_file(filename):
|
||||
return
|
||||
|
||||
if not channels:
|
||||
print("No channels specified, using default channel list.")
|
||||
channels = self.default_channels
|
||||
|
||||
acq = lambda: dapi_to_h5(filename, channels, **kwargs)
|
||||
return Acquisition(acq, hold=False)
|
||||
def _acquire(self, *args, **kwargs):
|
||||
dapi_to_h5(*args, **kwargs)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -68,7 +68,6 @@ class DIACounter(BaseCounter):
|
||||
|
||||
self.detector_config = {
|
||||
"timing": "trigger",
|
||||
|
||||
# FIXME: HARDCODED: For Alvra JF4.5 it's 0.000005, Bernina is using 0.00001
|
||||
"exptime": 0.000005,
|
||||
"cycles": self.n_frames,
|
||||
|
||||
Reference in New Issue
Block a user