[initial] first changes to supply an interface to an obspyDMT database
This commit is contained in:
@@ -1 +1 @@
|
||||
39f92-dirty
|
||||
7941-dirty
|
||||
|
||||
28
pylot/core/util/obspyDMT_interface.py
Normal file
28
pylot/core/util/obspyDMT_interface.py
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
from obspy import UTCDateTime
|
||||
|
||||
def check_obspydmt_structure(path):
|
||||
'''
|
||||
Check path for obspyDMT event structure.
|
||||
:param path:
|
||||
:return:
|
||||
'''
|
||||
ev_info = os.path.join(path, 'EVENTS-INFO')
|
||||
if os.path.isdir(ev_info):
|
||||
if os.path.isfile(os.path.join(ev_info, 'logger_command.txt')):
|
||||
return True
|
||||
return False
|
||||
|
||||
def check_obspydmt_eventfolder(folder):
|
||||
try:
|
||||
time = folder.split('.')[0]
|
||||
time = time.replace('_', 'T')
|
||||
time = UTCDateTime(time)
|
||||
return True, time
|
||||
except Exception as e:
|
||||
return False, e
|
||||
|
||||
check_obspydmt_eventfolder('20110311_054623.a')
|
||||
@@ -9,4 +9,4 @@ Created on Wed Jan 26 17:47:25 2015
|
||||
from pylot.core.io.data import SeiscompDataStructure, PilotDataStructure
|
||||
|
||||
DATASTRUCTURE = {'PILOT': PilotDataStructure, 'SeisComP': SeiscompDataStructure,
|
||||
None: None}
|
||||
'obspyDMT': None, None: None}
|
||||
|
||||
@@ -6,6 +6,7 @@ import os
|
||||
import platform
|
||||
import re
|
||||
import subprocess
|
||||
import warnings
|
||||
|
||||
import numpy as np
|
||||
from obspy import UTCDateTime, read
|
||||
@@ -13,6 +14,8 @@ from obspy.core import AttribDict
|
||||
from obspy.signal.rotate import rotate2zne
|
||||
from obspy.io.xseed.utils import SEEDParserException
|
||||
|
||||
from pylot.core.util.obspyDMT_interface import check_obspydmt_eventfolder
|
||||
|
||||
from pylot.core.io.inputs import PylotParameter, FilterOptions
|
||||
from pylot.styles import style_settings
|
||||
|
||||
@@ -1216,6 +1219,46 @@ def has_spe(pick):
|
||||
return pick['spe']
|
||||
|
||||
|
||||
def check_all_obspy(eventlist):
|
||||
ev_type = 'obspydmt'
|
||||
return check_event_folders(eventlist, ev_type)
|
||||
|
||||
|
||||
def check_all_pylot(eventlist):
|
||||
ev_type = 'pylot'
|
||||
return check_event_folders(eventlist, ev_type)
|
||||
|
||||
|
||||
def check_event_folders(eventlist, ev_type):
|
||||
checklist = []
|
||||
clean_eventlist = []
|
||||
for path in eventlist:
|
||||
folder_check = check_event_folder(path)
|
||||
if not folder_check:
|
||||
warnings.warn('Unrecognized event folder: {}'.format(path))
|
||||
continue
|
||||
checklist.append(folder_check == ev_type)
|
||||
clean_eventlist.append(path)
|
||||
if all(checklist) or len(checklist) == 0:
|
||||
return clean_eventlist
|
||||
else:
|
||||
warnings.warn('Not all selected folders of type {}'.format(ev_type))
|
||||
return []
|
||||
|
||||
|
||||
def check_event_folder(path):
|
||||
ev_type = None
|
||||
folder = path.split('/')[-1]
|
||||
# for pylot: select only folders that start with 'e', containin two dots and have length 12
|
||||
if (folder.startswith('e')
|
||||
and len(folder.split('.')) == 3
|
||||
and len(folder) == 12):
|
||||
ev_type = 'pylot'
|
||||
elif check_obspydmt_eventfolder(folder)[0]:
|
||||
ev_type = 'obspydmt'
|
||||
return ev_type
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import doctest
|
||||
|
||||
|
||||
Reference in New Issue
Block a user