Fix bscaquisition #5
@ -1,6 +1,5 @@
|
|||||||
|
|
||||||
import h5py
|
import h5py
|
||||||
import numpy as np
|
#import numpy as np
|
||||||
|
|
||||||
from slic.core.acquisition.acquisition import Acquisition
|
from slic.core.acquisition.acquisition import Acquisition
|
||||||
|
|
||||||
@ -9,32 +8,33 @@ from slic.core.acquisition.acquisition import Acquisition
|
|||||||
|
|
||||||
class BSCAcquisition(Acquisition):
|
class BSCAcquisition(Acquisition):
|
||||||
|
|
||||||
|
def __init__(self, bscache, *args, **kwargs):
|
||||||
|
self.bscache = bscache
|
||||||
|
self.grp = 0
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
def setGroup(self,idx):
|
def setGroup(self,idx):
|
||||||
self.grp = idx
|
self.grp = idx
|
||||||
|
|
||||||
def _acquire(self, filename, channels=None, data_base_dir=None, scan_info=None, n_pulses=100, **kwargs):
|
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
|
# write out the data file
|
||||||
hid = h5py.File(filename,'a')
|
with h5py.File(filename,'a') as hid:
|
||||||
# save the pulse ID
|
# save the pulse ID
|
||||||
singledata = [ele['pid'] for ele in data]
|
singledata = [ele['pid'] for ele in data]
|
||||||
pidname = 'pulse_id/group%d' % self.grp
|
pidname = 'pulse_id/group%d' % self.grp
|
||||||
hid.create_dataset(pidname, data = singledata)
|
hid.create_dataset(pidname, data=singledata)
|
||||||
for chn in queue.channels:
|
for chn in channels:
|
||||||
singledata = [ele[chn] for ele in data]
|
singledata = [ele[chn] for ele in data]
|
||||||
if not chn == 'pid':
|
if not chn == 'pid':
|
||||||
dname = chn.replace(':','/')+'/data'
|
dname = chn.replace(':','/')+'/data'
|
||||||
hid.create_dataset(dname, data = singledata)
|
hid.create_dataset(dname, data=singledata)
|
||||||
dpid = dname.replace('/data','/pid')
|
dpid = dname.replace('/data','/pid')
|
||||||
hid[dpid] = hid[pidname]
|
hid[dpid] = hid[pidname]
|
||||||
hid.close()
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user