From 05bdcb409363b5359deb0cf79b1c4beb4a24a4b1 Mon Sep 17 00:00:00 2001 From: Alexey Pechnikov Date: Fri, 28 Jun 2024 16:51:04 +0700 Subject: [PATCH] Enhance radar coordinate plot labels. Unify plotting functions data argument. --- pygmtsar/pygmtsar/Stack_incidence.py | 15 ++++++++------- pygmtsar/pygmtsar/Stack_phasediff.py | 9 ++++++--- pygmtsar/pygmtsar/Stack_ps.py | 16 ++++++++++------ pygmtsar/pygmtsar/Stack_sbas.py | 6 +++++- pygmtsar/pygmtsar/Stack_tidal.py | 13 ++++++++----- pygmtsar/pygmtsar/Stack_topo.py | 15 ++++++++------- pygmtsar/pygmtsar/Stack_unwrap.py | 3 ++- 7 files changed, 47 insertions(+), 30 deletions(-) diff --git a/pygmtsar/pygmtsar/Stack_incidence.py b/pygmtsar/pygmtsar/Stack_incidence.py index 75475c28..c57a8633 100644 --- a/pygmtsar/pygmtsar/Stack_incidence.py +++ b/pygmtsar/pygmtsar/Stack_incidence.py @@ -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): diff --git a/pygmtsar/pygmtsar/Stack_phasediff.py b/pygmtsar/pygmtsar/Stack_phasediff.py index 514db0ef..4856a0da 100644 --- a/pygmtsar/pygmtsar/Stack_phasediff.py +++ b/pygmtsar/pygmtsar/Stack_phasediff.py @@ -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) @@ -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) @@ -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) diff --git a/pygmtsar/pygmtsar/Stack_ps.py b/pygmtsar/pygmtsar/Stack_ps.py index 8c378aca..eba0de12 100644 --- a/pygmtsar/pygmtsar/Stack_ps.py +++ b/pygmtsar/pygmtsar/Stack_ps.py @@ -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): @@ -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) diff --git a/pygmtsar/pygmtsar/Stack_sbas.py b/pygmtsar/pygmtsar/Stack_sbas.py index 8e92193c..27e6e310 100644 --- a/pygmtsar/pygmtsar/Stack_sbas.py +++ b/pygmtsar/pygmtsar/Stack_sbas.py @@ -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) @@ -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]', diff --git a/pygmtsar/pygmtsar/Stack_tidal.py b/pygmtsar/pygmtsar/Stack_tidal.py index 4003bc18..08f35369 100644 --- a/pygmtsar/pygmtsar/Stack_tidal.py +++ b/pygmtsar/pygmtsar/Stack_tidal.py @@ -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) @@ -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]) @@ -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]) diff --git a/pygmtsar/pygmtsar/Stack_topo.py b/pygmtsar/pygmtsar/Stack_topo.py index 19ddedd1..cae34d95 100644 --- a/pygmtsar/pygmtsar/Stack_topo.py +++ b/pygmtsar/pygmtsar/Stack_topo.py @@ -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: @@ -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): diff --git a/pygmtsar/pygmtsar/Stack_unwrap.py b/pygmtsar/pygmtsar/Stack_unwrap.py index 28dc8873..221309d3 100644 --- a/pygmtsar/pygmtsar/Stack_unwrap.py +++ b/pygmtsar/pygmtsar/Stack_unwrap.py @@ -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)