create bad channels mask, first simple CMake script
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
from pathlib import Path
|
||||
from aare import JungfrauDataFile
|
||||
from helpers import get_first_file
|
||||
|
||||
class JungfrauCalibrationParameters:
|
||||
"""
|
||||
A class to hold calibration parameters for the Jungfrau detector.
|
||||
"""
|
||||
|
||||
@property
|
||||
def pedestal_file_dir(self) -> Path:
|
||||
return self._pedestal_file_dir
|
||||
|
||||
@pedestal_file_dir.setter
|
||||
def pedestal_file_dir(self, filepath : Path):
|
||||
if not filepath.exists():
|
||||
raise ValueError(f"Pedestal file directory {filepath} does not exist.")
|
||||
self._pedestal_file_dir = filepath
|
||||
|
||||
@property
|
||||
def pedestal_g0_file_prefix(self) -> str:
|
||||
return self._pedestal_g0_file_prefix
|
||||
|
||||
@pedestal_g0_file_prefix.setter
|
||||
def pedestal_g0_file_prefix(self, file_prefix : str):
|
||||
self._pedestal_g0_file_prefix = file_prefix
|
||||
|
||||
# TODO: add deprecated decorator
|
||||
@property
|
||||
def pedestal_file_prefix(self) -> str:
|
||||
return self._pedestal_file_prefix
|
||||
@pedestal_file_prefix.setter
|
||||
def pedestal_file_prefix(self, file_prefix : str):
|
||||
self._pedestal_file_prefix = file_prefix
|
||||
|
||||
@property
|
||||
def num_pedestals_g0(self) -> int:
|
||||
return self._num_pedestals_g0
|
||||
|
||||
@num_pedestals_g0.setter
|
||||
def num_pedestals_g0(self, num_pedestals : int):
|
||||
self._num_pedestals_g0 = num_pedestals
|
||||
|
||||
@property
|
||||
def num_pedestals_g1(self) -> int:
|
||||
return self._num_pedestals_g1
|
||||
|
||||
@num_pedestals_g1.setter
|
||||
def num_pedestals_g1(self, num_pedestals : int):
|
||||
self._num_pedestals_g1 = num_pedestals
|
||||
|
||||
@property
|
||||
def num_pedestals_g2(self) -> int:
|
||||
return self._num_pedestals_g2
|
||||
|
||||
@num_pedestals_g2.setter
|
||||
def num_pedestals_g2(self, num_pedestals : int):
|
||||
self._num_pedestals_g2 = num_pedestals
|
||||
|
||||
@property
|
||||
def raw_file_dir(self) -> Path:
|
||||
return self._raw_file_dir
|
||||
|
||||
@raw_file_dir.setter
|
||||
def raw_file_dir(self, filepath : Path):
|
||||
if not filepath.exists():
|
||||
raise ValueError(f"Raw file directory {filepath} does not exist.")
|
||||
self._raw_file_dir = filepath
|
||||
|
||||
@property
|
||||
def raw_file_prefix(self) -> str:
|
||||
return self._raw_file_prefix
|
||||
|
||||
@raw_file_prefix.setter
|
||||
def raw_file_prefix(self, file_prefix : str):
|
||||
self._raw_file_prefix = file_prefix
|
||||
|
||||
|
||||
# TODO add a read_config method
|
||||
|
||||
|
||||
def calculate_bad_pixels_mask(calibration_params: JungfrauCalibrationParameters):
|
||||
"""
|
||||
Calculate the bad pixels mask for the Jungfrau detector.
|
||||
|
||||
Returns:
|
||||
np.ndarray: A boolean array where True indicates a bad pixel.
|
||||
"""
|
||||
|
||||
if(calibration_params.num_pedestals_g0 is not None and calibration_params.num_pedestals_g1 is not None and calibration_params.num_pedestals_g2 is not None):
|
||||
|
||||
jungfrau_file = JungfrauDataFile(get_first_file(calibration_params.pedestal_file_dir, calibration_params.pedestal_file_prefix))
|
||||
|
||||
g0_pedestal_frames = jungfrau_file.read_n(calibration_params.num_pedestals_g0) # TODO: option to only read gain? - mmh reading things twice from filesystem also bad
|
||||
|
||||
g1_pedestal_frames = jungfrau_file.read_n(calibration_params.num_pedestals_g1)
|
||||
|
||||
g2_pedestal_frames = jungfrau_file.read_n(calibration_params.num_pedestals_g2)
|
||||
|
||||
|
||||
|
||||
# Placeholder for actual implementation
|
||||
# This function should analyze the detector data and identify bad pixels
|
||||
pass
|
||||
|
||||
|
||||
def main():
|
||||
calibration_params = JungfrauCalibrationParameters()
|
||||
|
||||
calibration_params.pedestal_file_dir = Path("/mnt/sls_det_storage/jungfrau_calib/data/Module_708_Calib")
|
||||
|
||||
calibration_params.pedestal_file_prefix = "pedeG0_M708_2025-12-09_"
|
||||
|
||||
calibration_params.num_pedestals_g0 = 1000
|
||||
calibration_params.num_pedestals_g1 = 1000
|
||||
calibration_params.num_pedestals_g2 = 1000
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import glob
|
||||
from pathlib import Path
|
||||
|
||||
def get_first_file(path : Path, file_prefix : str):
|
||||
"""
|
||||
Get the first file with lowest index in directory that matches the given prefix.
|
||||
"""
|
||||
first_file = min(path.glob(str(Path)+f'{file_prefix}*', default=None))
|
||||
if first_file is None:
|
||||
raise ValueError(f"No files found in {path} with prefix {file_prefix}")
|
||||
return first_file
|
||||
Reference in New Issue
Block a user