Ejemplo n.º 1
0
    def __init__(self, parent, plot_pp, plot_x, plot_y):
        assert isinstance(plot_pp, Canvas)
        assert isinstance(plot_x, Canvas)
        assert isinstance(plot_y, Canvas)

        # for deleting lineedits/etc. from parent class
        self.parent = parent
        self.plot_pp = plot_pp
        self.plot_x = plot_x
        self.plot_y = plot_y

        # register_graph plot_pp
        myEquilibria.register_graph(self.plot_pp)
        myNullclines.register_graph(self.plot_pp)
        myTrajectories.register_graph(self, self.plot_pp, self.plot_x,
                                      self.plot_y)
        myStreamlines.register_graph(self, self.plot_pp)
        myVectorfield.register_graph(self, self.plot_pp)

        # read initial values: vector field, streamlines, nullclines
        self.vf_toggle = myConfig.get_boolean("Vectorfield", "vf_onByDefault")
        self.nc_toggle = myConfig.get_boolean("Nullclines", "nc_onByDefault")
        self.sl_toggle = myConfig.get_boolean("Streamlines",
                                              "stream_onByDefault")

        myLogger.debug_message("Graph class initialized")
Ejemplo n.º 2
0
    def __init__(self, parent, canvas):
        self.myWidget = parent
        Plot.__init__(self, self.myWidget, canvas)

        # read initial values: vector field, streamlines, nullclines
        self.vf_toggle = myConfig.get_boolean("Vectorfield", "vf_onByDefault")
        self.nc_toggle = myConfig.get_boolean("Nullclines", "nc_onByDefault")
        self.sl_toggle = myConfig.get_boolean("Streamlines", "stream_onByDefault")
Ejemplo n.º 3
0
    def __init__(self, parent, canvas):
        self.myWidget = parent
        Plot.__init__(self, self.myWidget, canvas)

        # read initial values: vector field, streamlines, nullclines
        self.vf_toggle = myConfig.get_boolean("Vectorfield", "vf_onByDefault")
        self.nc_toggle = myConfig.get_boolean("Nullclines", "nc_onByDefault")
        self.sl_toggle = myConfig.get_boolean("Streamlines", "stream_onByDefault")
Ejemplo n.º 4
0
    def initialize_ui(self):
        # gets called after submitting a system (updae_ui() cannot be
        # used since the new system tab is not visible yet
        # values are taken from config file

        self.toggle_vectorfield_action.setChecked(myConfig.get_boolean("Vectorfield", "vf_onByDefault"))
        self.toggle_streamlines_action.setChecked(myConfig.get_boolean("Streamlines", "stream_onByDefault"))
        self.toggle_equilibrium_action.setChecked(False)
        self.toggle_nullclines_action.setChecked(myConfig.get_boolean("Nullclines", "nc_onByDefault"))
Ejemplo n.º 5
0
    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")
Ejemplo n.º 6
0
    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)
Ejemplo n.º 7
0
    def initialize(self):
        """
        this function gets called after myConfig instance has been created.
        logging before that is possible with hardcoded values.
        """
        from core.ConfigHandler import myConfig

        self.show_error = myConfig.get_boolean("Logging", "log_showError")
        self.show_warning = myConfig.get_boolean("Logging", "log_showWarning")
        self.show_debug = myConfig.get_boolean("Logging", "log_showDbg")

        myLogger.debug_message("Logging class initialized.")
Ejemplo n.º 8
0
    def initialize_ui(self):
        # gets called after submitting a system (updae_ui() cannot be
        # used since the new system tab is not visible yet
        # values are taken from config file

        self.toggle_vectorfield_action.setChecked(
            myConfig.get_boolean("Vectorfield", "vf_onByDefault"))
        self.toggle_streamlines_action.setChecked(
            myConfig.get_boolean("Streamlines", "stream_onByDefault"))
        self.toggle_equilibrium_action.setChecked(False)
        self.toggle_nullclines_action.setChecked(
            myConfig.get_boolean("Nullclines", "nc_onByDefault"))
