diff --git a/plugin/bids/CITATION.cff b/plugin/bids/CITATION.cff deleted file mode 100644 index 0f98d16..0000000 --- a/plugin/bids/CITATION.cff +++ /dev/null @@ -1,29 +0,0 @@ -cff-version: 1.2.0 -title: "bids" -version: "" -abstract: "" -message: "" -repository-code: "https://github.com/BrkRaw/brkraw-plugin/plugin/bids" - -identifiers: - - description: "" - type: doi - value: "/" - -contact: - - email: shlee@unc.edu - family-names: SungHo - given-names: Lee - -authors: - - email: shlee@unc.edu - family-names: SungHo - given-names: Lee - -license: - -keywords: - - Bruker - - BIDS - - converter - - plugin \ No newline at end of file diff --git a/plugin/bids/LICENSE b/plugin/bids/LICENSE deleted file mode 100644 index 04b5f04..0000000 --- a/plugin/bids/LICENSE +++ /dev/null @@ -1,15 +0,0 @@ -Copyright © [year] [affiliation] - -All rights reserved. - -This software, MyPlugIn, is developed by [author or team]. This plugin for BrkRaw is licensed under the [specific license] License. - -Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation and/or other materials provided with the distribution. - -3. Neither the name of [alliiation] the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/plugin/bids/README.md b/plugin/bids/README.md deleted file mode 100644 index 2b6de86..0000000 --- a/plugin/bids/README.md +++ /dev/null @@ -1 +0,0 @@ -# BrkRaw ToNifTi App Plugin for BIDS conversions \ No newline at end of file diff --git a/plugin/bids/bids.py b/plugin/bids/bids.py deleted file mode 100644 index 3cb34f7..0000000 --- a/plugin/bids/bids.py +++ /dev/null @@ -1,137 +0,0 @@ -"""This module defines MyPlugIn, a custom plugin for the nifti application within the BrkRaw framework. -The MyPlugIn class extends the BasePlugin class and is tailored to enhance the functionality of -BrkRaw's conversion process by allowing specific customizations for NIfTI conversions. - -Key Features: -- Allows custom handling of data objects, affine transformations, and NIfTI headers based on - specific scan, reconstruction, or file data. -- Includes methods for inspecting data compatibility and setting parameters based on the provided - PvObj instances (PvScan, PvReco, PvFiles). -- Supports the integration of additional processing needs by overriding mandatory and optional methods. - -The plugin architecture is designed to facilitate easy additions and modifications to the data processing -pipeline, making it adaptable to various research requirements. - -Author: SungHo Lee -Created: 2024-04-30 -""" - - -from __future__ import annotations -from brkraw.app.tonifti import BasePlugin -from typing import TYPE_CHECKING -if TYPE_CHECKING: - from numpy.typing import NDArray - from typing import Union, Optional - from nibabel.nifti1 import Nifti1Header - from brkraw.app.tonifti import PvScan, PvReco, PvFiles - - -class Bids(BasePlugin): - """ Boilerplate code for a plugin for the nifti app in BrkRaw. - - The BasePlugin class extends the Scan class in brkraw.api.data. Refer to any compatible methods from - brkraw.api.data.scan.Scan for further guidance. - - Mandatory methods that must be implemented: - - get_dataobj(self, reco_id: Optional[int] = None) -> NDArray: - This method returns a data object in numpy ndarray format. Include custom code for data processing as needed. - 'reco_id' is required when accessing data under the pdata folder (such as '2dseq'). - - - get_affine(self, reco_id: Optional[int] = None, subj_type: Optional[str] = None, subj_position: Optional[str] = None) -> NDArray: - This method returns an affine matrix. Include custom rotations as necessary. - 'reco_id', 'subj_type', and 'subj_position' are optional parameters to support type and position overrides. - - - get_nifti1header(self, reco_id: Optional[int] = None) -> Nifti1Header: - This method returns a modified NIfTI header. Make any necessary updates to the NIfTI Header here. - - Optional internal methods: - - _inspect(self): - This method should be implemented to check whether the given data is compatible with the plugin. - - _set_params(self): - This method should be implemented to set parameter data or map binary files to class attributes. - """ - - def __init__(self, pvobj: Union['PvScan', 'PvReco', 'PvFiles'], - # --- start of custom arguments --- - dti: Optional[bool], - msme: Optional[bool], - # --- end of custom arguments --- - **kwargs - ) -> None: - """Initialize the plugin with a PvObj class instance. - - Args: - pvobj (PvScan | PvReco | PvFiles): Primitive class for PvObj (PvStudy is not supported). - option (bool): If true, multiply dataobj by 2 - """ - super().__init__(pvobj, **kwargs) - # --- start of mapping custom argumentss --- - self.dti = dti - self.msme = msme - # --- end of mapping custom arguments --- - self._inspect() - self._set_params() - - def _inspect(self): - """Inspect the provided data to ensure compatibility with this plugin. - - Example checks might include verifying parameters in 'acqp', 'method', and 'visu_pars' files. - """ - pass - - def _set_params(self): - """Set parameter values or file objects as attributes of this class. - - Access parameter files and read necessary binary data. - """ - self.acqp = self.pvobj.acqp - self.method = self.pvobj.method - self.visu_pars = self.pvobj.get_visu_pars() # this will get visu_pars from first pdata available to the dataset - - with self.pvobj.get_fid() as f: - self.fid = f.read() - with self.pvobj.get_2dseq() as f: # this will get 2dseq from first pdata available to the dataset - self.dataarray = f.read() - - - def get_dataobj(self, reco_id: Optional[int] = None) -> NDArray: - """Retrieve the data object, optionally filtered by reco_id. - - Args: - reco_id (Optional[int]): Specifies the reconstruction ID to filter the data. - - Returns: - NDArray: The data object as a numpy ndarray. - """ - dataobj = super().get_dataobj(scanobj=self, - reco_id=reco_id) - if self.option: - dataobj *= 2 - return dataobj - - def get_affine(self, reco_id:Optional[int]=None, - subj_type:Optional[str]=None, - subj_position:Optional[str]=None) -> NDArray: - """Retrieve the affine transformation matrix. - - Args: - reco_id (Optional[int]): Reconstruction ID if specific data access is needed. - subj_type (Optional[str]): Subject type for custom processing. - subj_position (Optional[str]): Subject position for custom processing. - - Returns: - NDArray: Affine transformation matrix. - """ - return super().get_affine(scanobj=self, - reco_id=reco_id, - subj_type=subj_type, - subj_position=subj_position) - - def get_nifti1header(self) -> Nifti1Header: - """Retrieve the NIfTI header updated as necessary for this plugin. - - Returns: - Nifti1Header: The updated NIfTI header. - """ - return super().get_nifti1header(self) \ No newline at end of file diff --git a/plugin/bids/manifest.yaml b/plugin/bids/manifest.yaml deleted file mode 100644 index 02ee22a..0000000 --- a/plugin/bids/manifest.yaml +++ /dev/null @@ -1,36 +0,0 @@ -name: bids -type: plugin -subtype: tonifti -version: 0.0.1 -source: bids.py:Bids - -authors: -- Sung-Ho Lee (shlee@unc.edu) -license: MIT -description: "BIDS plugin for tonifti app" -documentation: "README.md" -citation: CITATION.cff - -dependencies: -- numpy>=1.18 - -argparser: - name: bids - help: plugin function for converting file based on various BIDS specification - arguments: - - name: "--msme" - help: "Option for command line integration." - action: "store_true" - default: false - - name: "--dti" - help: "Option for DTI image" - action: "store_true" - default: false - - name: "--fieldmap" - help: "Option for FieldMap image" - action: "store_true" - default: false - - name: "--tripilot" - help: "Option for TriPilot image" - action: "store_true" - default: false \ No newline at end of file diff --git a/plugin/myplugin/CITATION.cff b/plugin/myplugin/CITATION.cff deleted file mode 100644 index 6087189..0000000 --- a/plugin/myplugin/CITATION.cff +++ /dev/null @@ -1,28 +0,0 @@ -cff-version: 1.2.0 -title: "myplugin" -version: "" -abstract: "" -message: "" -repository-code: "https://github.com/BrkRaw/brkraw-plugin/plugin/myplugin" - -identifiers: - - description: "" - type: doi - value: "/" - -contact: - - email: shlee@unc.edu - family-names: SungHo - given-names: Lee - -authors: - - email: shlee@unc.edu - family-names: SungHo - given-names: Lee - -license: - -keywords: - - bruker - - converter - - plugin \ No newline at end of file diff --git a/plugin/myplugin/LICENSE b/plugin/myplugin/LICENSE deleted file mode 100644 index 04b5f04..0000000 --- a/plugin/myplugin/LICENSE +++ /dev/null @@ -1,15 +0,0 @@ -Copyright © [year] [affiliation] - -All rights reserved. - -This software, MyPlugIn, is developed by [author or team]. This plugin for BrkRaw is licensed under the [specific license] License. - -Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation and/or other materials provided with the distribution. - -3. Neither the name of [alliiation] the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/plugin/myplugin/README.md b/plugin/myplugin/README.md deleted file mode 100644 index 463da9f..0000000 --- a/plugin/myplugin/README.md +++ /dev/null @@ -1 +0,0 @@ -# Boilerplate Plugin source code for Brkraw nifti app \ No newline at end of file diff --git a/plugin/myplugin/manifest.yaml b/plugin/myplugin/manifest.yaml deleted file mode 100644 index 7bc6518..0000000 --- a/plugin/myplugin/manifest.yaml +++ /dev/null @@ -1,25 +0,0 @@ -name: myplugin -type: plugin -subtype: tonifti -version: 0.0.1 -source: myplugin.py:MyPlugIn - -authors: -- MyName (my@email.domain) -license: MyLicense -description: "My plugin." -documentation: "README.md" -citation: CITATION.cff - -dependencies: -- numpy>=1.18 - -argparser: - name: myplugin - help: plugin function to multiply dataobj by 2 - arguments: - - name: "--option" - help: "Option to activate multiplying dataobj by 2." - action: "store_true" - default: false - diff --git a/plugin/myplugin/myplugin.py b/plugin/myplugin/myplugin.py deleted file mode 100644 index b9fc7c1..0000000 --- a/plugin/myplugin/myplugin.py +++ /dev/null @@ -1,135 +0,0 @@ -"""This module defines MyPlugIn, a custom plugin for the nifti application within the BrkRaw framework. -The MyPlugIn class extends the BasePlugin class and is tailored to enhance the functionality of -BrkRaw's conversion process by allowing specific customizations for NIfTI conversions. - -Key Features: -- Allows custom handling of data objects, affine transformations, and NIfTI headers based on - specific scan, reconstruction, or file data. -- Includes methods for inspecting data compatibility and setting parameters based on the provided - PvObj instances (PvScan, PvReco, PvFiles). -- Supports the integration of additional processing needs by overriding mandatory and optional methods. - -The plugin architecture is designed to facilitate easy additions and modifications to the data processing -pipeline, making it adaptable to various research requirements. - -Author: SungHo Lee -Created: 2024-04-30 -""" - - -from __future__ import annotations -from brkraw.app.tonifti import BasePlugin -from typing import TYPE_CHECKING -if TYPE_CHECKING: - from numpy.typing import NDArray - from typing import Union, Optional - from nibabel.nifti1 import Nifti1Header - from brkraw.app.tonifti import PvScan, PvReco, PvFiles - - -class MyPlugIn(BasePlugin): - """ Boilerplate code for a plugin for the nifti app in BrkRaw. - - The BasePlugin class extends the Scan class in brkraw.api.data. Refer to any compatible methods from - brkraw.api.data.scan.Scan for further guidance. - - Mandatory methods that must be implemented: - - get_dataobj(self, reco_id: Optional[int] = None) -> NDArray: - This method returns a data object in numpy ndarray format. Include custom code for data processing as needed. - 'reco_id' is required when accessing data under the pdata folder (such as '2dseq'). - - - get_affine(self, reco_id: Optional[int] = None, subj_type: Optional[str] = None, subj_position: Optional[str] = None) -> NDArray: - This method returns an affine matrix. Include custom rotations as necessary. - 'reco_id', 'subj_type', and 'subj_position' are optional parameters to support type and position overrides. - - - get_nifti1header(self, reco_id: Optional[int] = None) -> Nifti1Header: - This method returns a modified NIfTI header. Make any necessary updates to the NIfTI Header here. - - Optional internal methods: - - _inspect(self): - This method should be implemented to check whether the given data is compatible with the plugin. - - _set_params(self): - This method should be implemented to set parameter data or map binary files to class attributes. - """ - - def __init__(self, pvobj: Union['PvScan', 'PvReco', 'PvFiles'], - # --- start of custom arguments --- - option: Optional[bool], - # --- end of custom arguments --- - **kwargs - ) -> None: - """Initialize the plugin with a PvObj class instance. - - Args: - pvobj (PvScan | PvReco | PvFiles): Primitive class for PvObj (PvStudy is not supported). - option (bool): If true, multiply dataobj by 2 - """ - super().__init__(pvobj, **kwargs) - # --- start of mapping custom argumentss --- - self.option = option - # --- end of mapping custom arguments --- - self._inspect() - self._set_params() - - def _inspect(self): - """Inspect the provided data to ensure compatibility with this plugin. - - Example checks might include verifying parameters in 'acqp', 'method', and 'visu_pars' files. - """ - pass - - def _set_params(self): - """Set parameter values or file objects as attributes of this class. - - Access parameter files and read necessary binary data. - """ - self.acqp = self.pvobj.acqp - self.method = self.pvobj.method - self.visu_pars = self.pvobj.get_visu_pars() # this will get visu_pars from first pdata available to the dataset - - with self.pvobj.get_fid() as f: - self.fid = f.read() - with self.pvobj.get_2dseq() as f: # this will get 2dseq from first pdata available to the dataset - self.dataarray = f.read() - - - def get_dataobj(self, reco_id: Optional[int] = None) -> NDArray: - """Retrieve the data object, optionally filtered by reco_id. - - Args: - reco_id (Optional[int]): Specifies the reconstruction ID to filter the data. - - Returns: - NDArray: The data object as a numpy ndarray. - """ - dataobj = super().get_dataobj(scanobj=self, - reco_id=reco_id) - if self.option: - dataobj *= 2 - return dataobj - - def get_affine(self, reco_id: Optional[int] = None, - subj_type: Optional[str] = None, - subj_position: Optional[str] = None) -> NDArray: - """Retrieve the affine transformation matrix. - - Args: - reco_id (Optional[int]): Reconstruction ID if specific data access is needed. - subj_type (Optional[str]): Subject type for custom processing. - subj_position (Optional[str]): Subject position for custom processing. - - Returns: - NDArray: Affine transformation matrix. - """ - return super().get_affine(scanobj = self, - reco_id = reco_id, - subj_type = subj_type, - subj_position = subj_position) - - def get_nifti1header(self) -> Nifti1Header: - """Retrieve the NIfTI header updated as necessary for this plugin. - - Returns: - Nifti1Header: The updated NIfTI header. - """ - return super().get_nifti1header(self) \ No newline at end of file diff --git a/plugin/sordino/manifest.yaml b/plugin/sordino/manifest.yaml index cb42f02..6090641 100644 --- a/plugin/sordino/manifest.yaml +++ b/plugin/sordino/manifest.yaml @@ -1,7 +1,8 @@ +package: brkraw>=0.4.0 name: sordino type: plugin subtype: tonifti -version: 24.4.27 +version: 1.0.0 source: sordino.py:Sordino authors: diff --git a/plugin/sordino/sordino.py b/plugin/sordino/sordino.py index 19b2668..54fb6f4 100644 --- a/plugin/sordino/sordino.py +++ b/plugin/sordino/sordino.py @@ -5,49 +5,72 @@ import tempfile import numpy as np import sigpy as sp +from nibabel.nifti1 import Nifti1Image from pathlib import Path from tqdm import tqdm from scipy.interpolate import interp1d -from brkraw.app.tonifti import BasePlugin -from typing import TYPE_CHECKING +from brkraw.app.tonifti.plugin import ToNiftiPlugin +from typing import TYPE_CHECKING, Type, Optional, Literal, List if TYPE_CHECKING: + from brkraw.app.tonifti.types import ScaleMode + from brkraw.api.pvobj.types import PvFileBuffer, PvObjType from io import BufferedReader, BufferedWriter from zipfile import ZipExtFile - from typing import List, Union, Optional, Tuple, Literal - from nibabel.nifti1 import Nifti1Header - from brkraw.app.tonifti import PvScan, PvFiles + from typing import Union, Tuple from numpy.typing import NDArray -class Sordino(BasePlugin): +ExtFactor = Type[Optional[List[float]]] + +NufftMode = Type[Optional[Literal['sigpy']]] + + +class Sordino(ToNiftiPlugin): """ SORDINO: Plugin to Convert Bruker's SORDINO Images to NifTi File for ToNifti App in Brkraw ParaVision Compatability: > 360.x """ _recon_dtype: Optional[np.dtype] = None - def __init__(self, pvobj: Union['PvScan', 'PvFiles'], - ext_factors: List[float, float, float] = None, + def __init__(self, pvobj: PvObjType, + ext_factors: ExtFactor = None, offset: Optional[int] = None, num_frames: Optional[int] = None, spoketiming: Optional[bool] = False, mem_limit: Optional[float] = None, tmpdir: Optional[Path] = None, - nufft: Optional[Literal['sigpy']] = 'sigpy', - scale_mode: Optional[Literal['header', 'apply']] = 'header', + nufft: NufftMode = 'sigpy', + scale_mode: ScaleMode = 'header', **kwargs ) -> None: super().__init__(pvobj, **kwargs) self._inspect() self._set_params() self._set_cache(tmpdir) - self.ext_factors: List[float, float, float] = ext_factors or [1,1,1] + self._set_ext_factor(ext_factors) self.offset: int = offset or 0 self.spoketiming: bool = spoketiming self.mem_limit: Optional[float] = mem_limit self.num_frames: Optional[int] = num_frames or self._num_frames - self.nufft: str = nufft - self.scale_mode = scale_mode - self.slope, self.inter = 1, 0 + self.nufft: NufftMode = nufft + self.scale_mode: ScaleMode = scale_mode + self.slope: float = 1 + self.inter: float = 0 + + def _set_ext_factor(self, ext_factors: ExtFactor): + if isinstance(ext_factors, list): + if len(ext_factors) != 3: + warnings.warn(f"The 'ext_factors' arguments expect three values; got {len(ext_factors)}. Argument ignored.") + ext_factors = [1,1,1] + self.ext_factors = ext_factors or [1,1,1] + + def get_nifti1image(self, + reco_id: Optional[int] = None, + subj_type: Optional[str] = None, + subj_position: Optional[str] = None) -> 'Nifti1Image': + dataobj = self.get_dataobj() + affine = self.get_affine(reco_id=reco_id, subj_type=subj_type, subj_position=subj_position) + nifti1image = Nifti1Image(dataobj=dataobj, affine=affine) + return self.update_nifti1header(nifti1image) def get_dataobj(self) -> NDArray: self._set_trajectory() @@ -63,22 +86,24 @@ def get_dataobj(self) -> NDArray: dataobj = self._dataobj_rescale_to_uint16(dataobj) return dataobj - def get_affine(self, reco_id:Optional[int]=None, - subj_type:Optional[str]=None, - subj_position:Optional[str]=None) -> NDArray: - return super().get_affine(self, reco_id=reco_id, + def get_affine(self, + reco_id: Optional[int] = None, + subj_type: Optional[str] = None, + subj_position: Optional[str] = None) -> NDArray: + return super().get_affine(self, + reco_id=reco_id, subj_type=subj_type, subj_position=subj_position) - def get_nifti1header(self) -> Nifti1Header: + def update_nifti1header(self, nifti1image: Nifti1Image) -> Nifti1Image: with warnings.catch_warnings(): warnings.simplefilter("ignore") - header = super().get_nifti1header(self) + nifti1image = super().update_nifti1header(self, nifti1image) if self.scale_mode == 'header': - header.set_slope_inter(slope=self.slope, inter=self.inter) - return header + nifti1image.header.set_slope_inter(slope=self.slope, inter=self.inter) + return nifti1image - def _calc_slope_inter(self, dataobj: np.ndarray) -> None: + def _calc_slope_inter(self, dataobj: NDArray) -> None: dmax = np.max(dataobj) self.inter = np.min(dataobj) self.slope = (dmax - self.inter) / 2**16 @@ -126,10 +151,10 @@ def _inspect(self) -> None: warnings.warn("Input object is missing the 'orientation' attribute. \ This is not critical, but the orientation of the reconstructed image might be incorrect.", UserWarning) - def _get_fid(self) -> Union[BufferedReader, ZipExtFile]: + def _get_fid(self) -> PvFileBuffer: return self.pvobj.get_fid() - def _get_traj(self) -> Union[BufferedReader, ZipExtFile]: + def _get_traj(self) -> PvFileBuffer: return self.pvobj['traj'] def _set_params(self) -> None: @@ -197,7 +222,7 @@ def _traj_correct_projection_order(self) -> None: self.traj = self.traj[:, :, proj_order] def _traj_apply_extension_factors(self) -> None: - for i, ef in self.ext_factors: + for i, ef in enumerate(self.ext_factors): self.traj[i] *= ef def _dataobj_correct_orientation(self, dataobj) -> None: @@ -216,12 +241,14 @@ def _dataobj_correct_orientation(self, dataobj) -> None: return corrected_dataobj @staticmethod - def _rotate_dataobj(dataobj: NDArray, rotation_matrix: NDArray) -> NDArray: - axis_order = np.nonzero(rotation_matrix.T)[1].tolist() + def _rotate_dataobj(dataobj: NDArray, + rotation_matrix: NDArray) -> NDArray: + rot_mat = np.round(rotation_matrix, decimals=0).astype(int) + axis_order = np.nonzero(rot_mat.T)[1].tolist() if len(dataobj.shape) > 3: axis_order += [3] corrected_dataobj = np.transpose(dataobj, axis_order) - x, y, z = rotation_matrix.sum(0) + x, y, z = rot_mat.sum(0) return corrected_dataobj[::x, ::y, ::z, ...] def _recon_fid(self, filepath: Path = None, buffer_size: int = None) -> NDArray: @@ -255,7 +282,7 @@ def _recon_fid(self, filepath: Path = None, buffer_size: int = None) -> NDArray: return recon def _recon_process(self, - fid_buffer: Union['BufferedReader', 'ZipExtFile'], + fid_buffer: PvFileBuffer, recon_buffer: 'BufferedWriter', buffer_offset: int, output_shape: list) -> None: @@ -298,7 +325,7 @@ def _fid_correct_spoketiming(self) -> Tuple[str, int]: self._buffers.append(stc_f) return stc_f.name, stc_buffer_size - def _fid_get_filesize(self, fid_buffer: Union['BufferedReader', 'ZipExtFile']) -> float: + def _fid_get_filesize(self, fid_buffer: PvFileBuffer) -> float: if self.pvobj.is_compressed: fid_fname = os.path.basename(fid_buffer.name) fid_idx = [i for i, f in enumerate(self.pvobj._contents['files']) if fid_fname in f].pop() diff --git a/preset/README.md b/preset/README.md deleted file mode 100644 index 1aabd81..0000000 --- a/preset/README.md +++ /dev/null @@ -1 +0,0 @@ -# Repository for sharing preset \ No newline at end of file diff --git a/preset/bids.yaml b/preset/bids.yaml deleted file mode 100644 index bccfcfd..0000000 --- a/preset/bids.yaml +++ /dev/null @@ -1,16 +0,0 @@ -name: bids -type: preset -authors: -- Sung-Ho Lee (shlee@unc.edu) -description: "The presets for 'bids' plugin" - -app: - target: tonifti - plugin: bids - -versions: - dti: - dti: true - msme: - msme: true - \ No newline at end of file diff --git a/preset/mypreset.yaml b/preset/mypreset.yaml deleted file mode 100644 index 30f0f64..0000000 --- a/preset/mypreset.yaml +++ /dev/null @@ -1,15 +0,0 @@ -name: mypreset -type: preset -authors: -- Sung-Ho Lee (shlee@unc.edu) -description: "This presets for 'myplugin' plugin" - -app: - target: tonifti - plugin: myplugin - -versions: - option_on: - option: true - option_off: - option: falses \ No newline at end of file diff --git a/recipe/recipe_bids_v1.2.2_brkraw.yaml b/recipe/recipe_bids_v1.2.2_brkraw.yaml deleted file mode 100644 index c32387c..0000000 --- a/recipe/recipe_bids_v1.2.2_brkraw.yaml +++ /dev/null @@ -1,129 +0,0 @@ -name: bids_v1.2.2_brkraw -type: recipe -subtype: bids-file_metadata -startup: - - 'import numpy as np' - -dataset: - Name: '' - BIDSVersion: 1.2.2 - License: '' - Authors: - - '' - Acknowledgements: '' - HowToAsknowledge: '' - Funding: - - '' - EthicApprovals: '' - ReferenceAndLinks: '' - DatasetDOI: '' - -common: - Manufacturer: visu_pars.VisuManufacturer - ManufacturersModelName: visu_pars.VisuStation - DeviceSerialNumber: visu_pars.VisuSystemOrderNumber - StationName: visu_pars.VisuStation - SoftwareVersion: visu_pars.VisuAcqSoftwareVersion - MagneticFieldStrength: - Freq: visu_pars.VisuAcqImagingFrequency - script: Freq / 42.576 - ReceiveCoilName: visu_pars.VisuCoilReceiveName - ReceiveCoilActiveElements: visu_pars.VisuCoilReceiveType - GradientSetType: acqp.ACQ_status - MRTransmitCoilSequence: - Name: visu_pars.VisuCoilTransmitName - Manufacture: visu_pars.VisuCoilTransmitManufacturer - Type: visu_pars.VisuCoilTransmitType - CoilConfigName: acqp.ACQ_coil_config_file - MatrixCoilMode: acqp.ACQ_experiment_mode - CoilCombinationMethod: null - PulseSequenceType: acqp.PULPROG - ScanningSequence: visu_pars.VisuAcqSequenceName - SequenceVariant: visu_pars.VisuAcqEchoSequenceType - ScanOptions: - RG: visu_pars.VisuRespSynchUsed - CG: visu_pars.VisuCardiacSynchUsed - PFF: - key: visu_pars.VisuAcqPartialFourier - idx: 0 - PFP: - key: visu_pars.VisuAcqPartialFourier - idx: 1 - FC: visu_pars.VisuAcqFlowCompensation - SP: method.PVM_FovSatOnOff - FP: visu_pars.VisuAcqSpectralSuppression - SequenceName: - - visu_pars.VisuAcquisitionProtocol - - acqp.ACQ_protocol_name - PulseSequenceDetails: acqp.ACQ_scan_name - NonlinearGradientCorrection: visu_pars.VisuAcqKSpaceTraversal - NumberShots: visu_pars.VisuAcqKSpaceTrajectoryCnt - ParallelReductionFactorInPlane: acqp.ACQ_phase_factor - ParallelAcquisitionTechnique: null - PartialFourier: visu_pars.VisuAcqPartialFourier - PartialFourierDirection: null - PhaseEncodingDirection: - - key: visu_pars.VisuAcqGradEncoding - where: phase_enc - - visu_pars.VisuAcqImagePhaseEncDir - EffectiveEchoSpacing: - BWhzPixel: visu_pars.VisuAcqPixelBandwidth - MatSizePE: - key: method.PVM_EncMatrix - idx: - - key: visu_pars.VisuAcqGradEncoding - where: phase_enc - - 1 - ACCfactor: acqp.ACQ_phase_factor - script: (1 / (MatSizePE * BWhzPixel)) / ACCfactor - TotalReadoutTime: - ETL: visu_pars.VisuAcqEchoTrainLength - BWhzPixel: visu_pars.VisuAcqPixelBandwidth - ACCfactor: acqp.ACQ_phase_factor - script: (1 / BWhzPixel) / ACCfactor - EchoTime: - TE: visu_pars.VisuAcqEchoTime - Equation: np.array(TE)/1000 - InversionTime: visu_pars.VisuAcqInversionTime - SliceTiming: - TR: visu_pars.VisuAcqRepetitionTime - Order: acqp.ACQ_obj_order - script: np.linspace(0, TR/1000, len(Order) + 1)[Order] - SliceEncodingDirection: - - key: visu_pars.VisuAcqGradEncoding - where: slice_enc - - EncSeq: visu_pars.VisuAcqGradEncoding - script: len(EncSeq) - DwellTime: - BWhzPixel: visu_pars.VisuAcqPixelBandwidth - script: 1/BWhzPixel - FlipAngle: visu_pars.VisuAcqFlipAngle - MultibandAccerlationFactor: null - AnatomicalLandmarkCoordinates: null - InstitutionName: visu_pars.VisuInstitution - InstitutionAddress: null - InstitutionalDepartmentName: null - -fmri: - RepetitionTime: - TR: visu_pars.VisuAcqRepetitionTime - script: TR/1000 - VolumeTiming: - TR: visu_pars.VisuAcqRepetitionTime - NR: method.PVM_NRepetitions - script: (np.arange(NR)*(TR/1000)).tolist() - TaskName: null - NumberOfVolumesDiscardedByScanner: method.PVM_DummyScans - NumberOfVolumesDiscardedByUser: null - DelayTime: null - AcquisitionDuration: - TR: method.PVM_ScanTime - script: TR/1000 - DelayAfterTrigger: null - Instructions: null - TaskDescription: null - CogAtlasID: https://www.cognitiveatlas.org/fillYourID - CogPOID: http://www.cogpo.org/fillYourID - -fieldmap: - IntendedFor: '' diff --git a/recipe/recipe_studyinfo_v0.0.1_brkraw.yaml b/recipe/recipe_studyinfo_v0.0.1_brkraw.yaml deleted file mode 100644 index f2e810a..0000000 --- a/recipe/recipe_studyinfo_v0.0.1_brkraw.yaml +++ /dev/null @@ -1,50 +0,0 @@ -name: studyinfo_v0.0.1_brkraw -type: recipe -subtype: studyinfo -startup: -- - -study: - date: - - header.study_date - - header.date - dob: header.dbirth - id: header.id - name: header.name_string - operator: study_operator - position: - - header.study_instrument_position - - entry: header.entry - position: header.position - script: entry.split("_").pop(-1) + "_" + position.split("_").pop(-1) - sex: - - header.gender - - header.sex - study_name: header.study_name - study_nr: header.study_nr - sw_version: header.sw_version - type: header.type - weight: - - header.study_weight - - header.weight - -scan: - dim: image.dim - in_plane_shape: image.shape - in_plann_resolution: image.resolution - method: protocol.scan_method - num_cycles: cycle.num_cycles - num_slice_packs: slicepack.num_slice_packs - num_slices_each_pack: slicepack.num_slices_each_pack - ppg: protocol.pulse_program - protocol: protocol.protocol_name - slice_distances_each_pack: slicepack.slice_distances_each_pack - slice_order_scheme: slicepack.slice_order_scheme - time_step: cycle.time_step - -reco: - dim_description: - dim_desc: image.dim_desc - fg_desc: frame_group.id - script: dim_desc + [f.split("_")[-1].lower() for f in fg_desc] - type: frame_group.type diff --git a/spec/spec_bids_v1.2.2_brkraw.yaml b/spec/spec_bids_v1.2.2_brkraw.yaml deleted file mode 100644 index f7837d4..0000000 --- a/spec/spec_bids_v1.2.2_brkraw.yaml +++ /dev/null @@ -1,78 +0,0 @@ -name: bids_v1.2.2_brkraw -type: bids-spec -subtype: converter -brkraw: - path: - type: string - pattern: '^[a-zA-Z0-9_/]{1,100}$' # Assuming paths can be longer and include slashes - description: "Path to the data file or directory" - scan-id: - type: int - description: "Numerical identifier for the scan" - reco-id: - type: int - description: "Reconstruction identifier for the scan" - offset: - type: int - description: "Offset value for the data read" - num-frames: - type: int - description: "Number of frames in the scan" - preset: - type: string - pattern: '^[a-zA-Z0-9]{1,20}$' - description: "Name of preset configurations for the tonifti conversion" - -bids-filename: - sub: - type: string - pattern: '^[a-zA-Z0-9]{1,13}$' - description: "Subject identifier, alphanumeric" - ses: - type: string - pattern: '^[a-zA-Z0-9]{1,13}$' - description: "Session identifier, alphanumeric" - task: - type: string - pattern: '^[a-zA-Z0-9]{1,20}$' - description: "Task label" - acq: - type: string - pattern: '^[a-zA-Z0-9]{1,20}$' - description: "Acquisition label" - ce: - type: string - pattern: '^[a-zA-Z0-9]{1,20}$' - description: "Contrast enhancement label" - rec: - type: string - pattern: '^[a-zA-Z0-9]{1,20}$' - description: "Reconstruction label" - dir: - type: string - pattern: '^[a-zA-Z0-9]{1,20}$' - description: "Direction label" - run: - type: string - pattern: '^[0-9]{1,2}$' - description: "Run identifier, zero-padded if numerical, e.g., 'run-01'" - inv: - type: string - pattern: '^[a-zA-Z0-9]{1,20}$' - description: "Inversion label" - flip: - type: string - pattern: '^[a-zA-Z0-9]{1,20}$' - description: "Flip angle" - mt: - type: string - pattern: '^[a-zA-Z0-9]{1,20}$' - description: "Magnetization transfer label" - part: - type: string - pattern: '^[a-zA-Z0-9]{1,20}$' - description: "Participant label" - modality: - type: string - pattern: '^[a-zA-Z0-9]{1,20}$' - description: "Imaging modality"