def __init__(self, parent, parameter): QtGui.QWidget.__init__(self) self.setupUi(self) self.mySystem = parent self.param = parameter # "x" or "y" # TODO: This should probably move to the Plot-class: self.latex_installed = self.mySystem.myPyplane.latex_installed self.Layout = QtGui.QVBoxLayout(self.frame) self.Canvas = Canvas(self, self.latex_installed) self.Layout.addWidget(self.Canvas) self.param_minLabel.setText("%smin" % (self.param)) self.param_maxLabel.setText("%smax" % (self.param)) self.xminLineEdit.setText(str(myConfig.read("%s-t-plot" % (self.param), "%s_tmin" % (self.param)))) self.xmaxLineEdit.setText(str(myConfig.read("%s-t-plot" % (self.param), "%s_tmax" % (self.param)))) self.yminLineEdit.setText(str(myConfig.read("%s-t-plot" % (self.param), "%s_%smin" % (self.param, self.param)))) self.ymaxLineEdit.setText(str(myConfig.read("%s-t-plot" % (self.param), "%s_%smax" % (self.param, self.param)))) self.Plot = Plot(self, self.Canvas) # connect buttons self.SetButton.clicked.connect(self.Plot.set_window_range) self.ZoomButton.clicked.connect(self.Canvas.toggle_zoom_mode) self.ZoomButton.setCheckable(True)
def update(self): """ This function plots streamlines. """ self.remove() if self.tgl: xmin, xmax, ymin, ymax = self.myWidget.Plot.canvas.axes.axis() N = int(myConfig.read("Streamlines", "stream_gridPointsInX")) M = int(myConfig.read("Streamlines", "stream_gridPointsInY")) stream_linewidth = float(myConfig.read("Streamlines", "stream_linewidth")) stream_color = str(myConfig.read("Streamlines", "stream_color")) stream_density = float(myConfig.read("Streamlines", "stream_density")) a = np.linspace(xmin, xmax, N) b = np.linspace(ymin, ymax, M) X1, Y1 = np.meshgrid(a, b) try: DX1, DY1 = self.myWidget.mySystem.equation.rhs([X1, Y1]) streamplot = self.myWidget.Plot.canvas.axes.streamplot(X1, Y1, DX1, DY1, density=stream_density, linewidth=stream_linewidth, color=stream_color) self.sl_stack.append(streamplot) myLogger.message("Streamplot created") except: myLogger.debug_message("No system yet") self.myWidget.Plot.canvas.draw()
def add(self): try: fct_string = str(self.mySystem.myPyplane.yLineEdit.text()) except UnicodeEncodeError as exc: myLogger.error_message("input error!") myLogger.debug_message(str(exc)) fct_string = str(self.mySystem.myPyplane.yLineEdit.text()) if fct_string != "": try: self.fct_expr = sp.sympify(fct_string) self.fct = sp.lambdify((self.x, self.y), self.fct_expr, 'numpy') xmin, xmax, ymin, ymax = self.mySystem.Phaseplane.Plot.canvas.axes.axis( ) # plot the function for an x-interval twice as big as the current window deltax = (xmax - xmin) / 2 deltay = (ymax - ymin) / 2 plot_xmin = xmin - deltax plot_xmax = xmax + deltax plot_ymin = ymin - deltay plot_ymax = ymax + deltay pts_in_x = int(myConfig.read("Functions", "fct_gridPointsInX")) pts_in_y = int(myConfig.read("Functions", "fct_gridPointsInY")) fct_color = myConfig.read("Functions", "fct_color") fct_linewidth = float( myConfig.read("Functions", "fct_linewidth")) x = np.arange(plot_xmin, plot_xmax, (xmax - xmin) / pts_in_x) y = np.arange(plot_ymin, plot_ymax, (ymax - ymin) / pts_in_y) X, Y = np.meshgrid(x, y) myfunc = self.fct(X, Y) # TODO: plots like y=1/x have a connection between -inf and +inf that is not actually there! # plot function and put on function-stack new_fct = self.mySystem.Phaseplane.Plot.canvas.axes.contour( X, Y, myfunc, [0], zorder=100, linewidths=fct_linewidth, colors=fct_color) # new_fct = self.myGraph.plot_pp.axes.plot(xvalue, yvalue, label="fct", color="green") self.fct_stack.append(new_fct) self.mySystem.Phaseplane.Plot.update() myLogger.message("function plot: 0 = " + fct_string) except Exception as error: # TODO: use handle_exception for this myLogger.error_message(str(error)) else: myLogger.error_message("Please enter function.")
def __init__(self, parent, latex_installed): self.myWidget = parent plot_background = myConfig.read("Plotting", "plot_background") plot_CanvasBackground = str(myConfig.read("Plotting", "plot_CanvasBackground")) plot_fontSize = int(myConfig.read("Plotting", "plot_fontSize")) plot_topOfPlot = float(myConfig.read("Plotting", "plot_topOfPlot")) plot_leftOfPlot = 0.12#float(myConfig.read("Plotting", "plot_leftOfPlot")) plot_rightOfPlot = float(myConfig.read("Plotting", "plot_rightOfPlot")) plot_bottomOfPlot = 0.1#float(myConfig.read("Plotting", "plot_bottomOfPlot")) self.fig = pl.Figure(facecolor=plot_background) pl.matplotlib.rc('font', size=plot_fontSize) # Check if LaTeX and dvipng are installed on this system since this # is required by matplotlib for fine rendering. If it is not installed # only basic rendering will be done in the following rc('text', usetex=latex_installed) # ALIASING # TODO: read aliasing variables: # pl.matplotlib.rc('lines', antialiased=False) # pl.matplotlib.rc('text', antialiased=False) # pl.matplotlib.rc('patch', antialiased=False) self.axes = self.fig.add_subplot(111) # Matplotlib 2.0 vs. 1.5 behavior... try: self.axes.set_facecolor(plot_CanvasBackground) # Matplotlib >= 2 except AttributeError: self.axes.set_axis_bgcolor(plot_CanvasBackground) # Matplotlib < 2 # matplotlib background transparent (issues on old versions?) if myConfig.get_boolean("Plotting", "plot_backgroundTransparent"): self.fig.frameon = False self.adjust = self.fig.subplots_adjust(top=plot_topOfPlot, left=plot_leftOfPlot, right=plot_rightOfPlot, bottom=plot_bottomOfPlot) FigureCanvas.__init__(self, self.fig) self.setParent(parent) self.navigationToolbar = Toolbar(self) # TODO: rather as a real toolbar: # self.toolbar = NavigationToolbar(self, self.myWidget.mpl_layout, coordinates=True) # self.myWidget.mplvl.addWidget(self.toolbar) FigureCanvas.setSizePolicy(self, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) FigureCanvas.updateGeometry(self) # zoom mode on/off self.zoomMode = False myLogger.debug_message(str(self) + ": initialized")
def plot_equilibrium(self, z_equilibrium, jacobian): """ this function plots an equilibrium point """ self.eq_plot = self.myWidget.Plot.canvas.axes.plot(z_equilibrium[0], z_equilibrium[1], 'ro', picker=5) # equilibrium point in t(x,y): # TODO: let user specify this in config! # TODO: show equilibria in x(t) and y(t) as well! if self.myWidget.mySystem.Phaseplane.backwardCheckbox.isChecked(): tmin = -float(myConfig.read("Trajectories", "traj_integrationtime")) else: tmin = 0 if self.myWidget.mySystem.Phaseplane.forwardCheckbox.isChecked(): tmax = float(myConfig.read("Trajectories", "traj_integrationtime")) else: tmax = 0 # equilibrium line from tmin to tmax if not (tmin == 0 and tmax == 0): self.myWidget.mySystem.Txy.Plot.canvas.axes.plot( [z_equilibrium[0], z_equilibrium[0]], [z_equilibrium[1], z_equilibrium[1]], [tmin, tmax], linestyle="dashed", color="r") # marker t=0: self.myWidget.mySystem.Txy.Plot.canvas.axes.plot([z_equilibrium[0]], [z_equilibrium[1]], [0], 'o', color="r") self.myWidget.mySystem.Txy.Plot.update() #~ self.stack[str(z_equilibrium)] = self.eq_plot equilibrium_point = Container() equilibrium_point.coordinates = z_equilibrium equilibrium_point.plot = self.eq_plot equilibrium_point.character = self.characterize_equilibrium(jacobian) self.stack.append(equilibrium_point) # label equilibrium point self.myWidget.Plot.canvas.axes.text(z_equilibrium[0], z_equilibrium[1], equilibrium_point.character, fontsize=10) self.update_equilibria() # TODO: this call probably move somewhere else: if len(self.stack) > 0: self.myWidget.show_linearization_objects() myLogger.message("Equilibrium Point found at: " + str(z_equilibrium)) myLogger.message("jacobian:\n" + str(jacobian))
def clear(self): self.canvas.axes.clear() if myConfig.get_boolean(self._section, self._token + "showGrid"): self.canvas.axes.grid() if myConfig.get_boolean(self._section, self._token + "showMinorTicks"): self.canvas.axes.minorticks_on() else: self.canvas.axes.minorticks_off() if not myConfig.get_boolean(self._section, self._token + "showTTicks"): self.canvas.axes.zaxis.set_ticks([]) if not myConfig.get_boolean(self._section, self._token + "showXTicks"): self.canvas.axes.xaxis.set_ticks([]) if not myConfig.get_boolean(self._section, self._token + "showYTicks"): self.canvas.axes.yaxis.set_ticks([]) if myConfig.get_boolean(self._section, self._token + "showTitle"): title_x_dot = sp.latex( self.myWidget.mySystem.equation.what_is_my_system()[0]) title_y_dot = sp.latex( self.myWidget.mySystem.equation.what_is_my_system()[1]) self.canvas.axes.set_title("$\\dot{x} = " + title_x_dot + "$\n$\\dot{y} = " + title_y_dot + "$") else: self.canvas.fig.subplots_adjust(top=0.99) if myConfig.get_boolean(self._section, self._token + "showXLabel"): xlabel = "$x$" label_fontsize = myConfig.read(self._section, self._token + "labelFontSize") self.canvas.axes.set_xlabel(xlabel, fontsize=label_fontsize) if myConfig.get_boolean(self._section, self._token + "showYLabel"): label_fontsize = myConfig.read(self._section, self._token + "labelFontSize") ylabel = "$y$" self.canvas.axes.set_ylabel(ylabel, fontsize=label_fontsize) if myConfig.get_boolean(self._section, self._token + "showTLabel"): label_fontsize = myConfig.read(self._section, self._token + "labelFontSize") tlabel = "$t$" self.canvas.axes.set_zlabel(tlabel, fontsize=label_fontsize) if not myConfig.get_boolean(self._section, self._token + "showSpines"): for spine in self.canvas.axes.spines.itervalues(): spine.set_visible(False) self.update() myLogger.debug_message("3d graph cleared")
def update(self): """ this function will show nullclines """ self.remove() if self.tgl: # get axis limits xmin, xmax, ymin, ymax = self.myWidget.Plot.canvas.axes.axis() pts_in_x = int(myConfig.read("Nullclines", "nc_gridPointsInX")) pts_in_y = int(myConfig.read("Nullclines", "nc_gridPointsInY")) nc_color_xdot = myConfig.read("Nullclines", "nc_color_xdot") nc_color_ydot = myConfig.read("Nullclines", "nc_color_ydot") nc_linewidth = float(myConfig.read("Nullclines", "nc_linewidth")) a = np.arange(xmin, xmax, (xmax - xmin) / pts_in_x) b = np.arange(ymin, ymax, (xmax - xmin) / pts_in_y) X1, Y1 = np.meshgrid(a, b) try: DX1, DY1 = self.myWidget.mySystem.equation.rhs([X1, Y1]) nullclines_xdot = self.myWidget.Plot.canvas.axes.contour( X1, Y1, DX1, levels=[0], linewidths=nc_linewidth, colors=nc_color_xdot) nullclines_ydot = self.myWidget.Plot.canvas.axes.contour( X1, Y1, DY1, levels=[0], linewidths=nc_linewidth, colors=nc_color_ydot) # proxy artist for legend proxy_x_nc = pyplot.Rectangle((0, 0), 1, 1, fc=nc_color_xdot) proxy_y_nc = pyplot.Rectangle((0, 0), 1, 1, fc=nc_color_ydot) self.myWidget.Plot.canvas.axes.legend( [proxy_x_nc, proxy_y_nc], ["x-Nullclines", "y-Nullclines"], bbox_to_anchor=(0., 1.02, 1., .102), loc=2, prop={'size': 8}, frameon=False) self.nc_stack.append(nullclines_xdot) self.nc_stack.append(nullclines_ydot) except: myLogger.debug_message("Please submit system.") # refresh graph self.myWidget.Plot.canvas.draw()
def plot_eigenvectors(self, equilibrium): if self.linear: # system is linear -> calculate jacobian x, y = sp.symbols("x, y") xdot = self.equation.x_dot_expr ydot = self.equation.y_dot_expr A11 = xdot.diff(x) A12 = xdot.diff(y) A21 = ydot.diff(x) A22 = ydot.diff(y) jac = np.array([[A11,A12],[A21,A22]], dtype=float) eigenvalues, eigenvectors = np.linalg.eig(jac) eigvec0 = eigenvectors[:,0] eigvec1 = eigenvectors[:,1] # calculating eigenvalues and eigenvectors: #~ eigenvalues, eigenvectors = self.Phaseplane.Equilibria.get_eigenval_eigenvec(equilibrium) myLogger.message("Eigenvectors: (" + str(eigvec0[0]) + ", " + str(eigvec0[1]) + ") and (" + str(eigvec1[0]) + ", " + str(eigvec1[1]) + ")") # scaling xmin, xmax, ymin, ymax = self.Phaseplane.Plot.get_limits() d1 = (xmax-xmin)/10 d2 = (ymax-ymin)/10 d_large = (xmax-xmin)*(ymax-ymin) EV0 = np.array([np.real(eigvec0[0]),np.real(eigvec0[1])]) EV0_norm = np.sqrt(EV0[0]**2+EV0[1]**2) EV0_scaled = np.array([d1*(1/EV0_norm)*EV0[0],d1*(1/EV0_norm)*EV0[1]]) EV1 = np.array([np.real(eigvec1[0]),np.real(eigvec1[1])]) EV1_norm = np.sqrt(EV1[0]**2+EV1[1]**2) EV1_scaled = np.array([d1*(1/EV1_norm)*EV1[0],d1*(1/EV1_norm)*EV1[1]]) # plot equilibrium: self.Phaseplane.Plot.canvas.axes.plot(equilibrium[0], equilibrium[1], 'ro', picker=2) # plot eigenvectors: color_eigenvec = myConfig.read("Linearization", "lin_eigenvector_color") color_eigenline = myConfig.read("Linearization", "lin_eigenvector_linecolor") if myConfig.get_boolean("Linearization","lin_show_eigenline"): self.Phaseplane.Plot.canvas.axes.arrow(equilibrium[0], equilibrium[1], d_large*EV0_scaled[0], d_large*EV0_scaled[1], head_width=0, head_length=0, color=color_eigenline) self.Phaseplane.Plot.canvas.axes.arrow(equilibrium[0], equilibrium[1], -d_large*EV0_scaled[0], -d_large*EV0_scaled[1], head_width=0, head_length=0, color=color_eigenline) if myConfig.get_boolean("Linearization","lin_show_eigenvector"): self.Phaseplane.Plot.canvas.axes.arrow(equilibrium[0], equilibrium[1], EV0_scaled[0], EV0_scaled[1], head_width=0, head_length=0, color=color_eigenvec) if myConfig.get_boolean("Linearization","lin_show_eigenline"): self.Phaseplane.Plot.canvas.axes.arrow(equilibrium[0], equilibrium[1], d_large*EV1_scaled[0], d_large*EV1_scaled[1], head_width=0, head_length=0, color=color_eigenline) self.Phaseplane.Plot.canvas.axes.arrow(equilibrium[0], equilibrium[1], -d_large*EV1_scaled[0], -d_large*EV1_scaled[1], head_width=0, head_length=0, color=color_eigenline) if myConfig.get_boolean("Linearization","lin_show_eigenvector"): self.Phaseplane.Plot.canvas.axes.arrow(equilibrium[0], equilibrium[1], EV1_scaled[0], EV1_scaled[1], head_width=0, head_length=0, color=color_eigenvec) self.Phaseplane.Plot.add_eigenvectors_to_title(eigvec0, eigvec1)
def add(self): try: fct_string = str(self.mySystem.myPyplane.yLineEdit.text()) except UnicodeEncodeError as exc: myLogger.error_message("input error!") myLogger.debug_message(str(exc)) fct_string = str(self.mySystem.myPyplane.yLineEdit.text()) if fct_string != "": try: self.fct_expr = sp.sympify(fct_string) self.fct = sp.lambdify((self.x, self.y), self.fct_expr, 'numpy') xmin, xmax, ymin, ymax = self.mySystem.Phaseplane.Plot.canvas.axes.axis() # plot the function for an x-interval twice as big as the current window deltax = (xmax - xmin) / 2 deltay = (ymax - ymin) / 2 plot_xmin = xmin - deltax plot_xmax = xmax + deltax plot_ymin = ymin - deltay plot_ymax = ymax + deltay pts_in_x = int(myConfig.read("Functions", "fct_gridPointsInX")) pts_in_y = int(myConfig.read("Functions", "fct_gridPointsInY")) fct_color = myConfig.read("Functions", "fct_color") fct_linewidth = float(myConfig.read("Functions", "fct_linewidth")) x = np.arange(plot_xmin, plot_xmax, (xmax - xmin) / pts_in_x) y = np.arange(plot_ymin, plot_ymax, (ymax - ymin) / pts_in_y) X, Y = np.meshgrid(x, y) myfunc = self.fct(X, Y) # TODO: plots like y=1/x have a connection between -inf and +inf that is not actually there! # plot function and put on function-stack new_fct = self.mySystem.Phaseplane.Plot.canvas.axes.contour(X, Y, myfunc, [0], zorder=100, linewidths=fct_linewidth, colors=fct_color) # new_fct = self.myGraph.plot_pp.axes.plot(xvalue, yvalue, label="fct", color="green") self.fct_stack.append(new_fct) self.mySystem.Phaseplane.Plot.update() myLogger.message("function plot: 0 = " + fct_string) except Exception as error: # TODO: use handle_exception for this myLogger.error_message(str(error)) else: myLogger.error_message("Please enter function.")
def plot_equilibrium(self, z_equilibrium, jacobian): """ this function plots an equilibrium point """ self.eq_plot = self.myWidget.Plot.canvas.axes.plot(z_equilibrium[0], z_equilibrium[1], 'ro', picker=5) # equilibrium point in t(x,y): # TODO: let user specify this in config! # TODO: show equilibria in x(t) and y(t) as well! if self.myWidget.mySystem.Phaseplane.backwardCheckbox.isChecked(): tmin = -float(myConfig.read("Trajectories", "traj_integrationtime")) else: tmin = 0 if self.myWidget.mySystem.Phaseplane.forwardCheckbox.isChecked(): tmax = float(myConfig.read("Trajectories", "traj_integrationtime")) else: tmax = 0 # equilibrium line from tmin to tmax if not(tmin==0 and tmax==0): self.myWidget.mySystem.Txy.Plot.canvas.axes.plot([z_equilibrium[0],z_equilibrium[0]], [z_equilibrium[1],z_equilibrium[1]], [tmin, tmax], linestyle="dashed", color="r") # marker t=0: self.myWidget.mySystem.Txy.Plot.canvas.axes.plot([z_equilibrium[0]], [z_equilibrium[1]], [0], 'o', color="r") self.myWidget.mySystem.Txy.Plot.update() #~ self.stack[str(z_equilibrium)] = self.eq_plot equilibrium_point = Container() equilibrium_point.coordinates = z_equilibrium equilibrium_point.plot = self.eq_plot equilibrium_point.character = self.characterize_equilibrium(jacobian) self.stack.append(equilibrium_point) # label equilibrium point self.myWidget.Plot.canvas.axes.text(z_equilibrium[0], z_equilibrium[1], equilibrium_point.character, fontsize=10) self.update_equilibria() # TODO: this call probably move somewhere else: if len(self.stack) > 0: self.myWidget.show_linearization_objects() myLogger.message("Equilibrium Point found at: " + str(z_equilibrium)) myLogger.message("jacobian:\n" + str(jacobian))
def __init__(self, parent): self.mySystem = parent QtWidgets.QWidget.__init__(self) self.setupUi(self) self.latex_installed = self.mySystem.myPyplane.latex_installed self.Layout = QtWidgets.QVBoxLayout(self.frame) self.Canvas = Canvas(self, self.latex_installed) self.Layout.addWidget(self.Canvas) # Axis labels self.xlabel_str = "x" self.ylabel_str = "y" # set forward and backward integration true if myConfig.get_boolean("Trajectories", "traj_checkForwardByDefault"): self.forwardCheckbox.setChecked(True) if myConfig.get_boolean("Trajectories", "traj_checkBackwardByDefault"): self.backwardCheckbox.setChecked(True) self.xminLineEdit.setText(str(myConfig.read("Phaseplane", "pp_xmin"))) self.xmaxLineEdit.setText(str(myConfig.read("Phaseplane", "pp_xmax"))) self.yminLineEdit.setText(str(myConfig.read("Phaseplane", "pp_ymin"))) self.ymaxLineEdit.setText(str(myConfig.read("Phaseplane", "pp_ymax"))) self.Plot = PhasePlot(self, self.Canvas) self.Plot.set_window_range() self.VF = Vectorfield(self) self.SL = StreamlineHandler(self) self.Nullclines = NullclineHandler(self) self.Equilibria = EquilibriumHandler(self) # menu checkers self.mySystem.myPyplane.toggle_vectorfield_action.setChecked( self.VF.tgl) # connect buttons self.SetButton.clicked.connect(self.Plot.set_window_range) self.ZoomButton.clicked.connect(self.Canvas.toggle_zoom_mode) self.ZoomButton.setCheckable(True) self.RefreshButton.clicked.connect(self.Plot.refresh) self.CreateTrajectoryButton.clicked.connect( self.mySystem.Trajectories.create_trajectory) # linearize button and combo box # TODO: Fix next line! # self.connect(self.linBox, QtCore.SIGNAL('activated(QString)'), self.eq_chosen) self.linButton.clicked.connect(self.linearize_system) self.hide_linearization_objects()
def __init__(self, parent): self.mySystem = parent QtWidgets.QWidget.__init__(self) self.setupUi(self) self.latex_installed = self.mySystem.myPyplane.latex_installed self.Layout = QtWidgets.QVBoxLayout(self.frame) self.Canvas = Canvas(self, self.latex_installed) self.Layout.addWidget(self.Canvas) # Axis labels self.xlabel_str = "x" self.ylabel_str = "y" # set forward and backward integration true if myConfig.get_boolean("Trajectories", "traj_checkForwardByDefault"): self.forwardCheckbox.setChecked(True) if myConfig.get_boolean("Trajectories", "traj_checkBackwardByDefault"): self.backwardCheckbox.setChecked(True) self.xminLineEdit.setText(str(myConfig.read("Phaseplane", "pp_xmin"))) self.xmaxLineEdit.setText(str(myConfig.read("Phaseplane", "pp_xmax"))) self.yminLineEdit.setText(str(myConfig.read("Phaseplane", "pp_ymin"))) self.ymaxLineEdit.setText(str(myConfig.read("Phaseplane", "pp_ymax"))) self.Plot = PhasePlot(self, self.Canvas) self.Plot.set_window_range() self.VF = Vectorfield(self) self.SL = StreamlineHandler(self) self.Nullclines = NullclineHandler(self) self.Equilibria = EquilibriumHandler(self) # menu checkers self.mySystem.myPyplane.toggle_vectorfield_action.setChecked(self.VF.tgl) # connect buttons self.SetButton.clicked.connect(self.Plot.set_window_range) self.ZoomButton.clicked.connect(self.Canvas.toggle_zoom_mode) self.ZoomButton.setCheckable(True) self.RefreshButton.clicked.connect(self.Plot.refresh) self.CreateTrajectoryButton.clicked.connect(self.mySystem.Trajectories.create_trajectory) # linearize button and combo box # TODO: Fix next line! # self.connect(self.linBox, QtCore.SIGNAL('activated(QString)'), self.eq_chosen) self.linButton.clicked.connect(self.linearize_system) self.hide_linearization_objects()
def clear(self): self.canvas.axes.clear() if myConfig.get_boolean(self._section, self._token + "showGrid"): self.canvas.axes.grid() if myConfig.get_boolean(self._section, self._token + "showMinorTicks"): self.canvas.axes.minorticks_on() else: self.canvas.axes.minorticks_off() if not myConfig.get_boolean(self._section, self._token + "showTTicks"): self.canvas.axes.zaxis.set_ticks([]) if not myConfig.get_boolean(self._section, self._token + "showXTicks"): self.canvas.axes.xaxis.set_ticks([]) if not myConfig.get_boolean(self._section, self._token + "showYTicks"): self.canvas.axes.yaxis.set_ticks([]) if myConfig.get_boolean(self._section, self._token + "showTitle"): title_x_dot = sp.latex(self.myWidget.mySystem.equation.what_is_my_system()[0]) title_y_dot = sp.latex(self.myWidget.mySystem.equation.what_is_my_system()[1]) self.canvas.axes.set_title("$\\dot{x} = " + title_x_dot + "$\n$\\dot{y} = " + title_y_dot + "$") else: self.canvas.fig.subplots_adjust(top=0.99) if myConfig.get_boolean(self._section, self._token + "showXLabel"): xlabel = "$x$" label_fontsize = myConfig.read(self._section, self._token + "labelFontSize") self.canvas.axes.set_xlabel(xlabel, fontsize=label_fontsize) if myConfig.get_boolean(self._section, self._token + "showYLabel"): label_fontsize = myConfig.read(self._section, self._token + "labelFontSize") ylabel = "$y$" self.canvas.axes.set_ylabel(ylabel, fontsize=label_fontsize) if myConfig.get_boolean(self._section, self._token + "showTLabel"): label_fontsize = myConfig.read(self._section, self._token + "labelFontSize") tlabel = "$t$" self.canvas.axes.set_zlabel(tlabel, fontsize=label_fontsize) if not myConfig.get_boolean(self._section, self._token + "showSpines"): for spine in self.canvas.axes.spines.itervalues(): spine.set_visible(False) self.update() myLogger.debug_message("3d graph cleared")
def update(self): """ this function will show nullclines """ self.remove() if self.nc_toggle: # get axis limits xmin, xmax, ymin, ymax = self.plot_pp.axes.axis() pts_in_x = int(myConfig.read("Nullclines", "nc_gridPointsInX")) pts_in_y = int(myConfig.read("Nullclines", "nc_gridPointsInY")) nc_color_xdot = myConfig.read("Nullclines", "nc_color_xdot") nc_color_ydot = myConfig.read("Nullclines", "nc_color_ydot") nc_linewidth = float(myConfig.read("Nullclines", "nc_linewidth")) a = np.arange(xmin, xmax, (xmax - xmin) / pts_in_x) b = np.arange(ymin, ymax, (xmax - xmin) / pts_in_y) X1, Y1 = np.meshgrid(a, b) try: DX1, DY1 = mySystem.rhs([X1, Y1]) nullclines_xdot = self.plot_pp.axes.contour(X1, Y1, DX1, levels=[0], linewidths=nc_linewidth, colors=nc_color_xdot) nullclines_ydot = self.plot_pp.axes.contour(X1, Y1, DY1, levels=[0], linewidths=nc_linewidth, colors=nc_color_ydot) # proxy artist for legend proxy_x_nc = pyplot.Rectangle((0, 0), 1, 1, fc=nc_color_xdot) proxy_y_nc = pyplot.Rectangle((0, 0), 1, 1, fc=nc_color_ydot) self.plot_pp.axes.legend([proxy_x_nc, proxy_y_nc], ["x-Nullclines", "y-Nullclines"], bbox_to_anchor=(0., 1.02, 1., .102), loc=2, prop={'size': 8}, frameon=False) self.nc_stack.append(nullclines_xdot) self.nc_stack.append(nullclines_ydot) except: myLogger.debug_message("Please submit system.") # refresh graph self.plot_pp.draw()
def __init__(self, parent=None): super(PyplaneMainWindow, self).__init__() QtGui.QWidget.__init__(self, parent) self.setupUi(self) self.setWindowTitle('PyPlane %s' % __version__) myLogger.register_output(self.logField) self.myLayout1 = QtGui.QVBoxLayout(self.frame1) self.plotCanvas1 = Canvas(self.frame1) self.myLayout1.addWidget(self.plotCanvas1) self.myLayout2 = QtGui.QVBoxLayout(self.frame2) self.plotCanvas2 = Canvas(self.frame2) self.myLayout2.addWidget(self.plotCanvas2) self.myLayout3 = QtGui.QVBoxLayout(self.frame3) self.plotCanvas3 = Canvas(self.frame3) self.myLayout3.addWidget(self.plotCanvas3) self.myGraph = Graph(parent=self, plot_pp=self.plotCanvas1, plot_x=self.plotCanvas2, plot_y=self.plotCanvas3) self.fct_stack = [] self.linearization_stack = [] self.xDotLabel.setText(u"\u1E8B(x,y) = ") self.yDotLabel.setText(u"\u1E8F(x,y) = ") try: test = myConfig.read("Test", "test_var") except: test = "Could not load config file. Please check existence" myLogger.debug_message("Loading config file: " + test)
def __init__(self, parent=None): super(PyplaneMainWindow, self).__init__() QtWidgets.QWidget.__init__(self, parent) self.setupUi(self) self.setWindowTitle('PyPlane') myLogger.register_output(self.logField) # Check if LaTeX and dvipng is installed on the system. This # is required in order to ensure that advanced formatting in # matplotlib works correctly (\left, \begin{array} etc.) self.latex_installed = myHelpers.check_if_latex() # Embed SettingsWidget: self.mySettings = SettingsWidget() self.SettingsLayout.addWidget(self.mySettings) self.fct_stack = [] self.linearization_stack = [] self.systems = [] self.xDotLabel.setText("\u1E8B(x,y) = ") self.yDotLabel.setText("\u1E8F(x,y) = ") try: test = myConfig.read("Test", "test_var") except: test = "Could not load config file. Please check existence" myLogger.debug_message("Loading config file: " + test)
def __init__(self, parent=None): super(PyplaneMainWindow, self).__init__() QtGui.QWidget.__init__(self, parent) self.setupUi(self) self.setWindowTitle('PyPlane') myLogger.register_output(self.logField) # Check if LaTeX and dvipng is installed on the system. This # is required in order to ensure that advanced formatting in # matplotlib works correctly (\left, \begin{array} etc.) self.latex_installed = myHelpers.check_if_latex() # Embed SettingsWidget: self.mySettings = SettingsWidget() self.SettingsLayout.addWidget(self.mySettings) self.fct_stack = [] self.linearization_stack = [] self.systems = [] self.xDotLabel.setText(u"\u1E8B(x,y) = ") self.yDotLabel.setText(u"\u1E8F(x,y) = ") try: test = myConfig.read("Test", "test_var") except: test = "Could not load config file. Please check existence" myLogger.debug_message("Loading config file: " + test)
def settings_item_clicked(self, index): # TODO: May be we should change this mechanism to a clear model-view # process. Maybe a tree view is appropriate? self.remove_visible_items() # set section title self.section = str(index.data()) # what was sec_elab supposed to mean? section_description = self.descr[self.section] self.SetupSectionTitle.setText(section_description) # iterate over items in section items = myConfig.config.items(self.section) self.remove_visible_items() for i in items: # add qlabel and a qlineedit to gui label = QtGui.QLabel() label.setObjectName(i[0]) label.setFixedWidth(300) # this does not seem to work, but why?: label.setAlignment(QtCore.Qt.AlignRight) #QtCore.pyqtRemoveInputHook() #embed() item_description = str(self.descr[i[0]][0]) label.setText(str(item_description) + ":") label.setAlignment(QtCore.Qt.AlignRight) #lineedit = QtGui.QLineEdit() #lineedit.setObjectName(i[0]) #lineedit.setFixedWidth(100) #lineedit.setAlignment(QtCore.Qt.AlignRight) value = myConfig.read(self.section, i[0]) #lineedit.setText(value) if (value.lower() == "true") | (value.lower() == "false"): input_widget = self.create_boolean_combo_box(i[0], value) elif "color" in item_description.lower(): input_widget = self.create_color_chooser(i[0], value) else: input_widget = self.create_line_edit(i[0], value) # add to stack_visible: # what was the 0 for? self.stack_visible.append([label, 0]) #self.stack_visible.append([lineedit, self.section, str(i[0])]) #self.add_to_layout(label, lineedit) self.stack_visible.append([input_widget, self.section, str(i[0])]) self.add_to_layout(label, input_widget)
def __init__(self, parent, parameter): QtWidgets.QWidget.__init__(self) self.setupUi(self) self.mySystem = parent self.param = parameter # "x" or "y" self.ylabel_str = self.param self.xlabel_str = "t" # TODO: This should probably move to the Plot-class: self.latex_installed = self.mySystem.myPyplane.latex_installed self.Layout = QtWidgets.QVBoxLayout(self.frame) self.Canvas = Canvas(self, self.latex_installed) self.Layout.addWidget(self.Canvas) self.param_minLabel.setText("%smin" % (self.param)) self.param_maxLabel.setText("%smax" % (self.param)) self.xminLineEdit.setText( str( myConfig.read("%s-t-plot" % (self.param), "%s_tmin" % (self.param)))) self.xmaxLineEdit.setText( str( myConfig.read("%s-t-plot" % (self.param), "%s_tmax" % (self.param)))) self.yminLineEdit.setText( str( myConfig.read("%s-t-plot" % (self.param), "%s_%smin" % (self.param, self.param)))) self.ymaxLineEdit.setText( str( myConfig.read("%s-t-plot" % (self.param), "%s_%smax" % (self.param, self.param)))) self.Plot = Plot(self, self.Canvas) # connect buttons self.SetButton.clicked.connect(self.Plot.set_window_range) self.ZoomButton.clicked.connect(self.Canvas.toggle_zoom_mode) self.ZoomButton.setCheckable(True)
def clear(self): self.canvas.axes.clear() if myConfig.get_boolean(self._section, self._token + "showGrid"): self.canvas.axes.grid() if myConfig.get_boolean(self._section, self._token + "showMinorTicks"): self.canvas.axes.minorticks_on() else: self.canvas.axes.minorticks_off() if not myConfig.get_boolean(self._section, self._token + "showXTicks"): self.canvas.axes.xaxis.set_ticks([]) if not myConfig.get_boolean(self._section, self._token + "showYTicks"): self.canvas.axes.yaxis.set_ticks([]) if myConfig.get_boolean(self._section, self._token + "showXLabel"): pp_label_fontsize = myConfig.read(self._section, self._token + "labelFontSize") xlabel = "$%s$" % self.myWidget.xlabel_str self.canvas.axes.set_xlabel(xlabel, fontsize=pp_label_fontsize) if myConfig.get_boolean(self._section, self._token + "showTitle"): title_x_dot = sp.latex(self.myWidget.mySystem.equation.what_is_my_system()[0]) title_y_dot = sp.latex(self.myWidget.mySystem.equation.what_is_my_system()[1]) self.canvas.axes.set_title("$\\dot{x} = " + title_x_dot + "$\n$\\dot{y} = " + title_y_dot + "$") else: self.canvas.fig.subplots_adjust(top=0.99) if myConfig.get_boolean(self._section, self._token + "showYLabel"): pp_label_fontsize = myConfig.read(self._section, self._token + "labelFontSize") ylabel = "$%s$" % self.myWidget.ylabel_str self.canvas.axes.set_ylabel(ylabel, fontsize=pp_label_fontsize) # TODO (jcw): Check if this can be removed (together with Graph class) # if not myConfig.get_boolean(self._section, self._token + "showSpines"): # for spine in Graph.axes.spines.values(): # spine.set_visible(False) self.update() myLogger.debug_message("Graph cleared")
def __init__(self, parent): QtWidgets.QWidget.__init__(self) self.setupUi(self) self.mySystem = parent # Axis labels self.xlabel_str = "x" self.ylabel_str = "y" self.zlabel_str = "t" # TODO: This should probably move to the Plot-class: self.latex_installed = self.mySystem.myPyplane.latex_installed self.Layout = QtWidgets.QVBoxLayout(self.frame) self.Canvas = ThreeDCanvas(self, self.latex_installed) self.Layout.addWidget(self.Canvas) self.tminLineEdit.setText(str(myConfig.read("3d-plot", "3d_tmin"))) self.tmaxLineEdit.setText(str(myConfig.read("3d-plot", "3d_tmax"))) self.xminLineEdit.setText(str(myConfig.read("3d-plot", "3d_xmin"))) self.xmaxLineEdit.setText(str(myConfig.read("3d-plot", "3d_xmax"))) self.yminLineEdit.setText(str(myConfig.read("3d-plot", "3d_ymin"))) self.ymaxLineEdit.setText(str(myConfig.read("3d-plot", "3d_ymax"))) self.Plot = ThreeDPlot(self, self.Canvas) # connect buttons self.SetButton.clicked.connect(self.Plot.set_window_range)
def __init__(self, parent, latex_installed): self.myWidget = parent plot_background = myConfig.read("Plotting", "plot_background") plot_CanvasBackground = str(myConfig.read("Plotting", "plot_CanvasBackground")) plot_fontSize = int(myConfig.read("Plotting", "plot_fontSize")) plot_topOfPlot = float(myConfig.read("Plotting", "plot_topOfPlot")) plot_leftOfPlot = float(myConfig.read("Plotting", "plot_leftOfPlot")) plot_rightOfPlot = float(myConfig.read("Plotting", "plot_rightOfPlot")) plot_bottomOfPlot = float(myConfig.read("Plotting", "plot_bottomOfPlot")) self.fig = pl.Figure(facecolor=plot_background) pl.matplotlib.rc('font', size=plot_fontSize) # Check if LaTeX and dvipng are installed on this system since this # is required by matplotlib for fine rendering. If it is not installed # only basic rendering will be done in the following rc('text', usetex=latex_installed) # ALIASING # TODO: read aliasing variables: # pl.matplotlib.rc('lines', antialiased=False) # pl.matplotlib.rc('text', antialiased=False) # pl.matplotlib.rc('patch', antialiased=False) self.axes = self.fig.add_subplot(111) self.axes.set_axis_bgcolor(plot_CanvasBackground) # matplotlib background transparent (issues on old versions?) if myConfig.get_boolean("Plotting", "plot_backgroundTransparent"): self.fig.frameon = False self.adjust = self.fig.subplots_adjust(top=plot_topOfPlot, left=plot_leftOfPlot, right=plot_rightOfPlot, bottom=plot_bottomOfPlot) FigureCanvas.__init__(self, self.fig) self.setParent(parent) self.navigationToolbar = Toolbar(self) # TODO: rather as a real toolbar: #~ self.toolbar = NavigationToolbar(self, self.myWidget.mpl_layout, coordinates=True) #~ self.myWidget.mplvl.addWidget(self.toolbar) FigureCanvas.setSizePolicy(self, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) FigureCanvas.updateGeometry(self) # zoom mode on/off self.zoomMode = False myLogger.debug_message(str(self) + ": initialized")
def settings_item_clicked(self, index): self.remove_visible_items() # set section title self.section = str(index.data().toString()) # what was sec_elab supposed to mean? section_description = self.descr[self.section] self.SetupSectionTitle.setText(section_description) # iterate over items in section items = myConfig.config.items(self.section) self.remove_visible_items() for i in items: # add qlabel and a qlineedit to gui label = QtGui.QLabel() label.setObjectName(i[0]) label.setFixedWidth(300) # this does not seem to work, but why?: label.setAlignment(QtCore.Qt.AlignRight) #QtCore.pyqtRemoveInputHook() #embed() item_description = str(self.descr[i[0]][0]) label.setText(str(item_description) + ":") label.setAlignment(QtCore.Qt.AlignRight) lineedit = QtGui.QLineEdit() lineedit.setObjectName(i[0]) lineedit.setFixedWidth(100) lineedit.setAlignment(QtCore.Qt.AlignRight) value = myConfig.read(self.section, i[0]) lineedit.setText(value) # add to stack_visible: # what was the 0 for? self.stack_visible.append([label, 0]) self.stack_visible.append([lineedit, self.section, str(i[0])]) self.add_to_layout(label, lineedit) # detect if entered new value # google "python lambda loop parameter" or see # http://stackoverflow.com/questions/938429/ # scope-of-python-lambda-functions-and-their-parameters/938493#938493 # noinspection PyUnresolvedReferences lineedit.textEdited.connect(self.callback_factory(lineedit, self.section, i[0]))
def update(self): """ This function plots streamlines. """ self.remove() if self.tgl: xmin, xmax, ymin, ymax = self.myWidget.Plot.canvas.axes.axis() N = int(myConfig.read("Streamlines", "stream_gridPointsInX")) M = int(myConfig.read("Streamlines", "stream_gridPointsInY")) stream_linewidth = float( myConfig.read("Streamlines", "stream_linewidth")) stream_color = str(myConfig.read("Streamlines", "stream_color")) stream_density = float( myConfig.read("Streamlines", "stream_density")) a = np.linspace(xmin, xmax, N) b = np.linspace(ymin, ymax, M) X1, Y1 = np.meshgrid(a, b) try: DX1, DY1 = self.myWidget.mySystem.equation.rhs([X1, Y1]) streamplot = self.myWidget.Plot.canvas.axes.streamplot( X1, Y1, DX1, DY1, density=stream_density, linewidth=stream_linewidth, color=stream_color) self.sl_stack.append(streamplot) myLogger.message("Streamplot created") except: myLogger.debug_message("No system yet") self.myWidget.Plot.canvas.draw()
def __init__(self, equation=(None, None)): self.x_dot_string, self.y_dot_string = equation #~ assert isinstance(x_dot_string, str) #~ assert isinstance(y_dot_string, str) self.x, self.y = sp.symbols('x, y') self.x_dot_expr = sp.sympify(self.x_dot_string) self.y_dot_expr = sp.sympify(self.y_dot_string) self.x_dot = sp.lambdify((self.x, self.y), self.x_dot_expr, 'numpy') self.y_dot = sp.lambdify((self.x, self.y), self.y_dot_expr, 'numpy') self.max_norm = float(myConfig.read("System", "sys_max_norm")) self.set_rhs(self.x_dot_string, self.y_dot_string)
def __init__(self, equation=(None,None)): self.x_dot_string, self.y_dot_string = equation #~ assert isinstance(x_dot_string, str) #~ assert isinstance(y_dot_string, str) self.x, self.y = sp.symbols('x, y') self.x_dot_expr = sp.sympify(self.x_dot_string) self.y_dot_expr = sp.sympify(self.y_dot_string) self.x_dot = sp.lambdify((self.x, self.y), self.x_dot_expr, 'numpy') self.y_dot = sp.lambdify((self.x, self.y), self.y_dot_expr, 'numpy') self.max_norm = float(myConfig.read("System", "sys_max_norm")) self.set_rhs(self.x_dot_string, self.y_dot_string)
def __init__(self): # naming variables self.x = sp.symbols('x') self.y = sp.symbols('y') self.x_dot = None self.y_dot = None self.x_dot_expr = None self.y_dot_expr = None try: self.max_norm = float(myConfig.read("System", "max_norm")) except: pass else: self.max_norm = 1e5
def update(self): """ This function updates the vectorfield in the phase plane. """ self.remove() if self.tgl: # get axis limits xmin, xmax, ymin, ymax = self.myWidget.Plot.canvas.axes.axis() N = int(myConfig.read("Vectorfield", "vf_gridPointsInX")) M = int(myConfig.read("Vectorfield", "vf_gridPointsInY")) vf_color = str(myConfig.read("Vectorfield", "vf_color")) vf_arrowHeadWidth = float( myConfig.read("Vectorfield", "vf_arrowHeadWidth")) vf_arrowHeadLength = float( myConfig.read("Vectorfield", "vf_arrowHeadLength")) vf_arrowWidth = float(myConfig.read("Vectorfield", "vf_arrowWidth")) vf_arrowPivot = str(myConfig.read("Vectorfield", "vf_arrowPivot")) a = np.linspace(xmin - xmin / N, xmax - xmax / N, N) b = np.linspace(ymin - ymin / M, ymax - ymax / M, M) X1, Y1 = np.meshgrid(a, b) try: DX1, DY1 = self.myWidget.mySystem.equation.rhs([X1, Y1]) M = np.hypot(DX1, DY1) M[M == 0] = 1. DX1_mix, DY1_mix = DX1 / M, DY1 / M quiver = self.myWidget.Plot.canvas.axes.quiver( X1, Y1, DX1_mix, DY1_mix, angles='xy', headwidth=vf_arrowHeadWidth, headlength=vf_arrowHeadLength, width=vf_arrowWidth, pivot=vf_arrowPivot, color=vf_color) self.stack.append(quiver) myLogger.message("vector field created") except: myLogger.debug_message("Please enter system.") self.myWidget.Plot.update()
def __init__(self, parent=None): plot_background = myConfig.read("Plotting", "plot_background") plot_CanvasBackground = str(myConfig.read("Plotting", "plot_CanvasBackground")) plot_fontSize = int(myConfig.read("Plotting", "plot_fontSize")) plot_topOfPlot = float(myConfig.read("Plotting", "plot_topOfPlot")) plot_leftOfPlot = float(myConfig.read("Plotting", "plot_leftOfPlot")) plot_rightOfPlot = float(myConfig.read("Plotting", "plot_rightOfPlot")) plot_bottomOfPlot = float(myConfig.read("Plotting", "plot_bottomOfPlot")) self.fig = pl.Figure(facecolor=plot_background) pl.matplotlib.rc('font', size=plot_fontSize) # use latex rc('text', usetex=True) # ALIASING # TODO: read aliasing variables: # pl.matplotlib.rc('lines', antialiased=False) # pl.matplotlib.rc('text', antialiased=False) # pl.matplotlib.rc('patch', antialiased=False) self.axes = self.fig.add_subplot(111) self.axes.set_axis_bgcolor(plot_CanvasBackground) # matplotlib background transparent (issues on old versions?) if myConfig.get_boolean("Plotting", "plot_backgroundTransparent"): self.fig.frameon = False self.adjust = self.fig.subplots_adjust(top=plot_topOfPlot, left=plot_leftOfPlot, right=plot_rightOfPlot, bottom=plot_bottomOfPlot) FigureCanvas.__init__(self, self.fig) self.setParent(parent) self.navigationToolbar = Toolbar(self) FigureCanvas.setSizePolicy(self, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) FigureCanvas.updateGeometry(self) # zoom mode on/off self.zoomMode = False myLogger.debug_message(str(self) + ": initialized")
def linearize_system(self): eq_identifier = str(self.linBox.currentText()) equilibrium = self.Equilibria.get_equilibrium_by_character_identifier(eq_identifier) jac = self.Equilibria.approx_ep_jacobian(equilibrium.coordinates) # set system properties accuracy = int(myConfig.read("Linearization","lin_round_decimals")) xe = round(equilibrium.coordinates[0], accuracy) ye = round(equilibrium.coordinates[1], accuracy) equilibrium = (xe, ye) A00 = str(round(jac[0,0], accuracy)) A01 = str(round(jac[0,1], accuracy)) A11 = str(round(jac[1,1], accuracy)) A10 = str(round(jac[1,0], accuracy)) x_dot_string = A00 + "*(x-(" + str(xe) + ")) + (" + A01 + ")*(y-(" + str(ye) + "))" y_dot_string = A10 + "*(x-(" + str(xe) + ")) + (" + A11 + ")*(y-(" + str(ye) + "))" equation_string = (x_dot_string, y_dot_string) self.mySystem.myPyplane.new_linearized_system(equation_string, eq_identifier, equilibrium)
def update(self): """ This function updates the vectorfield in the phase plane. """ self.remove() if self.tgl: # get axis limits xmin, xmax, ymin, ymax = self.myWidget.Plot.canvas.axes.axis() N = int(myConfig.read("Vectorfield", "vf_gridPointsInX")) M = int(myConfig.read("Vectorfield", "vf_gridPointsInY")) vf_color = str(myConfig.read("Vectorfield", "vf_color")) vf_arrowHeadWidth = float(myConfig.read("Vectorfield", "vf_arrowHeadWidth")) vf_arrowHeadLength = float(myConfig.read("Vectorfield", "vf_arrowHeadLength")) vf_arrowWidth = float(myConfig.read("Vectorfield", "vf_arrowWidth")) vf_arrowPivot = str(myConfig.read("Vectorfield", "vf_arrowPivot")) a = np.linspace(xmin - xmin / N, xmax - xmax / N, N) b = np.linspace(ymin - ymin / M, ymax - ymax / M, M) X1, Y1 = np.meshgrid(a, b) try: DX1, DY1 = self.myWidget.mySystem.equation.rhs([X1, Y1]) M = np.hypot(DX1, DY1) M[M == 0] = 1. DX1_mix, DY1_mix = DX1 / M, DY1 / M quiver = self.myWidget.Plot.canvas.axes.quiver(X1, Y1, DX1_mix, DY1_mix, angles='xy', headwidth=vf_arrowHeadWidth, headlength=vf_arrowHeadLength, width=vf_arrowWidth, pivot=vf_arrowPivot, color=vf_color) self.stack.append(quiver) myLogger.message("vector field created") except: myLogger.debug_message("Please enter system.") self.myWidget.Plot.update()
def linearize_system(self): eq_identifier = str(self.linBox.currentText()) equilibrium = self.Equilibria.get_equilibrium_by_character_identifier( eq_identifier) jac = self.Equilibria.approx_ep_jacobian(equilibrium.coordinates) # set system properties accuracy = int(myConfig.read("Linearization", "lin_round_decimals")) xe = round(equilibrium.coordinates[0], accuracy) ye = round(equilibrium.coordinates[1], accuracy) equilibrium = (xe, ye) A00 = str(round(jac[0, 0], accuracy)) A01 = str(round(jac[0, 1], accuracy)) A11 = str(round(jac[1, 1], accuracy)) A10 = str(round(jac[1, 0], accuracy)) x_dot_string = A00 + "*(x-(" + str( xe) + ")) + (" + A01 + ")*(y-(" + str(ye) + "))" y_dot_string = A10 + "*(x-(" + str( xe) + ")) + (" + A11 + ")*(y-(" + str(ye) + "))" equation_string = (x_dot_string, y_dot_string) self.mySystem.myPyplane.new_linearized_system(equation_string, eq_identifier, equilibrium)
def add_function_to_plot(self): """ will plot additional functions and put it on a stack """ self.x = sp.symbols('x') self.y = sp.symbols('y') self.fct = None try: fct_txt = str(self.yLineEdit.text()) except UnicodeEncodeError as exc: myLogger.error_message("input error!") myLogger.debug_message(str(exc)) if fct_txt != "": try: self.fct_string = str(self.yLineEdit.text()) self.fct_expr = sp.sympify(self.fct_string) # self.fct = sp.lambdify(self.x,self.fct_expr,'numpy') self.fct = sp.lambdify((self.x, self.y), self.fct_expr, 'numpy') xmin, xmax, ymin, ymax = self.myGraph.get_limits( self.myGraph.plot_pp) # plot the function for an x-interval twice as big as the current window deltax = (xmax - xmin) / 2 deltay = (ymax - ymin) / 2 plot_xmin = xmin - deltax plot_xmax = xmax + deltax plot_ymin = ymin - deltay plot_ymax = ymax + deltay pts_in_x = int(myConfig.read("Functions", "fct_gridPointsInX")) pts_in_y = int(myConfig.read("Functions", "fct_gridPointsInY")) fct_color = myConfig.read("Functions", "fct_color") fct_linewidth = float( myConfig.read("Functions", "fct_linewidth")) x = np.arange(plot_xmin, plot_xmax, (xmax - xmin) / pts_in_x) y = np.arange(plot_ymin, plot_ymax, (ymax - ymin) / pts_in_y) X, Y = np.meshgrid(x, y) #yvalue = self.fct(xvalue) myfunc = self.fct(X, Y) # TODO: plots like y=1/x have a connection between -inf and +inf that is not actually there! # plot function and put on function-stack new_fct = self.myGraph.plot_pp.axes.contour( X, Y, myfunc, [0], zorder=100, linewidths=fct_linewidth, colors=fct_color) # new_fct = self.myGraph.plot_pp.axes.plot(xvalue, yvalue, label="fct", color="green") self.fct_stack.append(new_fct) self.myGraph.update_graph(self.myGraph.plot_pp) myLogger.message("function plot: 0 = " + self.fct_string) except Exception as error: handle_exception(error) else: myLogger.error_message("Please enter function.")
def clear_graph(self, Graph): """ This function resets a graph. Depending on the default values in the config file, the following is shown: - grid - minor ticks in x and y direction - labels on x and y axes - title """ Graph.axes.clear() if Graph == self.plot_pp: section = "Phaseplane" token = "pp_" elif Graph == self.plot_x: section = "x-t-plot" token = "x_" else: section = "y-t-plot" token = "y_" if myConfig.get_boolean(section, token + "showGrid"): Graph.axes.grid() if myConfig.get_boolean(section, token + "showMinorTicks"): Graph.axes.minorticks_on() else: Graph.axes.minorticks_off() if not myConfig.get_boolean(section, token + "showXTicks"): Graph.axes.xaxis.set_ticks([]) if not myConfig.get_boolean(section, token + "showYTicks"): Graph.axes.yaxis.set_ticks([]) if myConfig.get_boolean(section, token + "showXLabel"): pp_label_fontsize = myConfig.read(section, token + "labelFontSize") if Graph == self.plot_pp: xlabel = "$x$" else: xlabel = "$t$" Graph.axes.set_xlabel(xlabel, fontsize=pp_label_fontsize) if myConfig.get_boolean(section, token + "showTitle"): title_x_dot = sp.latex(mySystem.what_is_my_system()[0]) title_y_dot = sp.latex(mySystem.what_is_my_system()[1]) Graph.axes.set_title("$\\dot{x} = " + title_x_dot + "$\n$\\dot{y} = " + title_y_dot + "$") else: Graph.fig.subplots_adjust(top=0.99) if myConfig.get_boolean(section, token + "showYLabel"): pp_label_fontsize = myConfig.read(section, token + "labelFontSize") if Graph == self.plot_pp: ylabel = "$\\dot{x}$" elif Graph == self.plot_x: ylabel = "$x$" else: ylabel = "$y$" Graph.axes.set_ylabel(ylabel, fontsize=pp_label_fontsize) if not myConfig.get_boolean(section, token + "showSpines"): for spine in Graph.axes.spines.itervalues(): spine.set_visible(False) self.update_graph(Graph) myLogger.debug_message("Graph cleared")
def plot_trajectory(self, initial_condition, forward=None, backward=None): """ This function plots the solution of the differential equation depending on the initial condition. In general, the trajectory consists of three elements: the forward trajectory, the backward trajectory and the marker for the initial condition, while each element can be turned off in the config file / settings tab. The elements are stored in a list. A dictionary stores this data with the initalCondition as its key, and the list as the value. Input variables: - initialCondition (list with x and y coordinate) Return variables: - none """ if not forward and not backward: myLogger.warn_message( "Please select forward and/or backward integration!") return False else: traj_stack = [] traj_integrationtime = float( myConfig.read("Trajectories", "traj_integrationtime")) traj_integrationstep = float( myConfig.read("Trajectories", "traj_integrationstep")) time = pl.arange(0, traj_integrationtime, traj_integrationstep) if forward: # while integrate.ode.successful(): # self.mySystem.jacobian(initialCondition) assert isinstance(initial_condition, list) self.x = integrate.odeint(self.mySystem.equation.rhs, initial_condition, time) #, full_output=1, printmessg=1, mxstep=20000) xvalue = self.x[:, 0] # extract the x vector yvalue = self.x[:, 1] # extract the dx/dt vector # masking xvalue (deleting invalid entries) # xvalue = np.ma.masked_outside(xvalue,-1*self.mySystem.max_norm, # self.mySystem.max_norm) # myMask = xvalue.mask # new_time = np.ma.array(self.t, mask=myMask).compressed() # yvalue = np.ma.array(yvalue, mask=myMask).compressed() # xvalue = xvalue.compressed() # QtCore.pyqtRemoveInputHook() # embed() # masking yvalue # yvalue = np.ma.masked_outside(yvalue,-1*self.mySystem.max_norm, # self.mySystem.max_norm) # myMask = yvalue.mask # new_time = np.ma.array(self.t, mask=myMask).compressed() # xvalue = np.ma.array(xvalue, mask=myMask) # yvalue = yvalue.compressed() # QtCore.pyqtRemoveInputHook() # embed() # plot solution in phase plane: traj_ppForwardColor = myConfig.read("Trajectories", "traj_ppForwardColor") plot1 = self.mySystem.Phaseplane.Plot.canvas.axes.plot( xvalue, yvalue, traj_ppForwardColor) plot3d_forward = self.mySystem.Txy.Plot.canvas.axes.plot( xvalue, yvalue, time, traj_ppForwardColor) zero_arrayx = np.array([10] * len(time)) zero_arrayy = np.array([-10] * len(time)) if myConfig.get_boolean("3d-plot", "3d_showXProjection"): plot3d_forward_projx = self.mySystem.Txy.Plot.canvas.axes.plot( xvalue, zero_arrayx, time, "0.75") traj_stack.append(plot3d_forward_projx) if myConfig.get_boolean("3d-plot", "3d_showYProjection"): plot3d_forward_projy = self.mySystem.Txy.Plot.canvas.axes.plot( zero_arrayy, yvalue, time, "0.75") traj_stack.append(plot3d_forward_projy) if myConfig.get_boolean("3d-plot", "3d_showYXProjection"): plot3d_forward_projxy = self.mySystem.Txy.Plot.canvas.axes.plot( xvalue, yvalue, 0, "0.75") traj_stack.append(plot3d_forward_projxy) # numpy array with both x and y values in pairs # TODO: might be faster if xvalues or yvalues greater than self.mySystem.max_norm # are masked before calculating the norm xvalue, yvalue = self.filter_values(xvalue, yvalue) # THIS HAS BEEN COMMENTED # z = np.column_stack((xvalue,yvalue)) # # # put norm of each pair in numpy array # normed_z = np.array([np.linalg.norm(v) for v in z]) # # # masking # max_norm = self.mySystem.max_norm # masked_normed_z = np.ma.masked_greater(normed_z, max_norm) # myMask = masked_normed_z.mask # # # new xvalue and yvalue # xvalue = np.ma.array(xvalue, mask=myMask) # yvalue = np.ma.array(yvalue, mask=myMask) # UNTIL HERE! # plot solution in x(t): traj_x_tColor = myConfig.read("Trajectories", "traj_x_tColor") plot2 = self.mySystem.Xt.Plot.canvas.axes.plot( time, xvalue, color=traj_x_tColor) # plot solution in y(t): traj_y_tColor = myConfig.read("Trajectories", "traj_y_tColor") plot3 = self.mySystem.Yt.Plot.canvas.axes.plot( time, yvalue, color=traj_y_tColor) # self.myLogger.message("forward trajectory done for initial condition "+str(initialCondition)) traj_stack.append(plot1) traj_stack.append(plot2) traj_stack.append(plot3) traj_stack.append(plot3d_forward) # backward in time -------------------------------------------- if backward: self.x_bw = integrate.odeint(self.mySystem.equation.n_rhs, initial_condition, time) #, full_output=1, printmessg=1)#, mxstep=5000) # self.x_bw, infodict2 = integrate.odeint(self.mySystem.n_rhs, # initialCondition, self.t)#, full_output=1, printmessg=1)#, mxstep=5000) xvalue_bw = self.x_bw[:, 0] yvalue_bw = self.x_bw[:, 1] # # masking xvalue_bw (deleting invalid entries) # xvalue_bw = np.ma.masked_outside(xvalue_bw,1*self.mySystem.max_norm, # self.mySystem.max_norm) # yvalue_bw = np.ma.array(yvalue_bw, mask=xvalue_bw.mask) # xvalue_bw = xvalue_bw.compressed() # # # masking yvalue_bw # yvalue_bw = np.ma.masked_outside(yvalue_bw,1*self.mySystem.max_norm, # self.mySystem.max_norm) # xvalue = np.ma.array(xvalue, mask=yvalue.mask) # yvalue_bw = yvalue_bw.compressed() # xvalue, yvalue = self.filter_values(xvalue,yvalue) # plot in phase plane: traj_ppBackwardColor = myConfig.read("Trajectories", "traj_ppBackwardColor") plot4 = self.mySystem.Phaseplane.Plot.canvas.axes.plot( xvalue_bw, yvalue_bw, color=traj_ppBackwardColor) plot3d_backward = self.mySystem.Txy.Plot.canvas.axes.plot( xvalue_bw, yvalue_bw, -time, traj_ppForwardColor) zero_arrayx = np.array([10] * len(time)) zero_arrayy = np.array([-10] * len(time)) if myConfig.get_boolean("3d-plot", "3d_showXProjection"): plot3d_backward_projx = self.mySystem.Txy.Plot.canvas.axes.plot( xvalue_bw, zero_arrayx, -time, "0.75") traj_stack.append(plot3d_backward_projx) if myConfig.get_boolean("3d-plot", "3d_showYProjection"): plot3d_backwardprojy = self.mySystem.Txy.Plot.canvas.axes.plot( zero_arrayy, yvalue_bw, -time, "0.75") traj_stack.append(plot3d_backwardprojy) if myConfig.get_boolean("3d-plot", "3d_showYXProjection"): plot3d_backward_projxy = self.mySystem.Txy.Plot.canvas.axes.plot( xvalue_bw, yvalue_bw, 0, "0.75") traj_stack.append(plot3d_backward_projxy) traj_stack.append(plot4) traj_stack.append(plot3d_backward) # self.myLogger.message("backward trajectory # done for initial condition "+str(initialCondition)) # mark init: if myConfig.get_boolean("Trajectories", "traj_plotInitPoint"): traj_initPointColor = myConfig.read("Trajectories", "traj_initPointColor") plot5 = self.mySystem.Phaseplane.Plot.canvas.axes.plot( initial_condition[0], initial_condition[1], '.', color=traj_initPointColor) plot3d_initpoint = self.mySystem.Txy.Plot.canvas.axes.plot( [initial_condition[0]], [initial_condition[1]], [0], '.', color=traj_initPointColor) traj_stack.append(plot5) traj_stack.append(plot3d_initpoint) if len(traj_stack) != 0: # mark init: self.traj_dict[str(initial_condition)] = traj_stack self.mySystem.update()
def add_function_to_plot(self): """ will plot additional functions and put it on a stack """ self.x = sp.symbols('x') self.y = sp.symbols('y') self.fct = None fct_txt = "" try: fct_txt = str(self.yLineEdit.text()) except UnicodeEncodeError as exc: myLogger.error_message("input error!") myLogger.debug_message(str(exc)) if fct_txt != "": try: self.fct_string = str(self.yLineEdit.text()) self.fct_expr = sp.sympify(self.fct_string) # self.fct = sp.lambdify(self.x,self.fct_expr,'numpy') self.fct = sp.lambdify((self.x, self.y), self.fct_expr, 'numpy') xmin, xmax, ymin, ymax = self.myGraph.get_limits(self.myGraph.plot_pp) # plot the function for an x-interval twice as big as the current window deltax = (xmax - xmin) / 2 deltay = (ymax - ymin) / 2 plot_xmin = xmin - deltax plot_xmax = xmax + deltax plot_ymin = ymin - deltay plot_ymax = ymax + deltay pts_in_x = int(myConfig.read("Functions", "fct_gridPointsInX")) pts_in_y = int(myConfig.read("Functions", "fct_gridPointsInY")) fct_color = myConfig.read("Functions", "fct_color") fct_linewidth = float(myConfig.read("Functions", "fct_linewidth")) x = np.arange(plot_xmin, plot_xmax, (xmax - xmin) / pts_in_x) y = np.arange(plot_ymin, plot_ymax, (ymax - ymin) / pts_in_y) X, Y = np.meshgrid(x, y) # yvalue = self.fct(xvalue) myfunc = self.fct(X, Y) # TODO: plots like y=1/x have a connection between -inf and +inf that is not actually there! # plot function and put on function-stack new_fct = self.myGraph.plot_pp.axes.contour(X, Y, myfunc, [0], zorder=100, linewidths=fct_linewidth, colors=fct_color) # new_fct = self.myGraph.plot_pp.axes.plot(xvalue, yvalue, label="fct", color="green") self.fct_stack.append(new_fct) self.myGraph.update_graph(self.myGraph.plot_pp) myLogger.message("function plot: 0 = " + self.fct_string) except Exception as error: handle_exception(error) else: myLogger.error_message("Please enter function.")
def plot_trajectory(self, initial_condition, forward=None, backward=None): """ This function plots the solution of the differential equation depending on the initial condition. In general, the trajectory consists of three elements: the forward trajectory, the backward trajectory and the marker for the initial condition, while each element can be turned off in the config file / settings tab. The elements are stored in a list. A dictionary stores this data with the initalCondition as its key, and the list as the value. Input variables: - initialCondition (list with x and y coordinate) Return variables: - none """ if not forward and not backward: myLogger.warn_message("Please select forward and/or backward integration!") return False else: traj_stack = [] traj_integrationtime = float(myConfig.read("Trajectories", "traj_integrationtime")) traj_integrationstep = float(myConfig.read("Trajectories", "traj_integrationstep")) time = pl.arange(0, traj_integrationtime, traj_integrationstep) if forward: # while integrate.ode.successful(): # self.mySystem.jacobian(initialCondition) assert isinstance(initial_condition, list) self.x = integrate.odeint(self.mySystem.equation.rhs, initial_condition, time) #, full_output=1, printmessg=1, mxstep=20000) xvalue = self.x[:, 0] # extract the x vector yvalue = self.x[:, 1] # extract the dx/dt vector # masking xvalue (deleting invalid entries) # xvalue = np.ma.masked_outside(xvalue,-1*self.mySystem.max_norm, # self.mySystem.max_norm) # myMask = xvalue.mask # new_time = np.ma.array(self.t, mask=myMask).compressed() # yvalue = np.ma.array(yvalue, mask=myMask).compressed() # xvalue = xvalue.compressed() # QtCore.pyqtRemoveInputHook() # embed() # masking yvalue # yvalue = np.ma.masked_outside(yvalue,-1*self.mySystem.max_norm, # self.mySystem.max_norm) # myMask = yvalue.mask # new_time = np.ma.array(self.t, mask=myMask).compressed() # xvalue = np.ma.array(xvalue, mask=myMask) # yvalue = yvalue.compressed() # QtCore.pyqtRemoveInputHook() # embed() # plot solution in phase plane: traj_ppForwardColor = myConfig.read("Trajectories", "traj_ppForwardColor") plot1 = self.mySystem.Phaseplane.Plot.canvas.axes.plot(xvalue, yvalue, traj_ppForwardColor) plot3d_forward = self.mySystem.Txy.Plot.canvas.axes.plot(xvalue, yvalue, time, traj_ppForwardColor) zero_arrayx = np.array([10]*len(time)) zero_arrayy = np.array([-10]*len(time)) if myConfig.get_boolean("3d-plot", "3d_showXProjection"): plot3d_forward_projx = self.mySystem.Txy.Plot.canvas.axes.plot(xvalue, zero_arrayx, time, "0.75") traj_stack.append(plot3d_forward_projx) if myConfig.get_boolean("3d-plot", "3d_showYProjection"): plot3d_forward_projy = self.mySystem.Txy.Plot.canvas.axes.plot(zero_arrayy, yvalue, time, "0.75") traj_stack.append(plot3d_forward_projy) if myConfig.get_boolean("3d-plot", "3d_showYXProjection"): plot3d_forward_projxy = self.mySystem.Txy.Plot.canvas.axes.plot(xvalue, yvalue, 0, "0.75") traj_stack.append(plot3d_forward_projxy) # numpy array with both x and y values in pairs # TODO: might be faster if xvalues or yvalues greater than self.mySystem.max_norm # are masked before calculating the norm xvalue, yvalue = self.filter_values(xvalue, yvalue) # THIS HAS BEEN COMMENTED # z = np.column_stack((xvalue,yvalue)) # # # put norm of each pair in numpy array # normed_z = np.array([np.linalg.norm(v) for v in z]) # # # masking # max_norm = self.mySystem.max_norm # masked_normed_z = np.ma.masked_greater(normed_z, max_norm) # myMask = masked_normed_z.mask # # # new xvalue and yvalue # xvalue = np.ma.array(xvalue, mask=myMask) # yvalue = np.ma.array(yvalue, mask=myMask) # UNTIL HERE! # plot solution in x(t): traj_x_tColor = myConfig.read("Trajectories", "traj_x_tColor") plot2 = self.mySystem.Xt.Plot.canvas.axes.plot(time, xvalue, color=traj_x_tColor) # plot solution in y(t): traj_y_tColor = myConfig.read("Trajectories", "traj_y_tColor") plot3 = self.mySystem.Yt.Plot.canvas.axes.plot(time, yvalue, color=traj_y_tColor) # self.myLogger.message("forward trajectory done for initial condition "+str(initialCondition)) traj_stack.append(plot1) traj_stack.append(plot2) traj_stack.append(plot3) traj_stack.append(plot3d_forward) # backward in time -------------------------------------------- if backward: self.x_bw = integrate.odeint(self.mySystem.equation.n_rhs, initial_condition, time) #, full_output=1, printmessg=1)#, mxstep=5000) # self.x_bw, infodict2 = integrate.odeint(self.mySystem.n_rhs, # initialCondition, self.t)#, full_output=1, printmessg=1)#, mxstep=5000) xvalue_bw = self.x_bw[:, 0] yvalue_bw = self.x_bw[:, 1] # # masking xvalue_bw (deleting invalid entries) # xvalue_bw = np.ma.masked_outside(xvalue_bw,1*self.mySystem.max_norm, # self.mySystem.max_norm) # yvalue_bw = np.ma.array(yvalue_bw, mask=xvalue_bw.mask) # xvalue_bw = xvalue_bw.compressed() # # # masking yvalue_bw # yvalue_bw = np.ma.masked_outside(yvalue_bw,1*self.mySystem.max_norm, # self.mySystem.max_norm) # xvalue = np.ma.array(xvalue, mask=yvalue.mask) # yvalue_bw = yvalue_bw.compressed() # xvalue, yvalue = self.filter_values(xvalue,yvalue) # plot in phase plane: traj_ppBackwardColor = myConfig.read("Trajectories", "traj_ppBackwardColor") plot4 = self.mySystem.Phaseplane.Plot.canvas.axes.plot(xvalue_bw, yvalue_bw, color=traj_ppBackwardColor) plot3d_backward = self.mySystem.Txy.Plot.canvas.axes.plot(xvalue_bw, yvalue_bw, -time, traj_ppForwardColor) zero_arrayx = np.array([10]*len(time)) zero_arrayy = np.array([-10]*len(time)) if myConfig.get_boolean("3d-plot", "3d_showXProjection"): plot3d_backward_projx = self.mySystem.Txy.Plot.canvas.axes.plot(xvalue_bw, zero_arrayx, -time, "0.75") traj_stack.append(plot3d_backward_projx) if myConfig.get_boolean("3d-plot", "3d_showYProjection"): plot3d_backwardprojy = self.mySystem.Txy.Plot.canvas.axes.plot(zero_arrayy, yvalue_bw, -time, "0.75") traj_stack.append(plot3d_backwardprojy) if myConfig.get_boolean("3d-plot", "3d_showYXProjection"): plot3d_backward_projxy = self.mySystem.Txy.Plot.canvas.axes.plot(xvalue_bw, yvalue_bw, 0, "0.75") traj_stack.append(plot3d_backward_projxy) traj_stack.append(plot4) traj_stack.append(plot3d_backward) # self.myLogger.message("backward trajectory # done for initial condition "+str(initialCondition)) # mark init: if myConfig.get_boolean("Trajectories", "traj_plotInitPoint"): traj_initPointColor = myConfig.read("Trajectories", "traj_initPointColor") plot5 = self.mySystem.Phaseplane.Plot.canvas.axes.plot(initial_condition[0], initial_condition[1], '.', color=traj_initPointColor) plot3d_initpoint = self.mySystem.Txy.Plot.canvas.axes.plot([initial_condition[0]], [initial_condition[1]], [0], '.', color=traj_initPointColor) traj_stack.append(plot5) traj_stack.append(plot3d_initpoint) if len(traj_stack) != 0: # mark init: self.traj_dict[str(initial_condition)] = traj_stack self.mySystem.update()
def find_equilibrium(self, z_init): """ hopf2.ppf has problems with this algorithm -> TODO: debug!!! """ # TODO: this try-loop is too long! try: if self.tgl: # newton's method to find equilibrium points iterlimit = 50 iter = 0 h = .000001 z_next = z_init functionf = self.myWidget.mySystem.equation.rhs(z_init) # allow for large/small solutions errorlim = np.linalg.norm(functionf, np.inf) * 0.000001 while ((np.linalg.norm(functionf, np.inf) > errorlim) & (iter < iterlimit)): iter = iter + 1 # now we calculate the jacobian jacobian = np.eye(2) for i in range(0, 2): sav = z_next[i] z_next[i] = z_next[i] + h functionfhj = self.myWidget.mySystem.equation.rhs(z_next) jac = (functionfhj - functionf) / h jacobian[0, i] = jac[0] jacobian[1, i] = jac[1] z_next[i] = sav z_next = z_next - np.linalg.solve(jacobian, functionf) functionf = self.myWidget.mySystem.equation.rhs(z_next) if iter > (iterlimit - 1): fLag = [0, 0] else: fLag = [1, 1] # TODO: this for loop is used twice: why not put it in a function? for i in range(0, 2): sav = z_next[i] z_next[i] = z_next[i] + h functionfhj = self.myWidget.mySystem.equation.rhs(z_next) jac = (functionfhj - functionf) / h jacobian[0, i] = jac[0] jacobian[1, i] = jac[1] z_next[i] = sav #TODO: use list instead of array and safe casting z_next = list(z_next) # due to numerical errors, this is not sufficient and # there could be multiple equilibria plotted where # only one should be: # calculate the distance to all existing equilibrium points # if the distance is smaller than a certain value epsilon, it is # assumed that this equilibrium point is already calculated epsilon = 1e-4 if len(self.stack) == 0: self.plot_equilibrium(z_next, jacobian) self.jacobians[str(z_next)] = jacobian return z_next else: # there are equilibria already # if the distance to an existing equilibrium point is less # than epsilon, do not plot if not self.calculated_before(z_next): myLogger.debug_message("Equilibrium Point already there!") else: self.plot_equilibrium(z_next, jacobian) # add to jacobians self.jacobians[str(z_next)] = jacobian return z_next # d_norm = [] # list with distance to equ. pts # # for ep in self.eqp_stack.keys(): # ep = ast.literal_eval(ep) # x_val = z_next[0] - ep[0] # y_val = z_next[1] - ep[1] # # d_norm.append(np.sqrt(x_val ** 2 + y_val ** 2)) # # if any(d < epsilon for d in d_norm): # myLogger.debug_message("Equilibrium Point already there!") # # else: # self.plot_equilibrium(z_next, jacobian) # # add to jacobians # self.jacobians[str(z_next)] = jacobian except Exception as error: myLogger.error_message("Something strange happened while calculating the equilibrium") if myConfig.read("Logging", "log_showDbg"): myLogger.debug_message(error)
def initializing(self): """ gets called after every submit call """ self.PP_xminLineEdit.setText(str(myConfig.read("Phaseplane", "pp_xmin"))) self.PP_xmaxLineEdit.setText(str(myConfig.read("Phaseplane", "pp_xmax"))) self.PP_yminLineEdit.setText(str(myConfig.read("Phaseplane", "pp_ymin"))) self.PP_ymaxLineEdit.setText(str(myConfig.read("Phaseplane", "pp_ymax"))) self.myGraph.set_window_range(self.myGraph.plot_pp) self.X_tminLineEdit.setText(str(myConfig.read("x-t-plot", "x_tmin"))) self.X_tmaxLineEdit.setText(str(myConfig.read("x-t-plot", "x_tmax"))) self.X_xminLineEdit.setText(str(myConfig.read("x-t-plot", "x_xmin"))) self.X_xmaxLineEdit.setText(str(myConfig.read("x-t-plot", "x_xmax"))) self.myGraph.set_window_range(self.myGraph.plot_x) self.Y_tminLineEdit.setText(str(myConfig.read("y-t-plot", "y_tmin"))) self.Y_tmaxLineEdit.setText(str(myConfig.read("y-t-plot", "y_tmax"))) self.Y_yminLineEdit.setText(str(myConfig.read("y-t-plot", "y_ymin"))) self.Y_ymaxLineEdit.setText(str(myConfig.read("y-t-plot", "y_ymax"))) self.myGraph.set_window_range(self.myGraph.plot_y) #self.myGraph.update() myNullclines.update() myVectorfield.update() myStreamlines.update()