Skip to content

Commit db8638e

Browse files
committed
DOC: clean up class and some function docstrings
Looking at the built docs pointed out that some classes in particular did not have good first line of docstrings. Go back over docstrings adding first lines to some, minor expansion for others.
1 parent 07ffd2d commit db8638e

File tree

8 files changed

+73
-28
lines changed

8 files changed

+73
-28
lines changed

nibabel/analyze.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,8 @@ def _chk_pixdims(hdr, fix=False):
894894

895895

896896
class AnalyzeImage(SpatialImage):
897+
""" Class for basic Analyze format image
898+
"""
897899
header_class = AnalyzeHeader
898900
files_types = (('image','.img'), ('header','.hdr'))
899901
_compressed_exts = ('.gz', '.bz2')

nibabel/freesurfer/mghformat.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# copyright and license terms.
77
#
88
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
9-
''' Header reading / writing functions for mgh image format
9+
''' Header and image reading / writing functions for MGH image format
1010
1111
Author: Krish Subramaniam
1212
'''
@@ -71,7 +71,8 @@ class MGHError(Exception):
7171

7272

7373
class MGHHeader(object):
74-
'''
74+
''' Class for MGH format header
75+
7576
The header also consists of the footer data which MGH places after the data
7677
chunk.
7778
'''
@@ -454,6 +455,8 @@ def writeftr_to(self, fileobj):
454455

455456

456457
class MGHImage(SpatialImage):
458+
""" Class for MGH format image
459+
"""
457460
header_class = MGHHeader
458461
files_types = (('image', '.mgh'),)
459462
_compressed_exts = (('.gz',))

nibabel/minc1.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@
3737

3838

3939
class MincError(Exception):
40-
pass
40+
""" Error when reading MINC files """
4141

4242

4343
class Minc1File(object):
44-
''' Class to wrap MINC 1 format opened netcdf object
44+
''' Class to wrap MINC1 format opened netcdf object
4545
4646
Although it has some of the same methods as a ``Header``, we use
4747
this only when reading a MINC file, to pull out useful header
@@ -239,7 +239,7 @@ def get_scaled_data(self, sliceobj=()):
239239

240240

241241
class MincImageArrayProxy(object):
242-
''' Minc implementation of array proxy protocol
242+
''' MINC implementation of array proxy protocol
243243
244244
The array proxy allows us to freeze the passed fileobj and
245245
header such that it returns the expected data array.
@@ -266,6 +266,8 @@ def __getitem__(self, sliceobj):
266266

267267

268268
class MincHeader(Header):
269+
""" Class to contain header for MINC formats
270+
"""
269271
# We don't use the data layout - this just in case we do later
270272
data_layout = 'C'
271273

@@ -279,7 +281,7 @@ def data_from_fileobj(self, fileobj):
279281

280282

281283
class Minc1Image(SpatialImage):
282-
''' Class for MINC 1 format images
284+
''' Class for MINC1 format images
283285
284286
The MINC1 image class uses the default header type, rather than a specific
285287
MINC header type - and reads the relevant information from the MINC file on
@@ -310,6 +312,10 @@ def from_file_map(klass, file_map):
310312

311313
# Backwards compatibility
312314
class MincFile(FutureWarningMixin, Minc1File):
315+
""" Deprecated alternative name for Minc1File
316+
"""
313317
warn_message = 'MincFile is deprecated; please use Minc1File instead'
314318
class MincImage(FutureWarningMixin, Minc1Image):
319+
""" Deprecated alternative name for Minc1Image
320+
"""
315321
warn_message = 'MincImage is deprecated; please use Minc1Image instead'

nibabel/nifti1.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#
88
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
99
''' Read / write access to NIfTI1 image format
10+
11+
NIfTI1 format defined at http://nifti.nimh.nih.gov/nifti-1/
1012
'''
1113
from __future__ import division, print_function
1214
import warnings
@@ -518,10 +520,10 @@ def from_fileobj(klass, fileobj, size, byteswap):
518520

519521

