Skip to content

Commit

Permalink
Enhance radar coordinate plot labels. Unify plotting functions data a…
Browse files Browse the repository at this point in the history
…rgument.
  • Loading branch information
AlexeyPechnikov committed Jun 28, 2024
1 parent 56c99a4 commit 05bdcb4
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 30 deletions.
15 changes: 8 additions & 7 deletions pygmtsar/pygmtsar/Stack_incidence.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,20 +333,21 @@ def incidence_angle(self):
incidence_ll = np.arctan2(np.sqrt(sat_look.look_E**2 + sat_look.look_N**2), sat_look.look_U).rename('incidence_angle')
return incidence_ll

def plot_incidence_angle(self, incidence_angle='auto', caption='Incidence Angle in Radar Coordinates, [rad]', cmap='gray', aspect=None, **kwargs):
def plot_incidence_angle(self, data='auto', caption='Incidence Angle in Radar Coordinates, [rad]', cmap='gray', aspect=None, **kwargs):
import matplotlib.pyplot as plt

plt.figure()
if isinstance(incidence_angle, str) and incidence_angle == 'auto':
self.incidence_angle().plot.imshow(cmap=cmap)
else:
incidence_angle.plot.imshow(cmap=cmap)
if isinstance(data, str) and data == 'auto':
data = self.incidence_angle()

data.plot.imshow(cmap=cmap)
self.plot_AOI(**kwargs)
self.plot_POI(**kwargs)
if aspect is not None:
plt.gca().set_aspect(aspect)
plt.xlabel('Range')
plt.ylabel('Azimuth')
if self.is_ra(data):
plt.xlabel('Range')
plt.ylabel('Azimuth')
plt.title(caption)

def vertical_displacement_mm(self, data):
Expand Down
9 changes: 6 additions & 3 deletions pygmtsar/pygmtsar/Stack_phasediff.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,8 @@ def plot_phases(self, data, caption='Phase, [rad]', cols=4, size=4, nbins=5, asp
col_wrap=cols, size=size, aspect=aspect,
vmin=vmin, vmax=vmax, cmap='turbo'
)
fg.set_axis_labels('Range', 'Azimuth')
if self.is_ra(data):
fg.set_axis_labels('Range', 'Azimuth')
fg.set_ticks(max_xticks=nbins, max_yticks=nbins)
fg.fig.suptitle(caption, y=y)

Expand Down Expand Up @@ -918,7 +919,8 @@ def plot_interferograms(self, data, caption='Phase, [rad]', cols=4, size=4, nbin
col_wrap=cols, size=size, aspect=aspect,
vmin=-np.pi, vmax=np.pi, cmap='gist_rainbow_r'
)
fg.set_axis_labels('Range', 'Azimuth')
if self.is_ra(data):
fg.set_axis_labels('Range', 'Azimuth')
fg.set_ticks(max_xticks=nbins, max_yticks=nbins)
fg.fig.suptitle(caption, y=y)

Expand Down Expand Up @@ -952,7 +954,8 @@ def plot_correlations(self, data, caption='Correlation', cmap='auto', cols=4, si
col_wrap=cols, size=size, aspect=aspect,
vmin=0, vmax=1, cmap=cmap
)
fg.set_axis_labels('Range', 'Azimuth')
if self.is_ra(data):
fg.set_axis_labels('Range', 'Azimuth')
fg.set_ticks(max_xticks=nbins, max_yticks=nbins)
fg.fig.suptitle(caption, y=y)

Expand Down
16 changes: 10 additions & 6 deletions pygmtsar/pygmtsar/Stack_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,26 @@ def psfunction(self, ps='auto', name='ps'):
psfunction = (ps.average/(2*ps.deviation))
return psfunction.where(np.isfinite(psfunction)).rename('psf')

def plot_psfunction(self, psfunction='auto', caption='PS Function', cmap='gray', quantile=None, vmin=None, vmax=None, **kwargs):
def plot_psfunction(self, data='auto', caption='PS Function', cmap='gray', quantile=None, vmin=None, vmax=None, **kwargs):
import numpy as np
import matplotlib.pyplot as plt

if isinstance(psfunction, str) and psfunction == 'auto':
psfunction = self.psfunction()
if isinstance(data, str) and data == 'auto':
data = self.psfunction()

if quantile is not None:
assert vmin is None and vmax is None, "ERROR: arguments 'quantile' and 'vmin', 'vmax' cannot be used together"

if quantile is not None:
vmin, vmax = np.nanquantile(psfunction, quantile)
vmin, vmax = np.nanquantile(data, quantile)

plt.figure()
psfunction.plot.imshow(cmap=cmap, vmin=vmin, vmax=vmax)
data.plot.imshow(cmap=cmap, vmin=vmin, vmax=vmax)
self.plot_AOI(**kwargs)
self.plot_POI(**kwargs)
if self.is_ra(data):
plt.xlabel('Range')
plt.ylabel('Azimuth')
plt.title(caption)

# def get_adi_threshold(self, threshold):
Expand Down Expand Up @@ -198,7 +201,8 @@ def plot_amplitudes(self, dates=None, data='auto', norm='auto', func=None, inten
vmin=vmin, vmax=vmax, cmap=cmap,
interpolation='none' # Disable interpolation
)
fg.set_axis_labels('Range', 'Azimuth')
if self.is_ra(data):
fg.set_axis_labels('Range', 'Azimuth')
fg.set_ticks(max_xticks=nbins, max_yticks=nbins)
fg.fig.suptitle(caption, y=y)

