[new] save event table as .csv file
This commit is contained in:
parent
8ae00529f0
commit
9764e12b19
84
PyLoT.py
84
PyLoT.py
@ -83,7 +83,7 @@ from pylot.core.io.location import create_creation_info, create_event
|
|||||||
from pylot.core.util.widgets import FilterOptionsDialog, NewEventDlg, \
|
from pylot.core.util.widgets import FilterOptionsDialog, NewEventDlg, \
|
||||||
PylotCanvas, WaveformWidgetPG, PropertiesDlg, HelpForm, createAction, PickDlg, \
|
PylotCanvas, WaveformWidgetPG, PropertiesDlg, HelpForm, createAction, PickDlg, \
|
||||||
ComparisonWidget, TuneAutopicker, PylotParaBox, AutoPickDlg, CanvasWidget, AutoPickWidget, \
|
ComparisonWidget, TuneAutopicker, PylotParaBox, AutoPickDlg, CanvasWidget, AutoPickWidget, \
|
||||||
CompareEventsWidget, ProgressBarWidget, AddMetadataWidget, FileExtensionDialog
|
CompareEventsWidget, ProgressBarWidget, AddMetadataWidget, SingleTextLineDialog
|
||||||
from pylot.core.util.array_map import Array_map
|
from pylot.core.util.array_map import Array_map
|
||||||
from pylot.core.util.structure import DATASTRUCTURE
|
from pylot.core.util.structure import DATASTRUCTURE
|
||||||
from pylot.core.util.thread import Thread, Worker
|
from pylot.core.util.thread import Thread, Worker
|
||||||
@ -167,6 +167,10 @@ class MainWindow(QMainWindow):
|
|||||||
# track deleted picks for logging
|
# track deleted picks for logging
|
||||||
self.deleted_picks = {}
|
self.deleted_picks = {}
|
||||||
|
|
||||||
|
# headers for event table
|
||||||
|
self.table_headers = ['', 'Event', 'Time', 'Lat', 'Lon', 'Depth', 'Mag', '[N] MP', '[N] AP', 'Tuning Set',
|
||||||
|
'Test Set', 'Notes']
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
if settings.value("user/FullName", None) is None:
|
if settings.value("user/FullName", None) is None:
|
||||||
@ -387,6 +391,10 @@ class MainWindow(QMainWindow):
|
|||||||
" source origin and magnitude.")
|
" source origin and magnitude.")
|
||||||
self.disableSaveEventAction()
|
self.disableSaveEventAction()
|
||||||
|
|
||||||
|
self.exportProjectTableAction = self.createAction(self, "Export Project table...",
|
||||||
|
self.exportProjectTableDialogs, None,
|
||||||
|
None, "Export Project table (csv)")
|
||||||
|
|
||||||
self.addEventDataAction = self.createAction(self, "Add &events ...",
|
self.addEventDataAction = self.createAction(self, "Add &events ...",
|
||||||
self.add_events,
|
self.add_events,
|
||||||
"Ctrl+E", addIcon,
|
"Ctrl+E", addIcon,
|
||||||
@ -546,6 +554,7 @@ class MainWindow(QMainWindow):
|
|||||||
self.saveProjectAsAction, None,
|
self.saveProjectAsAction, None,
|
||||||
self.addEventDataAction,
|
self.addEventDataAction,
|
||||||
self.openEventAction, self.saveEventAction, None,
|
self.openEventAction, self.saveEventAction, None,
|
||||||
|
self.exportProjectTableAction, None,
|
||||||
quitAction)
|
quitAction)
|
||||||
self.fileMenu.aboutToShow.connect(self.updateFileMenu)
|
self.fileMenu.aboutToShow.connect(self.updateFileMenu)
|
||||||
self.updateFileMenu()
|
self.updateFileMenu()
|
||||||
@ -948,10 +957,10 @@ class MainWindow(QMainWindow):
|
|||||||
return
|
return
|
||||||
refresh = False
|
refresh = False
|
||||||
events = self.project.eventlist
|
events = self.project.eventlist
|
||||||
fed = FileExtensionDialog()
|
sld = SingleTextLineDialog(label='Specify file extension: ', default_text='.xml')
|
||||||
if not fed.exec_():
|
if not sld.exec_():
|
||||||
return
|
return
|
||||||
fext = fed.file_extension.text()
|
fext = sld.lineEdit.text()
|
||||||
#fext = '.xml'
|
#fext = '.xml'
|
||||||
for event in events:
|
for event in events:
|
||||||
path = event.path
|
path = event.path
|
||||||
@ -3146,6 +3155,7 @@ class MainWindow(QMainWindow):
|
|||||||
self.setDirty(True)
|
self.setDirty(True)
|
||||||
|
|
||||||
current_event = self.get_current_event()
|
current_event = self.get_current_event()
|
||||||
|
scroll_item = None
|
||||||
|
|
||||||
# generate delete icon
|
# generate delete icon
|
||||||
del_icon = QIcon()
|
del_icon = QIcon()
|
||||||
@ -3160,18 +3170,7 @@ class MainWindow(QMainWindow):
|
|||||||
self.event_table = QtGui.QTableWidget(self)
|
self.event_table = QtGui.QTableWidget(self)
|
||||||
self.event_table.setColumnCount(12)
|
self.event_table.setColumnCount(12)
|
||||||
self.event_table.setRowCount(len(eventlist))
|
self.event_table.setRowCount(len(eventlist))
|
||||||
self.event_table.setHorizontalHeaderLabels(['',
|
self.event_table.setHorizontalHeaderLabels(self.table_headers)
|
||||||
'Event',
|
|
||||||
'Time',
|
|
||||||
'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 = []
|
||||||
@ -3257,6 +3256,9 @@ class MainWindow(QMainWindow):
|
|||||||
|
|
||||||
self.setItemColor(column, index, event, current_event)
|
self.setItemColor(column, index, event, current_event)
|
||||||
|
|
||||||
|
if event == current_event:
|
||||||
|
scroll_item = item_path
|
||||||
|
|
||||||
# manipulate items
|
# manipulate items
|
||||||
item_ref.setBackground(self._ref_test_colors['ref'])
|
item_ref.setBackground(self._ref_test_colors['ref'])
|
||||||
item_test.setBackground(self._ref_test_colors['test'])
|
item_test.setBackground(self._ref_test_colors['test'])
|
||||||
@ -3277,6 +3279,55 @@ class MainWindow(QMainWindow):
|
|||||||
self.events_layout.addWidget(self.event_table)
|
self.events_layout.addWidget(self.event_table)
|
||||||
self.tabs.setCurrentIndex(tabindex)
|
self.tabs.setCurrentIndex(tabindex)
|
||||||
|
|
||||||
|
self.event_table.scrollToItem(scroll_item)
|
||||||
|
|
||||||
|
def exportProjectTableDialogs(self):
|
||||||
|
if not self.project or not self.project._table:
|
||||||
|
QMessageBox.warning(self, 'Nothing to export', 'No project or no project table to export yet!')
|
||||||
|
return
|
||||||
|
|
||||||
|
sld = SingleTextLineDialog(label='Specify separator (do not use within notes!): ', default_text=';')
|
||||||
|
if not sld.exec_():
|
||||||
|
return
|
||||||
|
separator = sld.lineEdit.text()
|
||||||
|
|
||||||
|
fd = QtGui.QFileDialog()
|
||||||
|
fname = fd.getSaveFileName(self, 'Browse for file.',
|
||||||
|
filter='Table (*.csv)')[0]
|
||||||
|
if not fname: return
|
||||||
|
|
||||||
|
if not fname.endswith('.csv'):
|
||||||
|
fname += '.csv'
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.exportProjectTable(fname, separator)
|
||||||
|
except Exception as e:
|
||||||
|
QMessageBox.warning(self, 'Could not save file',
|
||||||
|
'Could not save file {}.'.format(fname))
|
||||||
|
return
|
||||||
|
|
||||||
|
def exportProjectTable(self, filename, separator=';'):
|
||||||
|
with open(filename, 'w') as outfile:
|
||||||
|
for header in self.table_headers[1:12]:
|
||||||
|
outfile.write('{}{}'.format(header, separator))
|
||||||
|
outfile.write('\n')
|
||||||
|
|
||||||
|
for row in self.project._table:
|
||||||
|
row = row[1:12]
|
||||||
|
event, time, lat, lon, depth, mag, nmp, nap, tune, test, notes = row
|
||||||
|
row_str = ''
|
||||||
|
for index in range(len(row)):
|
||||||
|
row_str += '{}'+'{}'.format(separator)
|
||||||
|
|
||||||
|
row_str = row_str.format(event.text(), time.text(), lat.text(), lon.text(), depth.text(), mag.text(),
|
||||||
|
nmp.text(), nap.text(), bool(tune.checkState()), bool(test.checkState()),
|
||||||
|
notes.text())
|
||||||
|
outfile.write(row_str + '\n')
|
||||||
|
|
||||||
|
message = 'Wrote table to file: {}'.format(filename)
|
||||||
|
print(message)
|
||||||
|
self.update_status(message)
|
||||||
|
|
||||||
def setItemColor(self, item_list, index, event, current_event):
|
def setItemColor(self, item_list, index, event, current_event):
|
||||||
def set_background_color(items, color):
|
def set_background_color(items, color):
|
||||||
for item in items:
|
for item in items:
|
||||||
@ -3295,6 +3346,7 @@ class MainWindow(QMainWindow):
|
|||||||
if event == current_event:
|
if event == current_event:
|
||||||
set_background_color(item_list, QtGui.QColor(*(0, 143, 143, 255)))
|
set_background_color(item_list, QtGui.QColor(*(0, 143, 143, 255)))
|
||||||
|
|
||||||
|
|
||||||
def set_metadata(self):
|
def set_metadata(self):
|
||||||
self.project.inventories = self.metadata.inventories
|
self.project.inventories = self.metadata.inventories
|
||||||
if self.metadata.inventories:
|
if self.metadata.inventories:
|
||||||
|
@ -1 +1 @@
|
|||||||
python ./autoPyLoT.py -i /home/marcel/.pylot/pylot_alparray_mantle.in -dmt processed -c $NSLOTS
|
python ./autoPyLoT.py -i /home/marcel/.pylot/pylot_alparray_mantle_m6.0-6.4.in -dmt processed -c $NSLOTS
|
||||||
|
@ -17,7 +17,7 @@ plt.interactive(False)
|
|||||||
|
|
||||||
|
|
||||||
class Array_map(QtGui.QWidget):
|
class Array_map(QtGui.QWidget):
|
||||||
def __init__(self, parent, figure=None):
|
def __init__(self, parent, figure=None, pointsize=30.):
|
||||||
'''
|
'''
|
||||||
Create a map of the array.
|
Create a map of the array.
|
||||||
:param parent: PyLoT Mainwindow class
|
:param parent: PyLoT Mainwindow class
|
||||||
@ -26,6 +26,7 @@ class Array_map(QtGui.QWidget):
|
|||||||
QtGui.QWidget.__init__(self)
|
QtGui.QWidget.__init__(self)
|
||||||
self._parent = parent
|
self._parent = parent
|
||||||
self.metadata = parent.metadata
|
self.metadata = parent.metadata
|
||||||
|
self.pointsize = pointsize
|
||||||
self.picks = None
|
self.picks = None
|
||||||
self.picks_dict = None
|
self.picks_dict = None
|
||||||
self.autopicks_dict = None
|
self.autopicks_dict = None
|
||||||
@ -432,7 +433,7 @@ class Array_map(QtGui.QWidget):
|
|||||||
|
|
||||||
def scatter_all_stations(self):
|
def scatter_all_stations(self):
|
||||||
stations, lats, lons = self.get_st_lat_lon_for_plot()
|
stations, lats, lons = self.get_st_lat_lon_for_plot()
|
||||||
self.sc = self.basemap.scatter(lons, lats, s=50, facecolor='none', latlon=True,
|
self.sc = self.basemap.scatter(lons, lats, s=self.pointsize, 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)
|
||||||
self._station_onpick_ids = stations
|
self._station_onpick_ids = stations
|
||||||
@ -449,10 +450,10 @@ class Array_map(QtGui.QWidget):
|
|||||||
cmap = self.get_colormap()
|
cmap = self.get_colormap()
|
||||||
# workaround because of an issue with latlon transformation of arrays with len <3
|
# workaround because of an issue with latlon transformation of arrays with len <3
|
||||||
if len(lons) <= 2 and len(lats) <= 2:
|
if len(lons) <= 2 and len(lats) <= 2:
|
||||||
self.sc_picked = self.basemap.scatter(lons[0], lats[0], s=50, edgecolors='white', cmap=cmap,
|
self.sc_picked = self.basemap.scatter(lons[0], lats[0], s=self.pointsize, edgecolors='white', cmap=cmap,
|
||||||
c=picks[0], latlon=True, zorder=11)
|
c=picks[0], latlon=True, zorder=11)
|
||||||
if len(lons) == 2 and len(lats) == 2:
|
if len(lons) == 2 and len(lats) == 2:
|
||||||
self.sc_picked = self.basemap.scatter(lons[1], lats[1], s=50, edgecolors='white', cmap=cmap,
|
self.sc_picked = self.basemap.scatter(lons[1], lats[1], s=self.pointsize, edgecolors='white', cmap=cmap,
|
||||||
c=picks[1], latlon=True, zorder=11)
|
c=picks[1], latlon=True, zorder=11)
|
||||||
else:
|
else:
|
||||||
self.sc_picked = self.basemap.scatter(lons, lats, s=50, edgecolors='white', cmap=cmap,
|
self.sc_picked = self.basemap.scatter(lons, lats, s=50, edgecolors='white', cmap=cmap,
|
||||||
@ -474,7 +475,8 @@ class Array_map(QtGui.QWidget):
|
|||||||
if st in self.marked_stations:
|
if st in self.marked_stations:
|
||||||
color = 'red'
|
color = 'red'
|
||||||
self.annotations.append(self.main_ax.annotate(' %s' % st, xy=(x, y),
|
self.annotations.append(self.main_ax.annotate(' %s' % st, xy=(x, y),
|
||||||
fontsize='x-small', color=color, zorder=14))
|
fontsize='x-small', fontweight='semibold',
|
||||||
|
color=color, zorder=14))
|
||||||
self.legend = self.main_ax.legend(loc=1)
|
self.legend = self.main_ax.legend(loc=1)
|
||||||
self.legend.get_frame().set_facecolor((1, 1, 1, 0.75))
|
self.legend.get_frame().set_facecolor((1, 1, 1, 0.75))
|
||||||
|
|
||||||
|
@ -1489,10 +1489,11 @@ class PylotCanvas(FigureCanvas):
|
|||||||
self.draw()
|
self.draw()
|
||||||
|
|
||||||
|
|
||||||
class FileExtensionDialog(QtGui.QDialog):
|
class SingleTextLineDialog(QtGui.QDialog):
|
||||||
def __init__(self, parent=None, default_extension='.xml'):
|
def __init__(self, parent=None, label='Text: ', default_text='.xml'):
|
||||||
super(FileExtensionDialog, self).__init__(parent)
|
super(SingleTextLineDialog, self).__init__(parent)
|
||||||
self.default_extension = default_extension
|
self.default_text = default_text
|
||||||
|
self.label = label
|
||||||
self.setButtons()
|
self.setButtons()
|
||||||
self.connectSignals()
|
self.connectSignals()
|
||||||
self.setupUi()
|
self.setupUi()
|
||||||
@ -1502,11 +1503,11 @@ class FileExtensionDialog(QtGui.QDialog):
|
|||||||
self.sub_layout = QtGui.QHBoxLayout()
|
self.sub_layout = QtGui.QHBoxLayout()
|
||||||
#
|
#
|
||||||
self.setLayout(self.main_layout)
|
self.setLayout(self.main_layout)
|
||||||
self.textLabel = QtGui.QLabel('Specify file extension: ')
|
self.textLabel = QtGui.QLabel(self.label)
|
||||||
self.file_extension = QtGui.QLineEdit(self.default_extension)
|
self.lineEdit = QtGui.QLineEdit(self.default_text)
|
||||||
|
|
||||||
self.sub_layout.addWidget(self.textLabel)
|
self.sub_layout.addWidget(self.textLabel)
|
||||||
self.sub_layout.addWidget(self.file_extension)
|
self.sub_layout.addWidget(self.lineEdit)
|
||||||
|
|
||||||
self.main_layout.addLayout(self.sub_layout)
|
self.main_layout.addLayout(self.sub_layout)
|
||||||
self.main_layout.addWidget(self._buttonbox)
|
self.main_layout.addWidget(self._buttonbox)
|
||||||
|
Loading…
Reference in New Issue
Block a user