feature/port-to-py3 #11

Merged
marcel merged 59 commits from feature/port-to-py3 into develop 2022-03-21 15:30:06 +01:00
3 changed files with 57 additions and 29 deletions
Showing only changes of commit 4fd27994f6 - Show all commits

View File

@ -32,14 +32,19 @@ from pylot.core.pick.utils import get_quality_class
class MplCanvas(FigureCanvas): class MplCanvas(FigureCanvas):
def __init__(self, parent=None, width=5, height=4, dpi=100): def __init__(self, parent=None, extern_axes=None, width=5, height=4, dpi=100):
if extern_axes is None:
self.fig = plt.figure(figsize=(width, height), dpi=dpi) self.fig = plt.figure(figsize=(width, height), dpi=dpi)
self.axes = self.fig.add_subplot(111) self.axes = self.fig.add_subplot(111)
else:
self.fig = extern_axes.figure
self.axes = extern_axes
super(MplCanvas, self).__init__(self.fig) super(MplCanvas, self).__init__(self.fig)
class Array_map(QtWidgets.QWidget): class Array_map(QtWidgets.QWidget):
def __init__(self, parent, metadata, parameter=None, figure=None, annotate=True, pointsize=25., def __init__(self, parent, metadata, parameter=None, axes=None, annotate=True, pointsize=25.,
linewidth=1.5, width=5e6, height=2e6): linewidth=1.5, width=5e6, height=2e6):
# super(Array_map, self).__init__(parent) # super(Array_map, self).__init__(parent)
QtWidgets.QWidget.__init__(self) QtWidgets.QWidget.__init__(self)
@ -50,6 +55,7 @@ class Array_map(QtWidgets.QWidget):
self.metadata = metadata self.metadata = metadata
self.pointsize = pointsize self.pointsize = pointsize
self.linewidth = linewidth self.linewidth = linewidth
self.extern_plot_axes = axes
self.width = width self.width = width
self.height = height self.height = height
self.annotate = annotate self.annotate = annotate
@ -91,8 +97,15 @@ class Array_map(QtWidgets.QWidget):
Initializes all GUI components and figure elements to be populeted by other functions Initializes all GUI components and figure elements to be populeted by other functions
""" """
# initialize figure elements # initialize figure elements
if self.extern_plot_axes is None:
self.canvas = MplCanvas(self) self.canvas = MplCanvas(self)
self.plotWidget = FigureCanvas(self.canvas.fig) self.plotWidget = FigureCanvas(self.canvas.fig)
else:
self.canvas = MplCanvas(self, extern_axes=self.extern_plot_axes)
#self.canvas.axes = self.extern_plot_axes
#self.canvas.fig = self.extern_plot_axes.figure
self.plotWidget = FigureCanvas(self.canvas.fig)
# initialize GUI elements # initialize GUI elements
self.status_label = QtWidgets.QLabel() self.status_label = QtWidgets.QLabel()
@ -173,7 +186,7 @@ class Array_map(QtWidgets.QWidget):
# self.plotWidget.draw_idle() # self.plotWidget.draw_idle()
def add_merid_paral(self): def add_merid_paral(self):
self.gridlines = self.canvas.axes.gridlines(draw_labels=False, alpha=0.5, zorder=7) self.gridlines = self.canvas.axes.gridlines(draw_labels=False, alpha=0.8, color='dimgray', linewidth=self.linewidth, zorder=7)
# current cartopy version does not support label removal. Devs are working on it. # current cartopy version does not support label removal. Devs are working on it.
# Should be fixed with next cartopy version # Should be fixed with next cartopy version
kaan marked this conversation as resolved
Review

consider adding "TODO:" comment for future releases of cartopy

