Merge branch 'develop' of ariadne.geophysik.rub.de:/data/git/pylot into develop

Conflicts:
	pylot/RELEASE-VERSION
This commit is contained in:
Ludger Küperkoch 2017-06-23 15:47:09 +02:00
commit 0f05be6a50
3 changed files with 118 additions and 22 deletions

View File

@ -42,7 +42,8 @@ from PySide.QtGui import QMainWindow, QInputDialog, QIcon, QFileDialog, \
import numpy as np import numpy as np
from obspy import UTCDateTime from obspy import UTCDateTime
from obspy.core.event import Event as ObsPyEvent from obspy.core.event import Event as ObsPyEvent
from obspy.core.event import Origin from obspy.core.event import Origin, Magnitude, ResourceIdentifier
from obspy.core.util import AttribDict
try: try:
import pyqtgraph as pg import pyqtgraph as pg
@ -804,7 +805,7 @@ class MainWindow(QMainWindow):
dirs = { dirs = {
'database': path.split('/')[-2], 'database': path.split('/')[-2],
'datapath': path.split('/')[-3], 'datapath': path.split('/')[-3],
'rootpath': os.path.join(*path.split('/')[:-3]) 'rootpath': '/'+os.path.join(*path.split('/')[:-3])
} }
except Exception as e: except Exception as e:
dirs = { dirs = {
@ -1795,7 +1796,7 @@ class MainWindow(QMainWindow):
for phase in stat_picks: for phase in stat_picks:
picks = stat_picks[phase] picks = stat_picks[phase]
if type(stat_picks[phase]) is not dict: if type(stat_picks[phase]) is not dict and type(stat_picks[phase]) is not AttribDict:
return return
colors = phase_col[phase[0].upper()] colors = phase_col[phase[0].upper()]
@ -1995,6 +1996,12 @@ class MainWindow(QMainWindow):
if not self.array_map: if not self.array_map:
return return
# refresh with new picks here!!! # refresh with new picks here!!!
event = self.get_current_event()
if hasattr(event, 'origins'):
if event.origins:
lat = event.origins[0].latitude
lon = event.origins[0].longitude
self.array_map.eventLoc = (lat, lon)
self.array_map.refresh_drawings(self.get_current_event().getPicks()) self.array_map.refresh_drawings(self.get_current_event().getPicks())
self._eventChanged[1] = False self._eventChanged[1] = False
@ -2021,19 +2028,19 @@ class MainWindow(QMainWindow):
# changes attributes of the corresponding event # changes attributes of the corresponding event
table = self.project._table table = self.project._table
event = self.project.getEventFromPath(table[row][0].text()) event = self.project.getEventFromPath(table[row][0].text())
if column == 3 or column == 4: if column == 8 or column == 9:
#toggle checked states (exclusive) #toggle checked states (exclusive)
item_ref = table[row][3] item_ref = table[row][8]
item_test = table[row][4] item_test = table[row][9]
if column == 3 and item_ref.checkState(): if column == 8 and item_ref.checkState():
item_test.setCheckState(QtCore.Qt.Unchecked) item_test.setCheckState(QtCore.Qt.Unchecked)
event.setRefEvent(True) event.setRefEvent(True)
elif column == 3 and not item_ref.checkState(): elif column == 8 and not item_ref.checkState():
event.setRefEvent(False) event.setRefEvent(False)
elif column == 4 and item_test.checkState(): elif column == 9 and item_test.checkState():
item_ref.setCheckState(QtCore.Qt.Unchecked) item_ref.setCheckState(QtCore.Qt.Unchecked)
event.setTestEvent(True) event.setTestEvent(True)
elif column == 4 and not item_test.checkState(): elif column == 9 and not item_test.checkState():
event.setTestEvent(False) event.setTestEvent(False)
self.fill_eventbox() self.fill_eventbox()
elif column == 5: elif column == 5:
@ -2049,11 +2056,19 @@ class MainWindow(QMainWindow):
# init new qtable # init new qtable
self.event_table = QtGui.QTableWidget() self.event_table = QtGui.QTableWidget()
self.event_table.setColumnCount(6) self.event_table.setColumnCount(11)
self.event_table.setRowCount(len(eventlist)) self.event_table.setRowCount(len(eventlist))
self.event_table.setHorizontalHeaderLabels(['Event', '[N] MP', self.event_table.setHorizontalHeaderLabels(['Event',
'[N] AP', 'Tuning Set', 'Time',
'Test Set', 'Notes']) 'Lat',
'Lon',
'Depth',
'Mag',
'[N] MP',
'[N] AP',
'Tuning Set',
'Test Set',
'Notes'])
# iterate through eventlist and generate items for table rows # iterate through eventlist and generate items for table rows
self.project._table = [] self.project._table = []
@ -2065,6 +2080,11 @@ class MainWindow(QMainWindow):
if event.autopicks: if event.autopicks:
event_nautopicks = len(event.autopicks) event_nautopicks = len(event.autopicks)
item_path = QtGui.QTableWidgetItem() item_path = QtGui.QTableWidgetItem()
item_time = QtGui.QTableWidgetItem()
item_lat = QtGui.QTableWidgetItem()
item_lon = QtGui.QTableWidgetItem()
item_depth = QtGui.QTableWidgetItem()
item_mag = QtGui.QTableWidgetItem()
item_nmp = QtGui.QTableWidgetItem(str(event_npicks)) item_nmp = QtGui.QTableWidgetItem(str(event_npicks))
item_nmp.setIcon(self.manupicksicon_small) item_nmp.setIcon(self.manupicksicon_small)
item_nap = QtGui.QTableWidgetItem(str(event_nautopicks)) item_nap = QtGui.QTableWidgetItem(str(event_nautopicks))
@ -2076,7 +2096,19 @@ class MainWindow(QMainWindow):
item_ref.setBackground(self._colors['ref']) item_ref.setBackground(self._colors['ref'])
item_test.setBackground(self._colors['test']) item_test.setBackground(self._colors['test'])
item_path.setText(event.path) item_path.setText(event.path)
item_notes.setText(event.notes) if hasattr(event, 'origins'):
if event.origins:
origin = event.origins[0]
item_time.setText(str(origin.time).split('.')[0])
item_lon.setText(str(origin.longitude))
item_lat.setText(str(origin.latitude))
item_depth.setText(str(origin.depth))
if hasattr(event, 'magnitudes'):
if event.magnitudes:
magnitude = event.magnitudes[0]
item_mag.setText(str(magnitude.mag))
item_notes.setText(event.notes)
set_enabled(item_path, True, False) set_enabled(item_path, True, False)
set_enabled(item_nmp, True, False) set_enabled(item_nmp, True, False)
set_enabled(item_nap, True, False) set_enabled(item_nap, True, False)
@ -2096,7 +2128,8 @@ class MainWindow(QMainWindow):
else: else:
item_test.setCheckState(QtCore.Qt.Unchecked) item_test.setCheckState(QtCore.Qt.Unchecked)
column=[item_path, item_nmp, item_nap, item_ref, item_test, item_notes] column=[item_path, item_time, item_lat, item_lon, item_depth, item_mag,
item_nmp, item_nap, item_ref, item_test, item_notes]
self.project._table.append(column) self.project._table.append(column)
for r_index, row in enumerate(self.project._table): for r_index, row in enumerate(self.project._table):
@ -2411,6 +2444,63 @@ class Project(object):
self.setDirty() self.setDirty()
else: else:
print('Skipping event with path {}. Already part of project.'.format(event.path)) print('Skipping event with path {}. Already part of project.'.format(event.path))
self.search_eventfile_info()
def read_eventfile_info(self, filename, separator=','):
'''
Try to read event information from file (:param:filename) comparing specific event datetimes.
File structure (each row): event, date, time, magnitude, latitude, longitude, depth
separated by :param:separator each.
'''
infile = open(filename, 'r')
for line in infile.readlines():
event, date, time, mag, lat, lon, depth = line.split(separator)[:7]
#skip first line
try:
month, day, year = date.split('/')
except:
continue
year = int(year)
#hardcoded, if year only consists of 2 digits (e.g. 16 instead of 2016)
if year<100:
year += 2000
datetime = '{}-{}-{}T{}'.format(year, month, day, time)
try:
datetime = UTCDateTime(datetime)
except Exception as e:
print(e, datetime, filename)
continue
for event in self.eventlist:
if not event.origins:
continue
origin = event.origins[0] #should have only one origin
if origin.time == datetime:
origin.latitude = float(lat)
origin.longitude = float(lon)
origin.depth = float(depth)
event.magnitudes.append(Magnitude(resource_id=event.resource_id,
mag=float(mag),
mag_type='M'))
def search_eventfile_info(self):
'''
Search all datapaths in rootpath for filenames with given file extension fext
and try to read event info from it
'''
datapaths = []
fext='.csv'
for event in self.eventlist:
if not event.datapath in datapaths:
datapaths.append(event.datapath)
for datapath in datapaths:
datapath = os.path.join(self.rootpath, datapath)
for filename in os.listdir(datapath):
filename = os.path.join(datapath, filename)
if os.path.isfile(filename) and filename.endswith(fext):
try:
self.read_eventfile_info(filename)
except Exception as e:
print('Failed on reading eventfile info from file {}: {}'.format(filename, e))
def getPaths(self): def getPaths(self):
''' '''
@ -2477,11 +2567,11 @@ class Event(ObsPyEvent):
''' '''
def __init__(self, path): def __init__(self, path):
# initialize super class # initialize super class
super(Event, self).__init__() super(Event, self).__init__(resource_id=ResourceIdentifier(path.split('/')[-1]))
self.path = path self.path = path
self.database = path.split('/')[-2] self.database = path.split('/')[-2]
self.datapath = path.split('/')[-3] self.datapath = path.split('/')[-3]
self.rootpath = os.path.join(*path.split('/')[:-3]) self.rootpath = '/' + os.path.join(*path.split('/')[:-3])
self.autopicks = {} self.autopicks = {}
self.picks = {} self.picks = {}
self.notes = '' self.notes = ''
@ -2502,7 +2592,7 @@ class Event(ObsPyEvent):
self.addNotes(text) self.addNotes(text)
try: try:
datetime = UTCDateTime(path.split('/')[-1]) datetime = UTCDateTime(path.split('/')[-1])
origin = Origin(time=datetime, latitude=0, longitude=0) origin = Origin(resource_id=self.resource_id, time=datetime, latitude=0, longitude=0, depth=0)
self.origins.append(origin) self.origins.append(origin)
except: except:
pass pass

View File

@ -1 +0,0 @@
c9f0b-dirty

View File

@ -22,6 +22,7 @@ class map_projection(QtGui.QWidget):
self.parser = parent.metadata[1] self.parser = parent.metadata[1]
self.picks = None self.picks = None
self.picks_dict = None self.picks_dict = None
self.eventLoc = None
self.figure = figure self.figure = figure
self.init_graphics() self.init_graphics()
self.init_stations() self.init_stations()
@ -244,6 +245,10 @@ class map_projection(QtGui.QWidget):
self.sc = self.basemap.scatter(self.lon, self.lat, s=50, facecolor='none', latlon=True, self.sc = self.basemap.scatter(self.lon, self.lat, s=50, facecolor='none', latlon=True,
zorder=10, picker=True, edgecolor='m', label='Not Picked') zorder=10, picker=True, edgecolor='m', label='Not Picked')
self.cid = self.canvas.mpl_connect('pick_event', self.onpick) self.cid = self.canvas.mpl_connect('pick_event', self.onpick)
if self.eventLoc:
lat, lon = self.eventLoc
self.sc_event = self.basemap.scatter(lon, lat, s=100, facecolor='red',
latlon=True, zorder=11, label='Event (might be outside map region)')
def scatter_picked_stations(self): def scatter_picked_stations(self):
lon = self.lon_no_nan lon = self.lon_no_nan
@ -274,8 +279,7 @@ class map_projection(QtGui.QWidget):
def refresh_drawings(self, picks=None): def refresh_drawings(self, picks=None):
self.picks_dict = picks self.picks_dict = picks
self.remove_drawings() self._refresh_drawings()
self.draw_everything()
def _refresh_drawings(self): def _refresh_drawings(self):
self.remove_drawings() self.remove_drawings()
@ -303,6 +307,9 @@ class map_projection(QtGui.QWidget):
if hasattr(self, 'sc_picked'): if hasattr(self, 'sc_picked'):
self.sc_picked.remove() self.sc_picked.remove()
del(self.sc_picked) del(self.sc_picked)
if hasattr(self, 'sc_event'):
self.sc_event.remove()
del(self.sc_event)
if hasattr(self, 'cbar'): if hasattr(self, 'cbar'):
self.cbar.remove() self.cbar.remove()
del(self.cbar) del(self.cbar)