520522
class Nifti1Header(SpmAnalyzeHeader):
521-
''' Class for NIFTI1 header
523+
''' Class for NIfTI1 header
522524
523-
The NIFTI1 header has many more coded fields than the simpler Analyze
524-
variants. Nifti1 headers also have extensions.
525+
The NIfTI1 header has many more coded fields than the simpler Analyze
526+
variants. NIfTI1 headers also have extensions.
525527
526528
Nifti allows the header to be a separate file, as part of a nifti image /
527529
header pair, or to precede the data in a single file. The object needs to
@@ -1067,7 +1069,7 @@ def set_slope_inter(self, slope, inter=None):
10671069
self._structarr['scl_inter'] = inter
10681070

10691071
def get_dim_info(self):
1070-
''' Gets nifti MRI slice etc dimension information
1072+
''' Gets NIfTI MRI slice etc dimension information
10711073
10721074
Returns
10731075
-------
@@ -1080,7 +1082,7 @@ def get_dim_info(self):
10801082
10811083
where ``data array`` is the array returned by ``get_data``
10821084
1083-
Because nifti1 files are natively Fortran indexed:
1085+
Because NIfTI1 files are natively Fortran indexed:
10841086
0 is fastest changing in file
10851087
1 is medium changing in file
10861088
2 is slowest changing in file
@@ -1262,7 +1264,7 @@ def get_slice_duration(self):
12621264
12631265
Notes
12641266
-----
1265-
The Nifti1 spec appears to require the slice dimension to be
1267+
The NIfTI1 spec appears to require the slice dimension to be
12661268
defined for slice_duration to have meaning.
12671269
'''
12681270
_, _, slice_dim = self.get_dim_info()
@@ -1572,12 +1574,14 @@ def _chk_xform_code(klass, code_type, hdr, fix):
15721574

15731575

15741576
class Nifti1PairHeader(Nifti1Header):
1575-
''' Class for nifti1 pair header '''
1577+
''' Class for NIfTI1 pair header '''
15761578
# Signal whether this is single (header + data) file
15771579
is_single = False
15781580

15791581

15801582
class Nifti1Pair(analyze.AnalyzeImage):
1583+
""" Class for NIfTI1 format image, header pair
1584+
"""
15811585
header_class = Nifti1PairHeader
15821586

15831587
def __init__(self, dataobj, affine, header=None,
@@ -1795,6 +1799,8 @@ def set_sform(self, affine, code=None, **kwargs):
17951799

17961800

17971801
class Nifti1Image(Nifti1Pair):
1802+
""" Class for single file NIfTI1 format image
1803+
"""
17981804
header_class = Nifti1Header
17991805
files_types = (('image', '.nii'),)
18001806

@@ -1815,7 +1821,7 @@ def update_header(self):
18151821

18161822

18171823
def load(filename):
1818-
""" Load nifti1 single or pair from `filename`
1824+
""" Load NIfTI1 single or pair from `filename`
18191825
18201826
Parameters
18211827
----------
@@ -1825,11 +1831,11 @@ def load(filename):
18251831
Returns
18261832
-------
18271833
img : Nifti1Image or Nifti1Pair
1828-
nifti1 single or pair image instance
1834+
NIfTI1 single or pair image instance
18291835
18301836
Raises
18311837
------
1832-
ImageFileError: if `filename` doesn't look like nifti1
1838+
ImageFileError: if `filename` doesn't look like NIfTI1
18331839
IOError : if `filename` does not exist
18341840
"""
18351841
try:
@@ -1840,7 +1846,7 @@ def load(filename):
18401846

18411847

18421848
def save(img, filename):
1843-
""" Save nifti1 single or pair to `filename`
1849+
""" Save NIfTI1 single or pair to `filename`
18441850
18451851
Parameters
18461852
----------

nibabel/nifti2.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
Stuff about the CIFTI file format here:
1616
1717
http://www.nitrc.org/plugins/mwiki/index.php/cifti:ConnectivityMatrixFileFormats
18-
1918
'''
2019

2120
import numpy as np
@@ -125,7 +124,12 @@
125124

126125

