Completed
Push — master ( 6d0d49...6d6a7d )
by Jasper
02:25 queued 57s
created

NiftiFile.inspect()   A

Complexity

Conditions 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
1
from datetime import datetime
2
from niprov.basefile import BaseFile
3
4
5
class NiftiFile(BaseFile):
6
7
    def __init__(self, location, **kwargs):
8
        super(NiftiFile, self).__init__(location, **kwargs)
9
        self.libs = self.dependencies.getLibraries()
10
        self.camera = self.dependencies.getCamera()
11
12
    def attach(self, form='json'):
13
        """
14
        Attach the current provenance to the file by injecting it as a 
15
        json-encoded extension to the nifti header.
16
17
        Args:
18
            form (str): Data format in which to serialize provenance. Defaults 
19
                to 'json'.
20
        """
21
        img = self.libs.nibabel.load(self.path)
22
        provstr = self.getProvenance(form)
23
        ext = self.libs.nibabel.nifti1.Nifti1Extension('comment', provstr)
24
        hdr = img.get_header()
25
        hdr.extensions.append(ext)
26
        img.to_filename(self.path)
27
28
    def inspect(self):
29
        provenance = super(NiftiFile, self).inspect()
30
        img = self.libs.nibabel.load(self.path)
31
        self.camera.saveSnapshot(img.get_data(), for_=self)
32
        return provenance
33