forked from evavra/InSAR-Tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plots.py
175 lines (140 loc) · 5.56 KB
/
plots.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import matplotlib.pyplot as plt
from matplotlib import cm
from mpl_toolkits.axes_grid1 import ImageGrid
from mpl_toolkits.axes_grid1 import make_axes_locatable
import numpy as np
import datetime as dt
"""
Plotting methods for InSAR time series with GMTSAR
"""
def network(intfTable, baselineTable, **kwargs):
"""
Make interferogram network/baseline plot
"""
# Establish figure
fig = plt.figure(1, (10, 5))
ax = plt.gca()
master = intfTable['Master']
repeat = intfTable['Repeat']
mbl = []
rbl = []
# Get relative baselines
for i in range(len(intfTable)):
# Search baselineTable for master baseline
for j, namestr in enumerate(baselineTable['Stem']):
if intfTable['Master'][i].strftime('%Y%m%d') in namestr:
mbl.append(baselineTable['OrbitBaseline'][j])
break
# Search baselineTable for repeat baseline
for j, namestr in enumerate(baselineTable['Stem']):
if intfTable['Repeat'][i].strftime('%Y%m%d') in namestr:
rbl.append(baselineTable['OrbitBaseline'][j])
break
# Manualy set supermaster baseline
superbl = -48.578476
# Plot interferogram pairs as lines
for i in range(len(intfTable)):
plt.plot([master[i], repeat[i]], [mbl[i] - superbl, rbl[i] - superbl], c='k', lw=0.5)
# Plot scenes over pair lines
if 'sceneTable' in kwargs:
sceneTable = kwargs['sceneTable']
im = plt.scatter(baselineTable['Dates'], baselineTable['OrbitBaseline'].subtract(superbl), s=30, c=sceneTable['MeanCorr'], zorder=3, cmap='Spectral_r', vmin=0, vmax=1)
plt.colorbar(im, label='Mean coherence')
else:
plt.scatter(master, np.array(mbl) - superbl, s=30, c='C0', zorder=3)
plt.scatter(repeat, np.array(rbl) - superbl, s=30, c='C0', zorder=3)
# Figure features
plt.grid(axis='x', zorder=1)
plt.xlim(min(master) - dt.timedelta(days=50), max(repeat) + dt.timedelta(days=50))
# plt.ylim(int(np.ceil((min(baselineTable[4]) - superbl - 50) / 50.0) ) * 50, int(np.floor((max(baselineTable[4]) - superbl + 50) / 50.0)) * 50)
plt.xlabel('Year')
plt.ylabel('Baseline relative to master (m)')
plt.show()
if 'figName' in kwargs:
print('Saving to {}...'.format(kwargs['figName']))
fig.savefig(kwargs['figName'] + '.eps')
plt.close()
def scenes(sceneTable, dataType, **kwargs):
"""
Plot mean coherence of each SAR scene for a given set of interferograms
---- INPUT ----------------------------------------------
intfTable - interferogram list with baseline and coherence data
---- OPTIONAL --------------------------------------------
ax - axis handle for plotting
cmap - colormap handle
"""
# Check for passes axis handle
if 'ax' in kwargs:
ax = kwargs['ax']
else:
ax = plt.gca()
# Check for passed colorbar axis handle
if 'cax' in kwargs:
cax = kwargs['cax']
else:
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="2.5%", pad=0.05)
# Plot settings
ax.set_xlim(sceneTable['Date'].min(), sceneTable['Date'].max())
ax.set_xlabel('Date')
# Make actual plot
if dataType == 'MeanCorr':
ax.set_ylabel('Mean coherence')
elif dataType == 'OrbitBaseline':
ax.set_ylabel('Mean orbital baseline (m)')
elif dataType == 'TempBaseline':
ax.set_ylabel('Mean temporal baseline (days)')
# Normalize data to make ImageGrid happy
normData = abs(sceneTable[dataType] / sceneTable[dataType].max())
# Plot data
im = ax.scatter(sceneTable['Date'], normData, c=sceneTable['TotalCount'])
# Get tick labels that correspond with original data
ticks = np.linspace(0, np.round(np.ceil(sceneTable[dataType].max()), 1), 5)
ax.set_yticks(np.linspace(0, 1, 5))
ax.set_yticklabels(ticks)
plt.colorbar(im, cax=cax, label='Number of interferograms')
return im
def baselineCorr(intfTable, **kwargs):
"""
Plot temporal baseline versus mean coherence
---- INPUT ----------------------------------------------
intfTable - interferogram list with baseline and coherence data
---- OPTIONAL --------------------------------------------
ax - axis handle for plotting
cmap - colormap handle
"""
# Check for passed axis handle
if 'ax' in kwargs:
ax = kwargs['ax']
else:
ax = plt.gca()
# Check for passed colorbar axis handle
if 'cax' in kwargs:
cax = kwargs['cax']
else:
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="2.5%", pad=0.05)
# Check for passed colormap handle
if 'cmap' in kwargs:
cmap = kwargs['cmap']
else:
cmap = 'viridis'
# Plot settings
ax.set_xlim(intfTable['Master'].min(), intfTable['Repeat'].max())
# ax.set_ylim(0, 1)
ax.set_xlabel('Date')
ax.set_ylabel('Mean coherence')
# ax.set_aspect(.01)
# Colorbar business
baselineRange = list(range(0, int(np.ceil(intfTable['OrbitBaseline'].max() / 10) * 10)))
n = len(baselineRange)
cmap = cm.get_cmap(cmap, n)
Z = [[0, 0], [0, 0]]
levels = range(0, n)
CS3 = ax.contourf(Z, levels, cmap=cmap)
plt.colorbar(CS3, cax=cax, label='Orbital baseline (m)')
# Make actual plot
for i in range(len(intfTable)):
lineColor = np.floor(intfTable['OrbitBaseline'][i]) / n
im = ax.plot([intfTable['Master'][i], intfTable['Repeat'][i]], [intfTable['MeanCorr'][i], intfTable['MeanCorr'][i]], color=cmap(lineColor))
return im