41 lines
1.2 KiB
Python
41 lines
1.2 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 _acquire(self, filename, channels=None, data_base_dir=None, scan_info=None, n_pulses=100, **kwargs):
|
|
|
|
queue =channels[0] # abusing interface since BSAcquisition assume a list of channels
|
|
|
|
# allocating space
|
|
data={}
|
|
chns = queue.channels
|
|
for chn in chns:
|
|
data[chn]={'data':np.zeros((n_pulses))}
|
|
data['pulse_id']=np.zeros((n_pulses))
|
|
|
|
# clear the queue
|
|
queue.flush()
|
|
for i in range(n_pulses):
|
|
msg = queue.__next__() # pull data from cache
|
|
for chn in chns:
|
|
data[chn]['data'][i] = msg[chn]
|
|
data['pulse_id'][i]=msg['pid']
|
|
|
|
# write out the data file
|
|
hid = h5py.File(filename,'w')
|
|
hid.create_dataset('pulse_id', data = data['pulse_id'])
|
|
for chn in chns:
|
|
gid = hid.create_group(chn)
|
|
for key in data[chn].keys():
|
|
gid.create_dataset(key, data = data[chn][key])
|
|
hid.close()
|
|
|
|
|