Skip to content
Snippets Groups Projects

[Generic][Shimadzu] Dynamic flat-field characterization and correction for MHz microscopy

Merged Egor Sobolev requested to merge feat/shimadzu-correction into master
1 file
+ 52
0
Compare changes
  • Side-by-side
  • Inline
+ 52
0
 
from dataclasses import dataclass
 
from cal_tools.calcat_interface2 import ConditionsBase
 
 
 
@dataclass
 
class ShimadzuHPVX2Conditions(ConditionsBase):
 
frame_size: float
 
 
calibration_types = {
 
"Offset": ["Frame Size"],
 
"DynamicFF": ["Frame Size"],
 
}
 
 
 
class ShimadzuHPVX2:
 
channel = "daqOutput"
 
image_key = "data.image.pixels"
 
 
def __init__(self, source_name_pattern: str, channel=None, image_key=None):
 
self.source_name_pattern = source_name_pattern
 
if channel is not None:
 
self.channel = channel
 
if image_key is not None:
 
self.image_key = image_key
 
self.image_index_group = self.image_key.partition('.')[0]
 
self.instrument = source_name_pattern.split('_')[0]
 
 
def conditions(self, dc: "DataCollection", module=None): # noqa: F821
 
if module is None:
 
source_pattern = self.source_name_pattern.format(
 
f"*:{self.channel}")
 
det_dc = dc.select(source_pattern)
 
if not det_dc.instrument_sources:
 
raise ValueError("No detector sources are found")
 
 
source_name = list(det_dc.instrument_sources)[0]
 
else:
 
source_name = self.instrument_source(module)
 
keydata = dc[source_name, self.image_key]
 
num_frames = keydata.shape[-3]
 
return ShimadzuHPVX2Conditions(frame_size=num_frames / 256)
 
 
def instrument_source(self, module: int):
 
source_name = self.source_name_pattern.format(module)
 
return f"{source_name}:{self.channel}"
 
 
def corrected_source(self, module: int):
 
source_name = self.source_name_pattern.format(module)
 
parts = source_name.split('/')
 
parts[1] = "CORR"
 
source_name = '/'.join(parts)
 
return f"{source_name}:output"
Loading