Skip to content

Commit

Permalink
Enhance RMSE calculation for case when data and solution include diff…
Browse files Browse the repository at this point in the history
…erent dates
  • Loading branch information
AlexeyPechnikov committed Mar 13, 2024
1 parent 6175251 commit 7f1b259
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pygmtsar/pygmtsar/Stack_sbas.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,24 +891,26 @@ def plot_baseline_displacement(self, phase, corr=None, caption=None, cmap='turbo
def rmse(self, data, solution, weight=None):
"""
Calculate difference between pairs and dates
Use to calculate solution vs pair unwrapped phases difference as
diff = sbas.stack_vs_cube(phase_unwrap, solution)
error = np.sqrt(sbas.wrap(diff)**2).sum('pair')
"""
import numpy as np
import xarray as xr

# extract pairs
pairs = self.get_pairs(data)
# unify data and solution
pairs = pairs[pairs.ref.isin(solution.date.values)&pairs.rep.isin(solution.date.values)]
# calculate differences between end and start dates for all the pairs
error_pairs = []
for rec in pairs.itertuples():
#print (rec.rep, rec.ref, rec.Index, rec)
error_pair = data.sel(pair=rec.pair) - (solution.sel(date=rec.rep) - solution.sel(date=rec.ref))
error_pair = self.wrap(data.sel(pair=rec.pair) - (solution.sel(date=rec.rep) - solution.sel(date=rec.ref)))
error_pairs.append(error_pair**2)
# form 3D stack
error = xr.concat(error_pairs, dim='pair').assign_coords({'pair': data.pair})
error = xr.concat(error_pairs, dim='pair').assign_coords({'pair': pairs.pair})
return np.sqrt((weight * error).sum('pair') / weight.sum('pair') / len(pairs))

def plot_displacement(self, data, caption='Cumulative LOS Displacement, [rad]',
Expand Down

0 comments on commit 7f1b259

Please sign in to comment.