44 lines
1.6 KiB
Python
44 lines
1.6 KiB
Python
import h5py
|
|
#import numpy as np
|
|
|
|
from slic.core.acquisition.acquisition import Acquisition
|
|
|
|
|
|
# class using the BSQueue to avoid to reestablish a stream for each step.
|
|
|
|
class BSCAcquisition(Acquisition):
|
|
|
|
def __init__(self, bscache, *args, use_channels=None, **kwargs):
|
|
self.bscache = bscache
|
|
self.use_channels = use_channels
|
|
self.grp = 0
|
|
super().__init__(*args, default_channels= self.use_channels or self.bscache.channels.keys(), **kwargs)
|
|
|
|
def setGroup(self,idx):
|
|
self.grp = idx
|
|
|
|
def _acquire(self, filename, channels=None, data_base_dir=None, scan_info=None, n_pulses=100, **kwargs):
|
|
self.bscache.flush()
|
|
data = []
|
|
for i in range(n_pulses):
|
|
data.append(next(self.bscache))
|
|
|
|
# write out the data file
|
|
use_channels = self.use_channels or self.bscache.channels.keys()
|
|
with h5py.File(filename,'a') as hid:
|
|
# save the pulse ID
|
|
singledata = [ele['pid'] for ele in data]
|
|
pidname = 'pulse_id/group%d' % self.grp
|
|
hid.create_dataset(pidname, data=singledata)
|
|
for chn in use_channels:
|
|
singledata = []
|
|
for ele in data:
|
|
if chn in ele:
|
|
singledata.append(ele[chn])
|
|
else:
|
|
print('%s not in data!' % chn)
|
|
if not chn == 'pid':
|
|
dname = chn.replace(':','/')+'/data'
|
|
hid.create_dataset(dname, data=singledata)
|
|
dpid = dname.replace('/data','/pid')
|
|
hid[dpid] = hid[pidname] |