def submit(self): """ This function gets called after clicking on the submit button """ try: xtxt = str(self.xDotLineEdit.text()) ytxt = str(self.yDotLineEdit.text()) except UnicodeEncodeError as exc: myLogger.warn_message("UnicodeEncodeError! Please check input.") myLogger.debug_message(str(exc)) else: cond1 = str(self.xDotLineEdit.text()) != "" cond2 = str(self.yDotLineEdit.text()) != "" if cond1 and cond2: x_string = str(self.xDotLineEdit.text()) y_string = str(self.yDotLineEdit.text()) equation = (x_string, y_string) system = System(self, equation) self.systems.insert(0, system) self.save_tmp_system() myLogger.message("------ new system created ------") myLogger.message(" x' = " + str(system.equation.what_is_my_system()[0])) myLogger.message( " y' = " + str(system.equation.what_is_my_system()[1]) + "\n", ) else: myLogger.error_message("Please check system!")
def submit(self): """ This function gets called after clicking on the submit button """ try: xtxt = str(self.xDotLineEdit.text()) ytxt = str(self.yDotLineEdit.text()) except UnicodeEncodeError as exc: myLogger.warn_message("UnicodeEncodeError! Please check input.") myLogger.debug_message(str(exc)) else: cond1 = str(self.xDotLineEdit.text()) != "" cond2 = str(self.yDotLineEdit.text()) != "" if cond1 and cond2: x_string = str(self.xDotLineEdit.text()) y_string = str(self.yDotLineEdit.text()) equation = (x_string, y_string) system = System(self, equation) self.systems.insert(0, system) self.save_tmp_system() myLogger.message("------ new system created ------") myLogger.message(" x' = " + str(system.equation.what_is_my_system()[0])) myLogger.message(" y' = " + str(system.equation.what_is_my_system()[1]) + "\n", ) else: myLogger.error_message("Please check system!")
def submit(self): """ This function gets called after clicking on the submit button """ myLogger.message("New system submitted...") try: xtxt = str(self.xDotLineEdit.text()) ytxt = str(self.yDotLineEdit.text()) except UnicodeEncodeError as exc: myLogger.warn_message("UnicodeEncodeError! Please check input.") myLogger.debug_message(str(exc)) else: cond1 = str(self.xDotLineEdit.text()) != "" cond2 = str(self.yDotLineEdit.text()) != "" if cond1 and cond2: x_string = str(self.xDotLineEdit.text()) y_string = str(self.yDotLineEdit.text()) try: # Non-modal (!) Box intended for calming down the user... info_box = QtWidgets.QMessageBox(self) info_box.setAttribute(Qt.WA_DeleteOnClose) info_box.setStandardButtons(QtWidgets.QMessageBox.Ok) info_box.setIcon(QtWidgets.QMessageBox.Information) info_box.setWindowTitle("New system submitted") info_box.setText( "The new system is being processed now, please wait! \n" "Especially when LaTeX is used for the labels this may take some time and the " "program might seem unresponsive!") info_box.setModal(False) info_box.show() QtCore.QCoreApplication.processEvents() # Processing equations equation = (x_string, y_string) system = System(self, equation) self.systems.insert(0, system) self.save_tmp_system() myLogger.message("------ new system created ------") myLogger.message( " x' = " + str(system.equation.what_is_my_system()[0])) myLogger.message( " y' = " + str(system.equation.what_is_my_system()[1]) + "\n", ) try: info_box.close() except RuntimeError: # if dialog has already been closed by the user pass except BaseException as exc: QtWidgets.QMessageBox.critical( self, "Error!", "An error occured while processing the system. " "Detailed error message: \n %s" % exc) myLogger.error_message(str(exc)) else: myLogger.error_message("Please check system!")
def submit(self): """ This function gets called after clicking on the submit button """ try: xtxt = str(self.xDotLineEdit.text()) ytxt = str(self.yDotLineEdit.text()) except UnicodeEncodeError as exc: myLogger.warn_message("UnicodeEncodeError! Please check input.") myLogger.debug_message(str(exc)) else: cond1 = str(self.xDotLineEdit.text()) != "" cond2 = str(self.yDotLineEdit.text()) != "" if cond1 and cond2: # set right hand side, print rhs to logfield, solve, # then plot vector field # initialize system mySystem.__init__() # set rhs x_string = str(self.xDotLineEdit.text()) y_string = str(self.yDotLineEdit.text()) mySystem.set_rhs(x_string, y_string) try: # write to tmp file: self.save_system('library/tmp.ppf') # clear figure, if there is any self.myGraph.clear() # delete linearization tabs (index 3 to n) if len(self.linearization_stack) > 0: for i in xrange(0, len(self.linearization_stack)): index = 3 + len(self.linearization_stack) - i self.tabWidget.removeTab(index) #reset stack self.linearization_stack = [] myLogger.debug_message("All linearization tabs removed.") self.initializing() myLogger.message("------ new system created ------") myLogger.message(" x' = " + str(mySystem.what_is_my_system()[0])) myLogger.message(" y' = " + str(mySystem.what_is_my_system()[1]) + "\n", ) except Exception as error: handle_exception(error) else: myLogger.error_message("No system entered")
def submit(self): """ This function gets called after clicking on the submit button """ myLogger.message("New system submitted...") try: xtxt = str(self.xDotLineEdit.text()) ytxt = str(self.yDotLineEdit.text()) except UnicodeEncodeError as exc: myLogger.warn_message("UnicodeEncodeError! Please check input.") myLogger.debug_message(str(exc)) else: cond1 = str(self.xDotLineEdit.text()) != "" cond2 = str(self.yDotLineEdit.text()) != "" if cond1 and cond2: x_string = str(self.xDotLineEdit.text()) y_string = str(self.yDotLineEdit.text()) try: # Non-modal (!) Box intended for calming down the user... info_box = QtWidgets.QMessageBox(self) info_box.setAttribute(Qt.WA_DeleteOnClose) info_box.setStandardButtons(QtWidgets.QMessageBox.Ok) info_box.setIcon(QtWidgets.QMessageBox.Information) info_box.setWindowTitle("New system submitted") info_box.setText("The new system is being processed now, please wait! \n" "Especially when LaTeX is used for the labels this may take some time and the " "program might seem unresponsive!") info_box.setModal(False) info_box.show() QtCore.QCoreApplication.processEvents() # Processing equations equation = (x_string, y_string) system = System(self, equation) self.systems.insert(0, system) self.save_tmp_system() myLogger.message("------ new system created ------") myLogger.message(" x' = " + str(system.equation.what_is_my_system()[0])) myLogger.message(" y' = " + str(system.equation.what_is_my_system()[1]) + "\n", ) try: info_box.close() except RuntimeError: # if dialog has already been closed by the user pass except BaseException as exc: QtWidgets.QMessageBox.critical(self, "Error!", "An error occured while processing the system. " "Detailed error message: \n %s" % exc) myLogger.error_message(str(exc)) else: myLogger.error_message("Please check system!")
def __init__(self): self.config = configparser.ConfigParser() self.config.optionxform = str __dir__ = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) filepath = os.path.abspath(os.path.join(__dir__, 'config/default')) try: data = self.config.read(filepath) except Exception as exc: myLogger.warn_message("input error!") myLogger.debug_message(str(exc)) print("Input error") # fallback values # read config-descriptions from dictionary self.descr = {} with open('core/config_description.py', 'r') as configdict: configdata = configdict.read() self.descr = ast.literal_eval(configdata) # Ensure that the configuration loaded from disk matches the requirments from the config description: # Missing sections and options are added and set to the default values from the config description # (See config_description.py) # sectioninfo[0] -> Name of section, sectioninfo[1] -> Prefix of the section options for sectioninfo in self.descr["sectionlist"]: # Add missing sections if not self.config.has_section(sectioninfo[0]): self.config.add_section(sectioninfo[0]) # Get the option names that BEGIN with the correct prefix associated with the section optionnames = [ optionname for optionname in self.descr if sectioninfo[1] in optionname[0:len(sectioninfo[1])] ] # Add missing options and set them to the default values for optionname in optionnames: if not self.config.has_option(sectioninfo[0], optionname): self.config.set(sectioninfo[0], optionname, str(self.descr[optionname][1]))
def __init__(self): self.config = ConfigParser.ConfigParser() self.config.optionxform = str __dir__ = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) filepath = os.path.abspath(os.path.join(__dir__, 'config/default')) try: data = self.config.read(filepath) except Exception as exc: myLogger.warn_message("input error!") myLogger.debug_message(str(exc)) print("Input error") # fallback values # read config-descriptions from dictionary self.descr = {} with open('core/config_description.py', 'r') as dict: data = dict.read() self.descr = ast.literal_eval(data)
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 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()