From 04e67fc5ecf8a9300908f84314b1bb2dce18a55b Mon Sep 17 00:00:00 2001 From: Ruben Verweij Date: Wed, 19 Jul 2017 17:09:16 +0200 Subject: [PATCH] Refactor CQ --- nd2reader/raw_metadata.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/nd2reader/raw_metadata.py b/nd2reader/raw_metadata.py index 7aba42d..67ae7e1 100644 --- a/nd2reader/raw_metadata.py +++ b/nd2reader/raw_metadata.py @@ -123,17 +123,13 @@ class RawMetadata(object): return channels def _process_channels_metadata(self, metadata): - try: - validity = self.image_metadata[six.b('SLxExperiment')][six.b('ppNextLevelEx')][six.b('')][0][ - six.b('ppNextLevelEx')][six.b('')][0][six.b('pItemValid')] - except (KeyError, TypeError): - # If none of the channels have been deleted, there is no validity list, so we just make one - validity = [True for _ in metadata] + validity = self._get_channel_validity_list(metadata) + # Channel information is contained in dictionaries with the keys a0, a1...an where the number # indicates the order in which the channel is stored. So by sorting the dicts alphabetically # we get the correct order. channels = [] - for (label, chan), valid in zip(sorted(metadata[six.b('sPlaneNew')].items()), validity): + for valid, (label, chan) in zip(validity, sorted(metadata[six.b('sPlaneNew')].items())): if not valid: continue if chan[six.b('sDescription')] is not None: @@ -142,6 +138,15 @@ class RawMetadata(object): channels.append('Unknown') return channels + def _get_channel_validity_list(self, metadata): + try: + validity = self.image_metadata[six.b('SLxExperiment')][six.b('ppNextLevelEx')][six.b('')][0][ + six.b('ppNextLevelEx')][six.b('')][0][six.b('pItemValid')] + except (KeyError, TypeError): + # If none of the channels have been deleted, there is no validity list, so we just make one + validity = [True for _ in metadata] + return validity + def _parse_fields_of_view(self): """The metadata contains information about fields of view, but it contains it even if some fields of view were cropped. We can't find anything that states which fields of view are actually