From d7f2657086ce0b5bf6377da544113a4caae791b5 Mon Sep 17 00:00:00 2001 From: T14SG3 Date: Mon, 20 Mar 2023 13:07:39 +0100 Subject: [PATCH 1/5] added option to read in complex reconstructed 2dseq files. for this, there is now a new property reco_type which uses VisuCoreFrameType to determine if the reco was magnitude or real and imaginary. This will be upgraded to also read in in real or imaginray or phase or IR reconstructed data --- brukerapi/config/properties_2dseq_core.json | 6 ++++++ brukerapi/schemas.py | 21 +++++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/brukerapi/config/properties_2dseq_core.json b/brukerapi/config/properties_2dseq_core.json index 69147f6..270e842 100644 --- a/brukerapi/config/properties_2dseq_core.json +++ b/brukerapi/config/properties_2dseq_core.json @@ -151,6 +151,12 @@ "conditions": [] } ], + "reco_type": [ + { + "cmd": "#VisuCoreFrameType", + "conditions": [] + } + ], "dim_type": [ { "cmd": "#VisuCoreDimDesc.list + ['spatial',] + #VisuFGOrderDesc.sub_list(1)", diff --git a/brukerapi/schemas.py b/brukerapi/schemas.py index 30c4d7f..de8d75b 100644 --- a/brukerapi/schemas.py +++ b/brukerapi/schemas.py @@ -42,7 +42,8 @@ "num_slice_packages", "slope", "offset", - "dim_type" + "dim_type", + "reco_type" # new addition so you can also load complex reco ], "rawdata": [ "numpy_dtype", @@ -553,25 +554,32 @@ def scale(self): self._dataset.data = np.reshape(self._dataset.data, self._dataset.shape_final, order='F') def deserialize(self, data, layouts): - # scale if self._dataset._state['scale']: data = self._scale_frames(data, layouts, 'FW') - # frames -> frame_groups data = self._frames_to_framegroups(data, layouts) - + if hasattr(self._dataset, 'reco_type'): + # complex reco: + if self._dataset.reco_type[0] == 'REAL_IMAGE' and self._dataset.reco_type[1] == 'IMAGINARY_IMAGE': + data = data[...,::2] + 1j * data[...,1::2] + elif self._dataset.reco_type[0] == 'IMAGINARY_IMAGE' and self._dataset.reco_type[1] == 'REAL_IMAGE': + data = data[...,1::2] + 1j * data[...,::2] + # standard (magntitude) reco: + elif self._dataset.reco_type == ['MAGNITUDE_IMAGE']: + pass + else: + pass return data def _scale_frames(self, data, layouts, dir): """ - + Does not work for complex data! :param data: :param layouts: :param dir: :return: """ - # dataset is created with scale state set to False if self._dataset._state['scale'] is False: return data @@ -593,6 +601,7 @@ def _scale_frames(self, data, layouts, dir): if dir == 'BW': data = np.round(data) + return data def _frames_to_framegroups(self, data, layouts, mask=None): From 058495284ff26803472cb49db80818aaa9eb91aa Mon Sep 17 00:00:00 2001 From: T14SG3 Date: Mon, 20 Mar 2023 14:53:05 +0100 Subject: [PATCH 2/5] added option to load real, imaginary, phase and IR data as well --- brukerapi/schemas.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/brukerapi/schemas.py b/brukerapi/schemas.py index de8d75b..58d9d96 100644 --- a/brukerapi/schemas.py +++ b/brukerapi/schemas.py @@ -43,7 +43,7 @@ "slope", "offset", "dim_type", - "reco_type" # new addition so you can also load complex reco + "reco_type" ], "rawdata": [ "numpy_dtype", @@ -565,6 +565,15 @@ def deserialize(self, data, layouts): data = data[...,::2] + 1j * data[...,1::2] elif self._dataset.reco_type[0] == 'IMAGINARY_IMAGE' and self._dataset.reco_type[1] == 'REAL_IMAGE': data = data[...,1::2] + 1j * data[...,::2] + # real reco: + elif self._dataset.reco_type[0] == 'REAL_IMAGE': + pass + # imaginary reco: + elif self._dataset.reco_type[0] == 'IMAGINARY_IMAGE': + pass + # imaginary reco: + elif self._dataset.reco_type[0] == 'PHASE_IMAGE': + pass # standard (magntitude) reco: elif self._dataset.reco_type == ['MAGNITUDE_IMAGE']: pass @@ -574,7 +583,6 @@ def deserialize(self, data, layouts): def _scale_frames(self, data, layouts, dir): """ - Does not work for complex data! :param data: :param layouts: :param dir: From e9a91d2ef30b35ea3ddc45cecea489af900e0658 Mon Sep 17 00:00:00 2001 From: LucaNagel Date: Tue, 21 Mar 2023 14:11:09 +0100 Subject: [PATCH 3/5] it seems to be necessary to add a squeeze to avoid a singleton dimension at the end of the array --- brukerapi/dataset.py | 3 +++ brukerapi/schemas.py | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/brukerapi/dataset.py b/brukerapi/dataset.py index edbfd87..5b60a6a 100644 --- a/brukerapi/dataset.py +++ b/brukerapi/dataset.py @@ -515,6 +515,7 @@ def load_data(self): self._data = DataRandomAccess(self) else: self._data = self._read_data() + print("self._data.shape = " + str(self._data.shape)) def unload_data(self): """ @@ -524,6 +525,8 @@ def unload_data(self): def _read_data(self): data = self._read_binary_file(self.path, self.numpy_dtype, self.shape_storage) + print("self.shape_storage = " + str(self.shape_storage)) + print("data.shape = " + str(data.shape)) return self._schema.deserialize(data, self._schema.layouts) def _read_binary_file(self, path, dtype, shape): diff --git a/brukerapi/schemas.py b/brukerapi/schemas.py index 58d9d96..3bc212b 100644 --- a/brukerapi/schemas.py +++ b/brukerapi/schemas.py @@ -558,13 +558,14 @@ def deserialize(self, data, layouts): if self._dataset._state['scale']: data = self._scale_frames(data, layouts, 'FW') # frames -> frame_groups + print("deserialize --> data.shape=" + str(data.shape)) data = self._frames_to_framegroups(data, layouts) if hasattr(self._dataset, 'reco_type'): # complex reco: if self._dataset.reco_type[0] == 'REAL_IMAGE' and self._dataset.reco_type[1] == 'IMAGINARY_IMAGE': - data = data[...,::2] + 1j * data[...,1::2] + data = np.squeeze(data[...,::2] + 1j * data[...,1::2]) elif self._dataset.reco_type[0] == 'IMAGINARY_IMAGE' and self._dataset.reco_type[1] == 'REAL_IMAGE': - data = data[...,1::2] + 1j * data[...,::2] + data = np.squeeze(data[...,1::2] + 1j * data[...,::2]) # real reco: elif self._dataset.reco_type[0] == 'REAL_IMAGE': pass @@ -579,6 +580,7 @@ def deserialize(self, data, layouts): pass else: pass + print("deserialize --> data.shape=" + str(data.shape)) return data def _scale_frames(self, data, layouts, dir): From 469e4f23786713c000148116bb482bb0e8a55f7d Mon Sep 17 00:00:00 2001 From: LucaNagel Date: Tue, 21 Mar 2023 14:21:59 +0100 Subject: [PATCH 4/5] had to remove the print statements --- brukerapi/schemas.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/brukerapi/schemas.py b/brukerapi/schemas.py index 3bc212b..ecee6fc 100644 --- a/brukerapi/schemas.py +++ b/brukerapi/schemas.py @@ -558,7 +558,6 @@ def deserialize(self, data, layouts): if self._dataset._state['scale']: data = self._scale_frames(data, layouts, 'FW') # frames -> frame_groups - print("deserialize --> data.shape=" + str(data.shape)) data = self._frames_to_framegroups(data, layouts) if hasattr(self._dataset, 'reco_type'): # complex reco: @@ -580,7 +579,6 @@ def deserialize(self, data, layouts): pass else: pass - print("deserialize --> data.shape=" + str(data.shape)) return data def _scale_frames(self, data, layouts, dir): From f0f1e3dd3313b3b30e82e45e6d772a3c37f2b107 Mon Sep 17 00:00:00 2001 From: LucaNagel Date: Tue, 21 Mar 2023 14:23:14 +0100 Subject: [PATCH 5/5] had to remove the print statements --- brukerapi/dataset.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/brukerapi/dataset.py b/brukerapi/dataset.py index 5b60a6a..edbfd87 100644 --- a/brukerapi/dataset.py +++ b/brukerapi/dataset.py @@ -515,7 +515,6 @@ def load_data(self): self._data = DataRandomAccess(self) else: self._data = self._read_data() - print("self._data.shape = " + str(self._data.shape)) def unload_data(self): """ @@ -525,8 +524,6 @@ def unload_data(self): def _read_data(self): data = self._read_binary_file(self.path, self.numpy_dtype, self.shape_storage) - print("self.shape_storage = " + str(self.shape_storage)) - print("data.shape = " + str(data.shape)) return self._schema.deserialize(data, self._schema.layouts) def _read_binary_file(self, path, dtype, shape):