Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
33573fc
RF: move to six.py module for py3k compatibility
matthew-brett Jun 14, 2013
3f746d9
RF: update netcdf from scipy
matthew-brett Jun 14, 2013
021c80c
RF: use print_function in obvious cases
matthew-brett Jun 14, 2013
905615f
RF: import configparser safely for Python3
matthew-brett Jun 14, 2013
8558ca7
RF: reorganize gifti imports for Python 3
matthew-brett Jun 14, 2013
a8c925e
RF: update onetime module from dipy
matthew-brett Jun 14, 2013
8c9608b
RF: remove use of xrange
matthew-brett Jun 14, 2013
e55b8ef
RF: remove use of "has_key"
matthew-brett Jun 14, 2013
b685de0
RF: refactor StringIO to BytesIO, StringIO
matthew-brett Jun 14, 2013
58662b2
RF: cleared up old exception syntax for dft
matthew-brett Jun 14, 2013
31d11d8
RF: import reduce for Eulerangles
matthew-brett Jun 14, 2013
8600136
RF: add list() round Python 3 iterators
matthew-brett Jun 14, 2013
ffb51c9
RF: use next function instead of next method
matthew-brett Jun 14, 2013
a536895
RF: remove 23dt doctest markup
matthew-brett Jun 14, 2013
3783674
RF: bytes / str doctests check equality not out string
matthew-brett Jun 14, 2013
8c782f9
RF: get keys into list before dict iteration
matthew-brett Jun 14, 2013
22e2fac
RF+TST: force int_to_float input to Python integer
matthew-brett Jun 15, 2013
02fe6c0
RF: turn off 2to3 conversion during py building
matthew-brett Jun 15, 2013
8848cd3
BF: remove unicode literal for Python 3.2
matthew-brett Jun 15, 2013
0aced13
BF : workaround for broken complex256 on Python 3
matthew-brett Jun 15, 2013
6bf8389
RF: fix dft for Python 3, maybe latest Pydicom
matthew-brett Jun 17, 2013
399de47
RF: update to DICOM canonical names
matthew-brett Jun 17, 2013
b6ea169
RF: replace future imports with Python 3 versions
matthew-brett Jun 17, 2013
8c9c346
NF: routine for private section finding
matthew-brett Jun 17, 2013
79b9686
RF+TST: get_csa_header uses find_private_section
matthew-brett Jun 18, 2013
2ad9355
TST: add wrapper check for slice normal test file
matthew-brett Jun 18, 2013
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
4 changes: 2 additions & 2 deletions nibabel/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,8 @@ def data_to_fileobj(self, data, fileobj):
>>> hdr = AnalyzeHeader()
>>> hdr.set_data_shape((1, 2, 3))
>>> hdr.set_data_dtype(np.float64)
>>> from StringIO import StringIO #23dt : BytesIO
>>> str_io = StringIO() #23dt : BytesIO
>>> from io import BytesIO
>>> str_io = BytesIO()
>>> data = np.arange(6).reshape(1,2,3)
>>> hdr.data_to_fileobj(data, str_io)
>>> data.astype(np.float64).tostring('F') == str_io.getvalue()
Expand Down
18 changes: 10 additions & 8 deletions nibabel/benchmarks/bench_load_save.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
environment variable), and you have a numpy version <= 1.6.1, this will also run
the doctests, let's hope they pass.
"""
from __future__ import division, print_function

import sys

import numpy as np

from ..py3k import BytesIO
from ..externals.six import BytesIO
from .. import Nifti1Image

from numpy.testing import measure
Expand All @@ -28,18 +30,18 @@ def bench_load_save():
img.file_map['image'].fileobj = sio
hdr = img.get_header()
sys.stdout.flush()
print "\nImage load save"
print "----------------"
print("\nImage load save")
print("----------------")
hdr.set_data_dtype(np.float32)
mtime = measure('img.to_file_map()', repeat)
print '%30s %6.2f' % ('Save float64 to float32', mtime)
print('%30s %6.2f' % ('Save float64 to float32', mtime))
mtime = measure('img.from_file_map(img.file_map)', repeat)
print '%30s %6.2f' % ('Load from float32', mtime)
print('%30s %6.2f' % ('Load from float32', mtime))
hdr.set_data_dtype(np.int16)
mtime = measure('img.to_file_map()', repeat)
print '%30s %6.2f' % ('Save float64 to int16', mtime)
print('%30s %6.2f' % ('Save float64 to int16', mtime))
mtime = measure('img.from_file_map(img.file_map)', repeat)
print '%30s %6.2f' % ('Load from int16', mtime)
print('%30s %6.2f' % ('Load from int16', mtime))
arr = np.random.random_integers(low=-1000,high=-1000, size=img_shape)
arr = arr.astype(np.int16)
img = Nifti1Image(arr, np.eye(4))
Expand All @@ -48,5 +50,5 @@ def bench_load_save():
hdr = img.get_header()
hdr.set_data_dtype(np.float32)
mtime = measure('img.to_file_map()', repeat)
print '%30s %6.2f' % ('Save Int16 to float32', mtime)
print('%30s %6.2f' % ('Save Int16 to float32', mtime))
sys.stdout.flush()
1 change: 1 addition & 0 deletions nibabel/casting.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ def int_to_float(val, flt_type):
"""
if not flt_type is np.longdouble:
return flt_type(val)
val = int(val)
faval = np.longdouble(0)
while val != 0:
f64 = np.float64(val)
Expand Down
4 changes: 3 additions & 1 deletion nibabel/checkwarns.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
''' Contexts for *with* statement allowing checks for warnings
'''
from __future__ import division, print_function