consider adding "TODO:" comment for future releases of cartopy
# self.gridlines.xformatter = LONGITUDE_FORMATTER # self.gridlines.xformatter = LONGITUDE_FORMATTER
@ -572,13 +585,14 @@ class Array_map(QtWidgets.QWidget):
if st in self.marked_stations: if st in self.marked_stations:
color = 'red' color = 'red'
self.annotations.append( self.annotations.append(
self.canvas.axes.annotate(' %s' % st, xy=(x + 0.003, y + 0.003), fontsize=self.pointsize / 5., self.canvas.axes.annotate(' %s' % st, xy=(x + 0.003, y + 0.003), fontsize=self.pointsize / 4.,
fontweight='semibold', color=color, alpha=0.8, fontweight='semibold', color=color, alpha=0.8,
transform=ccrs.PlateCarree(), zorder=14, transform=ccrs.PlateCarree(), zorder=14,
path_effects=[ path_effects=[PathEffects.withStroke(
PathEffects.withStroke(linewidth=self.pointsize / 6., foreground='k')])) linewidth=self.pointsize / 15., foreground='k')]))
self.legend = self.canvas.axes.legend(loc=1)
self.legend.get_frame().set_facecolor((1, 1, 1, 0.75)) self.legend = self.canvas.axes.legend(loc=1, framealpha=1)
self.legend.get_frame().set_facecolor((1, 1, 1, 0.95))
def add_cbar(self, label): def add_cbar(self, label):
self.cbax_bg = inset_axes(self.canvas.axes, width="6%", height="75%", loc=5) self.cbax_bg = inset_axes(self.canvas.axes, width="6%", height="75%", loc=5)

View File