Ejemplo n.º 9
0
    def initialize(self):
        """
        this function gets called after myConfig instance has been created.
        logging before that is possible with hardcoded values.
        """
        from core.ConfigHandler import myConfig

        self.show_error = myConfig.get_boolean("Logging", "log_showError")
        self.show_warning = myConfig.get_boolean("Logging", "log_showWarning")
        self.show_debug = myConfig.get_boolean("Logging", "log_showDbg")

        myLogger.debug_message("Logging class initialized.")
Ejemplo n.º 10
0
    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()
Ejemplo n.º 11
0
    def init(self):
        """ This function gets called only after program start.
        """

        # load tmp file
        self.load_tmp_system()

        # 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.initializing()
Ejemplo n.º 12
0
    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()
Ejemplo n.º 13
0
    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")
Ejemplo n.º 14
0
    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")
Ejemplo n.º 15
0
 def add_eigenvectors_to_title(self, vec0, vec1):
     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])
         dec_place = 2  # TODO: read from config
         self.canvas.axes.set_title("$\\dot{x} = " + title_x_dot + "$\n$\\dot{y} = " + title_y_dot +
                                    "$\n$\mathbf{v}_1=("+str(round(vec0[0],dec_place)) + "," +
                                    str(round(vec0[1],dec_place)) + ")^T\qquad\mathbf{v}_2=(" +
                                    str(round(vec1[0],dec_place)) + "," + str(round(vec1[1],dec_place)) + ")^T$")
Ejemplo n.º 16
0
    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")
Ejemplo n.º 17
0
    def __init__(self, parent, plot_pp, plot_x, plot_y):
        assert isinstance(plot_pp, Canvas)
        assert isinstance(plot_x, Canvas)
        assert isinstance(plot_y, Canvas)

        # for deleting lineedits/etc. from parent class
        self.parent = parent
        self.plot_pp = plot_pp
        self.plot_x = plot_x
        self.plot_y = plot_y

        # register_graph plot_pp
        myEquilibria.register_graph(self.plot_pp)
        myNullclines.register_graph(self.plot_pp)
        myTrajectories.register_graph(self, self.plot_pp, self.plot_x, self.plot_y)
        myStreamlines.register_graph(self, self.plot_pp)
        myVectorfield.register_graph(self, self.plot_pp)

        # read initial values: vector field, streamlines, nullclines
        self.vf_toggle = myConfig.get_boolean("Vectorfield", "vf_onByDefault")
        self.nc_toggle = myConfig.get_boolean("Nullclines", "nc_onByDefault")
        self.sl_toggle = myConfig.get_boolean("Streamlines", "stream_onByDefault")

        myLogger.debug_message("Graph class initialized")
Ejemplo n.º 18
0
    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")
Ejemplo n.º 19
0
    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")
Ejemplo n.º 20
0
 def __init__(self, parent):
     self.myWidget = parent
     self.stack = []
     self.tgl = myConfig.get_boolean("Vectorfield", "vf_onByDefault")
     self.update()
Ejemplo n.º 21
0
 def __init__(self, parent):
     self.myWidget = parent
     self.stack = []
     self.tgl = myConfig.get_boolean("Vectorfield", "vf_onByDefault")
     self.update()
Ejemplo n.º 22
0
    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()
