From bd5527c63695baea2e097db6efd8ad7ecfc26d43 Mon Sep 17 00:00:00 2001 From: Alexey Pechnikov Date: Sat, 6 Apr 2024 03:28:41 +0700 Subject: [PATCH] Enhance psfunction related functions to allow saving results with different names or return interactively --- pygmtsar/pygmtsar/Stack_ps.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/pygmtsar/pygmtsar/Stack_ps.py b/pygmtsar/pygmtsar/Stack_ps.py index ef93f80e..3a818ad6 100644 --- a/pygmtsar/pygmtsar/Stack_ps.py +++ b/pygmtsar/pygmtsar/Stack_ps.py @@ -12,8 +12,8 @@ class Stack_ps(Stack_stl): - def get_ps(self): - return self.open_cube('ps') + def get_ps(self, name='ps'): + return self.open_cube(name) #from pygmtsar import tqdm_dask #Stack.ps = ps @@ -25,7 +25,7 @@ def get_ps(self): #adi_dec = adi.coarsen({'y': 4, 'x': 16}, boundary='trim').min() #adi_dec # define PS candidates using Amplitude Dispersion Index (ADI) - def compute_ps(self, dates=None, data='auto'): + def compute_ps(self, dates=None, data='auto', name='ps', interactive=False): import xarray as xr import numpy as np import dask @@ -49,17 +49,19 @@ def compute_ps(self, dates=None, data='auto'): del data, norm ds = xr.merge([stats[0].rename('average'), stats[1].rename('deviation'), mean[0].rename('stack_average')]) del stats, mean - self.save_cube(ds, 'ps', 'Compute Stability Measures') + if interactive: + return ds + self.save_cube(ds, name, 'Compute Stability Measures') del ds - def psfunction(self, ps='auto'): + def psfunction(self, ps='auto', name='ps'): import numpy as np if isinstance(ps, str) and ps == 'auto': - ps = self.get_ps() + ps = self.get_ps(name) psfunction = (ps.average/(2*ps.deviation)) return psfunction.where(np.isfinite(psfunction)).rename('psf') - def plot_psfunction(self, psfunction='auto', cmap='gray', quantile=None, vmin=None, vmax=None, **kwargs): + def plot_psfunction(self, psfunction='auto', caption='PS Function', cmap='gray', quantile=None, vmin=None, vmax=None, **kwargs): import numpy as np import matplotlib.pyplot as plt @@ -76,7 +78,7 @@ def plot_psfunction(self, psfunction='auto', cmap='gray', quantile=None, vmin=No psfunction.plot.imshow(cmap=cmap, vmin=vmin, vmax=vmax) self.plot_AOI(**kwargs) self.plot_POI(**kwargs) - plt.title('PS Function') + plt.title(caption) # def get_adi_threshold(self, threshold): # """