Commit da05fb34 authored by Javier Quinteros's avatar Javier Quinteros

Improve logging output

parent ffb87982
...@@ -51,38 +51,38 @@ def printmetadata(data): ...@@ -51,38 +51,38 @@ def printmetadata(data):
print(data) print(data)
def str2date(dStr): def str2date(dstr):
"""Transform a string to a datetime. """Transform a string to a datetime.
:param dStr: A datetime in ISO format. :param dstr: A datetime in ISO format.
:type dStr: string :type dstr: string
:return: A datetime represented the converted input. :return: A datetime represented the converted input.
:rtype: datetime :rtype: datetime.datetime
""" """
# In case of empty string # In case of empty string
if (dStr is None) or (not len(dStr)): if (dstr is None) or (not len(dstr)):
return None return None
dateParts = dStr.replace('-', ' ').replace('T', ' ') dateparts = dstr.replace('-', ' ').replace('T', ' ')
dateParts = dateParts.replace(':', ' ').replace('.', ' ') dateparts = dateparts.replace(':', ' ').replace('.', ' ')
dateParts = dateParts.replace('Z', '').split() dateparts = dateparts.replace('Z', '').split()
# Consider the case in which just the first digits of microseconds # Consider the case in which just the first digits of microseconds
# are given and complete with 0's to have 6 digits # are given and complete with 0's to have 6 digits
if len(dateParts) == 7: if len(dateparts) == 7:
dateParts[6] = dateParts[6] + '0' * (6 - len(dateParts[6])) dateparts[6] = dateparts[6] + '0' * (6 - len(dateparts[6]))
return datetime.datetime(*map(int, dateParts)) return datetime.datetime(*map(int, dateparts))
def main(): def main():
# Inspect the archive.py module to list the Classes based on Archive # Inspect the archive.py module to list the Classes based on Archive
dictArchive = dict() dictarchive = dict()
for name, obj in inspect.getmembers(da): for name, obj in inspect.getmembers(da):
if inspect.isclass(obj): if inspect.isclass(obj):
if issubclass(obj, da.Archive) and name != 'Archive': if issubclass(obj, da.Archive) and name != 'Archive':
dictArchive[name] = obj dictarchive[name] = obj
helparchive = 'Available options are [%s]' % ', '.join(dictArchive.keys()) helparchive = 'Available options are [%s]' % ', '.join(dictarchive.keys())
# Check verbosity in the output # Check verbosity in the output
msg = 'Read, manipulate and convert seismic waveforms generated by a DAS system.' msg = 'Read, manipulate and convert seismic waveforms generated by a DAS system.'
...@@ -113,7 +113,7 @@ def main(): ...@@ -113,7 +113,7 @@ def main():
parser.add_argument('--decimate', type=int, choices=[1, 5], parser.add_argument('--decimate', type=int, choices=[1, 5],
help='Factor by which the sampling rate is lowered by decimation.', help='Factor by which the sampling rate is lowered by decimation.',
default=1) default=1)
parser.add_argument('-o', '--outstruct', type=str, choices=dictArchive.keys(), parser.add_argument('-o', '--outstruct', type=str, choices=dictarchive.keys(),
help=helparchive, default='StreamBased') help=helparchive, default='StreamBased')
parser.add_argument('--metadata', action='store_true', default=False, parser.add_argument('--metadata', action='store_true', default=False,
help='Read and display the metadata from the TDMS files') help='Read and display the metadata from the TDMS files')
...@@ -143,7 +143,7 @@ def main(): ...@@ -143,7 +143,7 @@ def main():
# Selected archive structure # Selected archive structure
# Archive files in current directory # Archive files in current directory
klass = dictArchive[args.outstruct] klass = dictarchive[args.outstruct]
archive = klass(root='.', experiment=args.filename, strictcheck=False) archive = klass(root='.', experiment=args.filename, strictcheck=False)
expectedtimes = dict() expectedtimes = dict()
...@@ -161,7 +161,7 @@ def main(): ...@@ -161,7 +161,7 @@ def main():
# Save the previous Stream completely # Save the previous Stream completely
if curstream is not None: if curstream is not None:
archive.archive(tr0) archive.archive(tr0)
logs.info('Storing channel %s' % curstream) logs.info('Storing channel %s. Starttime: %s' % (curstream, data[1].get('starttime', None)))
# Update which stream is being processed # Update which stream is being processed
curstream = nslc(data[1]) curstream = nslc(data[1])
...@@ -174,7 +174,6 @@ def main(): ...@@ -174,7 +174,6 @@ def main():
tr0 = Trace(data=data[0], header=data[1]) tr0 = Trace(data=data[0], header=data[1])
else: else:
tr0 += Trace(data=data[0], header=data[1]) tr0 += Trace(data=data[0], header=data[1])
# print(data[1], data[0])
# Update the datetime of the expected sample # Update the datetime of the expected sample
expectedtimes[curstream] = data[1]['starttime'] + data[1]['npts']/data[1]['sampling_rate'] expectedtimes[curstream] = data[1]['starttime'] + data[1]['npts']/data[1]['sampling_rate']
......
...@@ -44,7 +44,7 @@ class TDMS(object): ...@@ -44,7 +44,7 @@ class TDMS(object):
# convoluted during the decimation # convoluted during the decimation
# for channel in range(self.__chstart, self.__chstop + 1, self.__chstep): # for channel in range(self.__chstart, self.__chstop + 1, self.__chstep):
for channel in self.__channels: for channel in self.__channels:
logging.debug('Create empty buffers') logging.debug('Create empty buffer for channel %s' % channel)
self.__buffer[channel] = None self.__buffer[channel] = None
return self return self
...@@ -67,9 +67,9 @@ class TDMS(object): ...@@ -67,9 +67,9 @@ class TDMS(object):
:param channels: Selection of channels to work with (list of integers) :param channels: Selection of channels to work with (list of integers)
:type channels: list :type channels: list
:param starttime: Start of the selected time window :param starttime: Start of the selected time window
:type starttime: datetime.datetime :type starttime: datetime.datetime or NoneType
:param endtime: End of the selected time window :param endtime: End of the selected time window
:type endtime: datetime.datetime :type endtime: datetime.datetime or NoneType
:param iterate: Select either Data (D) or Metadata (M) :param iterate: Select either Data (D) or Metadata (M)
:type iterate: str :type iterate: str
:param decimate: Factor by which the sampling rate is lowered by decimation :param decimate: Factor by which the sampling rate is lowered by decimation
...@@ -339,8 +339,6 @@ class TDMS(object): ...@@ -339,8 +339,6 @@ class TDMS(object):
self.__currentfile = None self.__currentfile = None
self.__search_data() self.__search_data()
# print('reset', self.__twstart, self.starttime)
def __readmetadata(self): def __readmetadata(self):
# Metadata # Metadata
logs = logging.getLogger('Read Metadata') logs = logging.getLogger('Read Metadata')
......
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