Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conncomp.plot_bridge(): improve memory usage #1155

Merged
merged 6 commits into from
Mar 20, 2024
Merged
Changes from 4 commits
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
16 changes: 10 additions & 6 deletions src/mintpy/objects/conncomp.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,21 +355,25 @@ def unwrap_conn_comp(self, unw, radius=50, ramp_type=None, print_msg=False):


def plot_bridge(self, ax, cmap='jet', radius=50):
# label background
# background label
ax.imshow(self.labelImg, cmap=cmap, interpolation='nearest')
# bridges

for bridge in self.bridges:
# bridges
ax.plot([bridge['x0'], bridge['x1']],
[bridge['y0'], bridge['y1']], 'w-', lw=1)

# endpoint window
if radius > 0:
aoi_mask0, aoi_mask1 = self.get_bridge_endpoint_aoi_mask(bridge, radius=radius)
label_mask0 = self.labelImg == bridge['label0']
label_mask1 = self.labelImg == bridge['label1']
mask0 = np.ma.masked_where(~(aoi_mask0*label_mask0), np.zeros(self.labelImg.shape))
mask1 = np.ma.masked_where(~(aoi_mask1*label_mask1), np.zeros(self.labelImg.shape))
ax.imshow(mask0, cmap='gray', alpha=0.3, vmin=0, vmax=1)
ax.imshow(mask1, cmap='gray', alpha=0.3, vmin=0, vmax=1)
# Note by Emre Mar 2024: overlay bridge regions directly using plot() function,
# instead of using np.ma.masked_where() with imshow(),
# to save memory while calling this func in a loop (https://github.com/insarlab/MintPy/pull/1155)
ax.plot(np.nonzero(aoi_mask0*label_mask0)[1], np.nonzero(aoi_mask0*label_mask0)[0], 'gray', alpha=0.3)
ax.plot(np.nonzero(aoi_mask1*label_mask1)[1], np.nonzero(aoi_mask1*label_mask1)[0], 'gray', alpha=0.3)

# reference pixel
ax.plot(self.refX, self.refY, 'ks', ms=2)
return ax
Expand Down