Skip to content

Commit

Permalink
Enhance solid_tide() function
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexeyPechnikov committed Aug 7, 2023
1 parent d4fe840 commit c6f4fcd
Showing 1 changed file with 54 additions and 9 deletions.
63 changes: 54 additions & 9 deletions pygmtsar/pygmtsar/SBAS_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,21 +211,63 @@ def slc_stack(self, dates=None, intensity=False, chunksize=None):

def solid_tide(self, dates, coords, debug=False):
"""
Compute the tidal correction using GMTSAR binary tool solid_tide.
Compute the tidal correction using the GMTSAR binary tool solid_tide.
solid_tide yyyyddd.fffffff < lon_lat > lon_lat_dx_dy_dz
Parameters
----------
dates : array_like
Dates for which to compute the tidal correction. Should be in the format yyyyddd.fffffff.
coords : array_like
Coordinates for which to compute the tidal correction. Can be a single pair of coordinates [lon, lat],
or a list of pairs [[lon1, lat1], [lon2, lat2], ...].
debug : bool, optional
If True, print debug information. Default is False.
coords = sbas.solid_tide(sbas.df.index, coords=[13.40076, 47.40143])
coords = sbas.solid_tide(sbas.df.index, coords=[[13.40076, 47.40143]])
coords = sbas.solid_tide(sbas.df.index, coords=[[13.40076, 47.40143], [13.40076, 47.40143]])
Returns
-------
pandas.DataFrame
DataFrame with columns 'lon', 'lat', 'dx', 'dy', 'dz', indexed by 'date'.
Examples
--------
Compute the tidal correction for a single pair of coordinates:
coords = sbas.solid_tide(sbas.df.index, coords=[13.40076, 47.40143])
Compute the tidal correction for multiple pairs of coordinates:
coords = sbas.solid_tide(sbas.df.index, coords=[[13.40076, 47.40143], [13.40076, 47.40143]])
Output:
>>> sbas.solid_tide(sbas.df.index[:3], coords=[lon, lat])
lon lat dx dy dz
date
2022-06-16 13.400758 47.401431 -0.066918 -0.004765 0.016200
2022-06-28 13.400758 47.401431 -0.033571 0.012279 -0.099899
2022-07-10 13.400758 47.401431 -0.000806 -0.007983 -0.150675
>>> sbas.solid_tide(sbas.df.index[:3], coords=[[lon, lat], [lon+1, lat+1]])
lon lat dx dy dz
date
2022-06-16 13.400758 47.401431 -0.066918 -0.004765 0.016200
2022-06-16 14.400758 48.401431 -0.066594 -0.004782 0.010346
2022-06-28 13.400758 47.401431 -0.033571 0.012279 -0.099899
2022-06-28 14.400758 48.401431 -0.033011 0.012323 -0.100986
2022-07-10 13.400758 47.401431 -0.000806 -0.007983 -0.150675
2022-07-10 14.400758 48.401431 -0.001107 -0.007758 -0.151605
Notes
-----
This function computes the tidal correction in geographic coordinates based on the dates and coordinates provided.
The correction is computed by calling the GMTSAR binary tool 'solid_tide' with the date and coordinates as input.
"""
import numpy as np
import pandas as pd
from io import StringIO, BytesIO
import os
#import os
import subprocess

coords = np.asarray(coords)
if len(coords.shape) == 1:
coords = [coords]
Expand All @@ -236,7 +278,7 @@ def solid_tide(self, dates, coords, debug=False):

outs = []
for date in dates:
SC_clock_start, SC_clock_stop = sbas.PRM(None, date).get('SC_clock_start', 'SC_clock_stop')
SC_clock_start, SC_clock_stop = self.PRM(None, date).get('SC_clock_start', 'SC_clock_stop')
dt = (SC_clock_start + SC_clock_stop)/2
argv = ['solid_tide', str(dt)]
#cwd = os.path.dirname(self.filename) if self.filename is not None else '.'
Expand All @@ -252,4 +294,7 @@ def solid_tide(self, dates, coords, debug=False):

out = np.fromstring(stdout_data, dtype=float, sep=' ')
outs.append(out)
return np.asarray(outs) if len(outs)>1 else outs[0]

return pd.DataFrame(np.asarray(outs).reshape(-1,5),
columns=['lon', 'lat', 'dx', 'dy', 'dz'],
index=np.repeat(dates, len(coords)))

0 comments on commit c6f4fcd

Please sign in to comment.