From 60378ad06f9ae13bcb7c47153ae1a2f80f46a5a1 Mon Sep 17 00:00:00 2001 From: Ruben Verweij Date: Wed, 8 Mar 2017 10:28:30 +0100 Subject: [PATCH] Cleanup docstrings to use google python docs --- docs | 2 +- nd2reader/common.py | 57 ++++++++++++------------ nd2reader/exceptions.py | 6 ++- nd2reader/label_map.py | 3 +- nd2reader/parser.py | 94 +++++++++------------------------------ nd2reader/raw_metadata.py | 68 +++++++++------------------- nd2reader/reader.py | 48 ++++++++------------ sphinx/conf.py | 25 +---------- 8 files changed, 95 insertions(+), 208 deletions(-) diff --git a/docs b/docs index db1df91..3db501b 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit db1df91ec6d52b25ac2a2368fdef6b18277e8961 +Subproject commit 3db501b0c85343425c6e8269dcfce5b0ca28c845 diff --git a/nd2reader/common.py b/nd2reader/common.py index bd4cfdc..d350d34 100644 --- a/nd2reader/common.py +++ b/nd2reader/common.py @@ -7,11 +7,13 @@ from nd2reader.exceptions import InvalidVersionError def get_version(fh): - """ - Determines what version the ND2 is. + """Determines what version the ND2 is. + + Args: + fh: File handle of the .nd2 file - :param fh: an open file handle to the ND2 - :type fh: file + Returns: + tuple: Major and minor version """ # the first 16 bytes seem to have no meaning, so we skip them @@ -23,11 +25,13 @@ def get_version(fh): def parse_version(data): - """ - Parses a string with the version data in it. + """Parses a string with the version data in it. - :param data: the 19th through 54th byte of the ND2, representing the version - :type data: unicode + Args: + data (unicode): the 19th through 54th byte of the ND2, representing the version + + Returns: + tuple: Major and minor version """ match = re.search(r"""^ND2 FILE SIGNATURE CHUNK NAME01!Ver(?P\d)\.(?P\d)$""", data) @@ -40,14 +44,14 @@ def parse_version(data): def read_chunk(fh, chunk_location): - """ - Reads a piece of data given the location of its pointer. + """Reads a piece of data given the location of its pointer. - :param fh: an open file handle to the ND2 - :param chunk_location: a pointer - :type chunk_location: int + Args: + fh: an open file handle to the ND2 + chunk_location (int): location to read - :rtype: bytes + Returns: + bytes: the data at the chunk location """ if chunk_location is None: @@ -106,10 +110,10 @@ def _parse_char_array(data): def parse_date(text_info): - """ - The date and time when acquisition began. + """The date and time when acquisition began. - :rtype: datetime.datetime() or None + Returns: + datetime: The date and time when acquisition began. """ for line in text_info.values(): @@ -127,8 +131,10 @@ def parse_date(text_info): def _parse_metadata_item(data, cursor_position): - """ - Reads hierarchical data, analogous to a Python dict. + """Reads hierarchical data, analogous to a Python dict. + + Returns: + dict: the metadata item """ new_count, length = struct.unpack(" 0: diff --git a/nd2reader/reader.py b/nd2reader/reader.py index 0952054..943fb3b 100644 --- a/nd2reader/reader.py +++ b/nd2reader/reader.py @@ -4,8 +4,8 @@ import numpy as np class ND2Reader(FramesSequenceND): - """ - PIMS wrapper for the ND2 parser + """PIMS wrapper for the ND2 parser + """ def __init__(self, filename): @@ -26,25 +26,21 @@ class ND2Reader(FramesSequenceND): @classmethod def class_exts(cls): - """ - So PIMS open function can use this reader for opening .nd2 files - :return: + """Let PIMS open function use this reader for opening .nd2 files + """ return {'nd2'} | super(ND2Reader, cls).class_exts() def close(self): - """ - Correctly close the file handle - :return: + """Correctly close the file handle + """ if self._fh is not None: self._fh.close() def get_frame(self, i): - """ - Return one frame - :param i: - :return: + """Return one frame + """ fetch_all_channels = 'c' in self.bundle_axes @@ -54,9 +50,8 @@ class ND2Reader(FramesSequenceND): return self.get_frame_2D(self.default_coords['c'], i, self.default_coords['z']) def _get_frame_all_channels(self, i): - """ - Get all color channels for this frame - :return: + """Get all color channels for this frame + """ frames = None for c in range(len(self.metadata["channels"])): @@ -68,28 +63,22 @@ class ND2Reader(FramesSequenceND): return frames def get_frame_2D(self, c, t, z): - """ - Gets a given frame using the parser - :param c: - :param t: - :param z: - :return: + """Gets a given frame using the parser + """ c_name = self.metadata["channels"][c] return self._parser.get_image_by_attributes(t, 0, c_name, z, self.metadata["height"], self.metadata["width"]) @property def pixel_type(self): - """ - Return the pixel data type - :return: + """Return the pixel data type + """ return self._dtype def _setup_axes(self): - """ - Setup the xyctz axes, iterate over t axis by default - :return: + """Setup the xyctz axes, iterate over t axis by default + """ self._init_axis('x', self.metadata["width"]) self._init_axis('y', self.metadata["height"]) @@ -101,9 +90,8 @@ class ND2Reader(FramesSequenceND): self.iter_axes = 't' def get_timesteps(self): - """ - Get the timesteps of the experiment - :return: + """Get the timesteps of the experiment + """ timesteps = np.array([]) current_time = 0.0 diff --git a/sphinx/conf.py b/sphinx/conf.py index 87896ff..94c5592 100644 --- a/sphinx/conf.py +++ b/sphinx/conf.py @@ -3,28 +3,6 @@ from recommonmark.parser import CommonMarkParser -# -# nd2reader documentation build configuration file, created by -# sphinx-quickstart on Mon Mar 6 21:17:58 2017. -# -# This file is execfile()d with the current directory set to its -# containing dir. -# -# Note that not all possible configuration values are present in this -# autogenerated file. -# -# All configuration values have a default; values that are commented out -# serve to show the default. - -# If extensions (or modules to document with autodoc) are in another directory, -# add these directories to sys.path here. If the directory is relative to the -# documentation root, use os.path.abspath to make it absolute, like shown here. -# -# import os -# import sys -# sys.path.insert(0, '/home/ruben/PycharmProjects/nd2reader/nd2reader') - - # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. @@ -36,7 +14,8 @@ from recommonmark.parser import CommonMarkParser # ones. extensions = ['sphinx.ext.autodoc', 'sphinx.ext.todo', - 'sphinx.ext.viewcode'] + 'sphinx.ext.viewcode', + 'sphinx.ext.napoleon'] # Add any paths that contain templates here, relative to this directory. templates_path = []