@ -4,6 +4,11 @@
import os import os
import multiprocessing import multiprocessing
import sys
import glob
import matplotlib
matplotlib.use('Qt5Agg')
sys.path.append(os.path.join('/'.join(sys.argv[0].split('/')[:-1]), '../../..'))
from PyLoT import Project from PyLoT import Project
from pylot.core.util.dataprocessing import Metadata from pylot.core.util.dataprocessing import Metadata
@ -16,12 +21,8 @@ def main(project_file_path, manual=False, auto=True, file_format='png', f_ext=''
project = Project.load(project_file_path) project = Project.load(project_file_path)
nEvents = len(project.eventlist) nEvents = len(project.eventlist)
input_list = [] input_list = []
print('\n')
for index, event in enumerate(project.eventlist): for index, event in enumerate(project.eventlist):
# MP MP TESTING +++
# if not eventdir.endswith('20170908_044946.a'):
# continue
# MP MP ----
kwargs = dict(project=project, event=event, nEvents=nEvents, index=index, manual=manual, auto=auto, kwargs = dict(project=project, event=event, nEvents=nEvents, index=index, manual=manual, auto=auto,
file_format=file_format, f_ext=f_ext) file_format=file_format, f_ext=f_ext)
input_list.append(kwargs) input_list.append(kwargs)
@ -31,7 +32,7 @@ def main(project_file_path, manual=False, auto=True, file_format='png', f_ext=''
array_map_worker(item) array_map_worker(item)
else: else:
pool = multiprocessing.Pool(ncores) pool = multiprocessing.Pool(ncores)
result = pool.map(array_map_worker, input_list) pool.map(array_map_worker, input_list)
pool.close() pool.close()
pool.join() pool.join()
@ -40,6 +41,10 @@ def array_map_worker(input_dict):
event = input_dict['event'] event = input_dict['event']
eventdir = event.path eventdir = event.path
print('Working on event: {} ({}/{})'.format(eventdir, input_dict['index'] + 1, input_dict['nEvents'])) print('Working on event: {} ({}/{})'.format(eventdir, input_dict['index'] + 1, input_dict['nEvents']))
xml_picks = glob.glob(os.path.join(eventdir, f'*{input_dict["f_ext"]}.xml'))
if not len(xml_picks):
print('Event {} does not have any picks associated with event file extension {}'. format(eventdir, input_dict['f_ext']))
return
# check for picks # check for picks
manualpicks = event.getPicks() manualpicks = event.getPicks()
autopicks = event.getAutopicks() autopicks = event.getAutopicks()
@ -53,11 +58,12 @@ def array_map_worker(input_dict):
continue continue
if not metadata: if not metadata:
metadata = Metadata(inventory=metadata_path, verbosity=0) metadata = Metadata(inventory=metadata_path, verbosity=0)
# create figure to plot on # create figure to plot on
fig = plt.figure(figsize=(16, 9)) fig, ax = plt.subplots(figsize=(16, 9))
# create array map object # create array map object
map = Array_map(None, metadata, parameter=input_dict['project'].parameter, figure=fig, map = Array_map(None, metadata, parameter=input_dict['project'].parameter, axes=ax,
width=2.13e6, height=1.2e6, pointsize=15., linewidth=1.0) width=2.13e6, height=1.2e6, pointsize=25., linewidth=1.0)
# set combobox to auto/manual to plot correct pick type # set combobox to auto/manual to plot correct pick type
map.comboBox_am.setCurrentIndex(map.comboBox_am.findText(pick_type)) map.comboBox_am.setCurrentIndex(map.comboBox_am.findText(pick_type))
# add picks to map and save file # add picks to map and save file
@ -69,10 +75,10 @@ def array_map_worker(input_dict):
if __name__ == '__main__': if __name__ == '__main__':
dataroot = '/home/marcel' dataroot = '/home/kaan/master_thesis/waveformData/dmt_dir_proj'
infiles = ['alparray_all_events_0.03-0.1_mantle_correlated_v3.plp'] infiles = ['mag_8_sym_proj.plp']
for infile in infiles: for infile in infiles:
main(os.path.join(dataroot, infile), f_ext='_correlated_0.1Hz', ncores=10) main(os.path.join(dataroot, infile), f_ext='_correlated_0.03-0.1', ncores=1)
# main('E:\Shared\AlpArray\\test_aa.plp', f_ext='_correlated_0.5Hz', ncores=1) # main('E:\Shared\AlpArray\\test_aa.plp', f_ext='_correlated_0.5Hz', ncores=1)
# main('/home/marcel/alparray_m6.5-6.9_mantle_correlated_v3.plp', f_ext='_correlated_0.5Hz') # main('/home/marcel/alparray_m6.5-6.9_mantle_correlated_v3.plp', f_ext='_correlated_0.5Hz')

View File

@ -34,17 +34,25 @@ def qml_from_obspyDMT(path):
if not os.path.exists(path): if not os.path.exists(path):
return IOError('Could not find Event at {}'.format(path)) return IOError('Could not find Event at {}'.format(path))
infile = open(path, 'rb')
with open(path, 'rb') as infile:
event_dmt = pickle.load(infile)#, fix_imports=True) event_dmt = pickle.load(infile)#, fix_imports=True)
event_dmt['origin_id'].id = str(event_dmt['origin_id'].id) event_dmt['origin_id'].id = str(event_dmt['origin_id'].id)
ev = Event(resource_id=event_dmt['event_id']) ev = Event(resource_id=event_dmt['event_id'])
#small bugfix "unhashable type: 'newstr' " #small bugfix "unhashable type: 'newstr' "
event_dmt['origin_id'].id = str(event_dmt['origin_id'].id) event_dmt['origin_id'].id = str(event_dmt['origin_id'].id)
origin = Origin(resource_id=event_dmt['origin_id'], time=event_dmt['datetime'], longitude=event_dmt['longitude'],
latitude=event_dmt['latitude'], depth=event_dmt['depth']) origin = Origin(resource_id=event_dmt['origin_id'],
mag = Magnitude(mag=event_dmt['magnitude'], magnitude_type=event_dmt['magnitude_type'], time=event_dmt['datetime'],
longitude=event_dmt['longitude'],
latitude=event_dmt['latitude'],
depth=event_dmt['depth'])
mag = Magnitude(mag=event_dmt['magnitude'],
magnitude_type=event_dmt['magnitude_type'],
origin_id=event_dmt['origin_id']) origin_id=event_dmt['origin_id'])
ev.magnitudes.append(mag) ev.magnitudes.append(mag)
ev.origins.append(origin) ev.origins.append(origin)
return ev return ev