rewrite bsacquisition with help of Sven Augustin
This commit is contained in:
@ -1,6 +1,5 @@
|
||||
|
||||
import h5py
|
||||
import numpy as np
|
||||
#import numpy as np
|
||||
|
||||
from slic.core.acquisition.acquisition import Acquisition
|
||||
|
||||
@ -9,31 +8,31 @@ 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')
|
||||
for chn in queue.channels:
|
||||
singledata = [ele[chn] for ele in data]
|
||||
gid = hid.create_group(chn)
|
||||
gid.create_dataset('data', data = singledata)
|
||||
singledata = [ele['pid'] for ele in data]
|
||||
|
||||
if self.grp == 0:
|
||||
hid.create_dataset('pulse_id', data = singledata)
|
||||
else:
|
||||
hid.create_dataset('pulse_id_grp%d' % self.grp, data = singledata)
|
||||
hid.close()
|
||||
|
||||
with h5py.File(filename,'a') as hid:
|
||||
for chn in channels:
|
||||
singledata = [ele[chn] for ele in data]
|
||||
gid = hid.create_group(chn)
|
||||
gid.create_dataset('data', data=singledata)
|
||||
|
||||
singledata = [ele['pid'] for ele in data]
|
||||
if self.grp == 0:
|
||||
hid.create_dataset('pulse_id', data=singledata)
|
||||
else:
|
||||
hid.create_dataset('pulse_id_grp%d' % self.grp, data=singledata)
|
||||
|
||||
|
Reference in New Issue
Block a user