Commit 521a22a4 authored by Javier Quinteros's avatar Javier Quinteros

Minor refactor and addition of docstrings

parent 24d4b582
......@@ -93,7 +93,7 @@ def main():
'DEBUG'],
default='WARNING')
parser.add_argument('-d', '--directory',
help='Directory where files are located.',
help='Directory where files are located (default: ".")',
default='.')
parser.add_argument('--start', '--starttime',
help='Start of the selected time window.\nFormat: 2019-02-01T00:01:02.123456Z',
......
......@@ -8,6 +8,18 @@ from math import floor
from math import ceil
def tup2time(fraction, seconds):
# logs = logging.getLogger('tup2time')
# logs.debug('seconds: %s' % seconds)
# logs.debug('fraction: %s' % fraction)
dt1904 = datetime.datetime(1904, 1, 1)
delta = seconds + fraction * 2**(-64)
result = dt1904 + datetime.timedelta(seconds=delta)
# logs.debug('Date-time %s' % result)
return result
class TDMS(object):
"""Class to read and export seismic waveforms in TDMS format"""
......@@ -579,13 +591,19 @@ class TDMS(object):
break
def __readstring(self):
"""All strings in TDMS files, such as object paths, property names, property values, and raw data values,
are encoded in UTF-8 Unicode. All of them, except for raw data values, are preceded by a 32-bit unsigned
integer that contains the length of the string in bytes, not including the length value itself. Strings in
TDMS files can be null-terminated, but since the length information is stored, the null terminator will be
ignored when you read from the file.
"""
# logs = logging.getLogger('readstring')
strlen = struct.unpack('%cI' % self.__endian, self.__fi.read(4))
# logs.debug('String of length %s' % strlen)
return self.__fi.read(strlen[0]).decode()
def __readvalue(self):
logs = logging.getLogger('readvalue')
# logs = logging.getLogger('readvalue')
datatype = self.__readdatatype()
# logs.debug('datatype: 0x%x' % datatype)
......@@ -602,7 +620,7 @@ class TDMS(object):
# 0x44 is a timestamp. Read again!
if datatype == 0x44:
result = self.__tup2time(*result)
result = tup2time(*result)
else:
# Disassemble the tuple if not a timestamp
result = result[0]
......@@ -611,6 +629,11 @@ class TDMS(object):
return result
def __readproperties(self, result=dict()):
"""For each property, the following information is stored:
Name (string)
Data type (tdsDataType)
Value (numerics stored binary, strings stored as explained above).
"""
logs = logging.getLogger('readproperties')
numprops = struct.unpack('%cI' % self.__endian, self.__fi.read(4))[0]
......@@ -629,17 +652,6 @@ class TDMS(object):
def __readdatatype(self):
return struct.unpack('%cI' % self.__endian, self.__fi.read(4))[0]
def __tup2time(self, fraction, seconds):
# logs = logging.getLogger('tup2time')
# logs.debug('seconds: %s' % seconds)
# logs.debug('fraction: %s' % fraction)
dt1904 = datetime.datetime(1904, 1, 1)
delta = seconds + fraction * 2**(-64)
result = dt1904 + datetime.timedelta(seconds=delta)
# logs.debug('Date-time %s' % result)
return result
def __readdata(self, channels=[0]):
"""Read a chunk of data from the specified channels
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment