-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_network_from_intf.py
executable file
·99 lines (82 loc) · 3.57 KB
/
plot_network_from_intf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python
import argparse
from pathlib import Path
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.collections import LineCollection
from datetime import datetime
from utils import read_baseline_table
import glob
import pdb
def main():
args = get_args()
baseline_table = args.baseline_table
intf_dir = args.intf_dir
intf_out = args.intf_out
data = read_baseline_table(baseline_table)
fig, ax = plt.subplots(figsize=(12,8))
yearfrac = data['aligned_time'].to_numpy()
bperp = data.Bperp.to_numpy()
sat_orb = data.sat_orb.to_numpy()
xmin, xmax = yearfrac.min(), yearfrac.max()
ymin, ymax = bperp.min(), bperp.max()
pairs = list()
stem_pairs_list = list()
i = 0
for intf in intf_dir.iterdir():
print(f'Intf: {intf}')
if intf.is_dir() and "_" in intf.name and len(intf.name.split("_")) == 2:
prms = glob.glob(f'{intf}/*PRM')
prms.sort(key=lambda x: datetime.strptime(x.split("/")[-1][14:22], "%Y%m%d").date())
if len(prms) !=2:
print(f'WARNING: PRM files in: {intf} is different from two\nPRMs: {prms}')
continue
masterPRM, slavePRM = prms
orbmaster = masterPRM.split("/")[-1].split("_")[-2]
orbslave = slavePRM.split("/")[-1].split("_")[-2]
row_master = data.loc[data.sat_orb == orbmaster]
row_slave = data.loc[data.sat_orb == orbslave]
bperp1, bperp2 = row_master['Bperp'].values[0], row_slave['Bperp'].values[0]
p1 = [row_master['aligned_time'].values[0], bperp1]
p2 = [row_slave['aligned_time'].values[0], bperp2]
pairs.append([p1,p2])
stem_pair = f'{masterPRM.split("/")[-1].split(".")[0]}:{slavePRM.split("/")[-1].split(".")[0]}'
stem_pairs_list.append(stem_pair)
i += 1
collection = LineCollection(pairs, colors='darkorange', linewidths=0.6, alpha=0.7, linestyle='solid', label='network')
xticks = np.arange(int(np.floor(xmin)), int(np.ceil(xmax)+1), 0.5)
yticks = np.arange(ymin - (ymin%50), ymax + (100 - ymax%50), 50)
ax.scatter(yearfrac, bperp, marker='o', c='violet', s=14)
ax.add_collection(collection)
for ix, txt in enumerate(sat_orb):
ax.annotate(txt, (yearfrac[ix], bperp[ix]), xytext=(5,5), textcoords='offset points', fontsize='x-small')
title = f'Num of ifgs: {len(pairs)}'
ax.set_title(title)
ax.set_xlabel(f'Time')
ax.set_ylabel(f'Baseline (m)')
ax.tick_params(axis='x', labelrotation=40)
ax.set_yticks(yticks)
ax.set_xticks(xticks)
plt.show()
# writing intf_out
if intf_out:
with open(intf_out, 'w') as f:
print(f'Writing {intf_out}...')
for intf in stem_pairs_list:
f.write(f'{intf}\n')
print(f'{intf_out} written\n')
def get_args():
mess = "Plot network from baseline_table.dat and intf directory"
example = """EXAMPLE:
plot_network_from_intf.py path/to/baseline_table.dat path/intf
"""
parser = argparse.ArgumentParser(description=mess, epilog=example,
formatter_class=argparse.RawDescriptionHelpFormatter)
# Positional arguments
parser.add_argument('baseline_table', type=Path, help='Path to baseline_table.dat')
parser.add_argument('intf_dir', type=Path, help='Path to intf directory')
parser.add_argument('--intf', dest='intf_out', default=None, help='Name of optionally writing intf_out.in')
return parser.parse_args()
if __name__ == "__main__":
main()