From 9c79f65acad71d8680fecfec9299d3adcd9a5ee6 Mon Sep 17 00:00:00 2001 From: Egor Sobolev <egor.sobolev@xfel.eu> Date: Mon, 4 Mar 2024 17:41:12 +0100 Subject: [PATCH] Add docstrings in litpx_counter.py --- src/cal_tools/litpx_counter.py | 62 ++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/src/cal_tools/litpx_counter.py b/src/cal_tools/litpx_counter.py index 0a70097f0..8c47169cd 100644 --- a/src/cal_tools/litpx_counter.py +++ b/src/cal_tools/litpx_counter.py @@ -3,6 +3,8 @@ import sharedmem class AnalysisAddon: + """Base class for analysis addons""" + channel = "data" output_fields = [ "cellId", "pulseId", "trainId"] @@ -20,15 +22,55 @@ class AnalysisAddon: self.num_images = self.max_images def set_num_images(self, num_images): + """Sets the actual number of images in data. + + Parameters + ---------- + num_images: int + The actual number of images in data + """ self.num_images = num_images def process(self, chunk): + """Processes the image data. + + Parameters + ---------- + chunk: slice, sequence or array + The indices of images in `data` to process + """ raise NotImplementedError def source_name(self, karabo_id, channel): + """Returns the source name. + + Parameters + ---------- + karabo_id: str + The detector Karabo Id, e.g. SPB_DET_AGIPD1M-1 + channel: str + The detector channel Id, e.g. 15CH0:output + + Returns + ------- + source_name: str + The source name for EXDF files + """ return f"{karabo_id}/DANA/{channel}" def create_schema(self, source, file_trains=None, count=None): + """Creates the indices and keys in the source. + + Parameters + ---------- + source: InstrumentSource + The source, where to create the keys + file_trains: sequence or array + The list of trains in the file + count: array + The count of entry per train for this channel. If None, + then addons create it using `trainId` field in `data`. + """ if file_trains is None: file_trains = source.file["INDEX/trainId"][:] @@ -54,12 +96,21 @@ class AnalysisAddon: ) def write(self, source): + """Writes data to file. + + Parameters + ---------- + source: InstrumentSource + The source, where to write data + """ channel = source[self.channel] for key in self.output_fields: channel[key][:] = self.data[key][:self.num_images] class LitPixelCounter(AnalysisAddon): + """Lit-pixel counter analysis addon.""" + channel = "litpx" output_fields = [ "cellId", "pulseId", "trainId", "litPixels", "goodPixels"] @@ -67,6 +118,17 @@ class LitPixelCounter(AnalysisAddon): "data", "mask", "cellId", "pulseId", "trainId"] def __init__(self, data, threshold=0.8): + """Initialize the instance of lit-pixel analysis addon. + + Parameters + ---------- + data: dict + Dictionary with image data. It must include the fields: + `data`, `mask`, `cellId`, `pulseId`, `trainId` + threshold: float + The pixel intensity value, which if exceeded means + that the pixel is illuminated. + """ super().__init__(data) self.image = data["data"] -- GitLab