71 lines
2.2 KiB
Python
71 lines
2.2 KiB
Python
from cam_server.pipeline.data_processing import functions, processor
|
|
|
|
import json
|
|
import scipy.signal
|
|
import numpy as np
|
|
from collections import deque
|
|
from logging import getLogger
|
|
|
|
_logger = getLogger(__name__)
|
|
|
|
background = deque(maxlen=4)
|
|
|
|
DEFAULT_ROI_SIGNAL = None
|
|
DEFAULT_ROI_BACKGROUND = None
|
|
|
|
um_per_px = 3.33 # calibrated 2023-09-29 with pco edge 4.2 and 90% zoom, 49% focus
|
|
|
|
def get_roi_projection(image, roi, axis):
|
|
x_start, x_stop, y_start, y_stop = roi
|
|
cropped = image[x_start:x_stop, y_start:y_stop]
|
|
project = cropped.mean(axis=axis)
|
|
return project
|
|
|
|
def find_spacing(py, extend=5):
|
|
"finds the spacing of a ladder on a high viscosity jet from the microscope images"
|
|
|
|
py -= py.mean()
|
|
|
|
if extend > 1:
|
|
py = np.concatenate((py, np.zeros(len(py) * extend)))
|
|
|
|
spectrum = np.abs(np.fft.fft(py))
|
|
freq = np.fft.fftfreq(len(spectrum))
|
|
|
|
which = (freq > 0.005)
|
|
spectrum = spectrum[which]
|
|
freq = freq[which]
|
|
|
|
index_peaks = scipy.signal.find_peaks(spectrum)[0]
|
|
peaks_pos = freq[index_peaks]
|
|
peak_height = spectrum[index_peaks]
|
|
|
|
cut_freq = peaks_pos[np.argmax(peak_height)]
|
|
return freq, spectrum, cut_freq
|
|
|
|
|
|
def process_image(image, pulse_id, timestamp, x_axis, y_axis, parameters, bsdata=None):
|
|
|
|
processed_data = dict()
|
|
|
|
if bsdata is not None:
|
|
processed_data.update(bsdata)
|
|
|
|
#event = processed_data.get("SAR-CVME-TIFALL4:EvtSet", None)
|
|
image = image.astype("int64")
|
|
image_property_name = parameters["camera_name"]
|
|
roi_signal = parameters.get("roi_signal", DEFAULT_ROI_SIGNAL)
|
|
|
|
processed_data[image_property_name + ".processing_parameters"] = json.dumps({"roi_signal": roi_signal})
|
|
|
|
if roi_signal:
|
|
jet_projection = get_roi_projection(image, roi_signal, 1)
|
|
processed_data[image_property_name + ".jet_projection"] = jet_projection
|
|
jet_width = get_roi_projection(image, roi_signal, 0)
|
|
processed_data[image_property_name + ".jet_width"] = jet_width
|
|
|
|
freq, spectrum, cut_freq = find_spacing(jet_projection, extend=10)
|
|
jet_spacing = um_per_px / cut_freq
|
|
processed_data[image_property_name + ".jet_spacing"] = jet_spacing
|
|
|
|
return processed_data |