from logging import getLogger import epics import numpy import scipy.signal import scipy.optimize _logger = getLogger(__name__) from cam_server.pipeline.data_processing import functions, processor pv_names = ["TEST1", "TEST2"] initialized = False pv_connections = None def get_casts_connection(ioc_name): global pv_names ret = OrderedDict() # Do once at startup try: for pv_name in pv_names: # Create PV names here input_pv_name = casts_prefix + ":TEST" # Fetch the paramts input_pv = epics.PV(input_pv_name) input_pv.wait_for_connection() #TODO store connections globally ret[input_pv_name] = input_pv # set init true so this won't run again until script is restarted initialized = True except Exception as e: raise SystemExit(e) return ret def get_casts_values(): global pv_connections ret = OrderedDict() for input_pv_name, pv_conn in pv_connections.items(): if pv_conn.connected: ret[input_pv_name] = pv_conn.value else ret[input_pv_name] = 0 _logger.warning("input values fetched: " + str(ret)) return ret def crop(image, parameters): image_segment = 0 image_matrix = 0 return image_segment, image_matrix def process_segment(image, params): pid, data = 0, 0 """ input: image, params return pid: int data: PV( int , pv_SSEG_ROW0 , "{CAST}:REG_7SEG_USER_SEG0" , PV_NONE); PV( int , pv_SSEG_ROW1 , "{CAST}:REG_7SEG_USER_SEG1" , PV_NONE); PV( int , pv_SSEG_ROW2 , "{CAST}:REG_7SEG_USER_SEG2" , PV_NONE); PV( int , pv_SSEG_ROW3 , "{CAST}:REG_7SEG_USER_SEG3" , PV_NONE); """ return pid, data def process_matrix(image, params): """ input: image, params return pid: int data: PV( int , pv_MATRIX_ROW1 , "{CAST}:REG_MATRIX_USER_ROW1" , PV_NONE); PV( int , pv_MATRIX_ROW2 , "{CAST}:REG_MATRIX_USER_ROW2" , PV_NONE); PV( int , pv_MATRIX_ROW3 , "{CAST}:REG_MATRIX_USER_ROW3" , PV_NONE); PV( int , pv_MATRIX_ROW4 , "{CAST}:REG_MATRIX_USER_ROW4" , PV_NONE); PV( int , pv_MATRIX_ROW5 , "{CAST}:REG_MATRIX_USER_ROW5" , PV_NONE); PV( int , pv_MATRIX_ROW6 , "{CAST}:REG_MATRIX_USER_ROW6" , PV_NONE); PV( int , pv_MATRIX_ROW7 , "{CAST}:REG_MATRIX_USER_ROW7" , PV_NONE); PV( int , pv_MATRIX_ROW8 , "{CAST}:REG_MATRIX_USER_ROW8" , PV_NONE); """ pid, data = 0, 0 return pid, data def process_image(image, pulse_id, timestamp, x_axis, y_axis, parameters, bsdata=None): global initialized global pv_connections # Basic init ret = OrderedDict() prefix = parameters["camera_name"] # Do connection only once.. if not initialized: pv_connections = get_casts_connection(ioc_name="CASTMASTER") casts_values = get_casts_values() # example -- Calculate intensity (x_profile, y_profile) = functions.get_x_y_profile(image) intensity = x_profile.sum() # Crop image image_segment, image_matrix = crop(image, casts_values) # Process matrix matrix_pid, matrix_data = process_matrix(image_matrix, casts_values) # Process 7-segment segment_pid, segment_data = process_segment(image_segment, casts_values) # Construct return dict ret[prefix+":intensity"] = intensity ret[prefix+":matrix_pid"] = matrix_pid ret[prefix+":matrix_diff"] = pulse_id - matrix_pid ret[prefix+":matrix_pid"] = segment_pid ret[prefix+":matrix_diff"] = pulse_id - segment_pid # If softPV's can be created here without putting them in databuffer # parts of matrix and segment could be exposed here # otherwise only the retreived pid and difference return ret