Modified BSCAcquisition, so that the Cache is an argument of the function _acquire

This commit is contained in:
2023-07-07 11:59:55 +02:00
parent 0c928a8bb1
commit 10c7b37b99
2 changed files with 34 additions and 36 deletions

View File

@ -1,42 +1,40 @@
import zmq
import h5py
import numpy as np
from bstrd import BSCache
from slic.core.acquisition.acquisition import Acquisition
from slic.core.acquisition import BSAcquisition, PVAcquisition
# class using the BSQueue to avoid to reestablish a stream for each step.
class BSCAcquisition(Acquisition):
def release(self):
if not self.queue == None:
del self.queue
self.queue = None
def _acquire(self, filename, channels=None, data_base_dir=None, scan_info=None, n_pulses=100, **kwargs):
if not hasattr(self,'queue'):
self.queue = getStream(channels)
elif not self.queue:
self.queue = getStream(channels)
self.queue.flush()
print('Acquiring',n_pulses,'samples')
data = []
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):
data.append(self.queue.__next__())
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')
gid = hid.create_group(channels[0])
for key in data[0].keys():
gid.create_dataset(key, data = [rec[key].value for rec in data])
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()
def getStream(channels):
print('Generating stream with channels:',channels)
bs = BSCache(100000,10000) # 1 second time out, capazity for 100 second.
bs.get_vars(channels)
return bs