127126
class Nifti2Header(Nifti1Header):
128-
''' Class for Nifti2 single file header '''
127+
""" Class for NIfTI2 header
128+
129+
NIfTI2 is a slightly simplified variant of NIfTI1 which replaces 32-bit
130+
floats with 64-bit floats, and increases some integer widths to 32 or 64
131+
bits.
132+
"""
129133
template_dtype = header_dtype
130134
pair_vox_offset = 0
131135
single_vox_offset = 544
@@ -219,21 +223,25 @@ def _chk_eol_check(hdr, fix=False):
219223

220224

221225
class Nifti2PairHeader(Nifti2Header):
222-
''' Class for nifti2 pair header '''
226+
''' Class for NIfTI2 pair header '''
223227
# Signal whether this is single (header + data) file
224228
is_single = False
225229

226230

227231
class Nifti2Pair(Nifti1Pair):
232+
""" Class for NIfTI2 format image, header pair
233+
"""
228234
header_class = Nifti2PairHeader
229235

230236

231237
class Nifti2Image(Nifti1Image):
238+
""" Class for single file NIfTI2 format image
239+
"""
232240
header_class = Nifti2Header
233241

234242

235243
def load(filename):
236-
""" Load nifti2 single or pair from `filename`
244+
""" Load NIfTI2 single or pair image from `filename`
237245
238246
Parameters
239247
----------
@@ -258,7 +266,7 @@ def load(filename):
258266

259267

260268
def save(img, filename):
261-
""" Save nifti2 single or pair to `filename`
269+
""" Save NIfTI2 single or pair to `filename`
262270
263271
Parameters
264272
----------

nibabel/spm2analyze.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,14 @@
2525

2626

2727
class Spm2AnalyzeHeader(spm99.Spm99AnalyzeHeader):
28-
''' SPM2 header; adds possibility of reading, but not writing DC
29-
offset for data'''
28+
''' Class for SPM2 variant of basic Analyze header
29+
30+
SPM2 variant adds the following to basic Analyze format:
31+
32+
* voxel origin;
33+
* slope scaling of data;
34+
* reading - but not writing - intercept of data.
35+
'''
3036

3137
# Copies of module level definitions
3238
template_dtype = header_dtype
@@ -110,6 +116,8 @@ def get_slope_inter(self):
110116

111117

112118
class Spm2AnalyzeImage(spm99.Spm99AnalyzeImage):
119+
""" Class for SPM2 variant of basic Analyze image
120+
"""
113121
header_class = Spm2AnalyzeHeader
114122

115123

nibabel/spm99analyze.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,14 @@ def set_slope_inter(self, slope, inter=None):
9797

9898

9999
class Spm99AnalyzeHeader(SpmAnalyzeHeader):
100-
''' Adds origin functionality to base SPM header '''
100+
''' Class for SPM99 variant of basic Analyze header
101+
102+
SPM99 variant adds the following to basic Analyze format:
103+
104+
* voxel origin;
105+
* slope scaling of data.
106+
'''
107+
101108
def get_origin_affine(self):
102109
''' Get affine from header, using SPM origin field if sensible
103110
@@ -224,6 +231,8 @@ def _chk_origin(hdr, fix=False):
224231

225232

226233
class Spm99AnalyzeImage(analyze.AnalyzeImage):
234+
""" Class for SPM99 variant of basic Analyze image
235+
"""
227236
header_class = Spm99AnalyzeHeader
228237
files_types = (('image', '.img'),
229238
('header', '.hdr'),

nibabel/trackvis.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,13 @@
8686

8787

8888
class HeaderError(Exception):
89-
pass
89+
""" Error in trackvis header
90+
"""
9091

9192

9293
class DataError(Exception):
93-
pass
94+
""" Error in trackvis data
95+
"""
9496

9597

9698
def read(fileobj, as_generator=False, points_space=None):
@@ -741,7 +743,8 @@ def aff_to_hdr(affine, trk_hdr, pos_vox=None, set_order=None):
741743

742744

743745
class TrackvisFileError(Exception):
744-
pass
746+
""" Error from TrackvisFile class
747+
"""
745748

746749

747750
class TrackvisFile(object):

0 commit comments

Comments
 (0)