Passed
Push — master ( 4133e1...824ae8 )
by Fernando
06:45
created

torchio.data.orientation.name_dimensions()   A

Complexity

Conditions 2

Size

Total Lines 6
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nop 2
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
import warnings
2
import nibabel as nib
3
4
5
AXCODES_TO_WORDS = {
6
    'L': 'left',
7
    'R': 'right',
8
    'P': 'posterior',
9
    'A': 'anterior',
10
    'I': 'inferior',
11
    'S': 'superior',
12
    # 'C': 'caudal',
13
    # 'R': 'rostral',  # conflic with right
14
    # 'D': 'dorsal',
15
    # 'V': 'ventral',
16
}
17
18
19
def name_dimensions(tensor, affine):
20
    axcodes = nib.aff2axcodes(affine)
21
    names = [AXCODES_TO_WORDS[axcode] for axcode in axcodes]
22
    with warnings.catch_warnings():
23
        warnings.simplefilter('ignore', UserWarning)
24
        tensor.rename_(*names)
25