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.703000The 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]])}