Ejemplo n.º 23
0
    def __init__(self):
        # superclass constructor
        PyplaneMainWindow.__init__(self)
        QtCore.pyqtRemoveInputHook()

        # check config file if shown by default
        self.terminal_toggle = myConfig.get_boolean("Logging", "showTerminal")
        self.update_terminal()

        # connect buttons ------------------------------------------------------
        # connect buttons: system
        self.clearButton.clicked.connect(myTrajectories.remove_all)
        self.submitButton.clicked.connect(self.submit)

        # connect buttons: phase plane
        self.PP_SetButton.clicked.connect(lambda: self.myGraph.set_window_range(self.myGraph.plot_pp))
        self.PP_ZoomButton.clicked.connect(self.myGraph.plot_pp.toggle_zoom_mode)
        self.PP_ZoomButton.setCheckable(True)
        self.PP_RefreshButton.clicked.connect(self.myGraph.refresh)
        self.PP_CreateTrajectoryButton.clicked.connect(myTrajectories.create_trajectory)

        # connect buttons: x(t)
        self.X_SetButton.clicked.connect(lambda: self.myGraph.set_window_range(self.myGraph.plot_x))
        self.X_ZoomButton.clicked.connect(self.myGraph.plot_x.toggle_zoom_mode)
        self.X_ZoomButton.setCheckable(True)
        # self.X_ZoomButton.clicked.connect(self.plotCanvas2.zoomMode)

        # connect buttons: y(t)
        self.Y_SetButton.clicked.connect(lambda: self.myGraph.set_window_range(self.myGraph.plot_y))
        self.Y_ZoomButton.clicked.connect(self.myGraph.plot_y.toggle_zoom_mode)
        self.Y_ZoomButton.setCheckable(True)

        # connect buttons: additional function
        self.FctPlotButton.clicked.connect(self.add_function_to_plot)
        self.FctClearButton.clicked.connect(self.remove_function_from_plot)

        # connect mouse events (left mouse button click) in phase plane
        self.myGraph.plot_pp.mpl_connect('button_press_event', self.myGraph.onclick)
        self.myGraph.plot_pp.mpl_connect('pick_event', self.myGraph.onpick)

        # file menu ------------------------------------------------------
        # file
        self.file_menu = QtGui.QMenu('&File', self)

        self.load = QtGui.QMenu('&Open', self)
        self.file_menu.addMenu(self.load)
        self.load.addAction('&Recent', self.load_tmp_system)
        self.load.addAction('&From File', self.load_system_from_file,
                            QtCore.Qt.CTRL + QtCore.Qt.Key_O)

        self.file_menu.addAction('&Save System As...', self.save_file,
                                 QtCore.Qt.CTRL + QtCore.Qt.Key_S)
        self.file_menu.addAction('&Export As...', self.export_as, QtCore.Qt.CTRL + QtCore.Qt.Key_E)
        self.file_menu.addAction('&Quit', self.file_quit, QtCore.Qt.CTRL + QtCore.Qt.Key_Q)
        self.menuBar().addMenu(self.file_menu)

        # show
        self.show_menu = QtGui.QMenu('&Show', self)
        self.menuBar().addMenu(self.show_menu)

        # terminal checkbox
        self.toggle_terminal_action = QtGui.QAction('Terminal', self.show_menu)
        self.toggle_terminal_action.setCheckable(True)
        #self.toggle_nullclines_action.setShortcuts(
        if myConfig.get_boolean("Logging", "showTerminal"):
            self.toggle_terminal_action.setChecked(True)
        # noinspection PyUnresolvedReferences
        self.toggle_terminal_action.triggered.connect(self.toggle_terminal)
        self.show_menu.addAction(self.toggle_terminal_action)

        # vector field checkbox
        self.toggle_vectorfield_action = QtGui.QAction('&Plot Vector Field', self.show_menu)
        self.toggle_vectorfield_action.setCheckable(True)
        if myConfig.get_boolean("Vectorfield", "vf_onByDefault"):
            self.toggle_vectorfield_action.setChecked(True)
        # noinspection PyUnresolvedReferences
        self.toggle_vectorfield_action.triggered.connect(self.vf_helper_function)
        self.show_menu.addAction(self.toggle_vectorfield_action)

        # streamlines checkbox
        self.toggle_streamlines_action = QtGui.QAction('&Plot Streamlines', self.show_menu)
        self.toggle_streamlines_action.setCheckable(True)
        if myConfig.get_boolean("Streamlines", "stream_onByDefault"):
            self.toggle_streamlines_action.setChecked(True)
        self.toggle_streamlines_action.triggered.connect(self.sl_helper_function)
        self.show_menu.addAction(self.toggle_streamlines_action)

        # equilibrium checkbox
        self.toggle_equilibrium_action = QtGui.QAction('&Find an Equilibrium Point / Linearize', self.show_menu)
        self.toggle_equilibrium_action.setCheckable(True)
        self.toggle_equilibrium_action.setChecked(False)
        self.toggle_equilibrium_action.triggered.connect(myEquilibria.toggle)
        self.show_menu.addAction(self.toggle_equilibrium_action)
        #self.show_menu.addAction('&Find an Equilibrium Point', self.myGraph.toggleEP)

        # nullclines checkbox
        self.toggle_nullclines_action = QtGui.QAction('Nullclines', self.show_menu)
        self.toggle_nullclines_action.setCheckable(True)
        if myConfig.get_boolean("Nullclines", "nc_onByDefault"):
            self.toggle_nullclines_action.setChecked(True)
        self.toggle_nullclines_action.triggered.connect(myNullclines.toggle)
        self.show_menu.addAction(self.toggle_nullclines_action)

        self.show_menu.addAction('&Calculate Nullclines (symbolic)', myNullclines.print_symbolic_nullclines)

        # help
        self.help_menu = QtGui.QMenu('&Help', self)
        self.menuBar().addMenu(self.help_menu)
        self.help_menu.addAction('&About', self.about)

        # initializing with default values ------------------------------------------------------
        self.init()
        self.build_settings_tab()

        # from now on, plot only log messages as defined in config file.
        # for that, call initialize function in myLogger
        myLogger.initialize()
