1
1
from pathlib import Path
2
2
import typing as ty
3
- from fileformats .core import FileSet , extra_implementation
4
- from fileformats .generic import File
3
+ from fileformats .core import FileSet , extra_implementation , validated_property
4
+ from fileformats .generic import BinaryFile
5
5
from fileformats .application .archive import BaseGzip
6
6
from fileformats .core .mixin import WithMagicNumber
7
7
from fileformats .core .exceptions import FormatMismatchError
@@ -12,12 +12,12 @@ class MultiLineMetadataValue(list):
12
12
pass
13
13
14
14
15
- class BaseMrtrixImage (WithMagicNumber , fileformats .medimage .MedicalImage , File ):
15
+ class BaseMrtrixImage (WithMagicNumber , fileformats .medimage .MedicalImage , BinaryFile ):
16
16
17
17
magic_number = b"mrtrix image\n "
18
18
binary = True
19
19
20
- @property
20
+ @validated_property
21
21
def data_fspath (self ):
22
22
data_fspath = self .metadata ["file" ].split ()[0 ]
23
23
if data_fspath == "." :
@@ -48,8 +48,8 @@ class ImageFormat(BaseMrtrixImage):
48
48
ext = ".mif"
49
49
iana_mime = "application/x-mrtrix-image-format"
50
50
51
- @property
52
- def check_data_file (self ):
51
+ @validated_property
52
+ def _check_data_file (self ):
53
53
if self .data_fspath != self .fspath :
54
54
raise FormatMismatchError (
55
55
f"Data file ('{ self .data_fspath } ') is not set to the same file as header "
@@ -73,7 +73,7 @@ class ImageHeader(BaseMrtrixImage):
73
73
ext = ".mih"
74
74
iana_mime = "application/x-mrtrix-image-header"
75
75
76
- @property
76
+ @validated_property
77
77
def data_file (self ):
78
78
return ImageDataFile (self .data_fspath )
79
79
@@ -84,14 +84,14 @@ def __attrs_post_init__(self):
84
84
super ().__attrs_post_init__ ()
85
85
86
86
87
- class ImageDataFile (File ):
87
+ class ImageDataFile (BinaryFile ):
88
88
89
89
ext = ".dat"
90
90
91
91
92
92
@extra_implementation (FileSet .read_metadata )
93
93
def mrtrix_read_metadata (
94
- mif : BaseMrtrixImage , selected_keys : ty .Optional [ ty . Collection [ str ]] = None
94
+ mif : BaseMrtrixImage , ** kwargs : ty .Any
95
95
) -> ty .Mapping [str , ty .Any ]:
96
96
metadata = {}
97
97
with open (mif .fspath , "rb" ) as f :
@@ -127,6 +127,4 @@ def mrtrix_read_metadata(
127
127
else :
128
128
metadata [key ] = value
129
129
line = f .readline ().decode ("utf-8" )
130
- if selected_keys :
131
- metadata = {k : v for k , v in metadata .items () if k in selected_keys }
132
130
return metadata
0 commit comments