text
stringlengths
0
828
labelanchor=tk.N,
background='red')
toolbarframe = tk.Frame(self.toolbarcenterframe)
toolbar = CustomToolbar(self.canvas, toolbarframe, self.toolbarcenterframe, self)
toolbar.update()
self.fig.canvas.toolbar.set_message = lambda x: """" # remove state reporting
toolbarframe.pack()
self.toolbarcenterframe.pack(side=tk.BOTTOM, fill=tk.X)"
128,"def onpress(self, event):
""""""
Reacts to key commands
:param event: a keyboard event
:return: if 'c' is pressed, clear all region patches
""""""
if event.key == 'c': # clears all the contours
for patch in self.region_patches:
patch.remove()
self.region_patches = []
self.fig.canvas.draw_idle()
elif event.key == ""u"": # undo a label
self.undobutton_action()"
129,"def onclick(self, event):
""""""
Draw contours on the data for a click in the thematic map
:param event: mouse click on thematic map preview
""""""
if event.inaxes == self.previewax:
y, x = int(event.xdata), int(event.ydata)
label = self.selection_array[x, y]
contiguous_regions = scipy.ndimage.label(self.selection_array == label)[0]
this_region = contiguous_regions == (contiguous_regions[x, y])
# remove the boundaries so any region touching the edge isn't drawn odd
this_region[0, :] = 0
this_region[:, 0] = 0
this_region[this_region.shape[0]-1, :] = 0
this_region[:, this_region.shape[1]-1] = 0
# convert the region mask into just a true/false array of its boundary pixels
edges = binary_erosion(this_region) ^ this_region
# convert the boundary pixels into a path, moving around instead of just where
x, y = np.where(edges)
coords = np.dstack([x, y])[0]
path = [coords[0]]
coords = coords[1:]
while len(coords):
dist = np.sum(np.abs(path[-1] - coords), axis=1)
neighbor_index = np.argmin(dist)
if dist[neighbor_index] < 5:
path.append(coords[neighbor_index].copy())
coords[neighbor_index:-1] = coords[neighbor_index + 1:]
coords = coords[:-1]
else:
break
path = np.array(path)
clips = []
while len(coords) > 5:
dist = np.sum(np.abs(path[-1] - coords), axis=1)
neighbor_index = np.argmin(dist)
clip = [coords[neighbor_index].copy()]
coords[neighbor_index:-1] = coords[neighbor_index + 1:]
coords = coords[:-1]
while len(coords):
dist = np.sum(np.abs(clip[-1] - coords), axis=1)
neighbor_index = np.argmin(dist)
if dist[neighbor_index] < 5:
clip.append(coords[neighbor_index].copy())
coords[neighbor_index:-1] = coords[neighbor_index + 1:]
coords = coords[:-1]
else:
break
clips.append(np.array(clip))
# draw the continguous on the selection area
self.region_patches.append(PatchCollection(
[Polygon(np.dstack([path[:, 1], path[:, 0]])[0], False,
fill=False, facecolor=None,
edgecolor=""black"", alpha=1, lw=2.5)] +
[Polygon(np.dstack([clip[:, 1], clip[:, 0]])[0], False,
fill=False, facecolor=None,
edgecolor=""black"", alpha=1, lw=2.0) for clip in clips],
match_original=True))
self.imageax.add_collection(self.region_patches[-1])
self.fig.canvas.draw_idle()"
130,"def make_options_frame(self):
"""""" make the frame that allows for configuration and classification""""""
self.tab_frame = ttk.Notebook(self.option_frame, width=800)
self.tab_configure = tk.Frame(self.tab_frame)
self.tab_classify = tk.Frame(self.tab_frame)
self.make_configure_tab()
self.make_classify_tab()
self.tab_frame.add(self.tab_configure, text=""Configure"")
self.tab_frame.add(self.tab_classify, text=""Classify"")
self.tab_frame.pack(fill=tk.BOTH, expand=True)"