Skip to content
Snippets Groups Projects

Draft: cartopy projections

Closed Fraser William Goldsworth requested to merge m301014/pyicon:master into master
1 file
+ 72
1
Compare changes
  • Side-by-side
  • Inline
+ 72
1
@@ -205,7 +205,8 @@ class view(object):
res_menu.bind("<<ComboboxSelected>>", self.make_new_axis)
# Button to activate zoom mode
self.zoom_button = ttk.Button(root, text="Enable Zoom", command=self.activate_zoom)
self.zoom_button = ttk.Button(root, text="Enable Zoom",
command=self.activate_zoom)
self.zoom_button.grid(row=3, column=2)
# Variables to store zoom area
@@ -223,6 +224,12 @@ class view(object):
res_menu.grid(row=3, column=3)
res_menu.bind("<<ComboboxSelected>>", self.make_new_axis)
# checkbox for grid display
self.do_grid = tk.BooleanVar()
self.checkbox = tk.Checkbutton(root, text="Show grid",
variable=self.do_grid, command=self.toggle_grid)
self.checkbox.grid(row=2, column=3)
# initial plot
self.plot_data()
self.canvas.draw()
@@ -268,6 +275,7 @@ class view(object):
# Ensure correct ordering of coordinates
self.ax.set_xlim(min(x0, x1), max(x0, x1))
self.ax.set_ylim(min(y0, y1), max(y0, y1))
#self.toggle_grid()
# Remove the rectangle and redraw
self.rect.remove()
@@ -330,6 +338,7 @@ class view(object):
#self.X[valid], self.Y[valid], self.dai.data[valid],
self.X, self.Y, self.dai.data,
ax=self.ax, cax=self.cax)
# set ax limits
if self.proj=="+proj=stere +lat_0=90 +lon_0=0":
self.ax.set_xlim([-4660515.349812048, 4660515.349812048])
self.ax.set_ylim([-4658959.2511977535, 4658959.2511977535])
@@ -339,6 +348,14 @@ class view(object):
else:
self.ax.set_xlim(self.X.min(), self.X.max())
self.ax.set_ylim(self.Y.min(), self.Y.max())
# set ax labels
if self.proj=="None" or self.proj=="+proj=latlong":
#self.ax.set_xticks(np.arange(-180.,180.,45.))
#self.ax.set_yticks(np.arange(-90,90,45.))
pass
else:
self.ax.set_xticks([])
self.ax.set_yticks([])
self.ax.set_facecolor('0.7')
self.update_cmap()
# set titles
@@ -475,6 +492,60 @@ class view(object):
clim[1] = data.max().data
return clim
def toggle_grid(self):
if self.do_grid.get():
print('Adding grid lines')
color='k'
linewidth=0.5
if self.proj=="+proj=stere +lat_0=90 +lon_0=0":
lon_c_vals = np.arange(-180.,180., 45.)
lat_c_vals = [40, 50, 60, 70, 80]
elif self.proj=="+proj=stere +lat_0=-90 +lon_0=0":
lon_c_vals = np.arange(-180.,180., 45.)
lat_c_vals = [-30, -40, -50, -60, -70, -80]
if self.proj=="None" or self.proj=="+proj=latlong":
lon_c_vals = self.ax.get_xticks()
lat_c_vals = self.ax.get_yticks()
else:
lon_c_vals = np.arange(-180.,180., 45.)
lat_c_vals = np.arange(-90.,90., 45.)
#transformer = Proj.from_pipeline(self.proj)
nc = 51
X_c = np.empty((1,nc))
Y_c = np.empty((1,nc))
for nn, lat_c_val in enumerate(lat_c_vals):
lon_c = np.linspace(-180,180,nc)
lat_c = lat_c_val*np.ones(nc)
if self.proj!="None":
x_c, y_c = self.transformer.transform(
lon_c, lat_c, direction='FORWARD')
else:
x_c, y_c = lon_c, lat_c
X_c = np.concatenate([X_c, x_c[np.newaxis,:]], axis=0)
Y_c = np.concatenate([Y_c, y_c[np.newaxis,:]], axis=0)
for nn, lon_c_val in enumerate(lon_c_vals):
lon_c = lon_c_val*np.ones(nc)
lat_c = np.linspace(-90,90,nc)
if self.proj!="None":
x_c, y_c = self.transformer.transform(
lon_c, lat_c, direction='FORWARD')
else:
x_c, y_c = lon_c, lat_c
X_c = np.concatenate([X_c, x_c[np.newaxis,:]], axis=0)
Y_c = np.concatenate([Y_c, y_c[np.newaxis,:]], axis=0)
self.hgs = []
for nn in range(X_c.shape[0]):
hg, = self.ax.plot(X_c[nn,:], Y_c[nn,:],
color=color, linewidth=linewidth)
self.hgs.append(hg)
#print(f'nn = {nn}, {self.hgs}')
else:
print('Removing grid lines')
for hg in self.hgs:
hg.remove()
self.canvas.draw()
# capture mouse click, print coordinates and data
def on_click(self, event):
# Avoid clicking outside the axes
Loading