Fix bscaquisition #5

Merged
dijkstal_p merged 3 commits from fix_bscaquisition into master 2025-04-27 11:21:36 +02:00

View File

@ -1,6 +1,5 @@
import h5py
import numpy as np
#import numpy as np
from slic.core.acquisition.acquisition import Acquisition
@ -9,32 +8,33 @@ from slic.core.acquisition.acquisition import Acquisition
class BSCAcquisition(Acquisition):
def __init__(self, bscache, *args, **kwargs):
self.bscache = bscache
self.grp = 0
super().__init__(*args, **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):
#print('Requested %i' % i)
data.append(next(self.bscache))
#print('Received %i' % i)
if not hasattr(self,'grp'):
self.grp = 0
queue =channels[0] # abusing interface since BSAcquisition assume a list of channels
# clear the queue
queue.flush()
# gather data
data = [queue.__next__() for i in range(n_pulses)]
# write out the data file
hid = h5py.File(filename,'a')
# 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 queue.channels:
singledata = [ele[chn] for ele in data]
if not chn == 'pid':
dname = chn.replace(':','/')+'/data'
hid.create_dataset(dname, data = singledata)
dpid = dname.replace('/data','/pid')
hid[dpid] = hid[pidname]
hid.close()
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 channels:
singledata = [ele[chn] for ele in data]
if not chn == 'pid':
dname = chn.replace(':','/')+'/data'
hid.create_dataset(dname, data=singledata)
dpid = dname.replace('/data','/pid')
hid[dpid] = hid[pidname]