7
7
#
8
8
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
9
9
"""Common interface for any image format--volume or surface, binary or xml."""
10
+ from __future__ import annotations
10
11
11
12
import io
12
13
from copy import deepcopy
14
+ from typing import Type
13
15
from urllib import request
14
16
15
17
from .fileholders import FileHolder
@@ -74,7 +76,6 @@ class FileBasedImage:
74
76
75
77
properties:
76
78
77
- * shape
78
79
* header
79
80
80
81
methods:
@@ -118,25 +119,6 @@ class FileBasedImage:
118
119
119
120
img.to_file_map()
120
121
121
- You can get the data out again with::
122
-
123
- img.get_fdata()
124
-
125
- Less commonly, for some image types that support it, you might want to
126
- fetch out the unscaled array via the object containing the data::
127
-
128
- unscaled_data = img.dataoobj.get_unscaled()
129
-
130
- Analyze-type images (including nifti) support this, but others may not
131
- (MINC, for example).
132
-
133
- Sometimes you might to avoid any loss of precision by making the
134
- data type the same as the input::
135
-
136
- hdr = img.header
137
- hdr.set_data_dtype(data.dtype)
138
- img.to_filename(fname)
139
-
140
122
**Files interface**
141
123
142
124
The image has an attribute ``file_map``. This is a mapping, that has keys
@@ -158,20 +140,20 @@ class FileBasedImage:
158
140
contain enough information so that an existing image instance can save
159
141
itself back to the files pointed to in ``file_map``. When a file holder
160
142
holds active file-like objects, then these may be affected by the
161
- initial file read; in this case, the contains file-like objects need to
143
+ initial file read; in this case, the file-like objects need to
162
144
carry the position at which a write (with ``to_file_map``) should place the
163
145
data. The ``file_map`` contents should therefore be such, that this will
164
146
work.
165
147
"""
166
148
167
- header_class = FileBasedHeader
168
- _meta_sniff_len = 0
169
- files_types = (('image' , None ),)
170
- valid_exts = ()
171
- _compressed_suffixes = ()
149
+ header_class : Type [ FileBasedHeader ] = FileBasedHeader
150
+ _meta_sniff_len : int = 0
151
+ files_types : tuple [ tuple [ str , str | None ], ...] = (('image' , None ),)
152
+ valid_exts : tuple [ str , ...] = ()
153
+ _compressed_suffixes : tuple [ str , ...] = ()
172
154
173
- makeable = True # Used in test code
174
- rw = True # Used in test code
155
+ makeable : bool = True # Used in test code
156
+ rw : bool = True # Used in test code
175
157
176
158
def __init__ (self , header = None , extra = None , file_map = None ):
177
159
"""Initialize image
0 commit comments