Skip to content

Commit

Permalink
STY: Manual, blue-compatible touchups
Browse files Browse the repository at this point in the history
[git-blame-ignore-rev]
  • Loading branch information
effigies committed Jul 27, 2022
1 parent 8acd559 commit 60e4af9
Show file tree
Hide file tree
Showing 40 changed files with 113 additions and 118 deletions.
2 changes: 1 addition & 1 deletion nibabel/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ def set_slope_inter(self, slope, inter=None):
"""
if (slope in (None, 1) or np.isnan(slope)) and (inter in (None, 0) or np.isnan(inter)):
return
raise HeaderTypeError('Cannot set slope != 1 or intercept != 0 ' 'for Analyze headers')
raise HeaderTypeError('Cannot set slope != 1 or intercept != 0 for Analyze headers')

@classmethod
def _get_checks(klass):
Expand Down
2 changes: 1 addition & 1 deletion nibabel/arraywriters.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ def _range_scale(self, in_min, in_max):
if self._out_dtype.kind == 'u':
if in_min < 0 and in_max > 0:
raise WriterError(
'Cannot scale negative and positive ' 'numbers to uint without intercept'
'Cannot scale negative and positive numbers to uint without intercept'
)
if in_max <= 0: # All input numbers <= 0
self.slope = in_min / out_max
Expand Down
12 changes: 2 additions & 10 deletions nibabel/brikhead.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ def _unpack_var(var):
TEMPLATE_SPACE ORIG
"""

err_msg = (
'Please check HEAD file to ensure it is AFNI compliant. ' f'Offending attribute:\n{var}'
)
err_msg = f'Please check HEAD file to ensure it is AFNI compliant. Offending attribute:\n{var}'
atype, aname = TYPE_RE.findall(var), NAME_RE.findall(var)
if len(atype) != 1:
raise AFNIHeaderError(f'Invalid attribute type entry in HEAD file. {err_msg}')
Expand Down Expand Up @@ -354,13 +352,7 @@ def _calc_zooms(self):
origin", and second giving "Time step (TR)".
"""
xyz_step = tuple(np.abs(self.info['DELTA']))
t_step = self.info.get(
'TAXIS_FLOATS',
(
0,
0,
),
)
t_step = self.info.get('TAXIS_FLOATS', (0, 0))
if len(t_step) > 0:
t_step = (t_step[1],)
return xyz_step + t_step
Expand Down
16 changes: 11 additions & 5 deletions nibabel/casting.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,15 @@ def type_info(np_type):
if vals in (
(112, 15, 16), # binary128
(info_64.nmant, info_64.nexp, 8), # float64
(63, 15, 12),
(63, 15, 16),
): # Intel extended 80
(63, 15, 12), # Intel extended 80
(63, 15, 16), # Intel extended 80
):
return ret # these are OK without modification
# The remaining types are longdoubles with bad finfo values. Some we
# correct, others we wait to hear of errors.
# We start with float64 as basis
ret = type_info(np.float64)
if vals in ((52, 15, 12), (52, 15, 16)): # windows float96 # windows float128?
if vals in ((52, 15, 12), (52, 15, 16)): # windows float96 / windows float128?
# On windows 32 bit at least, float96 is Intel 80 storage but operating
# at float64 precision. The finfo values give nexp == 15 (as for intel
# 80) but in calculations nexp in fact appears to be 11 as for float64
Expand Down Expand Up @@ -298,7 +298,13 @@ def type_info(np_type):
if np_type is np.longcomplex:
max_val += 0j
ret = dict(
min=-max_val, max=max_val, nmant=112, nexp=15, minexp=-16382, maxexp=16384, width=width
min=-max_val,
max=max_val,
nmant=112,
nexp=15,
minexp=-16382,
maxexp=16384,
width=width,
)
else: # don't recognize the type
raise FloatingError(f'We had not expected long double type {np_type} with info {info}')
Expand Down
16 changes: 11 additions & 5 deletions nibabel/cifti2/cifti2.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Cifti2HeaderError(Exception):

CIFTI_MODEL_TYPES = (
'CIFTI_MODEL_TYPE_SURFACE', # Modeled using surface vertices
'CIFTI_MODEL_TYPE_VOXELS', # Modeled using voxels.
'CIFTI_MODEL_TYPE_VOXELS', # Modeled using voxels
)

CIFTI_SERIESUNIT_TYPES = ('SECOND', 'HERTZ', 'METER', 'RADIAN')
Expand Down Expand Up @@ -662,7 +662,7 @@ def __init__(self, name=None, voxel_indices_ijk=None, vertices=None):
self.vertices = vertices if vertices is not None else []
for val in self.vertices:
if not isinstance(val, Cifti2Vertices):
raise ValueError(('Cifti2Parcel vertices must be instances of ' 'Cifti2Vertices'))
raise ValueError(('Cifti2Parcel vertices must be instances of Cifti2Vertices'))

@property
def voxel_indices_ijk(self):
Expand Down Expand Up @@ -1237,7 +1237,7 @@ def _validate_new_mim(self, value):
a2md = self._get_indices_from_mim(value)
if not set(self.mapped_indices).isdisjoint(a2md):
raise Cifti2HeaderError(
'Indices in this Cifti2MatrixIndicesMap ' 'already mapped in this matrix'
'Indices in this Cifti2MatrixIndicesMap already mapped in this matrix'
)

def __setitem__(self, key, value):
Expand Down Expand Up @@ -1412,7 +1412,13 @@ class Cifti2Image(DataobjImage, SerializableImage):
rw = True

def __init__(
self, dataobj=None, header=None, nifti_header=None, extra=None, file_map=None, dtype=None
self,
dataobj=None,
header=None,
nifti_header=None,
extra=None,
file_map=None,
dtype=None,
):
"""Initialize image
Expand Down Expand Up @@ -1485,7 +1491,7 @@ def from_file_map(klass, file_map, *, mmap=True, keep_file_open=None):
cifti_header = item.get_content()
break
else:
raise ValueError('NIfTI2 header does not contain a CIFTI-2 ' 'extension')
raise ValueError('NIfTI2 header does not contain a CIFTI-2 extension')

