def onclick(self,event):
ix, iy = event.xdata, event.ydata
#Make sure the user clicks on the map
#If they don't, ix and iy will be None.
#This will result in an error in the row/col calculations
if (ix != None and iy != None):
if (self.plotObj.dataSet.runType != 'IDEAL'):
lon, lat = self.plotObj.dataSet.map[self.plotObj.currentGrid-1](
self.plotObj.dataSet.glons[self.plotObj.currentGrid-1],
self.plotObj.dataSet.glats[self.plotObj.currentGrid-1])
if (self.plotObj.dataSet.dsetname == 'Sounding'):
a = np.vstack((lat,lon)).T
pt = [iy, ix]
distance, index = spatial.KDTree(a).query(pt)
#print(distance)
#print(index)
#print(a[index])
#print(iy,ix)
col = index
row = index
print(self.plotObj.dataSet.stat_id[index])
else:
clon,clat = self.plotObj.dataSet.map[self.plotObj.currentGrid-1](
self.plotObj.dataSet.lon0[self.plotObj.currentGrid-1],
self.plotObj.dataSet.lat0[self.plotObj.currentGrid-1])
tmp = np.argsort(np.abs(lat[:,int(self.plotObj.dataSet.nx[self.plotObj.currentGrid -1]/2)] - clat))[0]
tmp2 = np.argsort(np.abs(lon[tmp,:] - clon))[0]
row = np.argsort(np.abs(lat[:,tmp2] - iy))[0]
col = np.argsort(np.abs(lon[row,:] - ix))[0]
else:
row = int(iy*1000/self.plotObj.dataSet.dy[self.plotObj.currentGrid-1] +
(self.plotObj.dataSet.ny[self.plotObj.currentGrid-1]-1)/2)
col = int(ix*1000/self.plotObj.dataSet.dx[self.plotObj.currentGrid-1] +
(self.plotObj.dataSet.nx[self.plotObj.currentGrid-1]-1)/2)
print( col, row )
coords = [ix, iy]
if len(coords) == 2:
self.plotObj.col = col
self.plotObj.row = row
self.plotObj.replot2d = False
self.plotObj.newvar = True
self.drawPlot()
else:
self.plotObj.col = None
self.plotObj.row = None
else:
self.errorClick()
#Throw an error for a bad click
评论列表
文章目录