Ejemplo n.º 24
0
    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()
Ejemplo n.º 25
0
    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")
Ejemplo n.º 26
0
    def add_linearization_tab(self, equilibrium):
        # TODO: REFACTOR THIS FUNCTION!!!


        # if linearization has not been shown do so, otherwise ignore:
        if equilibrium not in self.linearization_stack:
            # Set up the user interface from Designer.
            myWidget = Ui_Form()
            contents = QtGui.QWidget(self.tabWidget)
            myWidget.setupUi(contents)

            # add content to linearization tab!
            self.myLayout_Lin = QtGui.QVBoxLayout(myWidget.frame_lin)
            self.plotCanvas_Lin = Canvas(myWidget.frame_lin)
            self.myLayout_Lin.addWidget(self.plotCanvas_Lin)

            # window range should be equal to window range of phase plane
            #limits = self.myGraph.get_limits(self.myGraph.plot_pp)
            #print(limits)
            #self.myGraph.set_window_range(self.plotCanvas_Lin)

            # TODO make set_window_range-funtion reusable for this case
            xmin = float(self.PP_xminLineEdit.text())
            xmax = float(self.PP_xmaxLineEdit.text())
            ymin = float(self.PP_yminLineEdit.text())
            ymax = float(self.PP_ymaxLineEdit.text())

            self.plotCanvas_Lin.axes.set_xlim(xmin, xmax)
            self.plotCanvas_Lin.axes.set_ylim(ymin, ymax)

            # window range init
            section = "Phaseplane"
            token = "pp_"
            if myConfig.get_boolean(section, token + "showGrid"):
                self.plotCanvas_Lin.axes.grid()

            if myConfig.get_boolean(section, token + "showMinorTicks"):
                self.plotCanvas_Lin.axes.minorticks_on()
            else:
                self.plotCanvas_Lin.axes.minorticks_off()

            if not myConfig.get_boolean(section, token + "showXTicks"):
                self.plotCanvas_Lin.axes.xaxis.set_ticks([])

            if not myConfig.get_boolean(section, token + "showYTicks"):
                self.plotCanvas_Lin.axes.yaxis.set_ticks([])

            if myConfig.get_boolean(section, token + "showXLabel"):
                pp_label_fontsize = 9 #myConfig.read(section, token + "labelFontSize")
                xlabel = "$x$"
                self.plotCanvas_Lin.axes.set_xlabel(xlabel, fontsize=pp_label_fontsize)

            if myConfig.get_boolean(section, token + "showYLabel"):
                pp_label_fontsize = 9 #myConfig.read(section, token + "labelFontSize")
                ylabel = "$\\dot{x}$"
                self.plotCanvas_Lin.axes.set_ylabel(ylabel, fontsize=pp_label_fontsize)

            if not myConfig.get_boolean(section, token + "showSpines"):
                for spine in self.plotCanvas_Lin.axes.spines.itervalues():
                    spine.set_visible(False)

            #self.myGraph.plot_pp.mpl_connect('button_press_event', self.myGraph.onclick)

            # plot linearized vectorfield
            linearized_vectorfield = VectorfieldHandler()
            linearized_vectorfield.register_graph(None, self.plotCanvas_Lin)

            # create linearized system
            linearized_system = System()

            # set system properties
            jac = myEquilibria.approx_ep_jacobian(equilibrium)

            xe = equilibrium[0]
            ye = equilibrium[1]
            x_dot_string = str(jac[0,0]) + "*(x-(" + str(xe) + ")) + (" + str(jac[0,1]) + ")*(y-(" + str(ye) + "))"
            y_dot_string = str(jac[1,0]) + "*(x-(" + str(xe) + ")) + (" + str(jac[1,1]) + ")*(y-(" + str(ye) + "))"

            linearized_system.set_rhs(x_dot_string, y_dot_string)

            # set system for vectorfield
            linearized_vectorfield.set_system(linearized_system)

            #title_matrix = r"$A=\begin{Bmatrix}"+str(jac[0,0])+r" & "+str(jac[0,1])+r" \\"+str(jac[1,0])+r" & "+str(jac[1,1])+r"\end{Bmatrix}$"

            # set title
            title_matrix = r'$\underline{A}_{' + str(len(self.linearization_stack)) + r'} = \left( \begin{array}{ll} ' + str(jac[0,0]) + r' & ' + str(jac[0,1]) + r'\\ ' + str(jac[1,0]) + r' & ' + str(jac[1,1]) + r' \end{array} \right)$'

            # characterize EP:
            # stable focus:     SFOC
            # unstable focus:   UFOC
            # focus:            FOC
            # stable node:      SNOD
            # unstable node:    UNOD
            # saddle:           SAD

            # calculating eigenvalues and eigenvectors:
            eigenvalues, eigenvectors = myEquilibria.get_eigenval_eigenvec(equilibrium)

            # len(eigenvalues) should be 2!
            # real_part_1 = np.real(eigenvalues[0])
            # imag_part_1 = np.imag(eigenvalues[0])
            #
            # real_part_2 = np.real(eigenvalues[1])
            # imag_part_2 = np.real(eigenvalues[1])

            determinant = jac[0,0]*jac[1,1] - jac[1,0]*jac[0,1]
            trace = jac[0,0] + jac[1,1]

            ep_character = "hm"

            if trace==0 and determinant==0:
                ep_character = "Unclassified"

            elif determinant < 0:
                ep_character = "Saddle"

            elif (determinant > 0) and (determinant < ((trace**2)/4)):
                if trace < 0:
                    ep_character = "Nodal Sink"
                elif trace > 0:
                    ep_character = "Nodal Source"

            elif determinant > ((trace**2)/4):
                if trace == 0:
                    ep_character = "Center"
                elif trace < 0:
                    ep_character = "Spiral Sink"
                elif trace > 0:
                    ep_character = "Spiral Source"
            elif determinant == ((trace**2)/4):
                if trace < 0:
                    ep_character = "Sink"
                elif trace > 0:
                    ep_character = "Source"

            # plot eigenvectors:
            # eigenvalues = eigenvalues.tolist()
            # eigenvectors = eigenvectors.tolist()
            #
            # for i in xrange(0, len(eigenvectors)):
            #     x, y = equilibrium[0], equilibrium[1]
            #     dx, dy = eigenvectors[i][0], eigenvectors[i][1]
            #
            #     vector = [x, y, dx, dy]
            #
            #     self.myGraph.plot_vector(self.plotCanvas_Lin, vector)


            if myConfig.get_boolean(section, token + "showTitle"):
                title1 = str(ep_character) + r': (' + str(equilibrium[0]) + r', ' + str(equilibrium[1]) + r')'
                #self.plotCanvas_Lin.axes.set_title(str(title1)+"$\n$\\dot{x} = " + x_dot_string + "$\n$\\dot{y} = " + y_dot_string + "$", loc='center')
                self.plotCanvas_Lin.axes.set_title(r'$' + str(title1)+"$\n"+title_matrix, fontsize=11)
            else:
                self.plotCanvas_Lin.fig.subplots_adjust(top=0.99)

            # mark EP in linearized tab
            self.plotCanvas_Lin.axes.plot(equilibrium[0], equilibrium[1],'ro')

            # add annotation in phaseplane
            label = str(ep_character)

            self.plotCanvas1.axes.text(equilibrium[0], equilibrium[1], label, fontsize=10)

            self.plotCanvas1.draw()

            # plot vectorfield
            linearized_vectorfield.update()

            self.plotCanvas_Lin.draw()

            title = str(ep_character)
            self.index = self.tabWidget.addTab(contents, title)

            self.linearization_stack.append(equilibrium)
