From 25f7e5f661fadd7f70dd5439877b06b9b46e429d Mon Sep 17 00:00:00 2001 From: Gabriele Girelli Date: Sat, 15 Aug 2020 12:12:47 +0200 Subject: [PATCH] Complexity --- nd2reader/parser.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/nd2reader/parser.py b/nd2reader/parser.py index 5633bb1..a5239e2 100644 --- a/nd2reader/parser.py +++ b/nd2reader/parser.py @@ -246,14 +246,19 @@ class Parser(object): """ return {channel: n for n, channel in enumerate(self.metadata["channels"])} - def _remove_unwanted_bytes(self, image_group_data, image_data_start, height, width): - # Remove unwanted 0-bytes that can appear in stitched images + + def _find_unwanted_bytes(self, image_group_data, image_data_start, height, width): number_of_true_channels = int(len(image_group_data[4:]) / (height * width)) n_unwanted_bytes = (len(image_group_data[image_data_start:]))%(height*width) if not n_unwanted_bytes: - return - + return n_unwanted_bytes assert 0 == n_unwanted_bytes % height, "Unexpected unwanted bytes distribution." + return n_unwanted_bytes + + def _remove_unwanted_bytes(self, image_group_data, image_data_start, height, width): + # Remove unwanted 0-bytes that can appear in stitched images + n_unwanted_bytes = self._find_unwanted_bytes(image_group_data, image_data_start, height, width) + number_of_true_channels = int(len(image_group_data[4:]) / (height * width)) unwanted_byte_per_step = n_unwanted_bytes // height byte_ids = range(image_data_start+height*number_of_true_channels, len(image_group_data)-n_unwanted_bytes+1, height*number_of_true_channels) if all([0 == image_group_data[byte_ids[i]+i] for i in range(len(byte_ids))]):