feature/port-to-py3 #11
@ -32,14 +32,19 @@ from pylot.core.pick.utils import get_quality_class
|
||||
|
||||
class MplCanvas(FigureCanvas):
|
||||
|
||||
def __init__(self, parent=None, width=5, height=4, dpi=100):
|
||||
self.fig = plt.figure(figsize=(width, height), dpi=dpi)
|
||||
self.axes = self.fig.add_subplot(111)
|
||||
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.axes = self.fig.add_subplot(111)
|
||||
else:
|
||||
self.fig = extern_axes.figure
|
||||
self.axes = extern_axes
|
||||
|
||||
super(MplCanvas, self).__init__(self.fig)
|
||||
|
||||
|
||||
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):
|
||||
# super(Array_map, self).__init__(parent)
|
||||
QtWidgets.QWidget.__init__(self)
|
||||
@ -50,6 +55,7 @@ class Array_map(QtWidgets.QWidget):
|
||||
self.metadata = metadata
|
||||
self.pointsize = pointsize
|
||||
self.linewidth = linewidth
|
||||
self.extern_plot_axes = axes
|
||||
self.width = width
|
||||
self.height = height
|
||||
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
|
||||
"""
|
||||
# initialize figure elements
|
||||
self.canvas = MplCanvas(self)
|
||||
self.plotWidget = FigureCanvas(self.canvas.fig)
|
||||
|
||||
if self.extern_plot_axes is None:
|
||||
self.canvas = MplCanvas(self)
|
||||
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
|
||||
self.status_label = QtWidgets.QLabel()
|
||||
@ -173,7 +186,7 @@ class Array_map(QtWidgets.QWidget):
|
||||
# self.plotWidget.draw_idle()
|
||||
|
||||
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.
|
||||
# Should be fixed with next cartopy version
|
||||
kaan marked this conversation as resolved
|
||||
# self.gridlines.xformatter = LONGITUDE_FORMATTER
|
||||
@ -572,13 +585,14 @@ class Array_map(QtWidgets.QWidget):
|
||||
if st in self.marked_stations:
|
||||
color = 'red'
|
||||
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,
|
||||
transform=ccrs.PlateCarree(), zorder=14,
|
||||
path_effects=[
|
||||
PathEffects.withStroke(linewidth=self.pointsize / 6., foreground='k')]))
|
||||
self.legend = self.canvas.axes.legend(loc=1)
|
||||
self.legend.get_frame().set_facecolor((1, 1, 1, 0.75))
|
||||
path_effects=[PathEffects.withStroke(
|
||||
linewidth=self.pointsize / 15., foreground='k')]))
|
||||
|
||||
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):
|
||||
self.cbax_bg = inset_axes(self.canvas.axes, width="6%", height="75%", loc=5)
|
||||
|
@ -4,6 +4,11 @@
|
||||
|
||||
import os
|
||||
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.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)
|
||||
nEvents = len(project.eventlist)
|
||||
input_list = []
|
||||
|
||||
print('\n')
|
||||
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,
|
||||
file_format=file_format, f_ext=f_ext)
|
||||
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)
|
||||
else:
|
||||
pool = multiprocessing.Pool(ncores)
|
||||
result = pool.map(array_map_worker, input_list)
|
||||
pool.map(array_map_worker, input_list)
|
||||
pool.close()
|
||||
pool.join()
|
||||
|
||||
@ -40,6 +41,10 @@ def array_map_worker(input_dict):
|
||||
event = input_dict['event']
|
||||
eventdir = event.path
|
||||
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
|
||||
manualpicks = event.getPicks()
|
||||
autopicks = event.getAutopicks()
|
||||
@ -53,11 +58,12 @@ def array_map_worker(input_dict):
|
||||
continue
|
||||
if not metadata:
|
||||
metadata = Metadata(inventory=metadata_path, verbosity=0)
|
||||
|
||||
# create figure to plot on
|
||||
fig = plt.figure(figsize=(16, 9))
|
||||
fig, ax = plt.subplots(figsize=(16, 9))
|
||||
# create array map object
|
||||
map = Array_map(None, metadata, parameter=input_dict['project'].parameter, figure=fig,
|
||||
width=2.13e6, height=1.2e6, pointsize=15., linewidth=1.0)
|
||||
map = Array_map(None, metadata, parameter=input_dict['project'].parameter, axes=ax,
|
||||
width=2.13e6, height=1.2e6, pointsize=25., linewidth=1.0)
|
||||
# set combobox to auto/manual to plot correct pick type
|
||||
map.comboBox_am.setCurrentIndex(map.comboBox_am.findText(pick_type))
|
||||
# add picks to map and save file
|
||||
@ -69,10 +75,10 @@ def array_map_worker(input_dict):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
dataroot = '/home/marcel'
|
||||
infiles = ['alparray_all_events_0.03-0.1_mantle_correlated_v3.plp']
|
||||
dataroot = '/home/kaan/master_thesis/waveformData/dmt_dir_proj'
|
||||
infiles = ['mag_8_sym_proj.plp']
|
||||
|
||||
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('/home/marcel/alparray_m6.5-6.9_mantle_correlated_v3.plp', f_ext='_correlated_0.5Hz')
|
||||
|
@ -34,17 +34,25 @@ def qml_from_obspyDMT(path):
|
||||
|
||||
if not os.path.exists(path):
|
||||
return IOError('Could not find Event at {}'.format(path))
|
||||
infile = open(path, 'rb')
|
||||
event_dmt = pickle.load(infile)#, fix_imports=True)
|
||||
|
||||
with open(path, 'rb') as infile:
|
||||
event_dmt = pickle.load(infile)#, fix_imports=True)
|
||||
|
||||
event_dmt['origin_id'].id = str(event_dmt['origin_id'].id)
|
||||
|
||||
ev = Event(resource_id=event_dmt['event_id'])
|
||||
#small bugfix "unhashable type: 'newstr' "
|
||||
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'])
|
||||
mag = Magnitude(mag=event_dmt['magnitude'], magnitude_type=event_dmt['magnitude_type'],
|
||||
|
||||
origin = Origin(resource_id=event_dmt['origin_id'],
|
||||
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'])
|
||||
|
||||
ev.magnitudes.append(mag)
|
||||
ev.origins.append(origin)
|
||||
return ev
|
||||
|
Loading…
Reference in New Issue
Block a user
consider adding "TODO:" comment for future releases of cartopy