Ejemplo n.º 27
0
    def __init__(self):
        # superclass constructor
        PyplaneMainWindow.__init__(self)
        QtCore.pyqtRemoveInputHook()

        # If set to True the app crashes under MS Windows if it is immediately closed after startup without any
        # further actions
        sip.setdestroyonexit(False)

        # Set Version-number
        self.setWindowTitle("PyPlane " + self.__PYPLANE_VERSION)

        # check config file if shown by default
        self.terminal_toggle = myConfig.get_boolean("Logging",
                                                    "log_showTerminal")
        self.update_terminal()

        # # connect buttons ------------------------------------------------------
        # # connect buttons: system
        self.clearButton.clicked.connect(self.clear_trajectories)
        self.submitButton.clicked.connect(self.submit)

        # # connect buttons: additional function
        self.FctPlotButton.clicked.connect(self.add_function)
        self.FctClearButton.clicked.connect(self.remove_functions)

        # file menu ------------------------------------------------------
        # file
        self.file_menu = QtWidgets.QMenu('&System', self)

        self.load = QtWidgets.QMenu('&Open', self)
        self.file_menu.addMenu(self.load)
        self.load.addAction('&Recent', self.load_tmp_system)
        self.load.addAction('&From File', self.load_system_from_file,
                            QtCore.Qt.CTRL + QtCore.Qt.Key_O)

        self.file_menu.addAction('&Save As...', self.save_file,
                                 QtCore.Qt.CTRL + QtCore.Qt.Key_S)
        self.file_menu.addAction('&Export As...', self.export_as,
                                 QtCore.Qt.CTRL + QtCore.Qt.Key_E)
        self.file_menu.addAction('&Close', self.close_current_tab,
                                 QtCore.Qt.CTRL + QtCore.Qt.Key_W)
        # self.file_menu.addAction('&Close All', self.close_all_tabs, QtCore.Qt.CTRL + QtCore.Qt.ShiftModifier + QtCore.Qt.Key_W)
        self.file_menu.addAction('&Quit', self.file_quit,
                                 QtCore.Qt.CTRL + QtCore.Qt.Key_Q)
        self.menuBar().addMenu(self.file_menu)

        # show
        self.show_menu = QtWidgets.QMenu('&Show', self)
        self.menuBar().addMenu(self.show_menu)

        # terminal checkbox
        self.toggle_terminal_action = QtWidgets.QAction(
            'Terminal', self.show_menu)
        self.toggle_terminal_action.setShortcut(QtCore.Qt.CTRL +
                                                QtCore.Qt.Key_T)
        self.toggle_terminal_action.setCheckable(True)
        if myConfig.get_boolean("Logging", "log_showTerminal"):
            self.toggle_terminal_action.setChecked(True)
        self.toggle_terminal_action.triggered.connect(self.toggle_terminal)
        self.show_menu.addAction(self.toggle_terminal_action)

        # vector field checkbox
        self.toggle_vectorfield_action = QtWidgets.QAction(
            '&Plot Vector Field', self.show_menu)
        self.toggle_vectorfield_action.setShortcut(QtCore.Qt.CTRL +
                                                   QtCore.Qt.Key_V)
        self.toggle_vectorfield_action.setCheckable(True)
        # if myConfig.get_boolean("Vectorfield", "vf_onByDefault"):
        #    self.toggle_vectorfield_action.setChecked(True)
        self.toggle_vectorfield_action.triggered.connect(
            self.vf_helper_function)
        self.show_menu.addAction(self.toggle_vectorfield_action)

        # streamlines checkbox
        self.toggle_streamlines_action = QtWidgets.QAction(
            '&Plot Streamlines', self.show_menu)
        self.toggle_streamlines_action.setCheckable(True)
        # if myConfig.get_boolean("Streamlines", "stream_onByDefault"):
        #    self.toggle_streamlines_action.setChecked(True)
        self.toggle_streamlines_action.triggered.connect(
            self.sl_helper_function)
        self.show_menu.addAction(self.toggle_streamlines_action)

        # equilibrium checkbox
        self.toggle_equilibrium_action = QtWidgets.QAction(
            '&Find an Equilibrium Point / Linearize', self.show_menu)
        self.toggle_equilibrium_action.setCheckable(True)
        # self.toggle_equilibrium_action.setChecked(False)
        self.toggle_equilibrium_action.triggered.connect(
            self.eq_helper_function)
        self.show_menu.addAction(self.toggle_equilibrium_action)
        #self.show_menu.addAction('&Find an Equilibrium Point', self.myGraph.toggleEP)

        # linearize checkbox
        # self.linearize_action = QtWidgets.QAction('&Linearize', self.show_menu)
        # self.linearize_action.triggered.connect(self.linearize_helper_function)
        # self.show_menu.addAction(self.linearize_action)

        # nullclines checkbox
        self.toggle_nullclines_action = QtWidgets.QAction(
            'Nullclines', self.show_menu)
        self.toggle_nullclines_action.setShortcut(QtCore.Qt.CTRL +
                                                  QtCore.Qt.Key_N)
        self.toggle_nullclines_action.setCheckable(True)
        # if system exists: read toggle-value
        # if not: read from config
        # TODO: new systems tab chosen -> check/uncheck toggle!
        # if self.systems == []:
        # read current systems tab:
        # if myConfig.get_boolean("Nullclines", "nc_onByDefault"):
        # self.toggle_nullclines_action.setChecked(True)
        self.toggle_nullclines_action.triggered.connect(self.toggle_nullclines)
        self.show_menu.addAction(self.toggle_nullclines_action)

        # self.show_menu.addAction('&Calculate Nullclines (symbolic)', myNullclines.print_symbolic_nullclines)

        # help
        self.help_menu = QtWidgets.QMenu('&Help', self)
        self.menuBar().addMenu(self.help_menu)
        self.help_menu.addAction('&About', self.about)

        # initializing with default values ------------------------------------------------------
        self.init()
        # self.build_settings_tab()

        # from now on, plot only log messages as defined in config file.
        # for that, call initialize function in myLogger
        myLogger.initialize()