Expand Down
6 changes: 5 additions & 1 deletion pygmtsar/pygmtsar/Stack_sbas.py
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,8 @@ def plot_displacements(self, data, caption='Cumulative LOS Displacement, [rad]',
col_wrap=cols, size=size, aspect=aspect,
vmin=vmin, vmax=vmax, cmap='turbo'
)
#fg.set_axis_labels('Range', 'Azimuth')
if self.is_ra(data):
fg.set_axis_labels('Range', 'Azimuth')
fg.set_ticks(max_xticks=nbins, max_yticks=nbins)
fg.fig.suptitle(caption, y=y)

Expand Down Expand Up @@ -1027,6 +1028,9 @@ def plot_velocity(self, data, caption='Velocity, [rad/year]',
self.plot_POI(**kwargs)
if aspect is not None:
plt.gca().set_aspect(aspect)
if self.is_ra(data):
plt.xlabel('Range')
plt.ylabel('Azimuth')
plt.title(caption)

def plot_velocity_los_mm(self, data, caption='Velocity, [mm/year]',
Expand Down
13 changes: 8 additions & 5 deletions pygmtsar/pygmtsar/Stack_tidal.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,8 @@ def plot_tidal(self, data=None, caption='Tidal Displacement Amplitude, [mm]', cm
figsize=(cols * size, int(np.ceil(data.date.size / cols)) * size * aspect)
)
axes = axes.flatten()


is_ra = self.is_ra(data)
for i, date in enumerate(data.date.values):
# Select the data for the specific date
date_data = data.sel(date=date)
Expand All @@ -559,8 +560,9 @@ def plot_tidal(self, data=None, caption='Tidal Displacement Amplitude, [mm]', cm
add_colorbar=False
)
axes[i].set_title(str(date)[:10])
axes[i].set_xlabel('Range')
axes[i].set_ylabel('Azimuth')
if is_ra:
axes[i].set_xlabel('Range')
axes[i].set_ylabel('Azimuth')
# Add colorbar for each subplot
fig.colorbar(im, ax=axes[i])

Expand Down Expand Up @@ -598,8 +600,9 @@ def plot_tidal_los_rad(self, data=None, caption='Tidal Phase, [rad]', cmap='turb
add_colorbar=False
)
axes[i].set_title(str(date)[:10])
axes[i].set_xlabel('Range')
axes[i].set_ylabel('Azimuth')
if self.is_ra(data):
axes[i].set_xlabel('Range')
axes[i].set_ylabel('Azimuth')
# Add colorbar for each subplot
fig.colorbar(im, ax=axes[i])

Expand Down
15 changes: 8 additions & 7 deletions pygmtsar/pygmtsar/Stack_topo.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@ def get_topo(self):
"""
return self.get_trans_inv()['ele'].rename('topo')

def plot_topo(self, topo='auto', caption='Topography on WGS84 ellipsoid, [m]',
def plot_topo(self, data='auto', caption='Topography on WGS84 ellipsoid, [m]',
quantile=None, vmin=None, vmax=None, symmetrical=False,
cmap='gray', aspect=None, **kwargs):
import numpy as np
import matplotlib.pyplot as plt

if isinstance(topo, str) and topo == 'auto':
topo = self.get_topo()
if isinstance(data, str) and data == 'auto':
data = self.get_topo()

if quantile is not None:
assert vmin is None and vmax is None, "ERROR: arguments 'quantile' and 'vmin', 'vmax' cannot be used together"

if quantile is not None:
vmin, vmax = np.nanquantile(topo, quantile)
vmin, vmax = np.nanquantile(data, quantile)

# define symmetrical boundaries
if symmetrical is True and vmax > 0:
Expand All @@ -53,13 +53,14 @@ def plot_topo(self, topo='auto', caption='Topography on WGS84 ellipsoid, [m]',
vmax = minmax

plt.figure()
topo.plot.imshow(cmap=cmap, vmin=vmin, vmax=vmax)
data.plot.imshow(cmap=cmap, vmin=vmin, vmax=vmax)
self.plot_AOI(**kwargs)
self.plot_POI(**kwargs)
if aspect is not None:
plt.gca().set_aspect(aspect)
plt.xlabel('Range')
plt.ylabel('Azimuth')
if self.is_ra(data):
plt.xlabel('Range')
plt.ylabel('Azimuth')
plt.title(caption)

def topo_phase(self, pairs, topo='auto', debug=False):
Expand Down
3 changes: 2 additions & 1 deletion pygmtsar/pygmtsar/Stack_unwrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ def plot_conncomps(self, data, caption='Connected Components', cols=4, size=4, n
col_wrap=cols, size=size, aspect=aspect,
cmap=cmap, vmin=0, vmax=10
)
fg.set_axis_labels('Range', 'Azimuth')
if self.is_ra(data):
fg.set_axis_labels('Range', 'Azimuth')
fg.set_ticks(max_xticks=nbins, max_yticks=nbins)
fg.fig.suptitle(caption, y=y)

0 comments on commit 05bdcb4

Please sign in to comment.