From 480432df509ce6ece28c220c08162b22d0d198f5 Mon Sep 17 00:00:00 2001 From: Ruben Verweij Date: Tue, 14 Mar 2017 14:23:22 +0100 Subject: [PATCH] Improve documentation --- nd2reader/common.py | 93 ++++++++++++++++++++++++++++++++------- nd2reader/label_map.py | 2 +- nd2reader/parser.py | 25 ++++++----- nd2reader/raw_metadata.py | 28 +++++++----- nd2reader/reader.py | 3 +- 5 files changed, 113 insertions(+), 38 deletions(-) diff --git a/nd2reader/common.py b/nd2reader/common.py index b7dc8be..ec3c574 100644 --- a/nd2reader/common.py +++ b/nd2reader/common.py @@ -72,11 +72,12 @@ def read_array(fh, kind, chunk_location): """ Args: - fh: - kind: - chunk_location: + fh: File handle of the nd2 file + kind: data type, can be one of 'double', 'int' or 'float' + chunk_location: the location of the array chunk in the binary nd2 file Returns: + array.array: an array of the data """ kinds = {'double': 'd', @@ -91,22 +92,67 @@ def read_array(fh, kind, chunk_location): def _parse_unsigned_char(data): + """ + + Args: + data: binary data + + Returns: + char: the data converted to unsigned char + + """ return struct.unpack("B", data.read(1))[0] def _parse_unsigned_int(data): + """ + + Args: + data: binary data + + Returns: + int: the data converted to unsigned int + + """ return struct.unpack("I", data.read(4))[0] def _parse_unsigned_long(data): + """ + + Args: + data: binary data + + Returns: + long: the data converted to unsigned long + + """ return struct.unpack("Q", data.read(8))[0] def _parse_double(data): + """ + + Args: + data: binary data + + Returns: + double: the data converted to double + + """ return struct.unpack("d", data.read(8))[0] def _parse_string(data): + """ + + Args: + data: binary data + + Returns: + string: the data converted to string + + """ value = data.read(2) while not value.endswith(six.b("\x00\x00")): # the string ends at the first instance of \x00\x00 @@ -115,6 +161,15 @@ def _parse_string(data): def _parse_char_array(data): + """ + + Args: + data: binary data + + Returns: + array.array: the data converted to an array + + """ array_length = struct.unpack("Q", data.read(8))[0] return array.array("B", data.read(array_length)) @@ -124,9 +179,10 @@ def parse_date(text_info): The date and time when acquisition began. Args: - text_info: + text_info: the text that contains the date and time information Returns: + datetime: the date and time of the acquisition """ for line in text_info.values(): @@ -147,18 +203,21 @@ def _parse_metadata_item(data, cursor_position): """Reads hierarchical data, analogous to a Python dict. Args: - data: - cursor_position: + data: the binary data that needs to be parsed + cursor_position: the position in the binary nd2 file Returns: + dict: a dictionary containing the metadata item """ new_count, length = struct.unpack("