43 lines
1.6 KiB
Python
43 lines
1.6 KiB
Python
import json
|
|
from logging import getLogger
|
|
from cam_server.pipeline.data_processing import functions
|
|
import numpy as np
|
|
import os
|
|
|
|
_logger = getLogger(__name__)
|
|
curvature = np.loadtxt('configuration/user_scripts/data/curvature.txt')
|
|
|
|
def process_image(image, pulse_id, timestamp, x_axis, y_axis, parameters, bsdata=None):
|
|
global curvature
|
|
# Add return values
|
|
return_value = dict()
|
|
prefix = parameters["camera_name"]+":"
|
|
#(min_value, max_value) = functions.get_min_max(image)
|
|
(x_profile, y_profile) = functions.get_x_y_profile(image)
|
|
# Could be also y_profile.sum() -> it should give the same result.
|
|
intensity = x_profile.sum()
|
|
# Add return values
|
|
return_value[prefix+"timestamp"] = timestamp
|
|
#return_value[prefix+"min_value"] = min_value
|
|
#return_value[prefix+"max_value"] = max_value
|
|
return_value[prefix+"x_profile"] = x_profile
|
|
return_value[prefix+"y_profile"] = y_profile
|
|
return_value[prefix+"intensity"] = intensity
|
|
|
|
try:
|
|
# 1 Apply Threshold
|
|
low, high = 125, 300
|
|
mask = (image<high)*(image>low) #image is the single frame from the camera
|
|
mask= np.logical_not(mask)
|
|
image[mask] = 0
|
|
# 2 Correct Curvature
|
|
image_corr = np.zeros(image.shape)
|
|
for j in range(image.shape[0]):
|
|
image_corr[j] = np.roll(image[j],-int(curvature[j]))
|
|
# 3 Binning
|
|
spectrum = np.sum(image_corr,axis=0).astype('float32')
|
|
except:
|
|
spectrum = None
|
|
return_value[prefix+"spectrum"] = spectrum
|
|
|
|
return return_value |