diff --git a/pylot/core/util/map_projection.py b/pylot/core/util/map_projection.py index acb705a1..51e3f87f 100644 --- a/pylot/core/util/map_projection.py +++ b/pylot/core/util/map_projection.py @@ -4,23 +4,24 @@ import matplotlib.pyplot as plt import numpy as np import obspy -from PySide2 import QtGui +from PySide2 import QtWidgets from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar -from mpl_toolkits.basemap import Basemap +import cartopy +import cartopy.feature as cpf from pylot.core.util.widgets import PickDlg from scipy.interpolate import griddata plt.interactive(False) -class map_projection(QtGui.QWidget): +class map_projection(QtWidgets.QWidget): def __init__(self, parent, figure=None): ''' :param: picked, can be False, auto, manual :value: str ''' - QtGui.QWidget.__init__(self) + QtWidgets.QWidget.__init__(self) self._parent = parent self.metadata = parent.metadata self.parser = parent.metadata[1] @@ -30,14 +31,13 @@ class map_projection(QtGui.QWidget): self.figure = figure self.init_graphics() self.init_stations() - self.init_basemap(resolution='l') + self.init_basemap() self.init_map() # self.show() def init_map(self): self.init_lat_lon_dimensions() self.init_lat_lon_grid() - self.init_x_y_dimensions() self.connectSignals() self.draw_everything() @@ -83,7 +83,7 @@ class map_projection(QtGui.QWidget): def connectSignals(self): self.comboBox_phase.currentIndexChanged.connect(self._refresh_drawings) - self.zoom_id = self.basemap.ax.figure.canvas.mpl_connect('scroll_event', self.zoom) + self.zoom_id = self.main_ax.figure.canvas.mpl_connect('scroll_event', self.zoom) def init_graphics(self): if not self.figure: @@ -97,21 +97,21 @@ class map_projection(QtGui.QWidget): self.main_ax = self.figure.add_subplot(111) self.canvas = self.figure.canvas - self.main_box = QtGui.QVBoxLayout() + self.main_box = QtWidgets.QVBoxLayout() self.setLayout(self.main_box) - self.top_row = QtGui.QHBoxLayout() + self.top_row = QtWidgets.QHBoxLayout() self.main_box.addLayout(self.top_row) - self.comboBox_phase = QtGui.QComboBox() + self.comboBox_phase = QtWidgets.QComboBox() self.comboBox_phase.insertItem(0, 'P') self.comboBox_phase.insertItem(1, 'S') - self.comboBox_am = QtGui.QComboBox() + self.comboBox_am = QtWidgets.QComboBox() self.comboBox_am.insertItem(0, 'auto') self.comboBox_am.insertItem(1, 'manual') - self.top_row.addWidget(QtGui.QLabel('Select a phase: ')) + self.top_row.addWidget(QtWidgets.QLabel('Select a phase: ')) self.top_row.addWidget(self.comboBox_phase) self.top_row.setStretch(1, 1) # set stretch of item 1 to 1 @@ -196,29 +196,17 @@ class map_projection(QtGui.QWidget): self.londim, self.latdim = get_lon_lat_dim(self.lon, self.lat) - def init_x_y_dimensions(self): - def get_x_y_dim(x, y): - xdim = max(x) - min(x) - ydim = max(y) - min(y) - return xdim, ydim - - self.x, self.y = self.basemap(self.lon, self.lat) - self.xdim, self.ydim = get_x_y_dim(self.x, self.y) - def init_basemap(self, resolution='l'): - # basemap = Basemap(projection=projection, resolution = resolution, ax=self.main_ax) - basemap = Basemap(projection='lcc', resolution=resolution, ax=self.main_ax, - width=5e6, height=2e6, - lat_0=(min(self.lat) + max(self.lat)) / 2., - lon_0=(min(self.lon) + max(self.lon)) / 2.) + ax = self.main_ax(projection=cartopy.crs.PlateCarree()) - # basemap.fillcontinents(color=None, lake_color='aqua',zorder=1) - basemap.drawmapboundary(zorder=2) # fill_color='darkblue') - basemap.shadedrelief(zorder=3) - basemap.drawcountries(zorder=4) - basemap.drawstates(zorder=5) - basemap.drawcoastlines(zorder=6) - self.basemap = basemap + ax.add_feature(cpf.LAND) + ax.add_feature(cpf.OCEAN) + ax.add_feature(cpf.COASTLINE) + ax.add_feature(cpf.BORDERS, linestyle=':') + ax.add_feature(cpf.LAKES, alpha=0.5) + ax.add_feature(cpf.RIVERS) + + ax.set_extent([min(self.lon), max(self.lon), min(self.lat), max(self.lat)]) self.figure.tight_layout() def init_lat_lon_grid(self): @@ -244,16 +232,16 @@ class map_projection(QtGui.QWidget): def draw_contour_filled(self, nlevel='50'): levels = np.linspace(min(self.picks_no_nan), max(self.picks_no_nan), nlevel) - self.contourf = self.basemap.contourf(self.longrid, self.latgrid, self.picksgrid_no_nan, + self.contourf = self.main_ax.contourf(self.longrid, self.latgrid, self.picksgrid_no_nan, levels, latlon=True, zorder=9, alpha=0.5) def scatter_all_stations(self): - self.sc = self.basemap.scatter(self.lon, self.lat, s=50, facecolor='none', latlon=True, + self.sc = self.main_ax.scatter(self.lon, self.lat, s=50, facecolor='none', latlon=True, zorder=10, picker=True, edgecolor='m', label='Not Picked') 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', + self.sc_event = self.main_ax.scatter(lon, lat, s=100, facecolor='red', latlon=True, zorder=11, label='Event (might be outside map region)') def scatter_picked_stations(self): @@ -262,13 +250,13 @@ class map_projection(QtGui.QWidget): # workaround because of an issue with latlon transformation of arrays with len <3 if len(lon) <= 2 and len(lat) <= 2: - self.sc_picked = self.basemap.scatter(lon[0], lat[0], s=50, facecolor='white', + self.sc_picked = self.main_ax.scatter(lon[0], lat[0], s=50, facecolor='white', c=self.picks_no_nan[0], latlon=True, zorder=11, label='Picked') if len(lon) == 2 and len(lat) == 2: - self.sc_picked = self.basemap.scatter(lon[1], lat[1], s=50, facecolor='white', + self.sc_picked = self.main_ax.scatter(lon[1], lat[1], s=50, facecolor='white', c=self.picks_no_nan[1], latlon=True, zorder=11) else: - self.sc_picked = self.basemap.scatter(lon, lat, s=50, facecolor='white', + self.sc_picked = self.main_ax.scatter(lon, lat, s=50, facecolor='white', c=self.picks_no_nan, latlon=True, zorder=11, label='Picked') def annotate_ax(self): @@ -344,7 +332,7 @@ class map_projection(QtGui.QWidget): annotation.remove() def zoom(self, event): - map = self.basemap + map = self.main_ax xlim = map.ax.get_xlim() ylim = map.ax.get_ylim() x, y = event.xdata, event.ydata @@ -371,6 +359,6 @@ class map_projection(QtGui.QWidget): map.ax.figure.canvas.draw() def _warn(self, message): - self.qmb = QtGui.QMessageBox(QtGui.QMessageBox.Icon.Warning, + self.qmb = QtWidgets.QMessageBox(QtWidgets.QMessageBox.Icon.Warning, 'Warning', message) self.qmb.show()