def _write_to_file(self, _file_abs_path=None): """ :return: """ if _file_abs_path is not None: self._file_abs_path = _file_abs_path # number of coordinates and velocities of MBD system if self.MBD_item.typeInfo() == "MBDsystem": if self.solution_data.ndim == 2: [steps, self.cols] = np.shape(self.solution_data) else: steps = 0 self.cols = len(self.solution_data) self.solution_data = np.array([self.solution_data]) # check filename if self._file_abs_path is None: self._filename = self._name + self._filetype else: self._filename = self._file_abs_path if self._filetype not in self._filename: self._filename = self._filename + self._filetype if type(self._filename) == QtCore.QString: self._filename = str(self._filename) else: if self._solution_save_options == "save to new": self._filename = check_filename(self._filename) # save to file of selected type if self._filetype == ".dat" or self._filetype == ".sol": self._write_to_txt_file() elif self._filetype == ".xlsx": self._write_to_excel_file() elif self._filetype == ".csv": self._read_csv_file() else: raise ValueError, "Filetype not supported." self.simulation_status = "saved to file" # write info to log file logging.getLogger("DyS_logger").info( "Solution data saved to file: %s. Size is %s", self._filename, convert_bytes_to_.convert_size(os.path.getsize(self._filename)))
def write_to_file(self, _file_abs_path=None): """ Function saves data to file :param _file_abs_path: """ print "write_to_file()" if _file_abs_path != None: self._file_abs_path = _file_abs_path # number of coordinates and velocities of MBD system [steps, n] = np.shape(self.solution_data) self.n = n - self.__header0_size # nuimber of bodies self.n_b = self.n / 6. # create header ids self._header_ids = np.arange(0, self.n_b) # check filename # check filename if self._file_abs_path is None: self._filename = self._name+self._filetype else: self._filename = self._file_abs_path if self._filetype not in self._filename: self._filename = self._filename + self._filetype if type(self._filename) == QtCore.QString: self._filename = str(self._filename) else: self._filename = check_filename(self._filename) # save to file of selected type if self._filetype == ".dat" or self._filetype == ".sol": data = self._write_to_txt_file() elif self._filetype == ".xlsx": data = self._write_to_excel_file() elif self._filetype == ".csv": data = self._read_csv_file() else: raise ValueError, "Filetype not supported." self.simulation_status = "saved to file" # write info to log file logging.getLogger("DyS_logger").info("Solution data saved to file: %s. Size is %s", self._filename, convert_bytes_to_.convert_size(os.path.getsize(self._filename)))
def write_simulation_solution_to_file(self): """ Function writes solution data to solution data object """ print "write_simulation_solution_to_file()" # write solution data and info to solution data object if hasattr(self.MBD_system, "_solution_filetype"): self._solution_data.set_filetype( self.MBD_system._solution_filetype) else: self._solution_data.set_filetype(".sol") self.solution_filename = 'solution_data_%02d' % self.simulation_id #+self.MBD_system._solution_filetype # add to temp file # data = self.collect_solution_data() self._solution_data._append_data_to_temp_file() # read from temp file if os.path.isfile(self._solution_data._temp_filename): self._solution_data._solution_data_from_temp_file() if self.MBD_system._save_options == "save to new": # check filename if already exists self.solution_filename = check_filename(self.solution_filename) # set solution data filename self._solution_data.setName(self.solution_filename) # add data to object attribute self._solution_data.finished = True # print "self.MBD_system._solution_save_options =", self.MBD_system._solution_save_options if self.MBD_system._solution_save_options != "discard": # write data to file self._solution_data.write_to_file() # emit signal # self.solution_signal.solution_data.emit(id(self._solution_data), self._solution_data._filename) # write contact values of every simulation time step to file for contact in self.MBD_system.contacts: if contact._solution_save_options != "discard" and contact.active: contact.write_to_file() for joint in self.MBD_system.joints: if joint._solution_save_options != "discard" and joint.active: joint.write_to_file()
def run(self): """ :return: """ # check if folder exists and if not create it folder = self._name if not os.path.exists(folder): os.makedirs(folder) # absolute path to store animation images to use them to create video file animation_folder_abs_path = os.path.join(os.getcwd(), folder) # looop through solution data and create figure with opengl function grabFrameBuffer() every i-th step for _step in xrange(0, len(self._parent.step), int(self._parent._delta_step)): filename = "step_%06d"%_step+".png" # assign step and repaint GL widget self._parent._step = int(_step) self._parent._update_GL() # get image of current opengl widget scene image = self._parent.OpenGLWidget.grabFrameBuffer() # abs path to image object of current simulation time step file_abs_path = os.path.join(animation_folder_abs_path, filename) # save image to file image.save(file_abs_path) # create video object video = ImageSequenceClip(animation_folder_abs_path, fps=24)#24 # write data to video object __animation_filename = self._name+".avi" # check filename __animation_filename = check_filename(__animation_filename) video.write_videofile(__animation_filename,codec='mpeg4') # delete animation folder with animation figures shutil.rmtree(animation_folder_abs_path)
def write_simulation_solution_to_file(self): """ Function writes solution data to solution data object """ print "write_simulation_solution_to_file()" solution_data = self.collect_solution_data() # write solution data and info to solution data object self._solution_data.set_filetype(self.MBD_system._solution_filetype) self.solution_filename = 'solution_data_%02d'%self.simulation_id#+self.MBD_system._solution_filetype if self.MBD_system._save_options == "save to new": # check filename if already exists self.solution_filename = check_filename(self.solution_filename) # set solution data filename self._solution_data.setName(self.solution_filename) # add data to object attribute self._solution_data.add_data(solution_data) self._solution_data.finished = True # print "exe1" # print "self.MBD_system._solution_save_options =", self.MBD_system._solution_save_options if self.MBD_system._solution_save_options != "discard": print "exe2" # write data to file self._solution_data.write_to_file() # emit signal # self.solution_signal.solution_data.emit(id(self._solution_data), self._solution_data._filename) # write contact values of every simulation time step to file for contact in self.MBD_system.contacts: if contact._solution_save_options != "discard": contact.write_to_file()