From d3a75ad75118f474d0fe4fcef45d58c82b592983 Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauld.mccarthy@gmail.com>
Date: Wed, 8 Mar 2017 13:12:47 +0000
Subject: [PATCH] New Nifti methods  to return xyzt unit codes - nibabel
 returns labels, but I want the raw codes.

---
 fsl/data/image.py | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/fsl/data/image.py b/fsl/data/image.py
index 2b17dd65b..934bde5ec 100644
--- a/fsl/data/image.py
+++ b/fsl/data/image.py
@@ -42,7 +42,6 @@ import numpy             as np
 import nibabel           as nib
 import nibabel.fileslice as fileslice
 
-
 import fsl.utils.transform   as transform
 import fsl.utils.notifier    as notifier
 import fsl.utils.memoize     as memoize
@@ -314,6 +313,29 @@ class Nifti(notifier.Notifier):
         return self.__intent
 
 
+    @property
+    def xyzUnits(self):
+        """Returns the NIFTI XYZ dimension unit code. """
+
+        # The nibabel get_xyzt_units returns labels,
+        # but we want the NIFTI codes. So we use
+        # the (undocumented) nifti1.unit_codes field
+        # to convert back to the raw codes.
+        xyzUnits = self.header.get_xyzt_units()[0]
+        xyzUnits = nib.nifti1.unit_codes[xyzUnits]
+
+        return xyzUnits
+
+
+    def timeUnits(self):
+        """Returns the NIFTI time dimension unit code. """
+
+        # See xyzUnits
+        timeUnits = self.header.get_xyzt_units()[1]
+        timeUnits = nib.nifti1.unit_codes[timeUnits]
+        return timeUnits
+
+
     @property
     def worldToVoxMat(self):
         """Returns a ``numpy`` array of shape ``(4, 4)`` containing an
-- 
GitLab