Ejemplo n.º 28
0
    def __init__(self):
        # superclass constructor
        PyplaneMainWindow.__init__(self)
        QtCore.pyqtRemoveInputHook()

        # If set to True the app crashes under MS Windows if it is immediately closed after startup without any
        # further actions
        sip.setdestroyonexit(False)
        
        # Set Version-number
        self.setWindowTitle("PyPlane " + self.__PYPLANE_VERSION)

        # check config file if shown by default
        self.terminal_toggle = myConfig.get_boolean("Logging", "showTerminal")
        self.update_terminal()
        
        #~ # connect buttons ------------------------------------------------------
        #~ # connect buttons: system
        self.clearButton.clicked.connect(self.clear_trajectories)
        self.submitButton.clicked.connect(self.submit)

        #~ # connect buttons: additional function
        self.FctPlotButton.clicked.connect(self.add_function)
        self.FctClearButton.clicked.connect(self.remove_functions)

        # file menu ------------------------------------------------------
        # file
        self.file_menu = QtGui.QMenu('&System', self)

        self.load = QtGui.QMenu('&Open', self)
        self.file_menu.addMenu(self.load)
        self.load.addAction('&Recent', self.load_tmp_system)
        self.load.addAction('&From File', self.load_system_from_file,
                            QtCore.Qt.CTRL + QtCore.Qt.Key_O)

        self.file_menu.addAction('&Save As...', self.save_file,
                                 QtCore.Qt.CTRL + QtCore.Qt.Key_S)
        self.file_menu.addAction('&Export As...', self.export_as, QtCore.Qt.CTRL + QtCore.Qt.Key_E)
        self.file_menu.addAction('&Close', self.close_current_tab, QtCore.Qt.CTRL + QtCore.Qt.Key_W)
        #~ self.file_menu.addAction('&Close All', self.close_all_tabs, QtCore.Qt.CTRL + QtCore.Qt.ShiftModifier + QtCore.Qt.Key_W)
        self.file_menu.addAction('&Quit', self.file_quit, QtCore.Qt.CTRL + QtCore.Qt.Key_Q)
        self.menuBar().addMenu(self.file_menu)

        # show
        self.show_menu = QtGui.QMenu('&Show', self)
        self.menuBar().addMenu(self.show_menu)

        # terminal checkbox
        self.toggle_terminal_action = QtGui.QAction('Terminal', self.show_menu)
        self.toggle_terminal_action.setShortcut(QtCore.Qt.CTRL + QtCore.Qt.Key_T)
        self.toggle_terminal_action.setCheckable(True)
        if myConfig.get_boolean("Logging", "showTerminal"):
            self.toggle_terminal_action.setChecked(True)
        self.toggle_terminal_action.triggered.connect(self.toggle_terminal)
        self.show_menu.addAction(self.toggle_terminal_action)

        # vector field checkbox
        self.toggle_vectorfield_action = QtGui.QAction('&Plot Vector Field', self.show_menu)
        self.toggle_vectorfield_action.setShortcut(QtCore.Qt.CTRL + QtCore.Qt.Key_V)
        self.toggle_vectorfield_action.setCheckable(True)
        #~ if myConfig.get_boolean("Vectorfield", "vf_onByDefault"):
            #~ self.toggle_vectorfield_action.setChecked(True)
        self.toggle_vectorfield_action.triggered.connect(self.vf_helper_function)
        self.show_menu.addAction(self.toggle_vectorfield_action)

        # streamlines checkbox
        self.toggle_streamlines_action = QtGui.QAction('&Plot Streamlines', self.show_menu)
        self.toggle_streamlines_action.setCheckable(True)
        #~ if myConfig.get_boolean("Streamlines", "stream_onByDefault"):
            #~ self.toggle_streamlines_action.setChecked(True)
        self.toggle_streamlines_action.triggered.connect(self.sl_helper_function)
        self.show_menu.addAction(self.toggle_streamlines_action)

        # equilibrium checkbox
        self.toggle_equilibrium_action = QtGui.QAction('&Find an Equilibrium Point / Linearize', self.show_menu)
        self.toggle_equilibrium_action.setCheckable(True)
        #~ self.toggle_equilibrium_action.setChecked(False)
        self.toggle_equilibrium_action.triggered.connect(self.eq_helper_function)
        self.show_menu.addAction(self.toggle_equilibrium_action)
        #self.show_menu.addAction('&Find an Equilibrium Point', self.myGraph.toggleEP)

        # linearize checkbox
        #~ self.linearize_action = QtGui.QAction('&Linearize', self.show_menu)
        #~ self.linearize_action.triggered.connect(self.linearize_helper_function)
        #~ self.show_menu.addAction(self.linearize_action)

        # nullclines checkbox
        self.toggle_nullclines_action = QtGui.QAction('Nullclines', self.show_menu)
        self.toggle_nullclines_action.setShortcut(QtCore.Qt.CTRL + QtCore.Qt.Key_N)
        self.toggle_nullclines_action.setCheckable(True)
        # if system exists: read toggle-value
        # if not: read from config
        # TODO: new systems tab chosen -> check/uncheck toggle!
        #~ if self.systems == []:
            # read current systems tab:        
        #~ if myConfig.get_boolean("Nullclines", "nc_onByDefault"):
            #~ self.toggle_nullclines_action.setChecked(True)
        self.toggle_nullclines_action.triggered.connect(self.toggle_nullclines)
        self.show_menu.addAction(self.toggle_nullclines_action)

        #~ self.show_menu.addAction('&Calculate Nullclines (symbolic)', myNullclines.print_symbolic_nullclines)

        # help
        self.help_menu = QtGui.QMenu('&Help', self)
        self.menuBar().addMenu(self.help_menu)
        self.help_menu.addAction('&About', self.about)

        # initializing with default values ------------------------------------------------------
        self.init()
        #~ self.build_settings_tab()

        # from now on, plot only log messages as defined in config file.
        # for that, call initialize function in myLogger
        myLogger.initialize()      
Ejemplo n.º 29
0
    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")