|
1
|
|
|
from datetime import datetime |
|
2
|
|
|
import numpy |
|
3
|
|
|
from niprov.basefile import BaseFile |
|
4
|
|
|
from niprov.libraries import Libraries |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
class ParrecFile(BaseFile): |
|
8
|
|
|
|
|
9
|
|
|
def __init__(self, location, **kwargs): |
|
10
|
|
|
super(ParrecFile, self).__init__(location, **kwargs) |
|
11
|
|
|
self.libs = self.dependencies.getLibraries() |
|
12
|
|
|
self.camera = self.dependencies.getCamera() |
|
13
|
|
|
|
|
14
|
|
|
def inspect(self): |
|
15
|
|
|
provenance = super(ParrecFile, self).inspect() |
|
16
|
|
|
img = self.libs.nibabel.load(self.path) |
|
17
|
|
|
info = img.header.general_info |
|
18
|
|
|
provenance['dimensions'] = list(img.shape) |
|
19
|
|
|
dateformat = '%Y.%m.%d / %H:%M:%S' |
|
20
|
|
|
acqstring = info['exam_date'] |
|
21
|
|
|
provenance['acquired'] = datetime.strptime(acqstring, dateformat) |
|
22
|
|
|
provenance['subject'] = info['patient_name'] |
|
23
|
|
|
provenance['subject-position'] = info['patient_position'] |
|
24
|
|
|
provenance['protocol'] = info['protocol_name'] |
|
25
|
|
|
provenance['technique'] = info['tech'] |
|
26
|
|
|
tr = info['repetition_time'] |
|
27
|
|
|
if isinstance(tr, numpy.ndarray): |
|
28
|
|
|
tr = tr.tolist() |
|
29
|
|
|
provenance['repetition-time'] = tr |
|
30
|
|
|
provenance['field-of-view'] = info['fov'].tolist() |
|
31
|
|
|
provenance['epi-factor'] = info['epi_factor'] |
|
32
|
|
|
provenance['magnetization-transfer-contrast'] = bool(info['mtc']) |
|
33
|
|
|
provenance['diffusion'] = bool(info['diffusion']) |
|
34
|
|
|
provenance['duration'] = info['scan_duration'] |
|
35
|
|
|
provenance['water-fat-shift'] = info['water_fat_shift'] |
|
36
|
|
|
# per-image |
|
37
|
|
|
img0info = img.header.image_defs[0] |
|
38
|
|
|
provenance['slice-thickness'] = img0info['slice thickness'] |
|
39
|
|
|
provenance['slice-orientation'] = img0info['slice orientation'] |
|
40
|
|
|
provenance['echo-time'] = img0info['echo_time'] |
|
41
|
|
|
provenance['flip-angle'] = img0info['image_flip_angle'] |
|
42
|
|
|
provenance['inversion-time'] = img0info['Inversion delay'] |
|
43
|
|
|
if provenance['diffusion']: |
|
44
|
|
|
provenance['modality'] = 'DWI' |
|
45
|
|
|
else: |
|
46
|
|
|
provenance['modality'] = 'MRI' |
|
47
|
|
|
self.camera.saveSnapshot(img.get_data(), for_=self) |
|
48
|
|
|
return provenance |
|
49
|
|
|
|
|
50
|
|
|
def getProtocolFields(self): |
|
51
|
|
|
return ['repetition-time', 'echo-time', 'flip-angle', 'epi-factor', |
|
52
|
|
|
'water-fat-shift', 'subject-position'] |
|
53
|
|
|
|
|
54
|
|
|
|