From af8a7345cd3f8cf466b2bf3f7581f961e6566db4 Mon Sep 17 00:00:00 2001 From: dvm-shlee Date: Tue, 23 Apr 2024 20:23:50 -0400 Subject: [PATCH 1/2] [update] get_info reco_id as optional --- brkraw/api/brkobj/scan.py | 2 +- brkraw/api/helper/orientation.py | 1 + brkraw/app/__init__.py | 0 pyproject.toml | 3 ++- 4 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 brkraw/app/__init__.py diff --git a/brkraw/api/brkobj/scan.py b/brkraw/api/brkobj/scan.py index 479fc3a..b99372c 100644 --- a/brkraw/api/brkobj/scan.py +++ b/brkraw/api/brkobj/scan.py @@ -31,7 +31,7 @@ def __init__(self, pvscan: 'PvScan', reco_id: Optional[int] = None, def set_info(self): self.info = self.get_info(self.reco_id) - def get_info(self, reco_id:int, get_analyzer:bool = False): + def get_info(self, reco_id:Optional[int] = None, get_analyzer:bool = False): infoobj = ScanInfo() pvscan = self.retrieve_pvscan() analysed = ScanInfoAnalyzer(pvscan, reco_id, self.is_debug) diff --git a/brkraw/api/helper/orientation.py b/brkraw/api/helper/orientation.py index 564d2c9..b8a44c7 100644 --- a/brkraw/api/helper/orientation.py +++ b/brkraw/api/helper/orientation.py @@ -245,6 +245,7 @@ def _calc_eulerangle(matrix): def _get_gradient_encoding_dir(cls, visu_pars): if visu_pars["VisuVersion"] != 1: return visu_pars["VisuAcqGradEncoding"] + # routine for PV version < 6 phase_enc = visu_pars["VisuAcqImagePhaseEncDir"] phase_enc = phase_enc[0] if is_all_element_same(phase_enc) else phase_enc return ( diff --git a/brkraw/app/__init__.py b/brkraw/app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pyproject.toml b/pyproject.toml index c1a68cb..91d4b69 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,7 +16,8 @@ dependencies = [ 'pillow>=7.1.1', 'tqdm>=4.45.0', 'openpyxl>=3.0.3', - 'xlrd>=1.0.0' + 'xlrd>=1.0.0', + 'toml>=0.10.2' ] description = "Bruker PvDataset Loader" license = {text = "GNLv3"} From 52737319bc1086e50a4b6b2239318986aa33969c Mon Sep 17 00:00:00 2001 From: dvm-shlee Date: Tue, 23 Apr 2024 20:25:08 -0400 Subject: [PATCH 2/2] [update] fid helper separated --- brkraw/api/analyzer/dataarray.py | 6 +++--- brkraw/api/analyzer/scaninfo.py | 1 + brkraw/api/helper/__init__.py | 3 ++- brkraw/api/helper/base.py | 11 ++++++++++ brkraw/api/helper/dataarray.py | 32 ++++++---------------------- brkraw/api/helper/fid.py | 36 ++++++++++++++++++++++++++++++++ 6 files changed, 59 insertions(+), 30 deletions(-) create mode 100644 brkraw/api/helper/fid.py diff --git a/brkraw/api/analyzer/dataarray.py b/brkraw/api/analyzer/dataarray.py index b01b333..89a2a12 100644 --- a/brkraw/api/analyzer/dataarray.py +++ b/brkraw/api/analyzer/dataarray.py @@ -18,9 +18,9 @@ def __init__(self, infoobj: 'ScanInfo', fileobj: Union[BufferedReader, ZipExtFil def _parse_info(self, infoobj: 'ScanInfo'): if not hasattr(infoobj, 'dataarray'): raise AttributeError - self.slope = infoobj.dataarray['2dseq_slope'] - self.offset = infoobj.dataarray['2dseq_offset'] - self.dtype = infoobj.dataarray['2dseq_dtype'] + self.slope = infoobj.dataarray['slope'] + self.offset = infoobj.dataarray['offset'] + self.dtype = infoobj.dataarray['dtype'] self.shape = infoobj.image['shape'][:] self.shape_desc = infoobj.image['dim_desc'][:] if infoobj.frame_group and infoobj.frame_group['type']: diff --git a/brkraw/api/analyzer/scaninfo.py b/brkraw/api/analyzer/scaninfo.py index 23d328b..7d152fc 100644 --- a/brkraw/api/analyzer/scaninfo.py +++ b/brkraw/api/analyzer/scaninfo.py @@ -25,6 +25,7 @@ def __init__(self, self._set_pars(pvobj, reco_id) if not debug: self.info_protocol = helper.Protocol(self).get_info() + self.info_fid = helper.FID(self).get_info() if self.visu_pars: self._parse_info() diff --git a/brkraw/api/helper/__init__.py b/brkraw/api/helper/__init__.py index e872f1e..c2aed94 100644 --- a/brkraw/api/helper/__init__.py +++ b/brkraw/api/helper/__init__.py @@ -5,6 +5,7 @@ from .slicepack import SlicePack from .cycle import Cycle from .orientation import Orientation, to_matvec, from_matvec, rotate_affine +from .fid import FID -__all__ = [Protocol, FrameGroup, DataArray, Image, SlicePack, Cycle, Orientation, +__all__ = [Protocol, FID, FrameGroup, DataArray, Image, SlicePack, Cycle, Orientation, to_matvec, from_matvec, rotate_affine] \ No newline at end of file diff --git a/brkraw/api/helper/base.py b/brkraw/api/helper/base.py index 2b6fc55..8d3bd52 100644 --- a/brkraw/api/helper/base.py +++ b/brkraw/api/helper/base.py @@ -1,6 +1,17 @@ import warnings from functools import partial +WORDTYPE = \ + dict(_32BIT_SGN_INT = 'i', + _16BIT_SGN_INT = 'h', + _8BIT_UNSGN_INT = 'B', + _32BIT_FLOAT = 'f') + +BYTEORDER = \ + dict(littleEndian = '<', + bigEndian = '>') + + def is_all_element_same(listobj): if listobj is None: return True diff --git a/brkraw/api/helper/dataarray.py b/brkraw/api/helper/dataarray.py index 04edb0a..84a294c 100644 --- a/brkraw/api/helper/dataarray.py +++ b/brkraw/api/helper/dataarray.py @@ -1,22 +1,11 @@ from __future__ import annotations import numpy as np from typing import TYPE_CHECKING -from .base import BaseHelper, is_all_element_same +from .base import BaseHelper, is_all_element_same, BYTEORDER, WORDTYPE if TYPE_CHECKING: from ..analyzer import ScanInfoAnalyzer -WORDTYPE = \ - dict(_32BIT_SGN_INT = 'i', - _16BIT_SGN_INT = 'h', - _8BIT_UNSGN_INT = 'B', - _32BIT_FLOAT = 'f') - -BYTEORDER = \ - dict(littleEndian = '<', - bigEndian = '>') - - class DataArray(BaseHelper): """requires visu_pars and aqcp to pars parameter related to the dtype of binary files @@ -29,17 +18,8 @@ class DataArray(BaseHelper): """ def __init__(self, analobj: 'ScanInfoAnalyzer'): super().__init__() - acqp = analobj.acqp visu_pars = analobj.visu_pars - if acqp: - fid_word_type = f'_{"".join(acqp["ACQ_word_size"].split("_"))}_SGN_INT' - fid_byte_order = f'{acqp["BYTORDA"]}Endian' - self.fid_dtype = np.dtype(f'{BYTEORDER[fid_byte_order]}{WORDTYPE[fid_word_type]}') - else: - self.fid_dtype = None - self._warn("Failed to fetch 'fid_dtype' information because the 'acqp' file is missing from 'analobj'.") - byte_order = visu_pars["VisuCoreByteOrder"] word_type = visu_pars["VisuCoreWordType"] self.data_dtype = np.dtype(f'{BYTEORDER[byte_order]}{WORDTYPE[word_type]}') @@ -53,13 +33,13 @@ def __init__(self, analobj: 'ScanInfoAnalyzer'): if isinstance(self.data_slope, list) or isinstance(self.data_offset, list): self._warn("Data slope and data offset values are unusual. " - "They are expected to be either a list containing the same elements or a single float value.") + "They are expected to be either a list containing the same elements or a single float value.") + def get_info(self): return { - 'fid_dtype': self.fid_dtype, - '2dseq_dtype': self.data_dtype, - '2dseq_slope': self.data_slope, - '2dseq_offset': self.data_offset, + 'dtype': self.data_dtype, + 'slope': self.data_slope, + 'offset': self.data_offset, 'warns': self.warns } \ No newline at end of file diff --git a/brkraw/api/helper/fid.py b/brkraw/api/helper/fid.py new file mode 100644 index 0000000..9baf320 --- /dev/null +++ b/brkraw/api/helper/fid.py @@ -0,0 +1,36 @@ +from __future__ import annotations +import numpy as np +from typing import TYPE_CHECKING +from .base import BaseHelper, is_all_element_same, BYTEORDER, WORDTYPE +if TYPE_CHECKING: + from ..analyzer import ScanInfoAnalyzer + + +class FID(BaseHelper): + """requires visu_pars and aqcp to pars parameter related to the dtype of binary files + + Dependencies: + acqp + visu_pars + + Args: + BaseHelper (_type_): _description_ + """ + def __init__(self, analobj: 'ScanInfoAnalyzer'): + super().__init__() + acqp = analobj.acqp + + if acqp: + word_type = f'_{"".join(acqp["ACQ_word_size"].split("_"))}_SGN_INT' + byte_order = f'{acqp["BYTORDA"]}Endian' + self.dtype = np.dtype(f'{BYTEORDER[byte_order]}{WORDTYPE[word_type]}') + else: + self.fid_dtype = None + self._warn("Failed to fetch 'fid_dtype' information because the 'acqp' file is missing from 'analobj'.") + + + def get_info(self): + return { + 'dtype': self.dtype, + 'warns': self.warns + } \ No newline at end of file