40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
import sys
|
|
import os
|
|
|
|
from cam_server.pipeline.data_processing import functions
|
|
|
|
# Bunch length measurement using the streak camera
|
|
|
|
import numpy as np
|
|
from scipy import interpolate
|
|
from scipy.signal import find_peaks
|
|
import math
|
|
from logging import getLogger
|
|
|
|
_logger = getLogger(__name__)
|
|
|
|
class PpolPeakValley():
|
|
def __init__(self):
|
|
self.x, self.y = self.lensrms()
|
|
|
|
def lenrms(image, x_axis=None, row_range=(60, 80), offset=2100, plot=False):
|
|
row_start, row_end = row_range
|
|
if row_end >= image.shape[0]:
|
|
raise ValueError("Row range exceeds image height")
|
|
|
|
# Sum over selected rows to get horizontal profile
|
|
averaged_row = np.sum(image[row_start:row_end + 1, :], axis=0)
|
|
|
|
# Subtract offset and clip to zero
|
|
data = np.maximum(averaged_row - offset, 0)
|
|
|
|
# Use pixel index as x_axis if not provided
|
|
if x_axis is None:
|
|
x_axis = np.arange(data.shape[0])
|
|
|
|
# Compute moments
|
|
mx1 = np.sum(x_axis * data) / np.sum(data)
|
|
mx2 = np.sum((x_axis ** 2) * data) / np.sum(data)
|
|
lenrms = np.sqrt(mx2 - mx1 ** 2)
|
|
|
|
return ret |