Package: nifti-mrs
Python Tools for NIfTI-MRSThis package contains python-based tools for representing, validating, and manipulating theNIfTI-MRS format.NIfTI-MRSis a standardised format for storing Magnetic Resonance Spectroscopy data.These tools are used extensively in thespec2niiformat conversion program and theFSL-MRSanalysis software. However, this library can also be used as a stand-alone set of tools.If you use these tools please cite:Clarke, WT, Bell, TK, Emir, UE, et al. NIfTI-MRS: A standard data format for magnetic resonance spectroscopy. Magn Reson Med. 2022; 88: 2358- 2370. doi:10.1002/mrm.29418InstallationInstallation is viaconda(-forge)orPypi.conda install -c conda-forge nifti-mrsorpip install nifti-mrsNote this package is a requirement ofspec2nii(>v0.4.9) andFSL-MRS(>v2.0.9) and will automatically be installed with them.Using the packageCommand-line tool -mrs_toolsMRS data stored in NIfTI-MRS format can contain multiple higher dimensions. For example it might contain dimensions encoding multiple receive coils, multiple temporal averages, or even a spectral editing dimension.Data might need to be manipulated within the NIfTI-MRS storage framework before, after, or during preprocessing. For this, FLS-MRS provides themrs_toolscommand line script.mrs_toolshas the ability to merge and split NIfTI-MRS files along the higher encoding dimensions. It can also reorder the higher dimensions, or create a new singleton dimension for further manipulation.mrs_tools splittakes a single file and splits it along a specified dimension e.g.--dim DIM_DYN, at a single point (--index 8) or extracting multiple elements into a second file (--indices 8 9 10).mrs_tools mergetakes two or more files and merges them along a specified dimension e.g.--dim DIM_EDIT. Use--newaxisif that dimension doesn't exist in the files already.mrs_tools reorderpermutes the dimensions of an existing NIfTI-MRS file. For example, the 5th through 7th dimensions can be changed fromDIM_COIL, DIM_DYN, DIM_EDITtoDIM_DYN, DIM_EDIT, DIM_COILusing--dim_order DIM_DYN DIM_EDIT DIM_COIL. Reorder can be used to add a tag to a singleton dimension.mrs_tools reshapeallows Numpy-style reshaping of the higher dimensions. For example if two editing conditions are interleaved you can reshape a file from (32, 128) to (32, 64, 2), and by specifying-d6 DIM_DYN -d7 DIM_EDITyou can tag the new dimensions appropriately.mrs_toolsalso contains themrs_tools visandmrs_tools infooptions to provide quick visualisation and information on the command line. See theFSL-MRS Visualisation documentationfor more information onmrs_tools vis/info.Note: visualisation of NIfTI-MRS data usingmrs_toolsrequires the installation of theFSL-MRS packageAs a code libraryThe command-line tools presents an interface to the underlying code library. The library can be used directly in interactive or scripted python. For example:from nifti_mrs.nifti_mrs import NIFTI_MRS
from nifti_mrs import tools

obj = NIFTI_MRS('path/to/data.nii.gz')

# Split the object at index 16 (1-16, 17-N) along the dynamics dimension
part_1, part_2 = tools.split(obj, 'DIM_DYN', 15)

# Save the first part
part_1.save('output/location/part_1.nii.gz')See theAPI documentationfor details.Contributing and testsContributions to improve or extend these tools via pull requests are extremely welcome. Contributors, please take time to develop tests to continually validate new features or changes.AcknowledgementsContributorsWilliam Clarke, University of OxfordFunding acknowledgmentsThis work was funded by the Wellcome Trust [225924/Z/22/Z, 203139/Z/16/Z and 203139/A/16/Z].