forked from SmithB/PointDatabase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIndexPicker.py
More file actions
162 lines (146 loc) · 6.36 KB
/
IndexPicker.py
File metadata and controls
162 lines (146 loc) · 6.36 KB
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Oct 2 18:08:00 2019
@author: ben
"""
from PointDatabase import geo_index
from PointDatabase.geo_index import index_list_for_files
from PointDatabase import point_data, mapData
from PointDatabase import ATL06_data
import ATL11
import matplotlib.pyplot as plt
import numpy as np
import os
import sys
import scipy.stats as sps
class IndexPicker:
def __init__(self, fig, index_file, map_file=None, W=4e4, datatype='ATL06'):
self.xy=geo_index().from_file(index_file).bins_as_array()
self.index_file=index_file
self.map_file=map_file
self.fig=fig
self.datatype=datatype
self.W=4.e4
if fig is None:
self.fig=plt.figure()
if map_file is not None:
print("map file is " + map_file)
backgrnd=mapData().from_geotif(map_file)
cr=sps.scoreatpercentile(backgrnd.z[np.isfinite(backgrnd.z)], [16, 84])
hi=backgrnd.show(cmap='gray', vmin=cr[0]-np.diff(cr), vmax=cr[1]+np.diff(cr))
print("about to plot %d points" % len(self.xy[0]))
plt.plot(self.xy[0], self.xy[1],'.')
print("starting picker")
self.cid=self.fig.canvas.mpl_connect('button_press_event', self.click)
plt.show(block=True)
#self.fig.canvas.draw()
def click(self, event):
if not event.dblclick:
return
print('click', event)
if self.datatype=='ATL06':
field_dict={None:['delta_time','h_li','h_li_sigma','latitude','longitude','atl06_quality_summary','segment_id','sigma_geo_h'],
'fit_statistics':['dh_fit_dx'],
'ground_track':['x_atc', 'sigma_geo_xt','sigma_geo_at'],
'geophysical' : ['dac','tide_ocean','r_eff'],
'orbit_info':['rgt','cycle_number'],
'derived':['valid','matlab_time','LR','BP','spot','rss_along_track_dh']}
elif self.datatype=='ATL11':
field_dict={\
'corrected_h':['latitude','longitude','delta_time','h_corr','h_corr_sigma','ref_pt'],\
'cycle_stats':['ATL06_summary_zero_count'],\
'crossing_track_data':['delta_time','h_corr','h_corr_sigma','ref_pt','rgt',\
'spot_crossing', 'along_track_rss',\
'atl06_quality_summary','cycle_number'],
'ref_surf':['x_atc','y_atc']}
W=self.W
self.fig.gca().plot(event.xdata, event.ydata,'m*')
self.fig.canvas.draw()
xy0=np.round(np.array([event.xdata, event.ydata])/1.e4)*1.e4
print(xy0)
D=geo_index().from_file(self.index_file).query_xy_box(\
event.xdata+np.array([-W/2, W/2]), event.ydata+np.array([-W/2, W/2]), fields=field_dict)
#D=geo_index().from_file(self.index_file).query_xy_box((self.xy[0][best], self.xy[1][best]), fields=field_dict)
TrackPicker(D, self.map_file, self.index_file, self.datatype)
class TrackPicker:
def __init__(self, D, map_file, index_file, datatype):
self.files=[]
self.datatype=datatype
srs_proj4=geo_index().from_file(index_file).attrs['SRS_proj4']
if datatype == 'ATL06':
for ii, Di in enumerate(D):
Di.get_xy(srs_proj4)
Di.assign({'file_num':np.zeros_like(Di.x)+ii})
self.files += [Di.filename]
self.D_all=point_data().from_list(D)
elif datatype == 'ATL11':
D_list=[]
for ii, Di in enumerate(D):
self.files += [Di.filename]
Di.get_xy(srs_proj4)
D_list.append(point_data().from_dict({
'x':Di.x, 'y':Di.y, 'file_num':np.zeros_like(Di.x)+ii,
'h_corr':Di.corrected_h.h_corr[:,-1].ravel()}))
self.D_all=point_data().from_list(D_list)
self.D=D
XR=[np.nanmin(self.D_all.x), np.nanmax(self.D_all.x)]
YR=[np.nanmin(self.D_all.y), np.nanmax(self.D_all.y)]
self.fig=plt.figure()
if map_file is not None:
mapData().from_geotif(map_file, bounds=[XR, YR]).show(cmap='gray')
#for Di in D:
# plt.plot(Di.x, Di.y,'.')
if self.datatype=='ATL06':
plt.scatter(self.D_all.x, self.D_all.y, 6, c=self.D_all.r_eff, linewidth=0, vmax=1, vmin=0)
elif self.datatype=='ATL11':
plt.scatter(self.D_all.x, self.D_all.y, 6, c=self.D_all.h_corr); plt.colorbar()
self.cid=self.fig.canvas.mpl_connect('button_press_event', self)
plt.show()
def __call__(self, event):
xyp=event.xdata+1j*event.ydata
best = np.argmin(np.abs(self.D_all.x+1j*self.D_all.y - xyp))
this = int(self.D_all.file_num[best])
if self.datatype=='ATL06':
self.ATL06_plot(self.D[this], this)
else:
self.ATL11_plot(self.D[this], this)
def ATL06_plot(self, D, this):
fig=plt.figure()
plt.scatter(D.x_atc, D.h_li, c=np.log10(D.r_eff), cmap='rainbow', vmin=np.log10(0.25), vmax=np.log10(4))
plt.colorbar()
plt.title(self.files[this])
print(self.files[this])
fig.canvas.draw()
plt.show()
def ATL06_plot_old(self, D, this):
fig=plt.figure()
ax1=plt.subplot(211)
plt.plot(D.x_atc, D.h_li,'.')
plt.title(self.files[this])
plt.subplot(212, sharex=ax1)
plt.plot(D.x_atc, D.r_eff,'.')
plt.title(self.files[this])
print(self.files[this])
fig.canvas.draw()
plt.show()
def ATL11_plot(self, D, this):
print(self.files[this])
fig=plt.figure()
plt.subplot(211)
plt.scatter(D.corrected_h.ref_pt*20, D.corrected_h.h_corr[:,2], 4, D.corrected_h.h_corr_sigma[:,2]); plt.colorbar()
plt.subplot(212)
plt.plot(D.corrected_h.ref_pt*20, D.corrected_h.h_corr[:,2], 'k')
ref, xo, delta=D.get_xovers()
print(delta)
plt.scatter(ref.ref_pt*20, xo.h, 12, c=delta.h, linewidth=0); plt.colorbar()
plt.plot()
fig.canvas.draw()
plt.show()
def main():
#fig=plt.figure()
fig=None
IndexPicker(fig, sys.argv[1], sys.argv[2], sys.argv[3])
#plt.show(block=True)
if __name__=='__main__':
main()