import warnings


Expand All @@ -21,7 +23,7 @@ class ErrorWarnings(warnings.catch_warnings):
... try:
... warnings.warn('Message', UserWarning)
... except UserWarning:
... print 'I consider myself warned'
... print('I consider myself warned')
I consider myself warned
"""
filter = 'error'
Expand Down
10 changes: 5 additions & 5 deletions nibabel/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from os.path import join as pjoin
import glob
import sys
import ConfigParser
from .externals.six.moves import configparser
from distutils.version import LooseVersion

from .environment import get_nipy_user_dir, get_nipy_system_dir
Expand Down Expand Up @@ -122,14 +122,14 @@ def __init__(self, base_path, config_filename=None):
Datasource.__init__(self, base_path)
if config_filename is None:
config_filename = 'config.ini'
self.config = ConfigParser.SafeConfigParser()
self.config = configparser.SafeConfigParser()
cfg_file = self.get_filename(config_filename)
readfiles = self.config.read(cfg_file)
if not readfiles:
raise DataError('Could not read config file %s' % cfg_file)
try:
self.version = self.config.get('DEFAULT', 'version')
except ConfigParser.Error:
except configparser.Error:
raise DataError('Could not get version from %s' % cfg_file)
version_parts = self.version.split('.')
self.major_version = int(version_parts[0])
Expand All @@ -140,13 +140,13 @@ def __init__(self, base_path, config_filename=None):

def _cfg_value(fname, section='DATA', value='path'):
""" Utility function to fetch value from config file """
configp = ConfigParser.ConfigParser()
configp = configparser.ConfigParser()
readfiles = configp.read(fname)
if not readfiles:
return ''
try:
return configp.get(section, value)
except ConfigParser.Error:
except configparser.Error:
return ''


Expand Down
26 changes: 13 additions & 13 deletions nibabel/dft.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
# Copyright (C) 2011 Christian Haselgrove

from __future__ import with_statement
from __future__ import division, print_function, absolute_import

import os
from os.path import join as pjoin
Expand All @@ -20,7 +20,7 @@

import numpy

from .py3k import BytesIO
from .externals.six import BytesIO

from .nifti1 import Nifti1Header

Expand Down Expand Up @@ -119,13 +119,13 @@ def __getattribute__(self, name):
def as_png(self, index=None, scale_to_slice=True):
import PIL.Image
if index is None:
index = len(self.storage_instances) / 2
index = len(self.storage_instances) // 2
d = self.storage_instances[index].dicom()
data = d.pixel_array.copy()
if self.bits_allocated != 16:
raise VolumeError, 'unsupported bits allocated'
raise VolumeError('unsupported bits allocated')
if self.bits_stored != 12:
raise VolumeError, 'unsupported bits stored'
raise VolumeError('unsupported bits stored')
data = data / 16
if scale_to_slice:
min = data.min()
Expand All @@ -142,12 +142,12 @@ def png_size(self, index=None, scale_to_slice=True):

def as_nifti(self):
if len(self.storage_instances) < 2:
raise VolumeError, 'too few slices'
raise VolumeError('too few slices')
d = self.storage_instances[0].dicom()
if self.bits_allocated != 16:
raise VolumeError, 'unsupported bits allocated'
raise VolumeError('unsupported bits allocated')
if self.bits_stored != 12:
raise VolumeError, 'unsupported bits stored'
raise VolumeError('unsupported bits stored')
data = numpy.ndarray((len(self.storage_instances),
self.rows,
self.columns),
Expand Down Expand Up @@ -266,7 +266,7 @@ def _get_subdirs(base_dir, files_dict=None, followlinks=False):
for (dirpath, dirnames, filenames) in os.walk(base_dir, **kwargs):
abs_dir = os.path.realpath(dirpath)
if abs_dir in dirs:
raise CachingError, 'link cycle detected under %s' % base_dir
raise CachingError('link cycle detected under %s' % base_dir)
dirs.append(abs_dir)
if files_dict is not None:
files_dict[abs_dir] = filenames
Expand Down Expand Up @@ -391,10 +391,10 @@ def _update_file(c, path, fname, studies, series, storage_instances):
do.StudyDate,
do.StudyTime,
study_comments,
do.PatientsName,
str(do.PatientName),
do.PatientID,
do.PatientsBirthDate,
do.PatientsSex)
do.PatientBirthDate,
do.PatientSex)
c.execute(query, params)
studies.append(str(do.StudyInstanceUID))
if str(do.SeriesInstanceUID) not in series:
Expand Down Expand Up @@ -423,7 +423,7 @@ def _update_file(c, path, fname, studies, series, storage_instances):
params = (str(do.SOPInstanceUID), do.InstanceNumber, str(do.SeriesInstanceUID))
c.execute(query, params)
storage_instances.append(str(do.SOPInstanceUID))
except AttributeError, data:
except AttributeError as data:
logger.debug(' %s' % str(data))
return None
return str(do.SOPInstanceUID)
Expand Down
10 changes: 5 additions & 5 deletions nibabel/ecat.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,8 @@ def __getitem__(self, item):
Examples
--------
>>> hdr = EcatHeader()
>>> hdr['magic_number'] #23dt next : bytes
'MATRIX72'
>>> hdr['magic_number'] == b'MATRIX72'
True
'''
return self._header_data[item].item()

Expand All @@ -365,7 +365,7 @@ def get_patient_orient(self):
in header, not always reliable"""
orient_code = dict(self._patient_orient_defs)
code = self._header_data['patient_orientation'].item()
if not orient_code.has_key(code):
if not code in orient_code:
raise KeyError('Ecat Orientation CODE %d not recognized'%code)
return orient_code[code]

Expand All @@ -374,7 +374,7 @@ def get_filetype(self):
code stored in header"""
ft_codes = dict(self._ft_defs)
code = self._header_data['file_type'].item()
if not ft_codes.has_key(code):
if not code in ft_codes:
raise KeyError('Ecat Filetype CODE %d not recognized'%code)
return ft_codes[code]

Expand Down Expand Up @@ -972,7 +972,7 @@ def to_file_map(self, file_map=None):
hdr.write_to(hdrf)

#Write every frames
for index in xrange(0, self.get_header()['num_frames']):
for index in range(0, self.get_header()['num_frames']):
#Move to subheader offset
frame_offset = subheaders._get_frame_offset(index) - 512
imgf.seek(frame_offset)
Expand Down
2 changes: 2 additions & 0 deletions nibabel/eulerangles.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@

import math

from .externals.six.moves import reduce

import numpy as np


Expand Down
Loading