Merge branch 'develop' into feature/metadata_class
This commit is contained in:
commit
afade77922
17 files changed
+164
-22
No files matched your search
@@ -2,3 +2,4 @@
|
|||||||
*~
|
*~
|
||||||
pylot/RELEASE-VERSION
|
pylot/RELEASE-VERSION
|
||||||
*.idea
|
*.idea
|
||||||
|
autopylot.sh*
|
||||||
@@ -110,21 +110,8 @@ class MainWindow(QMainWindow):
|
|||||||
def __init__(self, parent=None, infile=None):
|
def __init__(self, parent=None, infile=None):
|
||||||
super(MainWindow, self).__init__(parent)
|
super(MainWindow, self).__init__(parent)
|
||||||
|
|
||||||
# check for default pylot.in-file
|
self.init_config_files(infile)
|
||||||
if not infile:
|
|
||||||
infile = os.path.join(os.path.expanduser('~'), '.pylot', 'pylot.in')
|
|
||||||
print('Using default input file {}'.format(infile))
|
|
||||||
if os.path.isfile(infile) == False:
|
|
||||||
infile = QFileDialog().getOpenFileName(caption='Choose PyLoT-input file')
|
|
||||||
|
|
||||||
if not os.path.exists(infile[0]):
|
|
||||||
QMessageBox.warning(self, "PyLoT Warning",
|
|
||||||
"No PyLoT-input file declared!")
|
|
||||||
sys.exit(0)
|
|
||||||
self.infile = infile[0]
|
|
||||||
else:
|
|
||||||
self.infile = infile
|
|
||||||
self._inputs = PylotParameter(infile)
|
|
||||||
self._props = None
|
self._props = None
|
||||||
|
|
||||||
self.dirty = False
|
self.dirty = False
|
||||||
@@ -208,6 +195,22 @@ class MainWindow(QMainWindow):
|
|||||||
|
|
||||||
self.loc = False
|
self.loc = False
|
||||||
|
|
||||||
|
|
||||||
|
def init_config_files(self, infile):
|
||||||
|
pylot_config_dir = os.path.join(os.path.expanduser('~'), '.pylot')
|
||||||
|
if not os.path.exists(pylot_config_dir):
|
||||||
|
os.mkdir(pylot_config_dir)
|
||||||
|
|
||||||
|
self._inputs = PylotParameter(infile)
|
||||||
|
if not infile:
|
||||||
|
self._inputs.reset_defaults()
|
||||||
|
# check for default pylot.in-file
|
||||||
|
infile = os.path.join(pylot_config_dir, '.pylot.in')
|
||||||
|
print('Using default input file {}'.format(infile))
|
||||||
|
self._inputs.export2File(infile)
|
||||||
|
self.infile = infile
|
||||||
|
|
||||||
|
|
||||||
def setupUi(self):
|
def setupUi(self):
|
||||||
try:
|
try:
|
||||||
self.startTime = min(
|
self.startTime = min(
|
||||||
@@ -1058,9 +1061,12 @@ class MainWindow(QMainWindow):
|
|||||||
eventlist = ed.selectedFiles()
|
eventlist = ed.selectedFiles()
|
||||||
basepath = eventlist[0].split(os.path.basename(eventlist[0]))[0]
|
basepath = eventlist[0].split(os.path.basename(eventlist[0]))[0]
|
||||||
if check_obspydmt_structure(basepath):
|
if check_obspydmt_structure(basepath):
|
||||||
print('Recognized obspyDMT structure in selected files.')
|
print('Recognized obspyDMT structure in selected files. Settings Datastructure to ObspyDMT')
|
||||||
|
self.dataStructure = DATASTRUCTURE['obspyDMT']()
|
||||||
eventlist = check_all_obspy(eventlist)
|
eventlist = check_all_obspy(eventlist)
|
||||||
else:
|
else:
|
||||||
|
print('Settings Datastructure to PILOT')
|
||||||
|
self.dataStructure = DATASTRUCTURE['PILOT']()
|
||||||
eventlist = check_all_pylot(eventlist)
|
eventlist = check_all_pylot(eventlist)
|
||||||
if not eventlist:
|
if not eventlist:
|
||||||
print('No events found! Expected structure for event folders: [eEVID.DOY.YR],\n'
|
print('No events found! Expected structure for event folders: [eEVID.DOY.YR],\n'
|
||||||
|
|||||||
@@ -733,6 +733,22 @@ class PilotDataStructure(GenericDataStructure):
|
|||||||
self.setExpandFields(['root', 'database'])
|
self.setExpandFields(['root', 'database'])
|
||||||
|
|
||||||
|
|
||||||
|
class ObspyDMTdataStructure(GenericDataStructure):
|
||||||
|
"""
|
||||||
|
Object containing the data access information for the old PILOT data
|
||||||
|
structure.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, **fields):
|
||||||
|
if not fields:
|
||||||
|
fields = {'database': '',
|
||||||
|
'root': ''}
|
||||||
|
|
||||||
|
GenericDataStructure.__init__(self, **fields)
|
||||||
|
|
||||||
|
self.setExpandFields(['root', 'database'])
|
||||||
|
|
||||||
|
|
||||||
class SeiscompDataStructure(GenericDataStructure):
|
class SeiscompDataStructure(GenericDataStructure):
|
||||||
"""
|
"""
|
||||||
Dictionary containing the data access information for an SDS data archive:
|
Dictionary containing the data access information for an SDS data archive:
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ defaults = {'rootpath': {'type': str,
|
|||||||
|
|
||||||
'ctrfile': {'type': str,
|
'ctrfile': {'type': str,
|
||||||
'tooltip': 'name of autoPyLoT-output control file for NLLoc',
|
'tooltip': 'name of autoPyLoT-output control file for NLLoc',
|
||||||
'value': 'Insheim_min1d2015_auto.in',
|
'value': '',
|
||||||
'namestring': 'Control filename'},
|
'namestring': 'Control filename'},
|
||||||
|
|
||||||
'ttpatter': {'type': str,
|
'ttpatter': {'type': str,
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ class PylotParameter(object):
|
|||||||
self.__init_default_paras()
|
self.__init_default_paras()
|
||||||
self.__init_subsettings()
|
self.__init_subsettings()
|
||||||
self.__filename = fnin
|
self.__filename = fnin
|
||||||
|
self.__parameter = {}
|
||||||
self._verbosity = verbosity
|
self._verbosity = verbosity
|
||||||
self._parFileCont = {}
|
self._parFileCont = {}
|
||||||
# io from parsed arguments alternatively
|
# io from parsed arguments alternatively
|
||||||
@@ -273,8 +274,8 @@ class PylotParameter(object):
|
|||||||
:rtype: None
|
:rtype: None
|
||||||
"""
|
"""
|
||||||
defaults = self.get_defaults()
|
defaults = self.get_defaults()
|
||||||
for param in defaults:
|
for param_name, param in defaults.items():
|
||||||
self.setParamKV(param, defaults[param]['value'])
|
self.setParamKV(param_name, param['value'])
|
||||||
|
|
||||||
def from_file(self, fnin=None):
|
def from_file(self, fnin=None):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -93,7 +93,9 @@ def autopickevent(data, param, iplot=0, fig_dict=None, fig_dict_wadatijack=None,
|
|||||||
#result = serial_picking(input_tuples)
|
#result = serial_picking(input_tuples)
|
||||||
|
|
||||||
for pick in result:
|
for pick in result:
|
||||||
if pick:
|
if type(pick) == BaseException:
|
||||||
|
print(pick)
|
||||||
|
elif pick:
|
||||||
station = pick['station']
|
station = pick['station']
|
||||||
pick.pop('station')
|
pick.pop('station')
|
||||||
all_onsets[station] = pick
|
all_onsets[station] = pick
|
||||||
@@ -130,7 +132,10 @@ def call_autopickstation(input_tuple):
|
|||||||
"""
|
"""
|
||||||
wfstream, pickparam, verbose, metadata, origin = input_tuple
|
wfstream, pickparam, verbose, metadata, origin = input_tuple
|
||||||
# multiprocessing not possible with interactive plotting
|
# multiprocessing not possible with interactive plotting
|
||||||
return autopickstation(wfstream, pickparam, verbose, iplot=0, metadata=metadata, origin=origin)
|
try:
|
||||||
|
return autopickstation(wfstream, pickparam, verbose, iplot=0, metadata=metadata, origin=origin)
|
||||||
|
except Exception as e:
|
||||||
|
return e
|
||||||
|
|
||||||
|
|
||||||
def get_source_coords(parser, station_id):
|
def get_source_coords(parser, station_id):
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ Created on Wed Jan 26 17:47:25 2015
|
|||||||
@author: sebastianw
|
@author: sebastianw
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from pylot.core.io.data import SeiscompDataStructure, PilotDataStructure
|
from pylot.core.io.data import SeiscompDataStructure, PilotDataStructure, ObspyDMTdataStructure
|
||||||
|
|
||||||
DATASTRUCTURE = {'PILOT': PilotDataStructure, 'SeisComP': SeiscompDataStructure,
|
DATASTRUCTURE = {'PILOT': PilotDataStructure, 'SeisComP': SeiscompDataStructure,
|
||||||
'obspyDMT': None, None: None}
|
'obspyDMT': ObspyDMTdataStructure, None: PilotDataStructure}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
000001V 010 65 2.3122012,213,12:05:00.0000~~2018,144,14:13:39.9981~GFZ~~011 21 1WETR 3 000002A 030 237Steim2 Integer Compression Format~ 1 5014F1 P4 W4 D C2 R1 P8 W4 D C2~P0 W4 N15 S2,0,1~T0 X W4~T1 Y4 W1 D C2~T2 W4 I D2~K0 X D30~K1 N0 D30 C2~K2 Y2 D15 C2~K3 Y3 D10 C2~T3 W4 I D2~K0 Y5 D6 C2~K1 Y6 D5 C2~K2 X D2 Y7 D4 C2~K3 X D30~033 21 1BayernNetz~033 16 2LE-3D~034 44 1M/S~Velocity in Meters per Second~034 18 2V~Volts~034 32 3COUNTS~Digital Counts~043 264 1RSSENSOR201509030717001~A 1 2 1.00000E+00 1.00000E+00 2 0.00000E+00 0.00000E+00 0.00000E-00 0.00000E-00 0.00000E+00 0.00000E+00 0.00000E-00 0.00000E-00 2-2.22100E-01 2.22100E-01 0.00000E-00 0.00000E-00-2.22100E-01-2.22100E-01 0.00000E-00 0.00000E-00044 51 3RLDATALOGGER201509030717~D 2 3 0 0047 78 4DLDATALOGGER201509030717~1.0000E+02 1 0 0.0000E+00 0.0000E+00048 57 2GSWETR2012213HEYYYY~ 1.00000E+03 1.00000E-01 0048 58 5GLWETR2012213HHEXXXX~ 1.67772E+06 0.00000E+00 0 Line truncated
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
000001V 010 65 2.3122012,213,12:05:00.0000~~2018,144,14:13:40.4553~GFZ~~011 21 1WETR 3 000002A 030 237Steim2 Integer Compression Format~ 1 5014F1 P4 W4 D C2 R1 P8 W4 D C2~P0 W4 N15 S2,0,1~T0 X W4~T1 Y4 W1 D C2~T2 W4 I D2~K0 X D30~K1 N0 D30 C2~K2 Y2 D15 C2~K3 Y3 D10 C2~T3 W4 I D2~K0 Y5 D6 C2~K1 Y6 D5 C2~K2 X D2 Y7 D4 C2~K3 X D30~033 21 1BayernNetz~033 16 2LE-3D~034 44 1M/S~Velocity in Meters per Second~034 18 2V~Volts~034 32 3COUNTS~Digital Counts~043 264 1RSSENSOR201509030717001~A 1 2 1.00000E+00 1.00000E+00 2 0.00000E+00 0.00000E+00 0.00000E-00 0.00000E-00 0.00000E+00 0.00000E+00 0.00000E-00 0.00000E-00 2-2.22100E-01 2.22100E-01 0.00000E-00 0.00000E-00-2.22100E-01-2.22100E-01 0.00000E-00 0.00000E-00044 51 3RLDATALOGGER201509030717~D 2 3 0 0047 78 4DLDATALOGGER201509030717~1.0000E+02 1 0 0.0000E+00 0.0000E+00048 57 2GSWETR2012213HNYYYY~ 1.00000E+03 1.00000E-01 0048 58 5GLWETR2012213HHNXXXX~ 1.67772E+06 0.00000E+00 0 Line truncated
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
000001V 010 65 2.3122012,213,12:05:00.0000~~2018,144,14:13:39.5005~GFZ~~011 21 1WETR 3 000002A 030 237Steim2 Integer Compression Format~ 1 5014F1 P4 W4 D C2 R1 P8 W4 D C2~P0 W4 N15 S2,0,1~T0 X W4~T1 Y4 W1 D C2~T2 W4 I D2~K0 X D30~K1 N0 D30 C2~K2 Y2 D15 C2~K3 Y3 D10 C2~T3 W4 I D2~K0 Y5 D6 C2~K1 Y6 D5 C2~K2 X D2 Y7 D4 C2~K3 X D30~033 21 1BayernNetz~033 16 2LE-3D~034 44 1M/S~Velocity in Meters per Second~034 18 2V~Volts~034 32 3COUNTS~Digital Counts~043 264 1RSSENSOR201509030717001~A 1 2 1.00000E+00 1.00000E+00 2 0.00000E+00 0.00000E+00 0.00000E-00 0.00000E-00 0.00000E+00 0.00000E+00 0.00000E-00 0.00000E-00 2-2.22100E-01 2.22100E-01 0.00000E-00 0.00000E-00-2.22100E-01-2.22100E-01 0.00000E-00 0.00000E-00044 51 3RLDATALOGGER201509030717~D 2 3 0 0047 78 4DLDATALOGGER201509030717~1.0000E+02 1 0 0.0000E+00 0.0000E+00048 57 2GSWETR2012213HZYYYY~ 1.00000E+03 1.00000E-01 0048 58 5GLWETR2012213HHZXXXX~ 1.67772E+06 0.00000E+00 0 Line truncated
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
000001V 010 65 2.3122007,262,00:00:00.0000~~2018,144,14:14:34.7940~GFZ~~011 21 1GRA1 3 000002A 030 237Steim2 Integer Compression Format~ 1 5014F1 P4 W4 D C2 R1 P8 W4 D C2~P0 W4 N15 S2,0,1~T0 X W4~T1 Y4 W1 D C2~T2 W4 I D2~K0 X D30~K1 N0 D30 C2~K2 Y2 D15 C2~K3 Y3 D10 C2~T3 W4 I D2~K0 Y5 D6 C2~K1 Y6 D5 C2~K2 X D2 Y7 D4 C2~K3 X D30~033 56 1German Regional Seismic Network, BGR Hannover~033 15 2STS2~034 44 1M/S~Velocity in Meters per Second~034 18 2V~Volts~034 32 3COUNTS~Digital Counts~043 264 1RSSENSOR201207231411139~A 1 2 1.00000E+00 1.00000E+00 2 0.00000E+00 0.00000E+00 0.00000E-00 0.00000E-00 0.00000E+00 0.00000E+00 0.00000E-00 0.00000E-00 2-3.67429E-02 3.67540E-02 0.00000E-00 0.00000E-00-3.67429E-02-3.67540E-02 0.00000E-00 0.00000E-00044 51 3RLDATALOGGER201207231411~D 2 3 0 0047 78 4DLDATALOGGER201207231411~1.0000E+02 1 0 0.0000E+00 0.0000E+00048 57 2GSGRGRA1HHE2007262S~ 9.44020E+08 1.00000E+00 0048 54 5GLSZGRFDUMMYXXXX~ 1.00000E+00 0.Line truncated
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
000001V 010 65 2.3122007,262,00:00:00.0000~~2018,144,14:14:35.2579~GFZ~~011 21 1GRA1 3 000002A 030 237Steim2 Integer Compression Format~ 1 5014F1 P4 W4 D C2 R1 P8 W4 D C2~P0 W4 N15 S2,0,1~T0 X W4~T1 Y4 W1 D C2~T2 W4 I D2~K0 X D30~K1 N0 D30 C2~K2 Y2 D15 C2~K3 Y3 D10 C2~T3 W4 I D2~K0 Y5 D6 C2~K1 Y6 D5 C2~K2 X D2 Y7 D4 C2~K3 X D30~033 56 1German Regional Seismic Network, BGR Hannover~033 15 2STS2~034 44 1M/S~Velocity in Meters per Second~034 18 2V~Volts~034 32 3COUNTS~Digital Counts~043 264 1RSSENSOR201207231411139~A 1 2 1.00000E+00 1.00000E+00 2 0.00000E+00 0.00000E+00 0.00000E-00 0.00000E-00 0.00000E+00 0.00000E+00 0.00000E-00 0.00000E-00 2-3.67429E-02 3.67540E-02 0.00000E-00 0.00000E-00-3.67429E-02-3.67540E-02 0.00000E-00 0.00000E-00044 51 3RLDATALOGGER201207231411~D 2 3 0 0047 78 4DLDATALOGGER201207231411~1.0000E+02 1 0 0.0000E+00 0.0000E+00048 57 2GSGRGRA1HHN2007262S~ 9.44020E+08 1.00000E+00 0048 54 5GLSZGRFDUMMYXXXX~ 1.00000E+00 0.Line truncated
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
000001V 010 65 2.3122007,262,00:00:00.0000~~2018,144,14:14:35.6913~GFZ~~011 21 1GRA1 3 000002A 030 237Steim2 Integer Compression Format~ 1 5014F1 P4 W4 D C2 R1 P8 W4 D C2~P0 W4 N15 S2,0,1~T0 X W4~T1 Y4 W1 D C2~T2 W4 I D2~K0 X D30~K1 N0 D30 C2~K2 Y2 D15 C2~K3 Y3 D10 C2~T3 W4 I D2~K0 Y5 D6 C2~K1 Y6 D5 C2~K2 X D2 Y7 D4 C2~K3 X D30~033 56 1German Regional Seismic Network, BGR Hannover~033 15 2STS2~034 44 1M/S~Velocity in Meters per Second~034 18 2V~Volts~034 32 3COUNTS~Digital Counts~043 264 1RSSENSOR201207231411139~A 1 2 1.00000E+00 1.00000E+00 2 0.00000E+00 0.00000E+00 0.00000E-00 0.00000E-00 0.00000E+00 0.00000E+00 0.00000E-00 0.00000E-00 2-3.67429E-02 3.67540E-02 0.00000E-00 0.00000E-00-3.67429E-02-3.67540E-02 0.00000E-00 0.00000E-00044 51 3RLDATALOGGER201207231411~D 2 3 0 0047 78 4DLDATALOGGER201207231411~1.0000E+02 1 0 0.0000E+00 0.0000E+00048 57 2GSGRGRA1HHZ2007262S~ 9.44020E+08 1.00000E+00 0048 54 5GLSZGRFDUMMYXXXX~ 1.00000E+00 0.Line truncated
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
000001V 010 65 2.3122007,242,00:00:00.0000~~2018,144,14:14:36.1800~GFZ~~011 21 1GRA2 3 000002A 030 237Steim2 Integer Compression Format~ 1 5014F1 P4 W4 D C2 R1 P8 W4 D C2~P0 W4 N15 S2,0,1~T0 X W4~T1 Y4 W1 D C2~T2 W4 I D2~K0 X D30~K1 N0 D30 C2~K2 Y2 D15 C2~K3 Y3 D10 C2~T3 W4 I D2~K0 Y5 D6 C2~K1 Y6 D5 C2~K2 X D2 Y7 D4 C2~K3 X D30~033 56 1German Regional Seismic Network, BGR Hannover~033 15 2STS2~034 44 1M/S~Velocity in Meters per Second~034 18 2V~Volts~034 32 3COUNTS~Digital Counts~043 264 1RSSENSOR201207231411139~A 1 2 1.00000E+00 1.00000E+00 2 0.00000E+00 0.00000E+00 0.00000E-00 0.00000E-00 0.00000E+00 0.00000E+00 0.00000E-00 0.00000E-00 2-3.67429E-02 3.67540E-02 0.00000E-00 0.00000E-00-3.67429E-02-3.67540E-02 0.00000E-00 0.00000E-00044 51 3RLDATALOGGER201207231411~D 2 3 0 0047 78 4DLDATALOGGER201207231411~1.0000E+02 1 0 0.0000E+00 0.0000E+00048 57 2GSGRGRA2HHE2007242S~ 9.44020E+08 1.00000E+00 0048 54 5GLSZGRFDUMMYXXXX~ 1.00000E+00 0.Line truncated
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
000001V 010 65 2.3122007,242,00:00:00.0000~~2018,144,14:14:38.5280~GFZ~~011 21 1GRA2 3 000002A 030 237Steim2 Integer Compression Format~ 1 5014F1 P4 W4 D C2 R1 P8 W4 D C2~P0 W4 N15 S2,0,1~T0 X W4~T1 Y4 W1 D C2~T2 W4 I D2~K0 X D30~K1 N0 D30 C2~K2 Y2 D15 C2~K3 Y3 D10 C2~T3 W4 I D2~K0 Y5 D6 C2~K1 Y6 D5 C2~K2 X D2 Y7 D4 C2~K3 X D30~033 56 1German Regional Seismic Network, BGR Hannover~033 15 2STS2~034 44 1M/S~Velocity in Meters per Second~034 18 2V~Volts~034 32 3COUNTS~Digital Counts~043 264 1RSSENSOR201207231411139~A 1 2 1.00000E+00 1.00000E+00 2 0.00000E+00 0.00000E+00 0.00000E-00 0.00000E-00 0.00000E+00 0.00000E+00 0.00000E-00 0.00000E-00 2-3.67429E-02 3.67540E-02 0.00000E-00 0.00000E-00-3.67429E-02-3.67540E-02 0.00000E-00 0.00000E-00044 51 3RLDATALOGGER201207231411~D 2 3 0 0047 78 4DLDATALOGGER201207231411~1.0000E+02 1 0 0.0000E+00 0.0000E+00048 57 2GSGRGRA2HHN2007242S~ 9.44020E+08 1.00000E+00 0048 54 5GLSZGRFDUMMYXXXX~ 1.00000E+00 0.Line truncated
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
000001V 010 65 2.3122007,242,00:00:00.0000~~2018,144,14:14:39.0145~GFZ~~011 21 1GRA2 3 000002A 030 237Steim2 Integer Compression Format~ 1 5014F1 P4 W4 D C2 R1 P8 W4 D C2~P0 W4 N15 S2,0,1~T0 X W4~T1 Y4 W1 D C2~T2 W4 I D2~K0 X D30~K1 N0 D30 C2~K2 Y2 D15 C2~K3 Y3 D10 C2~T3 W4 I D2~K0 Y5 D6 C2~K1 Y6 D5 C2~K2 X D2 Y7 D4 C2~K3 X D30~033 56 1German Regional Seismic Network, BGR Hannover~033 15 2STS2~034 44 1M/S~Velocity in Meters per Second~034 18 2V~Volts~034 32 3COUNTS~Digital Counts~043 264 1RSSENSOR201207231411139~A 1 2 1.00000E+00 1.00000E+00 2 0.00000E+00 0.00000E+00 0.00000E-00 0.00000E-00 0.00000E+00 0.00000E+00 0.00000E-00 0.00000E-00 2-3.67429E-02 3.67540E-02 0.00000E-00 0.00000E-00-3.67429E-02-3.67540E-02 0.00000E-00 0.00000E-00044 51 3RLDATALOGGER201207231411~D 2 3 0 0047 78 4DLDATALOGGER201207231411~1.0000E+02 1 0 0.0000E+00 0.0000E+00048 57 2GSGRGRA2HHZ2007242S~ 9.44020E+08 1.00000E+00 0048 54 5GLSZGRFDUMMYXXXX~ 1.00000E+00 0.Line truncated
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
import unittest
|
||||||
|
import os
|
||||||
|
|
||||||
|
from pylot.core.util.dataprocessing import Metadata
|
||||||
|
|
||||||
|
class TestMetadata(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.station_id = 'BW.WETR..HH'
|
||||||
|
metadata_folder = 'metadata1'
|
||||||
|
self.m = Metadata(metadata_folder)
|
||||||
|
|
||||||
|
def test_get_coordinates_sucess(self):
|
||||||
|
expected = {'Z': {u'elevation': 607.0, u'longitude': 12.87571, u'local_depth': 0.0, u'azimuth': 0.0, u'latitude': 49.14502, u'dip': -90.0},
|
||||||
|
'E': {u'azimuth': 90.0, u'dip': 0.0, u'elevation': 607.0, u'latitude': 49.14502, u'local_depth': 0.0, u'longitude': 12.87571},
|
||||||
|
'N': {u'azimuth': 0.0, u'dip': 0.0, u'elevation': 607.0, u'latitude': 49.14502, u'local_depth': 0.0, u'longitude': 12.87571}
|
||||||
|
}
|
||||||
|
result = {}
|
||||||
|
for channel in ('Z', 'N', 'E'):
|
||||||
|
coords = self.m.get_coordinates(self.station_id+channel)
|
||||||
|
result[channel] = coords
|
||||||
|
self.assertDictEqual(result[channel], expected[channel])
|
||||||
|
|
||||||
|
class TestMetadataAdding(unittest.TestCase):
|
||||||
|
"""Tests if adding files and directories to a metadata object works."""
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.station_id = 'BW.WETR..HH'
|
||||||
|
self.metadata_folders = ('metadata1', 'metadata2')
|
||||||
|
self.m = Metadata()
|
||||||
|
|
||||||
|
def test_add_inventory_folder(self):
|
||||||
|
"""Test if add_inventory adds the folder to the list of inventories"""
|
||||||
|
self.m.add_inventory(self.metadata_folders[0])
|
||||||
|
# adding an inventory folder should append it to the list of inventories
|
||||||
|
self.assertDictEqual({}, self.m.inventory_files)
|
||||||
|
self.assertDictEqual({}, self.m.seed_ids)
|
||||||
|
self.assertEqual([self.metadata_folders[0]], self.m.inventories)
|
||||||
|
|
||||||
|
def test_add_inventory_file(self):
|
||||||
|
"""Test if add_inventory_file adds the folder containing the file to the list of inventories and
|
||||||
|
if the files is added to inventory_files"""
|
||||||
|
fpath = os.path.join(self.metadata_folders[0], 'DATALESS.BW.WETR..HHZ')
|
||||||
|
self.m.add_inventory_file(fpath)
|
||||||
|
# adding an inventory file should append its folder to the list of inventories and the file to the
|
||||||
|
self.assertEqual(['metadata1/DATALESS.BW.WETR..HHZ'], self.m.inventory_files.keys()) # does the filename exist in inventory files?
|
||||||
|
self.assertEqual(['data', 'invtype'], self.m.inventory_files['metadata1/DATALESS.BW.WETR..HHZ'].keys()) # is the required information attacht to the filename?
|
||||||
|
self.assertDictEqual({}, self.m.seed_ids)
|
||||||
|
self.assertEqual([self.metadata_folders[0]], self.m.inventories)
|
||||||
|
|
||||||
|
def test_add_inventory_invalid_path(self):
|
||||||
|
"""Test if adding an inventory that is not an existing directory fails with an exception"""
|
||||||
|
with self.assertRaises(Exception):
|
||||||
|
self.m.add_inventory('InvalidDirName')
|
||||||
|
self.assertEqual([], self.m.inventories) # inventory list should still be empty
|
||||||
|
|
||||||
|
def test_add_inventory_file_invalid_path(self):
|
||||||
|
"""Test if adding a inventory file with an invalid path fails with an exception"""
|
||||||
|
with self.assertRaises(Exception):
|
||||||
|
self.m.add_inventory_file('/invalid/file/name')
|
||||||
|
self.assertEqual([], self.m.inventories) # inventory list should still be empty
|
||||||
|
|
||||||
|
|
||||||
|
class TestMetadataRemoval(unittest.TestCase):
|
||||||
|
"""Tests if removing files and directories to a metadata object works."""
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.station_id = 'BW.WETR..HH'
|
||||||
|
self.metadata_folders = ('metadata1', 'metadata2')
|
||||||
|
self.m = Metadata()
|
||||||
|
|
||||||
|
def test_remove_all_inventories(self):
|
||||||
|
"""Test if function remove_inventory cleans the Metadata object """
|
||||||
|
# add multiple inventories
|
||||||
|
for folder in self.metadata_folders:
|
||||||
|
self.m.add_inventory(folder)
|
||||||
|
self.m.remove_all_inventories()
|
||||||
|
self.isEmpty(self.m)
|
||||||
|
|
||||||
|
def test_remove_inventory(self):
|
||||||
|
"""Test if remove_inventory removes single inventories"""
|
||||||
|
# add multiple inventories
|
||||||
|
for folder in self.metadata_folders:
|
||||||
|
self.m.add_inventory(folder)
|
||||||
|
self.m.remove_inventory(self.metadata_folders[0])
|
||||||
|
self.assertNotIn(self.metadata_folders[0], self.m.inventories)
|
||||||
|
self.m.remove_inventory(self.metadata_folders[1])
|
||||||
|
self.assertNotIn(self.metadata_folders[1], self.m.inventories)
|
||||||
|
self.isEmpty(self.m)
|
||||||
|
|
||||||
|
def test_remove_inventory_not_in_inventory_list(self):
|
||||||
|
"""Test if remove_inventory does not modify the metadata instance if the given inventory to remove does not
|
||||||
|
exist in the instance."""
|
||||||
|
# add multiple inventories
|
||||||
|
self.m.add_inventory(self.metadata_folders[0])
|
||||||
|
self.m.remove_inventory('metadata_not_existing')
|
||||||
|
self.assertIn(self.metadata_folders[0], self.m.inventories)
|
||||||
|
|
||||||
|
def isEmpty(self, metadata):
|
||||||
|
"""Asserts if the given metadata object is empty"""
|
||||||
|
self.assertDictEqual({}, metadata.inventory_files)
|
||||||
|
self.assertDictEqual({}, metadata.seed_ids)
|
||||||
|
self.assertEqual([], metadata.inventories)
|
||||||
|
|
||||||
Reference in new issue
Block a user