• Xibabel documentation
  • Home
  • Basic read and slice with Xibabel
  • General linear model with Xibabel
  • Slice-timing correction
  • The Xi accessor
  • Published with MkDocs
  • Theme by GitBook

The Xi accessor¶

This is the xi accessor, with which we can add behavior to all DataArrays, including Xibabel images.

In [1]:
Copied!
import numpy as np
import pandas as pd

import xarray as xr

import nibabel as nib
import xibabel as xib

# For test images.
from xibabel import testing
import numpy as np import pandas as pd import xarray as xr import nibabel as nib import xibabel as xib # For test images. from xibabel import testing

Make sure we have the minimal test data.

In [2]:
Copied!
# Get the data
testing.get_set('minimal')
# Get the data testing.get_set('minimal')
Out[2]:
{PosixPath('/Users/mb312/.xibabel/data/ds000009/.git/annex/objects/jv/80/MD5E-s42750881--03498e47bc89b855e1e71c8b1231e338.nii.gz/MD5E-s42750881--03498e47bc89b855e1e71c8b1231e338.nii.gz'),
 PosixPath('/Users/mb312/.xibabel/data/ds000009/.git/annex/objects/w9/WZ/MD5E-s12474309--4997ec21f72f4e1f7b2f9fafaf3c805e.nii.gz/MD5E-s12474309--4997ec21f72f4e1f7b2f9fafaf3c805e.nii.gz'),
 PosixPath('/Users/mb312/.xibabel/data/ds000009/sub-07/func/sub-07_task-balloonanalogrisktask_events.tsv'),
 PosixPath('/Users/mb312/.xibabel/data/ds000105/.git/annex/objects/8K/Vj/MD5E-s25669537--7e1f97ca1367d33f06e12170feeabe4a.nii.gz/MD5E-s25669537--7e1f97ca1367d33f06e12170feeabe4a.nii.gz'),
 PosixPath('/Users/mb312/.xibabel/data/ds000105/sub-1/func/sub-1_task-objectviewing_run-01_events.tsv')}
In [3]:
Copied!
ximg = xib.load(testing.JC_EG_ANAT)
ximg
ximg = xib.load(testing.JC_EG_ANAT) ximg
Out[3]:
<xarray.DataArray 'sub-07_T1w' (i: 176, j: 256, k: 256)> Size: 92MB
dask.array<array, shape=(176, 256, 256), dtype=float64, chunksize=(176, 256, 256), chunktype=numpy.ndarray>
Coordinates:
  * i        (i) int64 1kB 0 1 2 3 4 5 6 7 8 ... 168 169 170 171 172 173 174 175
  * j        (j) int64 2kB 0 1 2 3 4 5 6 7 8 ... 248 249 250 251 252 253 254 255
  * k        (k) int64 2kB 0 1 2 3 4 5 6 7 8 ... 248 249 250 251 252 253 254 255
Attributes:
    xib-FrequencyEncodingDirection:  j
    PhaseEncodingDirection:          i
    SliceEncodingDirection:          k
    xib-affines:                     {'scanner': [[0.9979095458984375, 0.0392...
    ImagingFrequency:                123.249679
    SeriesDate:                      18681110
    SeriesNumber:                    10
    SeriesTime:                      173018.296000
    StudyID:                         1
    StudyTime:                       160942.703000
xarray.DataArray
'sub-07_T1w'
  • i: 176
  • j: 256
  • k: 256
  • dask.array<chunksize=(176, 256, 256), meta=np.ndarray>
    Array Chunk
    Bytes 88.00 MiB 88.00 MiB
    Shape (176, 256, 256) (176, 256, 256)
    Dask graph 1 chunks in 2 graph layers
    Data type float64 numpy.ndarray
    256 256 176
    • i
      (i)
      int64
      0 1 2 3 4 5 ... 171 172 173 174 175
      array([  0,   1,   2,   3,   4,   5,   6,   7,   8,   9,  10,  11,  12,  13,
              14,  15,  16,  17,  18,  19,  20,  21,  22,  23,  24,  25,  26,  27,
              28,  29,  30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,
              42,  43,  44,  45,  46,  47,  48,  49,  50,  51,  52,  53,  54,  55,
              56,  57,  58,  59,  60,  61,  62,  63,  64,  65,  66,  67,  68,  69,
              70,  71,  72,  73,  74,  75,  76,  77,  78,  79,  80,  81,  82,  83,
              84,  85,  86,  87,  88,  89,  90,  91,  92,  93,  94,  95,  96,  97,
              98,  99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
             112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125,
             126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139,
             140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153,
             154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167,
             168, 169, 170, 171, 172, 173, 174, 175])
    • j
      (j)
      int64
      0 1 2 3 4 5 ... 251 252 253 254 255
      array([  0,   1,   2, ..., 253, 254, 255])
    • k
      (k)
      int64
      0 1 2 3 4 5 ... 251 252 253 254 255
      array([  0,   1,   2, ..., 253, 254, 255])
    • i
      PandasIndex
      PandasIndex(Index([  0,   1,   2,   3,   4,   5,   6,   7,   8,   9,
             ...
             166, 167, 168, 169, 170, 171, 172, 173, 174, 175],
            dtype='int64', name='i', length=176))
    • j
      PandasIndex
      PandasIndex(Index([  0,   1,   2,   3,   4,   5,   6,   7,   8,   9,
             ...
             246, 247, 248, 249, 250, 251, 252, 253, 254, 255],
            dtype='int64', name='j', length=256))
    • k
      PandasIndex
      PandasIndex(Index([  0,   1,   2,   3,   4,   5,   6,   7,   8,   9,
             ...
             246, 247, 248, 249, 250, 251, 252, 253, 254, 255],
            dtype='int64', name='k', length=256))
  • xib-FrequencyEncodingDirection :
    j
    PhaseEncodingDirection :
    i
    SliceEncodingDirection :
    k
    xib-affines :
    {'scanner': [[0.9979095458984375, 0.0392538346350193, 0.04931356757879257, -102.19679260253906], [-0.04014434665441513, 0.975773274898529, -0.001983797876164317, -113.49977111816406], [-0.05053766071796417, -9.929630451210869e-09, 0.9753145575523376, -110.37702941894531], [0.0, 0.0, 0.0, 1.0]]}
    ImagingFrequency :
    123.249679
    SeriesDate :
    18681110
    SeriesNumber :
    10
    SeriesTime :
    173018.296000
    StudyID :
    1
    StudyTime :
    160942.703000

The xi accessor:

In [4]:
Copied!
ximg.xi.get_affines()
ximg.xi.get_affines()
Out[4]:
{'scanner': array([[ 9.97909546e-01,  3.92538346e-02,  4.93135676e-02,
         -1.02196793e+02],
        [-4.01443467e-02,  9.75773275e-01, -1.98379788e-03,
         -1.13499771e+02],
        [-5.05376607e-02, -9.92963045e-09,  9.75314558e-01,
         -1.10377029e+02],
        [ 0.00000000e+00,  0.00000000e+00,  0.00000000e+00,
          1.00000000e+00]])}