Continue writting

This commit is contained in:
Santiago Soler
2018-02-01 14:01:56 -03:00
parent 03340d4010
commit 902eb6b670
2 changed files with 18 additions and 11 deletions

View File

@@ -39,13 +39,15 @@ class Moulder(FigureCanvasQTAgg):
'n: New polygon', 'd: delete', 'click: select/move', 'a: add vertex', 'n: New polygon', 'd: delete', 'click: select/move', 'a: add vertex',
'r: reset view', 'esc: cancel']) 'r: reset view', 'esc: cancel'])
def __init__(self, parent, area, x, z, width=5, height=4, dpi=100): def __init__(self, parent, area, x, z, density_range=[-2000, 2000],
width=5, height=4, dpi=100):
self.fig = Figure(figsize=(width, height), dpi=dpi) self.fig = Figure(figsize=(width, height), dpi=dpi)
super().__init__(self.fig) super().__init__(self.fig)
self.setParent(parent) self.setParent(parent)
self._area = area self._area = area
self._x, self._z = x, z self._x, self._z = x, z
self.density_range = density_range
self._predicted = numpy.zeros_like(x) self._predicted = numpy.zeros_like(x)
self._data = None self._data = None
self.cmap = pyplot.cm.RdBu_r self.cmap = pyplot.cm.RdBu_r
@@ -60,6 +62,10 @@ class Moulder(FigureCanvasQTAgg):
self._density = 100 self._density = 100
self._error = 0 self._error = 0
# Data min and max (only for first implementations)
# They will be determined when data is imported
self.dmin, self.dmax = 0, 0
self._figure_setup() self._figure_setup()
self._init_markers() self._init_markers()
self._connect() self._connect()
@@ -139,6 +145,7 @@ class Moulder(FigureCanvasQTAgg):
self.modelax.set_ylim(self.area[2:]) self.modelax.set_ylim(self.area[2:])
self.modelax.grid(True) self.modelax.grid(True)
self.modelax.invert_yaxis() self.modelax.invert_yaxis()
self.predicted_line, = self.dataax.plot(self.x, self.predicted, '-r')
self.canvas.draw() self.canvas.draw()
def _init_markers(self): def _init_markers(self):
@@ -205,7 +212,7 @@ class Moulder(FigureCanvasQTAgg):
poly = patches.Polygon(vertices, animated=False, alpha=0.9, poly = patches.Polygon(vertices, animated=False, alpha=0.9,
color=self._density2color(density)) color=self._density2color(density))
x, y = list(zip(*poly.xy)) x, y = list(zip(*poly.xy))
line = Line2D(x, y, **self.line_args) line = Line2D(x, y, **LINE_ARGS)
return poly, line return poly, line
def _update_data_plot(self): def _update_data_plot(self):
@@ -236,7 +243,7 @@ class Moulder(FigureCanvasQTAgg):
if self._ipoly is not None: if self._ipoly is not None:
self.densities[self._ipoly] = value self.densities[self._ipoly] = value
self.polygons[self._ipoly].set_color(self._density2color(value)) self.polygons[self._ipoly].set_color(self._density2color(value))
self._update_data() # self._update_data()
self._update_data_plot() self._update_data_plot()
self.canvas.draw() self.canvas.draw()
@@ -346,7 +353,7 @@ class Moulder(FigureCanvasQTAgg):
self.modelax.add_line(line) self.modelax.add_line(line)
self.lines[self._ipoly].set_color([0, 1, 0, 0]) self.lines[self._ipoly].set_color([0, 1, 0, 0])
self.canvas.draw() self.canvas.draw()
self._update_data() # self._update_data()
self._update_data_plot() self._update_data_plot()
elif self._drawing: elif self._drawing:
if event.button == 1: if event.button == 1:
@@ -371,7 +378,7 @@ class Moulder(FigureCanvasQTAgg):
self.lines[self._ipoly].set_color([0, 1, 0, 0]) self.lines[self._ipoly].set_color([0, 1, 0, 0])
self.dataax.set_title(self.instructions) self.dataax.set_title(self.instructions)
self.canvas.draw() self.canvas.draw()
self._update_data() # self._update_data()
self._update_data_plot() self._update_data_plot()
def _button_release_callback(self, event): def _button_release_callback(self, event):
@@ -395,7 +402,7 @@ class Moulder(FigureCanvasQTAgg):
# self._ipoly is only released when clicking outside # self._ipoly is only released when clicking outside
# the polygons # the polygons
self._lastevent = None self._lastevent = None
self._update_data() # self._update_data()
self._update_data_plot() self._update_data_plot()
def _key_press_callback(self, event_key): def _key_press_callback(self, event_key):
@@ -420,7 +427,7 @@ class Moulder(FigureCanvasQTAgg):
poly.xy = numpy.array([xy for i, xy in enumerate(poly.xy) poly.xy = numpy.array([xy for i, xy in enumerate(poly.xy)
if i not in verts]) if i not in verts])
line.set_data(list(zip(*poly.xy))) line.set_data(list(zip(*poly.xy)))
self._update_data() # self._update_data()
self._update_data_plot() self._update_data_plot()
self.canvas.restore_region(self.background) self.canvas.restore_region(self.background)
self.modelax.draw_artist(poly) self.modelax.draw_artist(poly)
@@ -435,7 +442,7 @@ class Moulder(FigureCanvasQTAgg):
self.densities.pop(self._ipoly) self.densities.pop(self._ipoly)
self._ipoly = None self._ipoly = None
self.canvas.draw() self.canvas.draw()
self._update_data() # self._update_data()
self._update_data_plot() self._update_data_plot()
elif event_key == 'n': elif event_key == 'n':
self._ivert = None self._ivert = None
@@ -448,7 +455,7 @@ class Moulder(FigureCanvasQTAgg):
self.background = self.canvas.copy_from_bbox(self.modelax.bbox) self.background = self.canvas.copy_from_bbox(self.modelax.bbox)
self._drawing = True self._drawing = True
self._xy = [] self._xy = []
self._drawing_plot = Line2D([], [], **self.line_args) self._drawing_plot = Line2D([], [], **LINE_ARGS)
self._drawing_plot.set_animated(True) self._drawing_plot.set_animated(True)
self.modelax.add_line(self._drawing_plot) self.modelax.add_line(self._drawing_plot)
self.dataax.set_title(' | '.join([ self.dataax.set_title(' | '.join([

View File

@@ -42,8 +42,8 @@ class MoulderApp(QMainWindow):
keys_dict = {Qt.Key_N: "n", Qt.Key_R: "r", keys_dict = {Qt.Key_N: "n", Qt.Key_R: "r",
Qt.Key_A: "a", Qt.Key_D: "d", Qt.Key_A: "a", Qt.Key_D: "d",
Qt.Key_Escape: "escape"} Qt.Key_Escape: "escape"}
if event.key in keys_dict.keys(): if event.key() in keys_dict.keys():
self.canvas._key_press_callback(keys_dict[event.key]) self.canvas._key_press_callback(keys_dict[event.key()])
def closeEvent(self, event): def closeEvent(self, event):
event.ignore() event.ignore()