Skip to content

Commit

Permalink
Add new plotting function and update existing for new matplotlib comp…
Browse files Browse the repository at this point in the history
…atibility
  • Loading branch information
Alexey Pechnikov committed May 20, 2024
1 parent 6756cce commit e52d315
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions pygmtsar/pygmtsar/Stack_sbas.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ def plot_baseline_duration(self, baseline_pairs, interval_days=6, caption='Durat
# Normalize the average values for coloring
norm = mcolors.Normalize(vmin=vmin if vmin is not None else np.nanmin(averages),
vmax=vmax if vmax is not None else np.nanmax(averages))
cmap = plt.cm.get_cmap(cmap)
cmap = plt.colormaps[cmap]

for i in range(len(bin_midpoints)):
bin_color = 'white' if np.isnan(averages[i]) else cmap(norm(averages[i]))
Expand All @@ -681,7 +681,7 @@ def plot_baseline_duration(self, baseline_pairs, interval_days=6, caption='Durat
elif column is not None:
norm = mcolors.Normalize(vmin=vmin if vmin is not None else baseline_pairs[column].min(),
vmax=vmax if vmax is not None else baseline_pairs[column].max())
cmap = plt.cm.get_cmap(cmap)
cmap = plt.colormaps[cmap]

for i in range(len(bins) - 1):
bin_data = baseline_pairs[(baseline_pairs.duration >= bins[i]) & (baseline_pairs.duration < bins[i + 1])]
Expand Down Expand Up @@ -787,7 +787,7 @@ def plot_baseline_displacement(self, phase, corr=None, caption=None, cmap='turbo
assert isinstance(phase, xr.DataArray) and phase.dims == ('pair',), \
'ERROR: Argument phase should be 1D Xarray with "pair" dimension'
plt.figure()
colors = matplotlib.cm.get_cmap(cmap)
colors = plt.colormaps[cmap]

df = phase.to_dataframe()
df['corr'] = corr.values if corr is not None else 1
Expand Down Expand Up @@ -995,7 +995,13 @@ def plot_displacements(self, data, caption='Cumulative LOS Displacement, [rad]',
fg.set_ticks(max_xticks=nbins, max_yticks=nbins)
fg.fig.suptitle(caption, y=y)

def plot_velocity(self, data, caption='Velocity, mm/year',
def plot_displacements_los_mm(self, data, caption='Cumulative LOS Displacement, [mm]', cols=4, size=4, nbins=5, aspect=1.2, y=1.05,
quantile=None, vmin=None, vmax=None, symmetrical=False):
self.plot_displacements(self.los_displacement_mm(data),
caption=caption, cols=cols, size=size, nbins=nbins, aspect=aspect, y=y,
quantile=quantile, vmin=vmin, vmax=vmax, symmetrical=symmetrical)

def plot_velocity(self, data, caption='Velocity, [rad/year]',
quantile=None, vmin=None, vmax=None, symmetrical=False, aspect=None, alpha=1, **kwargs):
import numpy as np
import matplotlib.pyplot as plt
Expand All @@ -1020,7 +1026,13 @@ def plot_velocity(self, data, caption='Velocity, mm/year',
plt.gca().set_aspect(aspect)
plt.title(caption)

def plot_rmse(self, rmse, caption='RMSE', cmap='turbo',
def plot_velocity_los_mm(self, data, caption='Velocity, [mm/year]',
quantile=None, vmin=None, vmax=None, symmetrical=False, aspect=None, alpha=1, **kwargs):
self.plot_velocity(self.los_displacement_mm(data),
caption=caption, aspect=aspect, alpha=alpha,
quantile=quantile, vmin=vmin, vmax=vmax, symmetrical=symmetrical, **kwargs)

def plot_rmse(self, rmse, caption='RMSE, [rad]', cmap='turbo',
quantile=None, vmin=None, vmax=None, symmetrical=False, **kwargs):
import numpy as np
import matplotlib.pyplot as plt
Expand All @@ -1047,3 +1059,9 @@ def plot_rmse(self, rmse, caption='RMSE', cmap='turbo',
self.plot_AOI(**kwargs)
self.plot_POI(**kwargs)
plt.title(caption)

def plot_rmse_los_mm(self, rmse, caption='RMSE, [mm]', cmap='turbo',
quantile=None, vmin=None, vmax=None, symmetrical=False, **kwargs):
self.plot_rmse(abs(self.los_displacement_mm(rmse)),
caption=caption, cmap=cmap,
quantile=quantile, vmin=vmin, vmax=vmax, symmetrical=symmetrical, **kwargs)

0 comments on commit e52d315

Please sign in to comment.