30 lines
1.1 KiB
Python
30 lines
1.1 KiB
Python
import numpy
|
|
from cam_server.pipeline.data_processing import functions, processor
|
|
|
|
def get_fw(x, y, threshold=0.5):
|
|
try:
|
|
ymax, ymin = numpy.amax(y), numpy.amin(y)
|
|
hm = (ymax - ymin) * threshold
|
|
max_index, l_index, r_index = numpy.argmax(y), 0, len(x)-1
|
|
for i in range(max_index-1, 0, -1):
|
|
if (y[i] - ymin) <= hm:
|
|
l_index = i
|
|
break
|
|
for i in range(max_index+1, len(x), 1):
|
|
if (y[i] - ymin) <= hm:
|
|
r_index = i
|
|
break
|
|
fwhm = abs(x[l_index] - x[r_index])
|
|
return fwhm
|
|
except:
|
|
return 0.0
|
|
|
|
def process_image(image, pulse_id, timestamp, x_axis, y_axis, parameters, bsdata=None):
|
|
ret = processor.process_image(image, pulse_id, timestamp, x_axis, y_axis, parameters, bsdata)
|
|
fw_threshold = parameters.get("fw_threshold", 0.2)
|
|
x_axis, x_profile, y_axis, y_profile = ret["x_axis"], ret["x_profile"], ret["y_axis"], ret["y_profile"]
|
|
x_fw = get_fw(x_axis, x_profile, fw_threshold)
|
|
y_fw = get_fw(y_axis, y_profile, fw_threshold)
|
|
ret["x_fw"]=float(x_fw)
|
|
ret["y_fw"]=float(y_fw)
|
|
return ret |