7
7
* returns an array from ``numpy.asanyarray(obj)``;
8
8
* has an attribute or property ``shape``.
9
9
"""
10
+ from __future__ import annotations
11
+
12
+ import typing as ty
10
13
11
14
import numpy as np
15
+ import numpy .typing as npt
12
16
17
+ from .arrayproxy import ArrayLike
13
18
from .deprecated import deprecate_with_version
14
- from .filebasedimages import FileBasedImage
19
+ from .filebasedimages import FileBasedHeader , FileBasedImage , FileMap , FileSpec
15
20
16
21
17
22
class DataobjImage (FileBasedImage ):
18
23
"""Template class for images that have dataobj data stores"""
19
24
20
- def __init__ (self , dataobj , header = None , extra = None , file_map = None ):
25
+ _data_cache : np .ndarray | None
26
+ _fdata_cache : np .ndarray | None
27
+
28
+ def __init__ (
29
+ self ,
30
+ dataobj : ArrayLike ,
31
+ header : FileBasedHeader | ty .Mapping | None = None ,
32
+ extra : ty .Mapping | None = None ,
33
+ file_map : FileMap | None = None ,
34
+ ):
21
35
"""Initialize dataobj image
22
36
23
37
The datobj image is a combination of (dataobj, header), with optional
@@ -40,11 +54,11 @@ def __init__(self, dataobj, header=None, extra=None, file_map=None):
40
54
"""
41
55
super ().__init__ (header = header , extra = extra , file_map = file_map )
42
56
self ._dataobj = dataobj
43
- self ._fdata_cache = None
44
57
self ._data_cache = None
58
+ self ._fdata_cache = None
45
59
46
60
@property
47
- def dataobj (self ):
61
+ def dataobj (self ) -> ArrayLike :
48
62
return self ._dataobj
49
63
50
64
@deprecate_with_version (
@@ -202,7 +216,11 @@ def get_data(self, caching='fill'):
202
216
self ._data_cache = data
203
217
return data
204
218
205
- def get_fdata (self , caching = 'fill' , dtype = np .float64 ):
219
+ def get_fdata (
220
+ self ,
221
+ caching : ty .Literal ['fill' , 'unchanged' ] = 'fill' ,
222
+ dtype : npt .DTypeLike = np .float64 ,
223
+ ) -> np .ndarray :
206
224
"""Return floating point image data with necessary scaling applied
207
225
208
226
The image ``dataobj`` property can be an array proxy or an array. An
@@ -351,7 +369,7 @@ def get_fdata(self, caching='fill', dtype=np.float64):
351
369
return data
352
370
353
371
@property
354
- def in_memory (self ):
372
+ def in_memory (self ) -> bool :
355
373
"""True when any array data is in memory cache
356
374
357
375
There are separate caches for `get_data` reads and `get_fdata` reads.
@@ -363,7 +381,7 @@ def in_memory(self):
363
381
or self ._data_cache is not None
364
382
)
365
383
366
- def uncache (self ):
384
+ def uncache (self ) -> None :
367
385
"""Delete any cached read of data from proxied data
368
386
369
387
Remember there are two types of images:
@@ -392,15 +410,21 @@ def uncache(self):
392
410
self ._data_cache = None
393
411
394
412
@property
395
- def shape (self ):
413
+ def shape (self ) -> tuple [ int , ...] :
396
414
return self ._dataobj .shape
397
415
398
416
@property
399
- def ndim (self ):
417
+ def ndim (self ) -> int :
400
418
return self ._dataobj .ndim
401
419
402
420
@classmethod
403
- def from_file_map (klass , file_map , * , mmap = True , keep_file_open = None ):
421
+ def from_file_map (
422
+ klass ,
423
+ file_map : FileMap ,
424
+ * ,
425
+ mmap : bool | ty .Literal ['c' , 'r' ] = True ,
426
+ keep_file_open : bool | None = None ,
427
+ ):
404
428
"""Class method to create image from mapping in ``file_map``
405
429
406
430
Parameters
@@ -433,7 +457,13 @@ def from_file_map(klass, file_map, *, mmap=True, keep_file_open=None):
433
457
raise NotImplementedError
434
458
435
459
@classmethod
436
- def from_filename (klass , filename , * , mmap = True , keep_file_open = None ):
460
+ def from_filename (
461
+ klass ,
462
+ filename : FileSpec ,
463
+ * ,
464
+ mmap : bool | ty .Literal ['c' , 'r' ] = True ,
465
+ keep_file_open : bool | None = None ,
466
+ ):
437
467
"""Class method to create image from filename `filename`
438
468
439
469
Parameters
0 commit comments