From 0c2dffdbf3e51db105e9a94401963a4ce76b0fb7 Mon Sep 17 00:00:00 2001 From: Zvi Baratz Date: Sat, 18 Feb 2023 10:54:27 +0200 Subject: [PATCH 1/3] DOC: Homogenized module-level docstring formatting --- nibabel/affines.py | 5 ++--- nibabel/brikhead.py | 3 +-- nibabel/data.py | 4 +--- nibabel/deprecated.py | 3 +-- nibabel/deprecator.py | 3 +-- nibabel/dft.py | 3 +-- nibabel/environment.py | 4 +--- nibabel/filebasedimages.py | 2 +- nibabel/fileslice.py | 3 +-- nibabel/fileutils.py | 3 +-- nibabel/imagestats.py | 4 +--- nibabel/mriutils.py | 4 +--- nibabel/onetime.py | 3 +-- nibabel/openers.py | 3 +-- nibabel/parrec.py | 2 +- nibabel/processing.py | 12 +++++++----- nibabel/quaternions.py | 2 +- nibabel/tmpdirs.py | 3 +-- nibabel/tripwire.py | 3 +-- nibabel/viewers.py | 2 +- nibabel/xmlutils.py | 4 +--- 21 files changed, 28 insertions(+), 47 deletions(-) diff --git a/nibabel/affines.py b/nibabel/affines.py index 59b52e768e..d6c101ddd5 100644 --- a/nibabel/affines.py +++ b/nibabel/affines.py @@ -1,7 +1,6 @@ # emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- # vi: set ft=python sts=4 ts=4 sw=4 et: -"""Utility routines for working with points and affine transforms -""" +"""Utility routines for working with points and affine transforms""" from functools import reduce import numpy as np @@ -313,7 +312,7 @@ def voxel_sizes(affine): def obliquity(affine): r""" - Estimate the *obliquity* an affine's axes represent. + Estimate the *obliquity* an affine's axes represent The term *obliquity* is defined here as the rotation of those axes with respect to the cardinal axes. diff --git a/nibabel/brikhead.py b/nibabel/brikhead.py index f375b541dc..ee5f766722 100644 --- a/nibabel/brikhead.py +++ b/nibabel/brikhead.py @@ -6,8 +6,7 @@ # copyright and license terms. # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## -""" -Class for reading AFNI BRIK/HEAD datasets +"""Class for reading AFNI BRIK/HEAD datasets See https://afni.nimh.nih.gov/pub/dist/doc/program_help/README.attributes.html for information on what is required to have a valid BRIK/HEAD dataset. diff --git a/nibabel/data.py b/nibabel/data.py index 42826d2f67..7e2fe2af70 100644 --- a/nibabel/data.py +++ b/nibabel/data.py @@ -1,8 +1,6 @@ # emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- # vi: set ft=python sts=4 ts=4 sw=4 et: -""" -Utilities to find files from NIPY data packages -""" +"""Utilities to find files from NIPY data packages""" import configparser import glob import os diff --git a/nibabel/deprecated.py b/nibabel/deprecated.py index c353071954..092370106e 100644 --- a/nibabel/deprecated.py +++ b/nibabel/deprecated.py @@ -1,5 +1,4 @@ -"""Module to help with deprecating objects and classes -""" +"""Module to help with deprecating objects and classes""" from __future__ import annotations import typing as ty diff --git a/nibabel/deprecator.py b/nibabel/deprecator.py index 3ef6b45066..779fdb462d 100644 --- a/nibabel/deprecator.py +++ b/nibabel/deprecator.py @@ -1,5 +1,4 @@ -"""Class for recording and reporting deprecations -""" +"""Class for recording and reporting deprecations""" from __future__ import annotations import functools diff --git a/nibabel/dft.py b/nibabel/dft.py index c805128951..7a49d49f52 100644 --- a/nibabel/dft.py +++ b/nibabel/dft.py @@ -7,8 +7,7 @@ # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## # Copyright (C) 2011 Christian Haselgrove -"""DICOM filesystem tools -""" +"""DICOM filesystem tools""" import contextlib diff --git a/nibabel/environment.py b/nibabel/environment.py index 6f331eed5a..a828ccb865 100644 --- a/nibabel/environment.py +++ b/nibabel/environment.py @@ -1,8 +1,6 @@ # emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- # vi: set ft=python sts=4 ts=4 sw=4 et: -""" -Settings from the system environment relevant to NIPY -""" +"""Settings from the system environment relevant to NIPY""" import os from os.path import join as pjoin diff --git a/nibabel/filebasedimages.py b/nibabel/filebasedimages.py index 556d8b75e5..6e4ea86135 100644 --- a/nibabel/filebasedimages.py +++ b/nibabel/filebasedimages.py @@ -6,7 +6,7 @@ # copyright and license terms. # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## -"""Common interface for any image format--volume or surface, binary or xml.""" +"""Common interface for any image format--volume or surface, binary or xml""" from __future__ import annotations import io diff --git a/nibabel/fileslice.py b/nibabel/fileslice.py index 87cac05a4a..816f1cdaf6 100644 --- a/nibabel/fileslice.py +++ b/nibabel/fileslice.py @@ -1,5 +1,4 @@ -"""Utilities for getting array slices out of file-like objects -""" +"""Utilities for getting array slices out of file-like objects""" import operator from functools import reduce diff --git a/nibabel/fileutils.py b/nibabel/fileutils.py index da44fe51a9..1defbc62f7 100644 --- a/nibabel/fileutils.py +++ b/nibabel/fileutils.py @@ -6,8 +6,7 @@ # copyright and license terms. # # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## -"""Utilities for reading and writing to binary file formats -""" +"""Utilities for reading and writing to binary file formats""" def read_zt_byte_strings(fobj, n_strings=1, bufsize=1024): diff --git a/nibabel/imagestats.py b/nibabel/imagestats.py index 6f1b68178b..36fbddee0e 100644 --- a/nibabel/imagestats.py +++ b/nibabel/imagestats.py @@ -6,9 +6,7 @@ # copyright and license terms. # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## -""" -Functions for computing image statistics -""" +"""Functions for computing image statistics""" import numpy as np diff --git a/nibabel/mriutils.py b/nibabel/mriutils.py index d993d26a21..09067cc1e9 100644 --- a/nibabel/mriutils.py +++ b/nibabel/mriutils.py @@ -6,9 +6,7 @@ # copyright and license terms. # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## -""" -Utilities for calculations related to MRI -""" +"""Utilities for calculations related to MRI""" __all__ = ['calculate_dwell_time'] diff --git a/nibabel/onetime.py b/nibabel/onetime.py index 7c723d4c83..e365e81f74 100644 --- a/nibabel/onetime.py +++ b/nibabel/onetime.py @@ -1,5 +1,4 @@ -""" -Descriptor support for NIPY. +"""Descriptor support for NIPY Utilities to support special Python descriptors [1,2], in particular the use of a useful pattern for properties we call 'one time properties'. These are diff --git a/nibabel/openers.py b/nibabel/openers.py index d75839fe1a..d11c8834a4 100644 --- a/nibabel/openers.py +++ b/nibabel/openers.py @@ -6,8 +6,7 @@ # copyright and license terms. # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## -"""Context manager openers for various fileobject types -""" +"""Context manager openers for various fileobject types""" import gzip import warnings diff --git a/nibabel/parrec.py b/nibabel/parrec.py index 7c594dcb45..086f2a79d2 100644 --- a/nibabel/parrec.py +++ b/nibabel/parrec.py @@ -8,7 +8,7 @@ ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## # Disable line length checking for PAR fragments in module docstring # flake8: noqa E501 -"""Read images in PAR/REC format. +"""Read images in PAR/REC format This is yet another MRI image format generated by Philips scanners. It is an ASCII header (PAR) plus a binary blob (REC). diff --git a/nibabel/processing.py b/nibabel/processing.py index c7bd3888de..6027575d47 100644 --- a/nibabel/processing.py +++ b/nibabel/processing.py @@ -6,13 +6,15 @@ # copyright and license terms. # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## -"""Image processing functions for: +"""Image processing functions -* smoothing -* resampling -* converting sd to and from FWHM +Image processing functions for: -Smoothing and resampling routines need scipy + * smoothing + * resampling + * converting SD to and from FWHM + +Smoothing and resampling routines need scipy. """ import numpy as np diff --git a/nibabel/quaternions.py b/nibabel/quaternions.py index 04c570c84b..9732bc5c63 100644 --- a/nibabel/quaternions.py +++ b/nibabel/quaternions.py @@ -7,7 +7,7 @@ # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## """ -Functions to operate on, or return, quaternions. +Functions to operate on, or return, quaternions The module also includes functions for the closely related angle, axis pair as a specification for rotation. diff --git a/nibabel/tmpdirs.py b/nibabel/tmpdirs.py index 3074fca6f2..7fe47e6510 100644 --- a/nibabel/tmpdirs.py +++ b/nibabel/tmpdirs.py @@ -6,8 +6,7 @@ # copyright and license terms. # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## -"""Contexts for *with* statement providing temporary directories -""" +"""Contexts for *with* statement providing temporary directories""" import os import tempfile from contextlib import contextmanager diff --git a/nibabel/tripwire.py b/nibabel/tripwire.py index d0c3d4c50c..fa45e73382 100644 --- a/nibabel/tripwire.py +++ b/nibabel/tripwire.py @@ -1,5 +1,4 @@ -"""Class to raise error for missing modules or other misfortunes -""" +"""Class to raise error for missing modules or other misfortunes""" from typing import Any diff --git a/nibabel/viewers.py b/nibabel/viewers.py index 9dad3dd17f..5138610fe4 100644 --- a/nibabel/viewers.py +++ b/nibabel/viewers.py @@ -14,7 +14,7 @@ class OrthoSlicer3D: - """Orthogonal-plane slice viewer. + """Orthogonal-plane slice viewer OrthoSlicer3d expects 3- or 4-dimensional array data. It treats 4D data as a sequence of 3D spatial volumes, where a slice over the final diff --git a/nibabel/xmlutils.py b/nibabel/xmlutils.py index 8e0b18fb6e..9b47d81381 100644 --- a/nibabel/xmlutils.py +++ b/nibabel/xmlutils.py @@ -6,9 +6,7 @@ # copyright and license terms. # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## -""" -Thin layer around xml.etree.ElementTree, to abstract nibabel xml support. -""" +"""Thin layer around xml.etree.ElementTree, to abstract nibabel xml support""" from io import BytesIO from xml.etree.ElementTree import Element, SubElement, tostring # noqa From e7dc5fee1d847504c6c764b1030cc91af9953f48 Mon Sep 17 00:00:00 2001 From: Zvi Baratz Date: Sat, 18 Feb 2023 11:04:58 +0200 Subject: [PATCH 2/3] DOC: Removed spacing between module docstrings and imports --- nibabel/arraywriters.py | 1 - nibabel/ecat.py | 1 - nibabel/environment.py | 1 - nibabel/eulerangles.py | 1 - nibabel/fileholders.py | 1 - nibabel/filename_parser.py | 1 - nibabel/fileslice.py | 1 - nibabel/imageclasses.py | 1 - nibabel/imageglobals.py | 1 - nibabel/imagestats.py | 1 - nibabel/loadsave.py | 1 - nibabel/nifti2.py | 1 - nibabel/openers.py | 1 - nibabel/orientations.py | 2 -- nibabel/parrec.py | 1 - nibabel/processing.py | 1 - nibabel/quaternions.py | 1 - nibabel/rstutils.py | 1 - nibabel/spaces.py | 1 - nibabel/viewers.py | 1 - nibabel/xmlutils.py | 1 - 21 files changed, 22 deletions(-) diff --git a/nibabel/arraywriters.py b/nibabel/arraywriters.py index 5a0b04925e..bdd2d548f8 100644 --- a/nibabel/arraywriters.py +++ b/nibabel/arraywriters.py @@ -28,7 +28,6 @@ def __init__(self, array, out_dtype=None) something else to make sense of conversions between float and int, or between larger ints and smaller. """ - import numpy as np from .casting import ( diff --git a/nibabel/ecat.py b/nibabel/ecat.py index f1a40dd27c..23a58f752e 100644 --- a/nibabel/ecat.py +++ b/nibabel/ecat.py @@ -42,7 +42,6 @@ GPL and some of the header files are adapted from CTI files (called CTI code below). It's not clear what the licenses are for these files. """ - import warnings from numbers import Integral diff --git a/nibabel/environment.py b/nibabel/environment.py index a828ccb865..09aaa6320f 100644 --- a/nibabel/environment.py +++ b/nibabel/environment.py @@ -1,7 +1,6 @@ # emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- # vi: set ft=python sts=4 ts=4 sw=4 et: """Settings from the system environment relevant to NIPY""" - import os from os.path import join as pjoin diff --git a/nibabel/eulerangles.py b/nibabel/eulerangles.py index b1d187e8c1..13dc059644 100644 --- a/nibabel/eulerangles.py +++ b/nibabel/eulerangles.py @@ -82,7 +82,6 @@ ``y``, followed by rotation around ``x``, is known (confusingly) as "xyz", pitch-roll-yaw, Cardan angles, or Tait-Bryan angles. """ - import math from functools import reduce diff --git a/nibabel/fileholders.py b/nibabel/fileholders.py index f2ec992da5..691d31ecff 100644 --- a/nibabel/fileholders.py +++ b/nibabel/fileholders.py @@ -7,7 +7,6 @@ # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## """Fileholder class""" - from copy import copy from .openers import ImageOpener diff --git a/nibabel/filename_parser.py b/nibabel/filename_parser.py index 77949a6791..c4e47ee72c 100644 --- a/nibabel/filename_parser.py +++ b/nibabel/filename_parser.py @@ -7,7 +7,6 @@ # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## """Create filename pairs, triplets etc, with expected extensions""" - import os import pathlib diff --git a/nibabel/fileslice.py b/nibabel/fileslice.py index 816f1cdaf6..fe7d6bba54 100644 --- a/nibabel/fileslice.py +++ b/nibabel/fileslice.py @@ -1,5 +1,4 @@ """Utilities for getting array slices out of file-like objects""" - import operator from functools import reduce from mmap import mmap diff --git a/nibabel/imageclasses.py b/nibabel/imageclasses.py index ac27a6ecac..e2dbed129d 100644 --- a/nibabel/imageclasses.py +++ b/nibabel/imageclasses.py @@ -7,7 +7,6 @@ # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## """Define supported image classes and names""" - from .analyze import AnalyzeImage from .brikhead import AFNIImage from .cifti2 import Cifti2Image diff --git a/nibabel/imageglobals.py b/nibabel/imageglobals.py index 81a1742809..551719a7ee 100644 --- a/nibabel/imageglobals.py +++ b/nibabel/imageglobals.py @@ -23,7 +23,6 @@ Use ``logger.level = 1`` to see all messages. """ - import logging error_level = 40 diff --git a/nibabel/imagestats.py b/nibabel/imagestats.py index 36fbddee0e..38dc9d3f16 100644 --- a/nibabel/imagestats.py +++ b/nibabel/imagestats.py @@ -7,7 +7,6 @@ # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## """Functions for computing image statistics""" - import numpy as np from nibabel.imageclasses import spatial_axes_first diff --git a/nibabel/loadsave.py b/nibabel/loadsave.py index 6c1981ca77..f12b81b30b 100644 --- a/nibabel/loadsave.py +++ b/nibabel/loadsave.py @@ -8,7 +8,6 @@ ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## # module imports """Utilities to load and save image objects""" - import os import numpy as np diff --git a/nibabel/nifti2.py b/nibabel/nifti2.py index 9c898b47ba..8d9b81e1f9 100644 --- a/nibabel/nifti2.py +++ b/nibabel/nifti2.py @@ -12,7 +12,6 @@ https://www.nitrc.org/forum/message.php?msg_id=3738 """ - import numpy as np from .analyze import AnalyzeHeader diff --git a/nibabel/openers.py b/nibabel/openers.py index d11c8834a4..5f2bb0cde7 100644 --- a/nibabel/openers.py +++ b/nibabel/openers.py @@ -7,7 +7,6 @@ # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## """Context manager openers for various fileobject types""" - import gzip import warnings from bz2 import BZ2File diff --git a/nibabel/orientations.py b/nibabel/orientations.py index f9e1ea028c..075cbd4ffd 100644 --- a/nibabel/orientations.py +++ b/nibabel/orientations.py @@ -7,8 +7,6 @@ # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## """Utilities for calculating and applying affine orientations""" - - import numpy as np import numpy.linalg as npl diff --git a/nibabel/parrec.py b/nibabel/parrec.py index 086f2a79d2..22219382c8 100644 --- a/nibabel/parrec.py +++ b/nibabel/parrec.py @@ -121,7 +121,6 @@ utility via the option "--strict-sort". The dimension info can be exported to a CSV file by adding the option "--volume-info". """ - import re import warnings from collections import OrderedDict diff --git a/nibabel/processing.py b/nibabel/processing.py index 6027575d47..d634ce7086 100644 --- a/nibabel/processing.py +++ b/nibabel/processing.py @@ -16,7 +16,6 @@ Smoothing and resampling routines need scipy. """ - import numpy as np import numpy.linalg as npl diff --git a/nibabel/quaternions.py b/nibabel/quaternions.py index 9732bc5c63..ec40660607 100644 --- a/nibabel/quaternions.py +++ b/nibabel/quaternions.py @@ -25,7 +25,6 @@ >>> vec = np.array([1, 2, 3]).reshape((3,1)) # column vector >>> tvec = np.dot(M, vec) """ - import math import numpy as np diff --git a/nibabel/rstutils.py b/nibabel/rstutils.py index cb40633e54..625a2af477 100644 --- a/nibabel/rstutils.py +++ b/nibabel/rstutils.py @@ -2,7 +2,6 @@ * Make ReST table given array of values """ - import numpy as np diff --git a/nibabel/spaces.py b/nibabel/spaces.py index d06a39b0ed..e5b87171df 100644 --- a/nibabel/spaces.py +++ b/nibabel/spaces.py @@ -19,7 +19,6 @@ mapping), or * a length 2 sequence with the same information (shape, affine). """ - from itertools import product import numpy as np diff --git a/nibabel/viewers.py b/nibabel/viewers.py index 5138610fe4..f2b32a1fd9 100644 --- a/nibabel/viewers.py +++ b/nibabel/viewers.py @@ -3,7 +3,6 @@ Includes version of OrthoSlicer3D code originally written by our own Paul Ivanov. """ - import weakref import numpy as np diff --git a/nibabel/xmlutils.py b/nibabel/xmlutils.py index 9b47d81381..31637b5e0c 100644 --- a/nibabel/xmlutils.py +++ b/nibabel/xmlutils.py @@ -7,7 +7,6 @@ # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## """Thin layer around xml.etree.ElementTree, to abstract nibabel xml support""" - from io import BytesIO from xml.etree.ElementTree import Element, SubElement, tostring # noqa from xml.parsers.expat import ParserCreate From 7903364b86bb4d592e60895f36f2a085379f58b6 Mon Sep 17 00:00:00 2001 From: Zvi Baratz Date: Sat, 18 Feb 2023 11:14:36 +0200 Subject: [PATCH 3/3] DOC: Minor docstring formatting fixes to functions --- nibabel/affines.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/nibabel/affines.py b/nibabel/affines.py index d6c101ddd5..05fdd7bb58 100644 --- a/nibabel/affines.py +++ b/nibabel/affines.py @@ -99,7 +99,7 @@ def apply_affine(aff, pts, inplace=False): def to_matvec(transform): - """Split a transform into its matrix and vector components. + """Split a transform into its matrix and vector components The transformation must be represented in homogeneous coordinates and is split into its rotation matrix and translation vector components. @@ -311,8 +311,7 @@ def voxel_sizes(affine): def obliquity(affine): - r""" - Estimate the *obliquity* an affine's axes represent + r"""Estimate the *obliquity* an affine's axes represent The term *obliquity* is defined here as the rotation of those axes with respect to the cardinal axes.