Files
sfbd/app/spectralanalysis.py

60 lines
2.0 KiB
Python

from bstrd import BSCache
from epics import PV
athos_uncalibrated = 'SATFE10-PEPG046-EVR0:CALCI'
athos_calibrated = 'SATFE10-PEPG046:FCUP-INTENSITY-CAL'
aramis_uncalibrated = 'SARFE10-PBIG050-EVR0:CALCI'
aramis_calibrated = 'SARFE10-PBPG050:HAMP-INTENSITY-CAL'
channel_dict = {
'PSSS': ['SARFE10-PSSS059:SPECTRUM_Y', aramis_uncalibrated, aramis_calibrated],
'PMOS Maloja': ['SATOP21-PMOS127-2D:SPECTRUM_Y', athos_uncalibrated, athos_calibrated],
'PMOS Furka': ['SATOP31-PMOS132-2D:SPECTRUM_Y', athos_uncalibrated, athos_calibrated],
'PSSS LB': ['SARFE10-PSSS059-LB:SPECTRUM_Y', aramis_uncalibrated, aramis_calibrated],
}
names = ['PSSS', 'PMOS Maloja', 'PMOS Furka', 'PSSS LB']
class SpectralAnalysis:
def __init__(self):
self.bs = BSCache(100000,10000) # 100 second timeout, size for 100 second data taken
self.bs.stop()
self.channel = None
self.channels = [channel_dict[x] for x in names]
self.hasBStream=False
def connect_name(self, name):
index = names.index(name)
self.connect(index)
def connect(self,ich):
if ich < 0 or ich >= len(self.channels):
return False
self.channel = self.channels[ich]
print('Connecting to BS-Channel:',self.channel)
self.bs.channels.clear()
self.hasBStream=True
try:
self.bs.get_vars(self.channel) # this starts the stream into the cache
except ValueError:
print('Cannot find requested channels in BS stream')
self.hasBStream=False
self.pv = PV(self.channel[0].replace('_Y','_X'))
def terminate(self):
print('Stopping BSStream Thread...')
self.bs.stop()
self.bs.pt.running.clear() # for some reason I have to
self.pv.disconnect()
def flush(self):
self.bs.flush()
def read(self):
return next(self.bs)
def read_spectrum_axis(self):
return self.pv.value
def getSpectrometerName(self):
return self.channel