# Construct cifti image.
# Use array proxy object where possible
Expand Down
4 changes: 2 additions & 2 deletions nibabel/cifti2/cifti2_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ def __add__(self, other):
not np.allclose(other.affine, affine) or other.volume_shape != shape
):
raise ValueError(
'Trying to concatenate two BrainModels defined ' 'in a different brain volume'
'Trying to concatenate two BrainModels defined in a different brain volume'
)

nvertices = dict(self.nvertices)
Expand Down Expand Up @@ -1008,7 +1008,7 @@ def __add__(self, other):
not np.allclose(other.affine, affine) or other.volume_shape != shape
):
raise ValueError(
'Trying to concatenate two ParcelsAxis defined ' 'in a different brain volume'
'Trying to concatenate two ParcelsAxis defined in a different brain volume'
)
nvertices = dict(self.nvertices)
for name, value in other.nvertices.items():
Expand Down
4 changes: 2 additions & 2 deletions nibabel/cifti2/tests/test_new_cifti2.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ def test_pconnseries():
hdr = ci.Cifti2Header(matrix)
data = np.random.randn(4, 4, 13)
img = ci.Cifti2Image(data, hdr)
img.nifti_header.set_intent('NIFTI_INTENT_CONNECTIVITY_PARCELLATED_' 'PARCELLATED_SERIES')
img.nifti_header.set_intent('NIFTI_INTENT_CONNECTIVITY_PARCELLATED_PARCELLATED_SERIES')

with InTemporaryDirectory():
ci.save(img, 'test.pconnseries.nii')
Expand All @@ -496,7 +496,7 @@ def test_pconnscalar():
hdr = ci.Cifti2Header(matrix)
data = np.random.randn(4, 4, 2)
img = ci.Cifti2Image(data, hdr)
img.nifti_header.set_intent('NIFTI_INTENT_CONNECTIVITY_PARCELLATED_' 'PARCELLATED_SCALAR')
img.nifti_header.set_intent('NIFTI_INTENT_CONNECTIVITY_PARCELLATED_PARCELLATED_SCALAR')

