started to write initialization method for the GenericDataBase class in order to read data from an arbitrary data folder structure

This commit is contained in:
Sebastian Wehling-Benatelli 2014-03-28 05:30:55 +01:00
parent 0af8ab2b08
commit d58b671d36

View File

@ -13,26 +13,43 @@ class GenericDataBase(object):
GenericDataBase type holds all information about the current data- GenericDataBase type holds all information about the current data-
base working on. base working on.
''' '''
def __init__(self, stexp=None, **kwargs): def __init__(self, stexp=None, folderdepth=4, **kwargs):
dbRegExp = {} dbRegExp = {}
structExpression = []
structExpression = os.path.split(stexp) depth = 0
while stexp is not os.path.sep:
[stexp, tlexp] = os.path.split(stexp)
structExpression.append(tlexp)
depth += 1
if depth is folderdepth:
rootExpression = stexp
break
structExpression.reverse()
self.folderDepth = folderdepth
self.dataBaseDict = kwargs self.dataBaseDict = kwargs
class SeiscompDataStructure(object): class SeiscompDataStructure(object):
def __init__(self, dataType='waveform', **kwargs): def __init__(self, dataType='waveform', date=None, **kwargs):
''' '''
Object initialization method: Object initialization method:
:type dataType: str :param str dataType: Desired data type. Default: ``'waveform'``
:param dataType: Desired data type. Default: ``'waveform'`` :param date: Either date string or an instance of
obspy.core.utcdatetime.UTCDateTime. Default: ``None``
:type date: str or UTCDateTime or None
''' '''
# imports # imports
from obspy.core import UTCDateTime from obspy.core import UTCDateTime
now = UTCDateTime() if date is not None and not isinstance(date, UTCDateTime):
try:
dod = UTCDateTime(date)
except:
dod = UTCDateTime()
# Data type options # Data type options
self.__typeOptions = {'waveform': 'D', # Waveform data self.__typeOptions = {'waveform': 'D', # Waveform data
'detect': 'E', # Detection data 'detect': 'E', # Detection data
@ -47,10 +64,13 @@ class SeiscompDataStructure(object):
self.dataType = dataType self.dataType = dataType
else: else:
self.dataType = 'waveform' # default value for dataType self.dataType = 'waveform' # default value for dataType
print '''Warning: Selected datatype ('%s') not available.\n
Using 'waveform' instead!'''.format(dataType)
# SDS fields' default values # SDS fields' default values
# definitions from # definitions from
# http://www.seiscomp3.org/wiki/doc/applications/slarchive/SDS # http://www.seiscomp3.org/wiki/doc/applications/slarchive/SDS
self.__sdsFields = {'SDSdir': '/data/SDS', # base directory self.__sdsFields = {'SDSdir': '/data/SDS', # base directory
'YEAR': '{0:04d}'.format(now.year), # 4 digits 'YEAR': '{0:04d}'.format(now.year), # 4 digits
'NET': '??', # up to 8 characters 'NET': '??', # up to 8 characters