Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/dcmstack/dcmmeta.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
DcmMeta header extension and NiftiWrapper for working with extended Niftis.
"""
from __future__ import print_function

from builtins import range
import sys
import json, warnings
from copy import deepcopy
Expand Down Expand Up @@ -907,7 +907,7 @@ def _copy_slice(self, other, src_class, idx):

if len(subset_vals) < dest_mult:
full_vals = []
for val_idx in xrange(dest_mult / len(subset_vals)):
for val_idx in range(dest_mult / len(subset_vals)):
full_vals += deepcopy(subset_vals)
subset_vals = full_vals
if len(subset_vals) == 1:
Expand Down Expand Up @@ -936,7 +936,7 @@ def _global_slice_subset(self, key, sample_base, idx):
else:
result = []
slices_per_vec = n_slices * shape[3]
for vec_idx in xrange(shape[4]):
for vec_idx in range(shape[4]):
start_idx = (vec_idx * slices_per_vec) + (idx * n_slices)
end_idx = start_idx + n_slices
result.extend(src_dict[key][start_idx:end_idx])
Expand Down Expand Up @@ -1121,7 +1121,7 @@ def _insert_slice(self, key, other):
intlv = []
loc_start = 0
oth_start = 0
for vol_idx in xrange(n_vols):
for vol_idx in range(n_vols):
intlv += local_vals[loc_start:loc_start + n_slices]
intlv += other_vals[oth_start:oth_start + other_n_slices]
loc_start += n_slices
Expand Down Expand Up @@ -1171,7 +1171,7 @@ def _insert_sample(self, key, other, sample_base):
intlv = []
loc_start = 0
oth_start = 0
for vec_idx in xrange(shape[4]):
for vec_idx in range(shape[4]):
intlv += local_vals[loc_start:loc_start+slices_per_vec]
intlv += other_vals[oth_start:oth_start+oth_slc_per_vec]
loc_start += slices_per_vec
Expand Down Expand Up @@ -1447,7 +1447,7 @@ def split(self, dim=None):

split_hdr = header.copy()
slices = [slice(None)] * len(shape)
for idx in xrange(shape[dim]):
for idx in range(shape[dim]):
#Grab the split data, get rid of trailing singular dimensions
if dim >= 3 and dim == len(shape) - 1:
slices[dim] = idx
Expand Down Expand Up @@ -1623,7 +1623,7 @@ def from_sequence(klass, seq, dim=None):

#Pull out the three axes vectors for validation of other input affines
axes = []
for axis_idx in xrange(3):
for axis_idx in range(3):
axis_vec = affine[:3, axis_idx]
if axis_idx == dim:
axis_vec = axis_vec.copy()
Expand Down Expand Up @@ -1731,12 +1731,12 @@ def from_sequence(klass, seq, dim=None):
hdr_info['sform_code'] = None
in_dim_info = list(input_hdr.get_dim_info())
if in_dim_info != hdr_info['dim_info']:
for idx in xrange(3):
for idx in range(3):
if in_dim_info[idx] != hdr_info['dim_info'][idx]:
hdr_info['dim_info'][idx] = None
in_xyzt_units = list(input_hdr.get_xyzt_units())
if in_xyzt_units != hdr_info['xyzt_units']:
for idx in xrange(2):
for idx in range(2):
if in_xyzt_units[idx] != hdr_info['xyzt_units'][idx]:
hdr_info['xyzt_units'][idx] = None

Expand Down
21 changes: 11 additions & 10 deletions src/dcmstack/dcmstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Stack DICOM datasets into volumes. The contents of this module are imported
into the package namespace.
"""
from builtins import range
import warnings, re, dicom
from copy import deepcopy
import nibabel as nb
Expand Down Expand Up @@ -609,11 +610,11 @@ def _chk_order(self, slice_positions, files_per_vol, num_volumes,
key=lambda x: x[1][-1])

#Do a thorough check for correctness
for vec_idx in xrange(num_vec_comps):
for vec_idx in range(num_vec_comps):
file_idx = vec_idx*num_time_points*files_per_vol
curr_vec_val = self._files_info[file_idx][1][0]
for time_idx in xrange(num_time_points):
for slice_idx in xrange(files_per_vol):
for time_idx in range(num_time_points):
for slice_idx in range(files_per_vol):
file_idx = (vec_idx*num_time_points*files_per_vol +
time_idx*files_per_vol + slice_idx)
file_info = self._files_info[file_idx]
Expand Down Expand Up @@ -662,7 +663,7 @@ def get_shape(self):
#If more than one file per volume, check that slice spacing is equal
if files_per_vol > 1:
spacings = []
for idx in xrange(files_per_vol - 1):
for idx in range(files_per_vol - 1):
spacings.append(slice_positions[idx+1] - slice_positions[idx])
spacings = np.array(spacings)
avg_spacing = np.mean(spacings)
Expand Down Expand Up @@ -702,7 +703,7 @@ def get_shape(self):
#Try out each possible sort order
for time_order in possible_orders:
#Update sorting tuples
for idx in xrange(len(self._files_info)):
for idx in range(len(self._files_info)):
nii_wrp, curr_tuple = self._files_info[idx]
self._files_info[idx] = (nii_wrp,
(curr_tuple[0],
Expand Down Expand Up @@ -882,11 +883,11 @@ def to_nifti(self, voxel_order='LAS', embed_meta=False):
#This will keep the slice times and meta data order correct
if files_per_vol > 1 and flips[slice_dim] == -1:
self._shape_dirty = True
for vol_idx in xrange(n_vols):
for vol_idx in range(n_vols):
start = vol_idx * files_per_vol
stop = start + files_per_vol
self._files_info[start:stop] = [self._files_info[idx]
for idx in xrange(stop - 1,
for idx in range(stop - 1,
start - 1,
-1)
]
Expand Down Expand Up @@ -926,7 +927,7 @@ def to_nifti(self, voxel_order='LAS', embed_meta=False):

#If there is more than one volume, check if times are consistent
is_consistent = True
for vol_idx in xrange(1, n_vols):
for vol_idx in range(1, n_vols):
start_slice = vol_idx * n_slices
end_slice = start_slice + n_slices
slices_info = self._files_info[start_slice:end_slice]
Expand All @@ -952,7 +953,7 @@ def to_nifti(self, voxel_order='LAS', embed_meta=False):
#Build meta data for each volume if needed
vol_meta = []
if files_per_vol > 1:
for vol_idx in xrange(n_vols):
for vol_idx in range(n_vols):
start_slice = vol_idx * n_slices
end_slice = start_slice + n_slices
exts = [file_info[0].meta_ext
Expand All @@ -967,7 +968,7 @@ def to_nifti(self, voxel_order='LAS', embed_meta=False):
if len(data.shape) == 5:
if data.shape[3] != 1:
vec_meta = []
for vec_idx in xrange(data.shape[4]):
for vec_idx in range(data.shape[4]):
start_idx = vec_idx * data.shape[3]
end_idx = start_idx + data.shape[3]
meta = DcmMetaExtension.from_sequence(\
Expand Down
1 change: 1 addition & 0 deletions src/dcmstack/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import dicom
from dicom.datadict import keyword_for_tag
from nibabel.nicom import csareader
import sys
from .dcmstack import DicomStack
try:
from collections import OrderedDict
Expand Down
Loading