with InTemporaryDirectory():
ci.save(img, 'test.pconnscalar.nii')
Expand Down
4 changes: 2 additions & 2 deletions nibabel/cmdline/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ def get_opt_parser():
'--header-fields',
dest='header_fields',
default='all',
help='Header fields (comma separated) to be printed as well' ' (if present)',
help='Header fields (comma separated) to be printed as well (if present)',
),
Option(
'--ma',
'--data-max-abs-diff',
dest='data_max_abs_diff',
type=float,
default=0.0,
help='Maximal absolute difference in data between files' ' to tolerate.',
help='Maximal absolute difference in data between files to tolerate.',
),
Option(
'--mr',
Expand Down
2 changes: 1 addition & 1 deletion nibabel/cmdline/ls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import nibabel.cmdline.utils
from nibabel.cmdline.utils import _err, ap, safe_get, table2string, verbose

__copyright__ = 'Copyright (c) 2011-18 Yaroslav Halchenko ' 'and NiBabel contributors'
__copyright__ = 'Copyright (c) 2011-18 Yaroslav Halchenko and NiBabel contributors'
__license__ = 'MIT'


Expand Down
2 changes: 1 addition & 1 deletion nibabel/cmdline/nifti_dx.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import nibabel as nib

__author__ = 'Matthew Brett'
__copyright__ = 'Copyright (c) 2011-18 Matthew Brett ' 'and NiBabel contributors'
__copyright__ = 'Copyright (c) 2011-18 Matthew Brett and NiBabel contributors'
__license__ = 'MIT'


Expand Down
4 changes: 1 addition & 3 deletions nibabel/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@

from .environment import get_nipy_system_dir, get_nipy_user_dir

DEFAULT_INSTALL_HINT = (
'If you have the package, have you set the ' 'path to the package correctly?'
)
DEFAULT_INSTALL_HINT = 'If you have the package, have you set the path to the package correctly?'


class DataError(Exception):
Expand Down
2 changes: 1 addition & 1 deletion nibabel/dataobj_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def dataobj(self):

@property
@deprecate_with_version(
'_data attribute not part of public API. ' 'please use "dataobj" property instead.',
'_data attribute not part of public API. Please use "dataobj" property instead.',
'2.0',
'4.0',
)
Expand Down
6 changes: 3 additions & 3 deletions nibabel/ecat.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ def __init__(self, dataobj, affine, header, subheader, mlist, extra=None, file_m
def affine(self):
if not self._subheader._check_affines():
warnings.warn(
'Affines different across frames, loading affine ' 'from FIRST frame', UserWarning
'Affines different across frames, loading affine from FIRST frame', UserWarning
)
return self._affine

Expand Down Expand Up @@ -908,7 +908,7 @@ def from_file_map(klass, file_map, *, mmap=True, keep_file_open=None):
# Get affine
if not subheaders._check_affines():
warnings.warn(
'Affines different across frames, loading affine ' 'from FIRST frame', UserWarning
'Affines different across frames, loading affine from FIRST frame', UserWarning
)
aff = subheaders.get_frame_affine()
img = klass(data, aff, header, subheaders, mlist, extra=None, file_map=file_map)
Expand Down Expand Up @@ -1025,7 +1025,7 @@ def to_file_map(self, file_map=None):

@classmethod
def from_image(klass, img):
raise NotImplementedError('Ecat images can only be generated ' 'from file objects')
raise NotImplementedError('Ecat images can only be generated from file objects')

@classmethod
def load(klass, filespec):
Expand Down
4 changes: 2 additions & 2 deletions nibabel/filebasedimages.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def from_header(klass, header=None):
if type(header) == klass:
return header.copy()
raise NotImplementedError(
'Header class requires a conversion ' f'from {klass} to {type(header)}'
f'Header class requires a conversion from {klass} to {type(header)}'
)

@classmethod
Expand Down Expand Up @@ -209,7 +209,7 @@ def __getitem__(self, key):
raise TypeError('Cannot slice image objects.')

@deprecate_with_version(
'get_header method is deprecated.\n' 'Please use the ``img.header`` property ' 'instead.',
'get_header method is deprecated.\nPlease use the ``img.header`` property instead.',
'2.1',
'4.0',
)
Expand Down
2 changes: 1 addition & 1 deletion nibabel/filename_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def types_filenames(
"""
template_fname = _stringify_path(template_fname)
if not isinstance(template_fname, str):
raise TypesFilenamesError('Need file name as input ' 'to set_filenames')
raise TypesFilenamesError('Need file name as input to set_filenames')
if template_fname.endswith('.'):
template_fname = template_fname[:-1]
filename, found_ext, ignored, guessed_name = parse_filename(
Expand Down
2 changes: 1 addition & 1 deletion nibabel/fileslice.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def canonical_slicers(sliceobj, shape, check_inds=True):
if slicer == Ellipsis:
remaining = sliceobj[i + 1 :]
if Ellipsis in remaining:
raise ValueError('More than one Ellipsis in slicing ' 'expression')
raise ValueError('More than one Ellipsis in slicing expression')
real_remaining = [r for r in remaining if r is not None]
n_ellided = n_dim - n_real - len(real_remaining)
can_slicers.extend((slice(None),) * n_ellided)
Expand Down
4 changes: 2 additions & 2 deletions nibabel/freesurfer/mghformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def set_zooms(self, zooms):
raise HeaderDataError('Expecting %d zoom values' % ndims)
if np.any(zooms[:3] <= 0):
raise HeaderDataError(
'Spatial (first three) zooms must be positive; got ' f'{tuple(zooms[:3])}'
f'Spatial (first three) zooms must be positive; got {tuple(zooms[:3])}'
)
hdr['delta'] = zooms[:3]
if len(zooms) == 4:
Expand Down Expand Up @@ -475,7 +475,7 @@ def as_byteswapped(self, endianness=None):
"""
if endianness is None or endian_codes[endianness] != '>':
raise ValueError('Cannot byteswap MGHHeader - ' 'must always be big endian')
raise ValueError('Cannot byteswap MGHHeader - must always be big endian')
return self.copy()

@classmethod
Expand Down
Loading

0 comments on commit 60e4af9

Please sign in to comment.