def export_data(data: MotorCalc, destination: str) -> bool: limit = data.limit kls = data.kls_ klr = data.klr_ gs = data.gs_ gr = data.gr_ Ps = data.Ps PAl = data.PAl Pss = data.Pss Pp = data.Pp losses_pssv, losses_ppv = data.rotor_losses() losses_psv, losses_palv = data.stator_losses() stator_fluxes = data.stator_fluxes() rotor_fluxes = data.rotor_fluxes() losses_pssv = losses_pssv.to_list() losses_ppv = losses_ppv.to_list() losses_psv = losses_psv.to_list() losses_palv = losses_palv.to_list() stator_fluxes = stator_fluxes.to_list() rotor_fluxes = rotor_fluxes.to_list() kwargs = {"limit": limit, "kls": kls, "klr": klr, "gs": gs, "gr": gr, "Ps": Ps, "PAl": PAl, "Pss": Pss, "Pp": Pp, "losses_pssv": losses_pssv, "losses_ppv": losses_ppv, "losses_psv": losses_psv, "losses_palv": losses_palv, "stator_fluxes": stator_fluxes, "rotor_fluxes": rotor_fluxes} destination = destination + ".npz" if not destination.endswith(".npz") else destination path = ROOT_DIR + "/npz/" + destination np.savez(path, **kwargs) return True
def export_data(data: MotorCalc): vals_to_insert = (data.limit, data.kls_, data.klr_, data.gs_, data.gr_, data.Ps, data.PAl, data.Pss, data.Pp) Queries.insert_into_motor_results_table(vals_to_insert) id_added = Queries.getLastID(table_name="MotorResults") print(id_added) losses_pssv, losses_ppv = data.rotor_losses() losses_psv, losses_palv = data.stator_losses() stator_fluxes = data.stator_fluxes() rotor_fluxes = data.rotor_fluxes() Queries.insert_into_loss_table(loss_type=LossType.LOSS_PSS, losses=losses_pssv, id_to_add=id_added) Queries.insert_into_loss_table(loss_type=LossType.LOSS_PP, losses=losses_ppv, id_to_add=id_added) Queries.insert_into_loss_table(loss_type=LossType.LOSS_PS, losses=losses_psv, id_to_add=id_added) Queries.insert_into_loss_table(loss_type=LossType.LOSS_PAL, losses=losses_palv, id_to_add=id_added) Queries.insert_into_flux_table(flux_type=FluxType.StatorFlux, fluxes=stator_fluxes, id_to_add=id_added) Queries.insert_into_flux_table(flux_type=FluxType.RotorFlux, fluxes=rotor_fluxes, id_to_add=id_added) return id_added
def save_results(cls, filename, motor_calc: MotorCalc): losses_pssv, losses_ppv = motor_calc.rotor_losses() losses_psv, losses_palv = motor_calc.stator_losses() losses_array = np.array([[losses_psv], [losses_palv], [losses_pssv], [losses_ppv]]) np.savetxt('test.out', losses_array) # TODO: ADJUST THIS CODE TO MY NEEDS! import numpy as np a = np.array([1, 2, 3, 4, 5]) b = np.array([5.4, 2.3, 5.3, 2.4]) c = np.array([a, b]) print(c) np.savez('test.npz', c=c) d = np.load('test.npz', allow_pickle=True) print(d["c"]) print(list(d.keys()))