Files
2025-02-19 09:22:21 +01:00

130 lines
4.0 KiB
Python

#########################################################################
# The interface to integrate into the pipeline server
# The following files are needed to be added to the library:
# - CamDataProcess.py
# - Config_Param.py
# - LocalPV.py
# - RecordTemplate.py
# - RemotePV.py
# - Service_Log.py
# - Service_RFStation.py
# - Service_Screen.py
# - elog.py
#
# Created by Zheqiao Geng on 29.05.2024
#########################################################################
import os
import time
from cam_server.pipeline.data_processing import functions, processor
from cam_server import utils
from logging import getLogger
from CamDataProcess import *
from Service_RFStation import *
from Config_Param import *
from Service_Log import *
# ===============================================================
# global variables
# ===============================================================
_logger = getLogger(__name__)
initialized = False
moduleName = 'ARS05-RCAM-0310'
instName = 'SR4'
srvRFs = None
srvLog = None
camPrc = None
# ===============================================================
# init function
# ===============================================================
def initialize():
global srvRFs, srvLog, camPrc, moduleName, instName
# get the RF station info
if instName == 'TS':
cav_label = ts_cav_label
cpl_label = ts_cpl_label
elif instName == 'SR1':
cav_label = sr1_cav_label
cpl_label = sr1_cpl_label
elif instName == 'SR2':
cav_label = sr2_cav_label
cpl_label = sr2_cpl_label
elif instName == 'SR3':
cav_label = sr3_cav_label
cpl_label = sr3_cpl_label
elif instName == 'SR4':
cav_label = sr4_cav_label
cpl_label = sr4_cpl_label
else:
cav_label = ''
cpl_label = ''
# define the services
srvRFs = Service_RFStation(loc = instName,
cav_label = cav_label,
cpl_label = cpl_label)
srvLog = Service_Log(moduleName, loc = instName)
# define the jobs
camPrc = CamDataProcess(moduleName,
instName,
srv_scr = None,
srv_rfs = srvRFs,
srv_log = srvLog,
f_path = file_path)
# connect to all PVs
RemotePV.connect()
time.sleep(2.0)
# start the threads
camPrc.start()
_logger.info('EPICS_CA_ADDR_LIST = ' + str(os.environ.get('EPICS_CA_ADDR_LIST')))
_logger.info('Data Path: ' + camPrc.f_path)
_logger.info("Initialized")
# ===============================================================
# implement the image processing function (replacing the thread
# function "DataRecvProcFunc" in "CamDataProcess.py")
# ===============================================================
def process_image(image, pulse_id, timestamp, x_axis, y_axis, parameters, bsdata=None):
# declare the global variables
global camPrc, initialized
try:
# initialization
if not initialized:
initialize()
initialized = True
# basic process of the image
data = { 'timestamp' : utils.timestamp_as_float(timestamp),
'width' : len(image[0]),
'height' : len(image),
'image' : image,
'arc_found' : 0}
# calculate the properties for arc detection
x_profile, y_profile = functions.get_x_y_profile(image)
min_value, max_value = functions.get_min_max(image)
intensity = x_profile.sum()
data['intensity'] = intensity
data['min_value'] = min_value
data['max_value'] = max_value
data['x_profile'] = x_profile
data['y_profile'] = y_profile
# store to the circular buffer
camPrc.receiveImage(data)
return data
except Exception as e:
_logger.warning(str(e))
return None