Commit da05fb34 authored by Javier Quinteros's avatar Javier Quinteros

Improve logging output

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