Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 60 additions & 23 deletions src/mintpy/plot_coherence_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,14 @@ class coherenceMatrixViewer():

def __init__(self, inps):
# figure variables
self.figname = 'Coherence matrix'
self.fig_size = None
self.fig = None
self.figname_img = 'Image'
Comment thread
yunjunz marked this conversation as resolved.
self.figsize_img = None
self.fig_img = None
self.ax_img = None

self.figname_mat = 'Coherence Matrix'
self.figsize_mat = None
self.fig_mat = None
self.ax_mat = None

# copy inps to self object
Expand All @@ -89,11 +93,20 @@ def open(self):
self = read_network_info(self)

# auto figure size
if not self.fig_size:
if not self.figsize_img:
ds_shape = readfile.read(self.img_file)[0].shape
fig_size = pp.auto_figure_size(ds_shape, disp_cbar=True, scale=0.7)
self.fig_size = [fig_size[0]+fig_size[1], fig_size[1]]
vprint(f'create figure in size of {self.fig_size} inches')
self.figsize_img = pp.auto_figure_size(ds_shape, disp_cbar=True, scale=0.7)
vprint(f'create image figure in size of {self.figsize_img} inches')

if not self.figsize_mat:
num_ifg = len(self.date12_list)
if num_ifg <= 50:
self.figsize_mat = [6, 5]
elif num_ifg <= 100:
self.figsize_mat = [8, 6]
else:
self.figsize_mat = [10, 8]
vprint(f'create matrix figure in size of {self.figsize_mat} inches')

# read aux data
# 1. temporal coherence value
Expand All @@ -111,11 +124,26 @@ def open(self):


def plot(self):
# Figure 1
self.fig = plt.figure(self.figname, figsize=self.fig_size)
# Figure 1 - Image
self.fig_img, self.ax_img = plt.subplots(num=self.figname_img, figsize=self.figsize_img)
self.plot_init_image()

# Figure 2 - Coherence Matrix
self.fig_mat, self.ax_mat = plt.subplots(num=self.figname_mat, figsize=self.figsize_mat)
self.colormap = pp.ColormapExt(self.cmap_name, vlist=self.cmap_vlist).colormap
if all(i is not None for i in self.yx):
self.plot_coherence_matrix4pixel(self.yx)

# Link the canvas to the plots.
self.cid_img = self.fig_img.canvas.mpl_connect('button_press_event', self.update_coherence_matrix)
self.cid_mat = self.fig_mat.canvas.mpl_connect('button_press_event', self.update_coherence_matrix)

if self.disp_fig:
plt.show()
return

# Axes 1 - Image
self.ax_img = self.fig.add_axes([0.05, 0.1, 0.4, 0.8])
def plot_init_image(self):
"""Plot the initial image."""
view_cmd = self.view_cmd.format(self.img_file)
d_img, atr, view_inps = view.prep_slice(view_cmd)
self.coord = ut.coordinate(atr)
Expand All @@ -137,16 +165,8 @@ def plot(self):
self.ax_img = view.plot_slice(self.ax_img, d_img, atr, view_inps)[0]
self.fig_coord = view_inps.fig_coord

# Axes 2 - coherence matrix
self.ax_mat = self.fig.add_axes([0.55, 0.125, 0.40, 0.75])
self.colormap = pp.ColormapExt(self.cmap_name, vlist=self.cmap_vlist).colormap
if all(i is not None for i in self.yx):
self.plot_coherence_matrix4pixel(self.yx)

# Link the canvas to the plots.
self.cid = self.fig.canvas.mpl_connect('button_press_event', self.update_coherence_matrix)
if self.disp_fig:
plt.show()
self.fig_img.canvas.manager.set_window_title(self.figname_img)
Comment thread
yunjunz marked this conversation as resolved.
self.fig_img.tight_layout()
return

def plot_coherence_matrix4pixel(self, yx):
Expand Down Expand Up @@ -203,16 +223,33 @@ def format_coord(x, y):
msg += f'temporal coherence: {tcoh:.2f}'
vprint(msg)

self.fig_mat.canvas.manager.set_window_title(self.figname_mat)
self.fig_mat.tight_layout()
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Outdated

# update figure
self.fig.canvas.draw_idle()
self.fig.canvas.flush_events()
self.fig_mat.canvas.draw_idle()
self.fig_mat.canvas.flush_events()
return

def update_coherence_matrix(self, event):
"""Update coherence matrix when clicking on either window."""
if event.inaxes == self.ax_img:
if self.fig_coord == 'geo':
yx = self.coord.lalo2yx(event.ydata, event.xdata)
else:
yx = [int(event.ydata+0.5),
int(event.xdata+0.5)]
self.plot_coherence_matrix4pixel(yx)
self.update_image_marker(yx)

elif event.inaxes == self.ax_mat:
pass

def update_image_marker(self, yx):
"""Update the marker point in the image window."""
for artist in self.ax_img.get_children():
if hasattr(artist, 'get_marker') and artist.get_marker() == '^':
artist.remove()

self.ax_img.plot(yx[1], yx[0], 'r^', markersize=10, markeredgecolor='black')
Comment thread
yunjunz marked this conversation as resolved.
Outdated
self.fig_img.canvas.draw_idle()