58
58
2 1 1 1 0 2 1 16 62 64 64 0.00000 1.29035 4.28404e-003 1122 1951 -13.26 -0.00 -0.00 2.51 6.98 -10.53 6.000 2.000 0 1 0 2 3.750 3.750 30.00 0.00 0.00 0.00 0 90.00 0 0 0 39 0.0 1 1 8 0 0.000 0.000 0.000 1
59
59
3 1 1 1 0 2 2 16 62 64 64 0.00000 1.29035 4.28404e-003 1137 1977 -13.26 -0.00 -0.00 2.51 14.77 -12.36 6.000 2.000 0 1 0 2 3.750 3.750 30.00 0.00 0.00 0.00 0 90.00 0 0 0 39 0.0 1 1 8 0 0.000 0.000 0.000 1
60
60
61
- ###########
62
61
Orientation
63
62
###########
64
63
68
67
Anterior, inferior to Superior). The correspondence of the PAR file's axes to
69
68
RAS axes is:
70
69
71
- * ap = anterior -> posterior = negative A in RAS
72
- * fh = foot -> head = S in RAS
73
- * rl = right -> left = negative R in RAS
70
+ * ap = anterior -> posterior = negative A in RAS = P
71
+ * fh = foot -> head = S in RAS = S
72
+ * rl = right -> left = negative R in RAS = L
73
+
74
+ We therefore call the PAR file's axis system "PSL" (Posterior, Superior, Left).
74
75
75
76
The orientation of the PAR file axes corresponds to DICOM's LPS coordinate
76
77
system (right to Left, anterior to Posterior, inferior to Superior), but in a
77
78
different order.
78
79
79
- We call the PAR file's axis system "PSL" (Posterior, Superior, Left)
80
-
81
- #########
82
80
Data type
83
81
#########
84
82
@@ -333,8 +331,8 @@ def _process_image_lines(image_lines, version):
333
331
def vol_numbers (slice_nos ):
334
332
""" Calculate volume numbers inferred from slice numbers `slice_nos`
335
333
336
- The volume number for each slice is the number of times this slice has
337
- occurred previously in the `slice_nos` sequence
334
+ The volume number for each slice is the number of times this slice number
335
+ has occurred previously in the `slice_nos` sequence
338
336
339
337
Parameters
340
338
----------
@@ -366,8 +364,8 @@ def vol_is_full(slice_nos, slice_max, slice_min=1):
366
364
slice_max : int
367
365
Highest slice number for a full slice set. Slice set will be
368
366
``range(slice_min, slice_max+1)``.
369
- slice_min : int
370
- Lowest slice number for full slice set.
367
+ slice_min : int, optional
368
+ Lowest slice number for full slice set. Default is 1.
371
369
372
370
Returns
373
371
-------
@@ -379,7 +377,7 @@ def vol_is_full(slice_nos, slice_max, slice_min=1):
379
377
Raises
380
378
------
381
379
ValueError
382
- if any `slice_nos` value is outside slice set.
380
+ if any value in `slice_nos` is outside slice set indices .
383
381
"""
384
382
slice_set = set (range (slice_min , slice_max + 1 ))
385
383
if not slice_set .issuperset (slice_nos ):
@@ -465,7 +463,7 @@ def parse_PAR_header(fobj):
465
463
466
464
def _data_from_rec (rec_fileobj , in_shape , dtype , slice_indices , out_shape ,
467
465
scalings = None , mmap = True ):
468
- """Get data from REC file
466
+ """Load and return array data from REC file
469
467
470
468
Parameters
471
469
----------
@@ -485,10 +483,10 @@ def _data_from_rec(rec_fileobj, in_shape, dtype, slice_indices, out_shape,
485
483
be broadcast to `out_shape`.
486
484
mmap : {True, False, 'c', 'r', 'r+'}, optional
487
485
`mmap` controls the use of numpy memory mapping for reading data. If
488
- False, do not try numpy ``memmap`` for data array. If one of {'c', 'r',
489
- 'r+'}, try numpy memmap with ``mode=mmap``. A `mmap` value of True
490
- gives the same behavior as ``mmap='c'``. If `rec_fileobj` cannot be
491
- memory-mapped, ignore `mmap` value and read array from file.
486
+ False, do not try numpy ``memmap`` for data array. If one of {'c',
487
+ 'r', 'r +'}, try numpy memmap with ``mode=mmap``. A `mmap` value of
488
+ True gives the same behavior as ``mmap='c'``. If `rec_fileobj` cannot
489
+ be memory-mapped, ignore `mmap` value and read array from file.
492
490
493
491
Returns
494
492
-------
@@ -810,8 +808,8 @@ def _calc_zooms(self):
810
808
811
809
Notes
812
810
-----
813
- This routine called in ``__init__``, so may not be able to use
814
- some attributes available in the fully initalized object.
811
+ This routine gets called in ``__init__``, so may not be able to use
812
+ some attributes available in the fully initialized object.
815
813
"""
816
814
# slice orientation for the whole image series
817
815
slice_gap = self ._get_unique_image_prop ('slice gap' )
@@ -917,8 +915,8 @@ def _calc_data_shape(self):
917
915
918
916
Notes
919
917
-----
920
- This routine called in ``__init__``, so may not be able to use
921
- some attributes available in the fully initalized object.
918
+ This routine gets called in ``__init__``, so may not be able to use
919
+ some attributes available in the fully initialized object.
922
920
"""
923
921
inplane_shape = tuple (self ._get_unique_image_prop ('recon resolution' ))
924
922
shape = inplane_shape + (self ._get_n_slices (),)
@@ -945,13 +943,15 @@ def get_data_scaling(self, method="dv"):
945
943
The PAR header contains two different scaling settings: 'dv' (value on
946
944
console) and 'fp' (floating point value). Here is how they are defined:
947
945
946
+ DV = PV * RS + RI
947
+ FP = DV / (RS * SS)
948
+
949
+ where:
950
+
948
951
PV: value in REC
949
952
RS: rescale slope
950
953
RI: rescale intercept
951
954
SS: scale slope
952
-
953
- DV = PV * RS + RI
954
- FP = DV / (RS * SS)
955
955
"""
956
956
# These will be 3D or 4D
957
957
scale_slope = self .image_defs ['scale slope' ]
@@ -987,14 +987,22 @@ def get_rec_shape(self):
987
987
return inplane_shape + (len (self .image_defs ),)
988
988
989
989
def get_sorted_slice_indices (self ):
990
- """Indices to sort (and maybe discard) slices in REC file
990
+ """Return indices to sort (and maybe discard) slices in REC file.
991
+
992
+ Sorts by (fast to slow): slice number, volume number.
991
993
992
- Returns list for indexing into the last (third) dimension of the REC
993
- data array, and (equivalently) the only dimension of
994
- ``self.image_defs``.
994
+ We calculate volume number by looking for repeating slice numbers (see
995
+ :func:`vol_numbers`).
995
996
996
997
If the recording is truncated, the returned indices take care of
997
- discarding any indices that are not meant to be used.
998
+ discarding any slice indices from incomplete volumes.
999
+
1000
+ Returns
1001
+ -------
1002
+ slice_indices : list
1003
+ List for indexing into the last (third) dimension of the REC data
1004
+ array, and (equivalently) the only dimension of
1005
+ ``self.image_defs``.
998
1006
"""
999
1007
slice_nos = self .image_defs ['slice number' ]
1000
1008
is_full = vol_is_full (slice_nos , self .general_info ['max_slices' ])
@@ -1026,10 +1034,10 @@ def from_file_map(klass, file_map, mmap=True, permit_truncated=False,
1026
1034
mmap : {True, False, 'c', 'r'}, optional, keyword only
1027
1035
`mmap` controls the use of numpy memory mapping for reading image
1028
1036
array data. If False, do not try numpy ``memmap`` for data array.
1029
- If one of {'c', 'r'}, try numpy memmap with ``mode=mmap``. A `mmap`
1030
- value of True gives the same behavior as ``mmap='c'``. If image
1031
- data file cannot be memory-mapped, ignore `mmap` value and read
1032
- array from file.
1037
+ If one of {'c', 'r'}, try numpy memmap with ``mode=mmap``. A
1038
+ `mmap` value of True gives the same behavior as ``mmap='c'``. If
1039
+ image data file cannot be memory-mapped, ignore `mmap` value and
1040
+ read array from file.
1033
1041
permit_truncated : {False, True}, optional, keyword-only
1034
1042
If False, raise an error for an image where the header shows signs
1035
1043
that fewer slices / volumes were recorded than were expected.
@@ -1060,10 +1068,10 @@ def from_filename(klass, filename, mmap=True, permit_truncated=False,
1060
1068
mmap : {True, False, 'c', 'r'}, optional, keyword only
1061
1069
`mmap` controls the use of numpy memory mapping for reading image
1062
1070
array data. If False, do not try numpy ``memmap`` for data array.
1063
- If one of {'c', 'r'}, try numpy memmap with ``mode=mmap``. A `mmap`
1064
- value of True gives the same behavior as ``mmap='c'``. If image
1065
- data file cannot be memory-mapped, ignore `mmap` value and read
1066
- array from file.
1071
+ If one of {'c', 'r'}, try numpy memmap with ``mode=mmap``. A
1072
+ `mmap` value of True gives the same behavior as ``mmap='c'``. If
1073
+ image data file cannot be memory-mapped, ignore `mmap` value and
1074
+ read array from file.
1067
1075
permit_truncated : {False, True}, optional, keyword-only
1068
1076
If False, raise an error for an image where the header shows signs
1069
1077
that fewer slices / volumes were recorded than were expected.
0 commit comments