Commit 70055a5f authored by Javier Quinteros's avatar Javier Quinteros
Browse files

Skip files with wrong formatting in the name

Improve TDMS class:
raise Exception in case of no data while being created.
Pass missing parameter for setting the log level.
parent ebcdedc4
__version__ = '0.6b1'
__version__ = '0.7a1'
......@@ -33,6 +33,7 @@ import pprint
import datetime
from obspy import Trace
from .tdms import TDMS
from .tdms import NoData
from dastools import __version__
import dastools.archive as da
import inspect
......@@ -163,9 +164,13 @@ def main():
logs.error('Channel code must be three alphanumeric characters')
return
td = TDMS(args.filename, directory=args.directory, iterate='M' if args.metadata else 'D',
chstart=args.chstart, chstop=args.chstop, chstep=args.chstep,
starttime=dtstart, endtime=dtend, decimate=args.decimate)
try:
td = TDMS(args.filename, directory=args.directory, iterate='M' if args.metadata else 'D',
chstart=args.chstart, chstop=args.chstop, chstep=args.chstep,
starttime=dtstart, endtime=dtend, decimate=args.decimate, loglevel=args.loglevel)
except NoData:
logs.error('There seems to be no data under the experiment name provided')
sys.exit(-1)
# Selected archive structure
# Archive files in current directory
......
......@@ -214,11 +214,20 @@ class TDMS(object):
if not file.startswith(filename):
continue
dt = datetime.datetime.strptime(file[len(filename):-len('.tdms')], '_%Z_%Y%m%d_%H%M%S.%f')
# Check that the format of the filename is exactly as expected. Otherwise, send a warning
try:
dt = datetime.datetime.strptime(file[len(filename):-len('.tdms')], '_%Z_%Y%m%d_%H%M%S.%f')
except ValueError:
logs.warning('Unexpected format after experiment name! Skipping... (%s)' % file[len(filename):])
continue
self.__available.append({'dt': dt, 'name': file, 'samples': None})
if self.__twstart is None:
self.__twstart = dt
if not len(self.__available):
logs.warning('No files found with proper filename.')
raise NoData()
# Set the time window selection to the minimum datetime found
if self.__twstart < self.__available[0]['dt']:
self.__twstart = self.__available[0]['dt']
......
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