# writer = csv.writer(csv_file) # # for item in temp_data: # # writer.writerow(item) # # return True # # except: # # raise OSError('Error when writing CSV file ' + str_file_path) # # return False # ============================================================================= aaa = gsyIO.save_csv_gui(name_list, temp_list) print('Done') # ============================================================================= # with open(r'C:\Users\306235\Documents\_Temp\CSV\test.csv', 'w', newline='') as f: # # writer = csv.writer(f) # # for item in temp_zip_list: # # writer.writerow(item) # ============================================================================= # ============================================================================= # output = open(r'C:\Users\306235\Documents\_Temp\CSV\test.csv', 'w', newline='') #
def save_data(self): ''' Save the generated data in CSV. ''' print(gsyIO.date_time_now() + 'Updating data before save') self.print_info('Saving data as CSV...') bool_temp = self.update_data() if bool_temp == False: root = tk.Tk() root.withdraw() msgbox.showerror( 'Error', 'Error when making phase data. Time cannot be zero.') root.destroy() return False header = [ 'time', 'Phase-A Mag', 'Phase-A Omega', 'Phase-A Phi', 'Phase-A DC', 'Phase-A Real', 'Phase-A Imag', 'Phase-A Radius', 'Phase-A Angle', 'Phase-B Mag', 'Phase-B Omega', 'Phase-B Phi', 'Phase-B DC', 'Phase-B Real', 'Phase-B Imag', 'Phase-B Radius', 'Phase-B Angle', 'Phase-C Mag', 'Phase-C Omega', 'Phase-C Phi', 'Phase-C DC', 'Phase-C Real', 'Phase-C Imag', 'Phase-C Radius', 'Phase-C Angle', 'Phase-A + Real', 'Phase-A + Imag', 'Phase-A + Radius', 'Phase-A + Angle', 'Phase-B + Real', 'Phase-B + Imag', 'Phase-B + Radius', 'Phase-B + Angle', 'Phase-C + Real', 'Phase-C + Imag', 'Phase-C + Radius', 'Phase-C + Angle', 'Phase-A - Real', 'Phase-A - Imag', 'Phase-A - Radius', 'Phase-A - Angle', 'Phase-B - Real', 'Phase-B - Imag', 'Phase-B - Radius', 'Phase-B - Angle', 'Phase-C - Real', 'Phase-C - Imag', 'Phase-C - Radius', 'Phase-C - Angle', 'Zero Real', 'Zero Imag', 'Zero Radius', 'Zero Angle', 'Alpha Real', 'Alpha Imag', 'Alpha Radius', 'Alpha Angle', 'Beta Real', 'Beta Imag', 'Beta Radius', 'Beta Angle', 'Alpha + Real', 'Alpha + Image', 'Alpha + Radius', 'Alpha + Angle', 'Beta + Real', 'Beta + Image', 'Beta + Radius', 'Beta + Angle', 'Alpha - Real', 'Alpha - Imag', 'Alpha - Radius', 'Alpha - Angle', 'Beta - Real', 'Beta - Imag', 'Beta - Radius', 'Beta - Angle', 'd Real', 'd Imag', 'd Radius', 'd Angle', 'q Real', 'q Imag', 'q Radius', 'q Angle', 'd + Real', 'd + Imag', 'd + Radius', 'd + Angle', 'q + Real', 'q + Imag', 'q + Radius', 'q + Angle', 'd - Real', 'd - Imag', 'd - Radius', 'd - Angle', 'q - Real', 'q - Imag', 'q - Radius', 'q - Angle', 'PLL Omega', 'PLL Phi', 'PLL theta' ] # data length needs to be the same phase_a_mag = [self.phaseAMag] * len(self.time_samples) phase_a_omega = [self.phaseAOmega] * len(self.time_samples) phase_a_phi = [self.phaseAPhi] * len(self.time_samples) phase_a_dc = [self.phaseADC] * len(self.time_samples) phase_b_mag = [self.phaseBMag] * len(self.time_samples) phase_b_omega = [self.phaseBOmega] * len(self.time_samples) phase_b_phi = [self.phaseBPhi] * len(self.time_samples) phase_b_dc = [self.phaseBDC] * len(self.time_samples) phase_c_mag = [self.phaseCMag] * len(self.time_samples) phase_c_omega = [self.phaseCOmega] * len(self.time_samples) phase_c_phi = [self.phaseCPhi] * len(self.time_samples) phase_c_dc = [self.phaseCDC] * len(self.time_samples) pll_omega = [self.pllOmega] * len(self.time_samples) pll_phi = [self.pllPhi] * len(self.time_samples) data_sets = [ self.time_samples, phase_a_mag, phase_a_omega, phase_a_phi, phase_a_dc, self.phaseAdata.real, self.phaseAdata.imag, abs(self.phaseAdata), np.angle(self.phaseAdata), phase_b_mag, phase_b_omega, phase_b_phi, phase_b_dc, self.phaseBdata.real, self.phaseBdata.imag, abs(self.phaseBdata), np.angle(self.phaseBdata), phase_c_mag, phase_c_omega, phase_c_phi, phase_c_dc, self.phaseCdata.real, self.phaseCdata.imag, abs(self.phaseCdata), np.angle(self.phaseCdata), self.phaseA_pos.real, self.phaseA_pos.imag, abs(self.phaseA_pos), np.angle(self.phaseA_pos), self.phaseB_pos.real, self.phaseB_pos.imag, abs(self.phaseB_pos), np.angle(self.phaseB_pos), self.phaseC_pos.real, self.phaseC_pos.imag, abs(self.phaseC_pos), np.angle(self.phaseC_pos), self.phaseA_neg.real, self.phaseA_neg.imag, abs(self.phaseA_neg), np.angle(self.phaseA_neg), self.phaseB_neg.real, self.phaseB_neg.imag, abs(self.phaseB_neg), np.angle(self.phaseB_neg), self.phaseC_neg.real, self.phaseC_neg.imag, abs(self.phaseC_neg), np.angle(self.phaseC_neg), self.phaseZero.real, self.phaseZero.imag, abs(self.phaseZero), np.angle(self.phaseZero), self.alpha.real, self.alpha.imag, abs(self.alpha), np.angle(self.alpha), self.beta.real, self.beta.imag, abs(self.beta), np.angle(self.beta), self.alpha_pos.real, self.alpha_pos.imag, abs(self.alpha_pos), np.angle(self.alpha_pos), self.beta_pos.real, self.beta_pos.imag, abs(self.beta_pos), np.angle(self.beta_pos), self.alpha_neg.real, self.alpha_neg.imag, abs(self.alpha_neg), np.angle(self.alpha_neg), self.beta_neg.real, self.beta_neg.imag, abs(self.beta_neg), np.angle(self.beta_neg), self.d.real, self.d.imag, abs(self.d), np.angle(self.d), self.q.real, self.q.imag, abs(self.q), np.angle(self.q), self.d_pos.real, self.d_pos.imag, abs(self.d_pos), np.angle(self.d_pos), self.q_pos.real, self.q_pos.imag, abs(self.q_pos), np.angle(self.q_pos), self.d_neg.real, self.d_neg.imag, abs(self.d_neg), np.angle(self.d_neg), self.q_neg.real, self.q_neg.imag, abs(self.q_neg), np.angle(self.q_neg), pll_omega, pll_phi, self.thetaPLL ] gsyIO.save_csv_gui(header, data_sets) self.save_setting() self.print_info('Data saved as CSV') return True
def save_data(self): ''' Save the generated data in CSV. ''' bool_temp = self.update_data() if bool_temp == False: root = tk.Tk() root.withdraw() msgbox.showerror( 'Error', 'Error when making phase data. Time cannot be zero.') root.destroy() return False header = [ 'time', 'Phase-A Mag', 'Phase-A Omega', 'Phase-A Phi', 'Phase-A Real', 'Phase-A Imag', 'Phase-B Mag', 'Phase-B Omega', 'Phase-B Phi', 'Phase-B Real', 'Phase-B Imag', 'Phase-C Mag', 'Phase-C Omega', 'Phase-C Phi', 'Phase-C Real', 'Phase-C Imag', 'Phase-A + Real', 'Phase-A + Imag', 'Phase-B + Real', 'Phase-B + Imag', 'Phase-C + Real', 'Phase-C + Imag', 'Phase-A - Real', 'Phase-A - Imag', 'Phase-B - Real', 'Phase-B - Imag', 'Phase-C - Real', 'Phase-C - Imag', 'Zero Real', 'Zero Imag', 'Alpha Real', 'Alpha Imag', 'Beta Real', 'Beta Imag', 'Alpha + Real', 'Alpha + Image', 'Beta + Real', 'Beta + Image', 'Alpha - Real', 'Alpha - Imag', 'Beta - Real', 'Beta - Imag', 'd Real', 'd Imag', 'q Real', 'q Imag', 'd + Real', 'd + Imag', 'q + Real', 'q + Imag', 'd - Real', 'd - Imag', 'q - Real', 'q - Imag', 'PLL Omega', 'PLL Phi', 'PLL theta' ] phase_a_mag = [self.phaseAMag] * len(self.time_samples) phase_a_omega = [self.phaseAOmega] * len(self.time_samples) phase_a_phi = [self.phaseAPhi] * len(self.time_samples) phase_b_mag = [self.phaseBMag] * len(self.time_samples) phase_b_omega = [self.phaseBOmega] * len(self.time_samples) phase_b_phi = [self.phaseBPhi] * len(self.time_samples) phase_c_mag = [self.phaseCMag] * len(self.time_samples) phase_c_omega = [self.phaseCOmega] * len(self.time_samples) phase_c_phi = [self.phaseCPhi] * len(self.time_samples) pll_omega = [self.pllOmega] * len(self.time_samples) pll_phi = [self.pllPhi] * len(self.time_samples) data_sets = [ self.time_samples, phase_a_mag, phase_a_omega, phase_a_phi, self.phaseAdata.real, self.phaseAdata.imag, phase_b_mag, phase_b_omega, phase_b_phi, self.phaseBdata.real, self.phaseBdata.imag, phase_c_mag, phase_c_omega, phase_c_phi, self.phaseCdata.real, self.phaseCdata.imag, self.phaseA_pos.real, self.phaseA_pos.imag, self.phaseB_pos.real, self.phaseB_pos.imag, self.phaseC_pos.real, self.phaseC_pos.imag, self.phaseA_neg.real, self.phaseA_neg.imag, self.phaseB_neg.real, self.phaseB_neg.imag, self.phaseC_neg.real, self.phaseC_neg.imag, self.phaseZero.real, self.phaseZero.imag, self.alpha.real, self.alpha.imag, self.beta.real, self.beta.imag, self.alpha_pos.real, self.alpha_pos.imag, self.beta_pos.real, self.beta_pos.imag, self.alpha_neg.real, self.alpha_neg.imag, self.beta_neg.real, self.beta_neg.imag, self.d.real, self.d.imag, self.q.real, self.q.imag, self.d_pos.real, self.d_pos.imag, self.q_pos.real, self.q_pos.imag, self.d_neg.real, self.d_neg.imag, self.q_neg.real, self.q_neg.imag, pll_omega, pll_phi, self.thetaPLL ] gsyIO.save_csv_gui(header, data_sets) return True