From dd7e5e9761119cc63949eabd0184dad95e48a759 Mon Sep 17 00:00:00 2001 From: Simran S Sangha Date: Wed, 1 Feb 2023 20:43:57 -0800 Subject: [PATCH 1/2] Export supplemental gps CSV file When plotting GPS stations and specifying a specific GPS reference station, it would be convenient if an additional CSV file (e.g. reref_gps_X.csv) would be created which tracks the rereferenced velocity values and accounts for any potential unit factor changes. This would make it easier to make separate, supplemental plots independent of MintPy. For example, in this case, station 70DM is the reference station and I wish to convert the velocities to cm/yr: (mintpy) [ssangha@leffe reref]$ more gps_enu2los.csv Site,Lon,Lat,Displacement,Velocity 7ODM,-117.09358508816442,34.11640732493536,-0.13098726,-0.010960488 BBRY,-116.88515702033878,34.26427837432715,-0.04806125,-0.0043038945 P613,-117.04706501804391,34.19618514313232,-0.05000028,-0.0059998427 (mintpy) [ssangha@leffe reref]$ (mintpy) [ssangha@leffe reref]$ more reref_gps_enu2los.csv Site,Lon,Lat,Displacement,Velocity 7ODM,-117.09358508816442,34.11640732493536,0.0,0.0 BBRY,-116.88515702033878,34.26427837432715,0.08292601,0.66565935 P613,-117.04706501804391,34.19618514313232,0.08098697999999999,0.49606452999999995 --- src/mintpy/utils/plot.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/mintpy/utils/plot.py b/src/mintpy/utils/plot.py index c1be83fe6..49d098fed 100644 --- a/src/mintpy/utils/plot.py +++ b/src/mintpy/utils/plot.py @@ -7,6 +7,7 @@ # from mintpy.utils import plot as pp +import csv import datetime as dt import os import warnings @@ -1188,6 +1189,29 @@ def plot_gps(ax, SNWE, inps, metadata=dict(), print_msg=True): if not np.isnan(ref_val): site_obs -= ref_val + # read GPS velocity from CSV file (generated by gps.get_gps_los_obs()) + csv_file = f'gps_{inps.gps_component}.csv' + vprint(f'write rereferenced GPS observations to file: {csv_file}') + og_csv = os.path.join(os.path.dirname(metadata['FILE_PATH']), + os.path.basename(csv_file)) + reref_csv = os.path.join(os.path.dirname(metadata['FILE_PATH']), + 'reref_' + os.path.basename(csv_file)) + col_names = ['Site', 'Lon', 'Lat', 'Displacement', 'Velocity'] + num_col = len(col_names) + col_types = ['U10'] + ['f8'] * (num_col - 1) + fc = np.genfromtxt(og_csv, dtype=col_types, delimiter=',', names=True) + # write updated CSV file + fc[col_names[-1]] -= fc[col_names[-1]][ref_ind] + fc[col_names[-1]] *= unit_fac + fc[col_names[-2]] -= fc[col_names[-2]][ref_ind] + data_list_reref = [] + for i in fc: + data_list_reref.append(i) + with open(reref_csv, 'w') as fc2: + fcw = csv.writer(fc2) + fcw.writerow(col_names) + fcw.writerows(data_list_reref) + # scale to the same unit as InSAR site_obs *= unit_fac From 737579dcd1583b09bde5a31dc4f4b01781ea903c Mon Sep 17 00:00:00 2001 From: Simran S Sangha Date: Thu, 2 Feb 2023 19:14:10 -0800 Subject: [PATCH 2/2] Generalize and clean-up Before the updated CSV file was only generated if a reference GPS station were specified. Now, this file is generated and captures at least the unit factor conversion regardless of the specification of a reference GPS station. --- src/mintpy/utils/plot.py | 45 ++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/src/mintpy/utils/plot.py b/src/mintpy/utils/plot.py index 49d098fed..13b5ed4de 100644 --- a/src/mintpy/utils/plot.py +++ b/src/mintpy/utils/plot.py @@ -1179,6 +1179,19 @@ def plot_gps(ax, SNWE, inps, metadata=dict(), print_msg=True): redo=inps.gps_redo, ) + # create CSV reflecting plotting changes imposed on input GPS data + # read GPS velocity from CSV file + csv_file = f'gps_{inps.gps_component}.csv' + vprint(f'write rereferenced GPS observations to file: {csv_file}') + og_csv = os.path.join(os.path.dirname(metadata['FILE_PATH']), + os.path.basename(csv_file)) + update_csv = os.path.join(os.path.dirname(metadata['FILE_PATH']), + 'reref_' + os.path.basename(csv_file)) + col_names = ['Site', 'Lon', 'Lat', 'Displacement', 'Velocity'] + num_col = len(col_names) + col_types = ['U10'] + ['f8'] * (num_col - 1) + fc = np.genfromtxt(og_csv, dtype=col_types, delimiter=',', names=True) + # reference GPS if inps.ref_gps_site: ref_ind = site_names.tolist().index(inps.ref_gps_site) @@ -1189,31 +1202,23 @@ def plot_gps(ax, SNWE, inps, metadata=dict(), print_msg=True): if not np.isnan(ref_val): site_obs -= ref_val - # read GPS velocity from CSV file (generated by gps.get_gps_los_obs()) - csv_file = f'gps_{inps.gps_component}.csv' - vprint(f'write rereferenced GPS observations to file: {csv_file}') - og_csv = os.path.join(os.path.dirname(metadata['FILE_PATH']), - os.path.basename(csv_file)) - reref_csv = os.path.join(os.path.dirname(metadata['FILE_PATH']), - 'reref_' + os.path.basename(csv_file)) - col_names = ['Site', 'Lon', 'Lat', 'Displacement', 'Velocity'] - num_col = len(col_names) - col_types = ['U10'] + ['f8'] * (num_col - 1) - fc = np.genfromtxt(og_csv, dtype=col_types, delimiter=',', names=True) - # write updated CSV file + # update CSV values fc[col_names[-1]] -= fc[col_names[-1]][ref_ind] - fc[col_names[-1]] *= unit_fac fc[col_names[-2]] -= fc[col_names[-2]][ref_ind] - data_list_reref = [] - for i in fc: - data_list_reref.append(i) - with open(reref_csv, 'w') as fc2: - fcw = csv.writer(fc2) - fcw.writerow(col_names) - fcw.writerows(data_list_reref) # scale to the same unit as InSAR site_obs *= unit_fac + fc[col_names[-1]] *= unit_fac + fc[col_names[-2]] *= unit_fac + + # write updated CSV file + data_list_update = [] + for i in fc: + data_list_update.append(i) + with open(update_csv, 'w') as fc2: + fcw = csv.writer(fc2) + fcw.writerow(col_names) + fcw.writerows(data_list_update) # exclude sites if inps.ex_gps_sites: