From ec7a71846bd59df9048b47d0a8dd6ffef5c86fcd Mon Sep 17 00:00:00 2001 From: Vince Reuter Date: Wed, 19 Feb 2025 13:17:53 +0100 Subject: [PATCH] safety against negative z-slice in signal analysis program --- CHANGELOG.md | 1 + bin/cli/run_signal_analysis.py | 27 +++++++++++++++------------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 44d8ed35..fc8a9172 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project will adhere to [Semantic Versioning](https://semver.org/spec/v2 ### Fixed * Field of view name matching for cross-channel signal analysis. See [Issue 424](https://github.com/gerlichlab/looptrace/issues/424). +* Safety against negative z-slice in cross-channel signal analysis ## [v0.12.0] - 2025-02-18 diff --git a/bin/cli/run_signal_analysis.py b/bin/cli/run_signal_analysis.py index 556860f8..6fb3268f 100644 --- a/bin/cli/run_signal_analysis.py +++ b/bin/cli/run_signal_analysis.py @@ -200,18 +200,21 @@ def workflow( except ValueError as e: logging.error(f"Can't compute shifted center for original center {pt0}: {e}") else: - # TODO: need to be robust to bounding box with negative coordinate(s) - # TODO: https://github.com/gerlichlab/gertils/issues/34 - for stats in compute_pixel_statistics( - img=img, - pt=dc_pt, - channels=spec.channels, - diameter=spec.roi_diameter, - channel_column=SIGNAL_CHANNEL_COLUMN, - ): - ch: int = stats[SIGNAL_CHANNEL_COLUMN] - # Add the original record and signal stats to the growing collection for this channel. - by_raw_channel[ch].append({**r.to_dict(), **stats}) + if dc_pt.z < 0: + logging.error(f"Can't extract signal for negative z-coordinate: {dc_pt.z}") + else: + # TODO: need to be robust to bounding box with negative coordinate(s) + # TODO: https://github.com/gerlichlab/gertils/issues/34 + for stats in compute_pixel_statistics( + img=img, + pt=dc_pt, + channels=spec.channels, + diameter=spec.roi_diameter, + channel_column=SIGNAL_CHANNEL_COLUMN, + ): + ch: int = stats[SIGNAL_CHANNEL_COLUMN] + # Add the original record and signal stats to the growing collection for this channel. + by_raw_channel[ch].append({**r.to_dict(), **stats}) # Write the output file for this ROI type, across all FOVs. for raw_channel, records in sorted(by_raw_channel.items(), key=itemgetter(0)):