From 4565b04661c8b29f0baf676d9e8b3634294b755c Mon Sep 17 00:00:00 2001 From: kushalbakshi Date: Wed, 15 Mar 2023 17:24:51 -0500 Subject: [PATCH 01/13] Fix multiple z device ingestion in `prairieviewreader.py` --- .gitignore | 1 + CHANGELOG.md | 6 ++ element_interface/prairieviewreader.py | 108 ++++++++++++++++++------- element_interface/version.py | 2 +- 4 files changed, 87 insertions(+), 30 deletions(-) diff --git a/.gitignore b/.gitignore index ae6db6f..fb7f874 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # User data .DS_Store temp* +user_data/ # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 74a7bd6..53b4fd2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,12 @@ Observes [Semantic Versioning](https://semver.org/spec/v2.0.0.html) standard and [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) convention. +## [0.4.3] - 2023-03-15 + ++ Fix - ingestion routine for multiple Z devices in `prairieviewreader.py`. + ## [0.4.2] - 2022-12-16 + + Update - PrairieView loader checks for multi-plane vs single-plane scans. ## [0.4.1] - 2022-12-15 @@ -44,6 +49,7 @@ Observes [Semantic Versioning](https://semver.org/spec/v2.0.0.html) standard and + Add - Readers for: `ScanImage`, `Suite2p`, `CaImAn`. +[0.4.3]: https://github.com/datajoint/element-interface/releases/tag/0.4.3 [0.4.2]: https://github.com/datajoint/element-interface/releases/tag/0.4.2 [0.4.1]: https://github.com/datajoint/element-interface/releases/tag/0.4.1 [0.4.0]: https://github.com/datajoint/element-interface/releases/tag/0.4.0 diff --git a/element_interface/prairieviewreader.py b/element_interface/prairieviewreader.py index ef09f18..7bd4fe2 100644 --- a/element_interface/prairieviewreader.py +++ b/element_interface/prairieviewreader.py @@ -1,3 +1,4 @@ +from collections import defaultdict import pathlib import xml.etree.ElementTree as ET from datetime import datetime @@ -43,8 +44,7 @@ def get_pv_metadata(pvtiffile: str) -> dict: bidirectional_scan = False # Does not support bidirectional roi = 1 n_fields = 1 # Always contains 1 field - record_start_time = root.find( - ".//Sequence/[@cycle='1']").attrib.get("time") + record_start_time = root.find(".//Sequence/[@cycle='1']").attrib.get("time") # Get all channels and find unique values channel_list = [ @@ -54,8 +54,7 @@ def get_pv_metadata(pvtiffile: str) -> dict: n_channels = len(set(channel_list)) n_frames = len(root.findall(".//Sequence/Frame")) framerate = 1 / float( - root.findall( - './/PVStateValue/[@key="framePeriod"]')[0].attrib.get("value") + root.findall('.//PVStateValue/[@key="framePeriod"]')[0].attrib.get("value") ) # rate = 1/framePeriod usec_per_line = ( @@ -67,16 +66,14 @@ def get_pv_metadata(pvtiffile: str) -> dict: * 1e6 ) # Convert from seconds to microseconds - scan_datetime = datetime.strptime( - root.attrib.get("date"), "%m/%d/%Y %I:%M:%S %p") + scan_datetime = datetime.strptime(root.attrib.get("date"), "%m/%d/%Y %I:%M:%S %p") total_duration = float( root.findall(".//Sequence/Frame")[-1].attrib.get("relativeTime") ) px_height = int( - root.findall( - ".//PVStateValue/[@key='pixelsPerLine']")[0].attrib.get("value") + root.findall(".//PVStateValue/[@key='pixelsPerLine']")[0].attrib.get("value") ) # All PrairieView-acquired images have square dimensions (512 x 512; 1024 x 1024) px_width = px_height @@ -100,11 +97,17 @@ def get_pv_metadata(pvtiffile: str) -> dict: ".//PVStateValue/[@key='currentScanCenter']/IndexedValue/[@index='YAxis']" ).attrib.get("value") ) - if root.find(".//Sequence/[@cycle='1']/Frame/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/[@index='ZAxis']") is None: + if ( + root.find( + ".//Sequence/[@cycle='1']/Frame/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/[@index='ZAxis']" + ) + is None + ): z_fields = np.float64( root.find( - ".//PVStateValue/[@key='positionCurrent']/SubindexedValues/[@index='ZAxis']/SubindexedValue").attrib.get("value") + ".//PVStateValue/[@key='positionCurrent']/SubindexedValues/[@index='ZAxis']/SubindexedValue" + ).attrib.get("value") ) n_depths = 1 assert z_fields.size == n_depths @@ -112,8 +115,11 @@ def get_pv_metadata(pvtiffile: str) -> dict: else: - bidirection_z = bool( - root.find(".//Sequence").attrib.get("bidirectionalZ")) + bidir_z = root.find(".//Sequence").attrib.get("bidirectionalZ") + if bidir_z == "False": + bidirection_z = False + elif bidir_z == "True": + bidirection_z = True # One "Frame" per depth. Gets number of frames in first sequence planes = [ @@ -121,23 +127,67 @@ def get_pv_metadata(pvtiffile: str) -> dict: for plane in root.findall(".//Sequence/[@cycle='1']/Frame") ] n_depths = len(set(planes)) - z_min = float( - root.findall( - ".//Sequence/[@cycle='1']/Frame/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/SubindexedValue/[@subindex='0']" - )[0].attrib.get("value") - ) - z_max = float( - root.findall( - ".//Sequence/[@cycle='1']/Frame/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/SubindexedValue/[@subindex='0']" - )[-1].attrib.get("value") - ) - z_step = float( - root.find( - ".//PVStateShard/PVStateValue/[@key='micronsPerPixel']/IndexedValue/[@index='ZAxis']" - ).attrib.get("value") - ) - z_fields = np.arange(z_min, z_max + 1, z_step) - assert z_fields.size == n_depths + + # find z_depths controller if there is more than 1. + z_dicts = [] + + if ( + len( + root.findall( + ".//Sequence/[@cycle='1']/Frame/[@index='1']/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/[@index='ZAxis']/SubindexedValue" + ) + ) + > 1 + ): + + for z_pos in root.findall( + ".//Sequence/[@cycle='1']/Frame/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/[@index='ZAxis']/SubindexedValue" + ): + z_dicts.append(z_pos.attrib) + + z_values = [d["value"] for d in z_dicts] + + zdata_dictionary = defaultdict(list) + for idx, val in enumerate(z_values): + zdata_dictionary[val].append(idx) + repeating_values = {k: v for k, v in zdata_dictionary.items() if len(v) > 1} + if len(repeating_values) > 0: + idx_to_drop = list(repeating_values.values())[0] + idx_to_drop.sort(reverse=True) + for idx in idx_to_drop: + del z_values[idx] + z_values = [float(num) for num in z_values] + z_min = min(z_values) + z_max = max(z_values) + z_step = z_max / n_depths + z_fields = z_values + assert len(z_fields) == n_depths + else: + z_values = [float(num) for num in z_values] + z_min = min(z_values) + z_max = max(z_values) + z_step = z_max / n_depths + z_fields = z_values + assert len(z_fields) == n_depths + + else: + z_min = float( + root.findall( + ".//Sequence/[@cycle='1']/Frame/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/SubindexedValue/[@subindex='0']" + )[0].attrib.get("value") + ) + z_max = float( + root.findall( + ".//Sequence/[@cycle='1']/Frame/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/SubindexedValue/[@subindex='0']" + )[-1].attrib.get("value") + ) + z_step = float( + root.find( + ".//PVStateShard/PVStateValue/[@key='micronsPerPixel']/IndexedValue/[@index='ZAxis']" + ).attrib.get("value") + ) + z_fields = np.arange(z_min, z_max + 1, z_step) + assert z_fields.size == n_depths metainfo = dict( num_fields=n_fields, diff --git a/element_interface/version.py b/element_interface/version.py index 2f158f7..30929ac 100644 --- a/element_interface/version.py +++ b/element_interface/version.py @@ -1,3 +1,3 @@ """Package metadata""" -__version__ = "0.4.2" +__version__ = "0.4.3" From 46e730e86b3acf6b63b7c14d0973d1e144fa9bc3 Mon Sep 17 00:00:00 2001 From: Kushal Bakshi <52367253+kushalbakshi@users.noreply.github.com> Date: Thu, 16 Mar 2023 09:37:44 -0500 Subject: [PATCH 02/13] Update element_interface/prairieviewreader.py Co-authored-by: Kabilar Gunalan --- element_interface/prairieviewreader.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/element_interface/prairieviewreader.py b/element_interface/prairieviewreader.py index b3181cd..569d8d3 100644 --- a/element_interface/prairieviewreader.py +++ b/element_interface/prairieviewreader.py @@ -117,10 +117,7 @@ def get_pv_metadata(pvtiffile: str) -> dict: else: bidir_z = root.find(".//Sequence").attrib.get("bidirectionalZ") - if bidir_z == "False": - bidirection_z = False - elif bidir_z == "True": - bidirection_z = True + bidirection_z = bidir_z == 'True' # One "Frame" per depth. Gets number of frames in first sequence planes = [ From 6c65b3388c2eb7dbb6729f83840a8f2ab517705d Mon Sep 17 00:00:00 2001 From: Kushal Bakshi <52367253+kushalbakshi@users.noreply.github.com> Date: Thu, 16 Mar 2023 13:19:57 -0500 Subject: [PATCH 03/13] Update element_interface/prairieviewreader.py Co-authored-by: Kabilar Gunalan --- element_interface/prairieviewreader.py | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/element_interface/prairieviewreader.py b/element_interface/prairieviewreader.py index 569d8d3..266aa4d 100644 --- a/element_interface/prairieviewreader.py +++ b/element_interface/prairieviewreader.py @@ -154,19 +154,12 @@ def get_pv_metadata(pvtiffile: str) -> dict: idx_to_drop.sort(reverse=True) for idx in idx_to_drop: del z_values[idx] - z_values = [float(num) for num in z_values] - z_min = min(z_values) - z_max = max(z_values) - z_step = z_max / n_depths - z_fields = z_values - assert len(z_fields) == n_depths - else: - z_values = [float(num) for num in z_values] - z_min = min(z_values) - z_max = max(z_values) - z_step = z_max / n_depths - z_fields = z_values - assert len(z_fields) == n_depths + z_values = [float(num) for num in z_values] + z_min = min(z_values) + z_max = max(z_values) + z_step = z_max / n_depths + z_fields = z_values + assert len(z_fields) == n_depths else: z_min = float( From cb20c61f060fceedf4577d2553429aee1d67e8d5 Mon Sep 17 00:00:00 2001 From: Kushal Bakshi <52367253+kushalbakshi@users.noreply.github.com> Date: Thu, 16 Mar 2023 14:50:28 -0500 Subject: [PATCH 04/13] Update element_interface/prairieviewreader.py Co-authored-by: Kabilar Gunalan --- element_interface/prairieviewreader.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/element_interface/prairieviewreader.py b/element_interface/prairieviewreader.py index 266aa4d..cc9e27c 100644 --- a/element_interface/prairieviewreader.py +++ b/element_interface/prairieviewreader.py @@ -138,10 +138,7 @@ def get_pv_metadata(pvtiffile: str) -> dict: > 1 ): - for z_pos in root.findall( - ".//Sequence/[@cycle='1']/Frame/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/[@index='ZAxis']/SubindexedValue" - ): - z_dicts.append(z_pos.attrib) + z_dicts = [z_pos.attrib for z_pos in root.findall(".//Sequence/[@cycle='1']/Frame/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/[@index='ZAxis']/SubindexedValue")] z_values = [d["value"] for d in z_dicts] From 8ede93fb8781ba8b9d912f5b72c7139aea811560 Mon Sep 17 00:00:00 2001 From: Kushal Bakshi <52367253+kushalbakshi@users.noreply.github.com> Date: Thu, 16 Mar 2023 14:50:39 -0500 Subject: [PATCH 05/13] Update element_interface/prairieviewreader.py Co-authored-by: Kabilar Gunalan --- element_interface/prairieviewreader.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/element_interface/prairieviewreader.py b/element_interface/prairieviewreader.py index cc9e27c..a61daa5 100644 --- a/element_interface/prairieviewreader.py +++ b/element_interface/prairieviewreader.py @@ -127,8 +127,6 @@ def get_pv_metadata(pvtiffile: str) -> dict: n_depths = len(set(planes)) # find z_depths controller if there is more than 1. - z_dicts = [] - if ( len( root.findall( From 826f4e2733aba1d2ae8328b42988c142d24c9d87 Mon Sep 17 00:00:00 2001 From: Kushal Bakshi <52367253+kushalbakshi@users.noreply.github.com> Date: Thu, 16 Mar 2023 14:50:54 -0500 Subject: [PATCH 06/13] Update element_interface/prairieviewreader.py Co-authored-by: Kabilar Gunalan --- element_interface/prairieviewreader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/element_interface/prairieviewreader.py b/element_interface/prairieviewreader.py index a61daa5..28529de 100644 --- a/element_interface/prairieviewreader.py +++ b/element_interface/prairieviewreader.py @@ -138,7 +138,7 @@ def get_pv_metadata(pvtiffile: str) -> dict: z_dicts = [z_pos.attrib for z_pos in root.findall(".//Sequence/[@cycle='1']/Frame/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/[@index='ZAxis']/SubindexedValue")] - z_values = [d["value"] for d in z_dicts] + z_values = list(z_dicts.values()) zdata_dictionary = defaultdict(list) for idx, val in enumerate(z_values): From 3a68aa15bab97d652685ceda6c33151bb51ecfc0 Mon Sep 17 00:00:00 2001 From: Kushal Bakshi <52367253+kushalbakshi@users.noreply.github.com> Date: Thu, 16 Mar 2023 14:51:28 -0500 Subject: [PATCH 07/13] Update element_interface/prairieviewreader.py Co-authored-by: Kabilar Gunalan --- element_interface/prairieviewreader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/element_interface/prairieviewreader.py b/element_interface/prairieviewreader.py index 28529de..4ab3ce1 100644 --- a/element_interface/prairieviewreader.py +++ b/element_interface/prairieviewreader.py @@ -144,7 +144,7 @@ def get_pv_metadata(pvtiffile: str) -> dict: for idx, val in enumerate(z_values): zdata_dictionary[val].append(idx) repeating_values = {k: v for k, v in zdata_dictionary.items() if len(v) > 1} - if len(repeating_values) > 0: + if repeating_values: idx_to_drop = list(repeating_values.values())[0] idx_to_drop.sort(reverse=True) for idx in idx_to_drop: From 32861b7c6dab291d93ee885d4a170a254e517018 Mon Sep 17 00:00:00 2001 From: Kushal Bakshi <52367253+kushalbakshi@users.noreply.github.com> Date: Thu, 16 Mar 2023 14:51:51 -0500 Subject: [PATCH 08/13] Update element_interface/prairieviewreader.py Co-authored-by: Kabilar Gunalan --- element_interface/prairieviewreader.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/element_interface/prairieviewreader.py b/element_interface/prairieviewreader.py index 4ab3ce1..30d72bf 100644 --- a/element_interface/prairieviewreader.py +++ b/element_interface/prairieviewreader.py @@ -116,8 +116,7 @@ def get_pv_metadata(pvtiffile: str) -> dict: else: - bidir_z = root.find(".//Sequence").attrib.get("bidirectionalZ") - bidirection_z = bidir_z == 'True' + bidirection_z = root.find(".//Sequence").attrib.get("bidirectionalZ") == 'True' # One "Frame" per depth. Gets number of frames in first sequence planes = [ From 95431398f2902af29ba98879c086dd423fa56f8f Mon Sep 17 00:00:00 2001 From: kushalbakshi Date: Mon, 20 Mar 2023 11:43:11 -0500 Subject: [PATCH 09/13] Update code from code review --- element_interface/prairieviewreader.py | 44 ++++---------------------- 1 file changed, 7 insertions(+), 37 deletions(-) diff --git a/element_interface/prairieviewreader.py b/element_interface/prairieviewreader.py index 30d72bf..384ec35 100644 --- a/element_interface/prairieviewreader.py +++ b/element_interface/prairieviewreader.py @@ -1,4 +1,3 @@ -from collections import defaultdict import pathlib import xml.etree.ElementTree as ET from datetime import datetime @@ -135,44 +134,15 @@ def get_pv_metadata(pvtiffile: str) -> dict: > 1 ): - z_dicts = [z_pos.attrib for z_pos in root.findall(".//Sequence/[@cycle='1']/Frame/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/[@index='ZAxis']/SubindexedValue")] - - z_values = list(z_dicts.values()) - - zdata_dictionary = defaultdict(list) - for idx, val in enumerate(z_values): - zdata_dictionary[val].append(idx) - repeating_values = {k: v for k, v in zdata_dictionary.items() if len(v) > 1} - if repeating_values: - idx_to_drop = list(repeating_values.values())[0] - idx_to_drop.sort(reverse=True) - for idx in idx_to_drop: - del z_values[idx] - z_values = [float(num) for num in z_values] - z_min = min(z_values) - z_max = max(z_values) - z_step = z_max / n_depths - z_fields = z_values - assert len(z_fields) == n_depths + z_repeats = [z_pos.attrib.get("value") for z_pos in root.findall(".//Sequence/[@cycle='1']/Frame/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/[@index='ZAxis']/SubindexedValue")] + + z_coordinates = [float(z) for z in z_repeats if z_repeats.count(z) == 1] else: - z_min = float( - root.findall( - ".//Sequence/[@cycle='1']/Frame/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/SubindexedValue/[@subindex='0']" - )[0].attrib.get("value") - ) - z_max = float( - root.findall( - ".//Sequence/[@cycle='1']/Frame/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/SubindexedValue/[@subindex='0']" - )[-1].attrib.get("value") - ) - z_step = float( - root.find( - ".//PVStateShard/PVStateValue/[@key='micronsPerPixel']/IndexedValue/[@index='ZAxis']" - ).attrib.get("value") - ) - z_fields = np.arange(z_min, z_max + 1, z_step) - assert z_fields.size == n_depths + z_coordinates = [z_pos.attrib.get("value") for z_pos in root.findall(".//Sequence/[@cycle='1']/Frame/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/[@index='ZAxis']/SubindexedValue/[@subindex='0']")] + + z_fields = z_coordinates + assert len(z_fields) == n_depths metainfo = dict( num_fields=n_fields, From 4eac2288f1c296733bce334cf1690d92dabf445a Mon Sep 17 00:00:00 2001 From: kushalbakshi Date: Mon, 20 Mar 2023 11:58:07 -0500 Subject: [PATCH 10/13] Final revisions + Black formatting --- element_interface/prairieviewreader.py | 36 +++++++++++++++----------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/element_interface/prairieviewreader.py b/element_interface/prairieviewreader.py index 384ec35..61368f6 100644 --- a/element_interface/prairieviewreader.py +++ b/element_interface/prairieviewreader.py @@ -115,7 +115,7 @@ def get_pv_metadata(pvtiffile: str) -> dict: else: - bidirection_z = root.find(".//Sequence").attrib.get("bidirectionalZ") == 'True' + bidirection_z = root.find(".//Sequence").attrib.get("bidirectionalZ") == "True" # One "Frame" per depth. Gets number of frames in first sequence planes = [ @@ -124,25 +124,31 @@ def get_pv_metadata(pvtiffile: str) -> dict: ] n_depths = len(set(planes)) - # find z_depths controller if there is more than 1. - if ( - len( - root.findall( - ".//Sequence/[@cycle='1']/Frame/[@index='1']/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/[@index='ZAxis']/SubindexedValue" + # find z-axis controller if there is more than 1. + z_controllers = root.findall( + ".//Sequence/[@cycle='1']/Frame/[@index='1']/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/[@index='ZAxis']/SubindexedValue" + ) + if len(z_controllers) > 1: + z_repeats = [ + z.attrib.get("value") + for z in root.findall( + ".//Sequence/[@cycle='1']/Frame/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/[@index='ZAxis']/SubindexedValue" ) - ) - > 1 - ): + ] - z_repeats = [z_pos.attrib.get("value") for z_pos in root.findall(".//Sequence/[@cycle='1']/Frame/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/[@index='ZAxis']/SubindexedValue")] - - z_coordinates = [float(z) for z in z_repeats if z_repeats.count(z) == 1] + z_fields = [float(z) for z in z_repeats if z_repeats.count(z) == 1] else: - z_coordinates = [z_pos.attrib.get("value") for z_pos in root.findall(".//Sequence/[@cycle='1']/Frame/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/[@index='ZAxis']/SubindexedValue/[@subindex='0']")] + z_fields = [ + z.attrib.get("value") + for z in root.findall( + ".//Sequence/[@cycle='1']/Frame/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/[@index='ZAxis']/SubindexedValue/[@subindex='0']" + ) + ] - z_fields = z_coordinates - assert len(z_fields) == n_depths + assert ( + len(z_fields) == n_depths + ), "Number of z fields does not match number of depths." metainfo = dict( num_fields=n_fields, From 6edcf653dcfb21f0211e198d96785ef3bcf7266f Mon Sep 17 00:00:00 2001 From: Kushal Bakshi <52367253+kushalbakshi@users.noreply.github.com> Date: Mon, 20 Mar 2023 12:12:45 -0500 Subject: [PATCH 11/13] Update element_interface/prairieviewreader.py Co-authored-by: Kabilar Gunalan --- element_interface/prairieviewreader.py | 1 - 1 file changed, 1 deletion(-) diff --git a/element_interface/prairieviewreader.py b/element_interface/prairieviewreader.py index 61368f6..e220f15 100644 --- a/element_interface/prairieviewreader.py +++ b/element_interface/prairieviewreader.py @@ -124,7 +124,6 @@ def get_pv_metadata(pvtiffile: str) -> dict: ] n_depths = len(set(planes)) - # find z-axis controller if there is more than 1. z_controllers = root.findall( ".//Sequence/[@cycle='1']/Frame/[@index='1']/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/[@index='ZAxis']/SubindexedValue" ) From 5fab07b0dceb6bbabdea245e33c1bce04fb355c3 Mon Sep 17 00:00:00 2001 From: kushalbakshi Date: Tue, 28 Mar 2023 16:16:19 -0500 Subject: [PATCH 12/13] Change nroi to 0 in PV loader --- element_interface/prairieviewreader.py | 37 +++++++++++++++++++------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/element_interface/prairieviewreader.py b/element_interface/prairieviewreader.py index e220f15..788537c 100644 --- a/element_interface/prairieviewreader.py +++ b/element_interface/prairieviewreader.py @@ -42,7 +42,7 @@ def get_pv_metadata(pvtiffile: str) -> dict: ) bidirectional_scan = False # Does not support bidirectional - roi = 1 + roi = 0 n_fields = 1 # Always contains 1 field record_start_time = root.find(".//Sequence/[@cycle='1']").attrib.get("time") @@ -128,14 +128,33 @@ def get_pv_metadata(pvtiffile: str) -> dict: ".//Sequence/[@cycle='1']/Frame/[@index='1']/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/[@index='ZAxis']/SubindexedValue" ) if len(z_controllers) > 1: - z_repeats = [ - z.attrib.get("value") - for z in root.findall( - ".//Sequence/[@cycle='1']/Frame/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/[@index='ZAxis']/SubindexedValue" + subindicies = [ + subindex.attrib.get("subindex") + for subindex in root.findall( + ".//Sequence/[@cycle='1']/Frame/[@index='1']/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/[@index='ZAxis']/" ) ] - z_fields = [float(z) for z in z_repeats if z_repeats.count(z) == 1] + z_repeats = [] + for subindex in subindicies: + z_repeats.append( + [ + float(z.attrib.get("value")) + for z in root.findall( + ".//Sequence/[@cycle='1']/Frame/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/[@index='ZAxis']/SubindexedValue/[@subindex='{0}']".format( + subindex + ) + ) + ] + ) + + z_fields = np.delete( + z_repeats, np.diff(z_repeats).mean(axis=1) == 0, axis=0 + ).flatten() + + assert ( + z_fields.shape[1] == n_depths + ), "Number of z fields does not match number of depths." else: z_fields = [ @@ -145,9 +164,9 @@ def get_pv_metadata(pvtiffile: str) -> dict: ) ] - assert ( - len(z_fields) == n_depths - ), "Number of z fields does not match number of depths." + assert ( + len(z_fields) == n_depths + ), "Number of z fields does not match number of depths." metainfo = dict( num_fields=n_fields, From 215264f13747beccb15e9f4240c646018f7b412d Mon Sep 17 00:00:00 2001 From: kushalbakshi Date: Thu, 6 Apr 2023 16:49:47 -0500 Subject: [PATCH 13/13] Code refinements --- element_interface/prairieviewreader.py | 28 ++++++++++---------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/element_interface/prairieviewreader.py b/element_interface/prairieviewreader.py index 788537c..31e0170 100644 --- a/element_interface/prairieviewreader.py +++ b/element_interface/prairieviewreader.py @@ -128,34 +128,28 @@ def get_pv_metadata(pvtiffile: str) -> dict: ".//Sequence/[@cycle='1']/Frame/[@index='1']/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/[@index='ZAxis']/SubindexedValue" ) if len(z_controllers) > 1: - subindicies = [ - subindex.attrib.get("subindex") - for subindex in root.findall( - ".//Sequence/[@cycle='1']/Frame/[@index='1']/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/[@index='ZAxis']/" - ) - ] z_repeats = [] - for subindex in subindicies: + for controller in root.findall( + ".//Sequence/[@cycle='1']/Frame/[@index='1']/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/[@index='ZAxis']/"): z_repeats.append( [ float(z.attrib.get("value")) for z in root.findall( ".//Sequence/[@cycle='1']/Frame/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/[@index='ZAxis']/SubindexedValue/[@subindex='{0}']".format( - subindex + controller.attrib.get("subindex") ) ) ] ) + - z_fields = np.delete( - z_repeats, np.diff(z_repeats).mean(axis=1) == 0, axis=0 - ).flatten() + controller_assert = [not all(z == z_controller[0] for z in z_controller) for z_controller in z_repeats] - assert ( - z_fields.shape[1] == n_depths - ), "Number of z fields does not match number of depths." + assert sum(controller_assert)==1, "Multiple controllers changing z depth is not supported" + z_fields = z_repeats[controller_assert.index(True)] + else: z_fields = [ z.attrib.get("value") @@ -164,9 +158,9 @@ def get_pv_metadata(pvtiffile: str) -> dict: ) ] - assert ( - len(z_fields) == n_depths - ), "Number of z fields does not match number of depths." + assert ( + len(z_fields) == n_depths + ), "Number of z fields does not match number of depths." metainfo = dict( num_fields=n_fields,