From d5cc68bc2c9de365d2ee458ddc95ff882321d286 Mon Sep 17 00:00:00 2001 From: Bradley Lowekamp Date: Mon, 2 Oct 2023 16:39:43 -0400 Subject: [PATCH] Raise detailed exception with unsupported channel information --- pytools/HedwigZarrImage.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pytools/HedwigZarrImage.py b/pytools/HedwigZarrImage.py index cc95a57..3b4ba9c 100644 --- a/pytools/HedwigZarrImage.py +++ b/pytools/HedwigZarrImage.py @@ -225,9 +225,20 @@ def neuroglancer_shader_parameters(self, mad_scale=3) -> dict: if _shader_type == "MultiChannel": assert self._ome_ngff_multiscale_dims()[1] == "C" - assert len(list(self.ome_info.channel_names(self.ome_idx))) == self.shape[1] + + if len(list(self.ome_info.channel_names(self.ome_idx))) != self.shape[1]: + raise RuntimeError( + f"Mismatch of number of Channels! Array has {self.shape[1]} but there" + f"are {len(list(self.ome_info.channel_names(self.ome_idx)))} names:" + f"{list(self.ome_info.channel_names(self.ome_idx))}" + ) color_sequence = ["red", "green", "blue", "cyan", "yellow", "magenta"] - assert self.shape[1] <= len(color_sequence) + + if self.shape[1] > len(color_sequence): + raise RuntimeError( + f"Too many channels! The array has {self.shape[1]} channels but" + f" only {len(color_sequence)} is supported!" + ) json_channel_array = []