SeiscompDataStructure objects contain all relevant information to expand a desired data path (including unix shell wildcards) [not tested for Windows yet]
This commit is contained in:
parent
e38b917623
commit
c0f7060368
@ -20,9 +20,19 @@ class GenericDataBase(object):
|
|||||||
self.dataBaseDict = kwargs
|
self.dataBaseDict = kwargs
|
||||||
|
|
||||||
|
|
||||||
class SeiscompDataStructure(GenericDataBase):
|
class SeiscompDataStructure(object):
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, dataType='waveform', **kwargs):
|
||||||
|
'''
|
||||||
|
Object initialization method:
|
||||||
|
|
||||||
|
:type dataType: str
|
||||||
|
:param dataType: Desired data type. Default: ``'waveform'``
|
||||||
|
'''
|
||||||
|
# imports
|
||||||
|
from obspy.core import UTCDateTime
|
||||||
|
|
||||||
|
now = 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
|
||||||
@ -32,19 +42,51 @@ class SeiscompDataStructure(GenericDataBase):
|
|||||||
'resp': 'R', # Response data
|
'resp': 'R', # Response data
|
||||||
'opaque': 'O' # Opaque data
|
'opaque': 'O' # Opaque data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if dataType in self.__typeOptions.keys():
|
||||||
|
self.dataType = dataType
|
||||||
|
else:
|
||||||
|
self.dataType = 'waveform' # default value for 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 list
|
self.__sdsFields = {'SDSdir': '/data/SDS', # base directory
|
||||||
'YEAR': '1970', # 4 digits
|
'YEAR': '{0:04d}'.format(now.year), # 4 digits
|
||||||
'NET': 'XX', # up to 8 characters
|
'NET': '??', # up to 8 characters
|
||||||
'STA': 'XXXX', # up to 8 characters
|
'STA': '????', # up to 8 characters
|
||||||
'CHAN': 'HHZ', # up to 8 characters
|
'CHAN': 'HH?', # up to 8 characters
|
||||||
'TYPE': self.getType('waveform'), # 1 character
|
'TYPE': self._getType(), # 1 character
|
||||||
'LOC': '', # up to 8 characters
|
'LOC': '', # up to 8 characters
|
||||||
'DAY': '001' # 3 digit day of year
|
'DAY': '{0:03d}'.format(now.julday) # 3 digit doy
|
||||||
}
|
}
|
||||||
pass
|
self.modifiyFields(**kwargs)
|
||||||
|
|
||||||
def getType(self, typeName=None):
|
def modifiyFields(self, **kwargs):
|
||||||
pass
|
if kwargs and isinstance(kwargs, dict):
|
||||||
|
for key, value in kwargs.iteritems():
|
||||||
|
try:
|
||||||
|
if key in self.__sdsFields.keys():
|
||||||
|
self.__sdsFields[key] = str(value)
|
||||||
|
else:
|
||||||
|
raise KeyError('unknown SDS wildcard: %s.' % key)
|
||||||
|
except KeyError, e:
|
||||||
|
errmsg = ''
|
||||||
|
errmsg += 'WARNING:\n'
|
||||||
|
errmsg += 'unable to set values for SDS fields\n'
|
||||||
|
errmsg += '%s; desired value was: %s\n' % (e, value)
|
||||||
|
print errmsg
|
||||||
|
|
||||||
|
def _getType(self):
|
||||||
|
return self.__typeOptions[self.dataType]
|
||||||
|
|
||||||
|
def expandDataPath(self):
|
||||||
|
fullChan = '{0}.{1}'.format(self.__sdsFields['CHAN'], self._getType())
|
||||||
|
dataPath = os.path.join(self.__sdsFields['SDSdir'],
|
||||||
|
self.__sdsFields['YEAR'],
|
||||||
|
self.__sdsFields['NET'],
|
||||||
|
self.__sdsFields['STA'],
|
||||||
|
fullChan,
|
||||||
|
'*{0}'.format(self.__sdsFields['DAY'])
|
||||||
|
)
|
||||||
|
return dataPath
|
||||||
|
Loading…
Reference in New Issue
Block a user