diff --git a/explore_data.py b/explore_data.py deleted file mode 100644 index 4a36b965310a4cef745bddf07e2ac8e5abdd656a..0000000000000000000000000000000000000000 --- a/explore_data.py +++ /dev/null @@ -1,162 +0,0 @@ -import scipy.io -import os -from glob import glob -from matplotlib import pyplot as plt -# import numpy as np -# import uuid -from utils.create_path import create_path - - -def convert_matlab_datetime_vector_to_utc(date_vector): - # f'{val:02}' TODO - string_time = str(int(date_vector[0])) + "-" + \ - f'{int(date_vector[1]):02}' + "-" + \ - f'{int(date_vector[2]):02}' + "T" + \ - f'{int(date_vector[3]):02}' + ":" + \ - f'{int(date_vector[4]):02}' + ":" + \ - f'{float(date_vector[5]):06.3f}' - - return string_time - - -def filter_mat(mat, test_type): - return [x for x in mat if x[0][0] == test_type] - - -def plot(name, values, path, datetime, filename, current_color): - plt.figure(name) - axe = str(hex(current_color))[2:] - if len(axe) == 1: - axe = "0" + str(axe) - plt.plot(range(len(values)), values, color='#A0'+axe+axe) - - datetime = str(datetime).replace('.', '_') - datetime = str(datetime).replace(':', '-') - filepath = os.path.join(path, name, filename, datetime + '.png') - create_path(filepath) - plt.savefig(filepath) - - -# def format_temperature(temp: float) -> int: -def format_temperature(temp): - if temp < 6: - return 4 - elif temp < 26: - return 24 - else: - return 43 - - -def charge_iteration(charge_items, filename): - max_len = len(charge_items) - for idx, item in enumerate(charge_items): - # test_type = item[0][0] # charge impedence discharge - ambiant_temp = format_temperature(item[1][0][0]) # temperature: 4 ~24 ~43 - datetime = convert_matlab_datetime_vector_to_utc(item[2][0]) - - path = os.path.join("output_graphs", "charges", "degree" + str(ambiant_temp)) - - voltage_measured = item[3][0][0][0][0] # Battery terminal voltage (Volts) floats - current_measured = item[3][0][0][1][0] # Battery output current (Amps) floats - temperature_measured = item[3][0][0][2][0] # Battery temperature (degree C) floats - current_charge = item[3][0][0][3][0] # Current measured at charger (Amps) floats - voltage_charge = item[3][0][0][4][0] # Voltage measured at charger (Volts) floats - # MEH - # time = item[3][0][0][5] # Time vector for the cycle (secs) floats - - percentage = idx / max_len - current_color = int(255 * percentage) - - plot("voltage_measured", voltage_measured, path, datetime, filename, current_color) - plot("current_measured", current_measured, path, datetime, filename, current_color) - plot("temperature_measured", temperature_measured, path, datetime, filename, current_color) - plot("current_charge", current_charge, path, datetime, filename, current_color) - plot("voltage_charge", voltage_charge, path, datetime, filename, current_color) - - plt.close('all') - - -def discharge_iteration(discharge_items, filename): - max_len = len(discharge_items) - # TODO extract for with maps - for idx, item in enumerate(discharge_items): - # test_type = item[0][0] # charge impedence discharge - ambiant_temp = format_temperature(item[1][0][0]) # temperature: 4 ~24 ~43 - datetime = convert_matlab_datetime_vector_to_utc(item[2][0]) - - path = "output_graphs/discharge/degree" + str(ambiant_temp) - - voltage_measured = item[3][0][0][0][0] # Battery terminal voltage (Volts) floats - current_measured = item[3][0][0][1][0] # Battery output current (Amps) flaots - temperature_measured = item[3][0][0][2][0] # Battery temperature (degree C) floats - current_charge = item[3][0][0][3][0] # Current measured at charger (Amps) floats - voltage_charge = item[3][0][0][4][0] # Voltage measured at charger (Volts) floats - # MEH - # time = item[3][0][0][5][0] # Time vector for the cycle (secs) floats - # capacity = item[3][0][0][6][0] # Battery capacity (Ahr) for discharge till 2.7V float_ - - percentage = idx / max_len - current_color = int(255 * percentage) - - plot("voltage_measured", voltage_measured, path, datetime, filename, current_color) - plot("current_measured", current_measured, path, datetime, filename, current_color) - plot("temperature_measured", temperature_measured, path, datetime, filename, current_color) - plot("current_charge", current_charge, path, datetime, filename, current_color) - plot("voltage_charge", voltage_charge, path, datetime, filename, current_color) - - plt.close('all') - - -def impedance_iteration(impedance_items, filename): - max_len = len(impedance_items) - for idx, item in enumerate(impedance_items): - # test_type = item[0][0] # charge impedence discharge - ambiant_temp = format_temperature(item[1][0][0]) # temperature: 4 ~24 ~43 - datetime = convert_matlab_datetime_vector_to_utc(item[2][0]) - - path = "output_graphs/impedance/degree" + str(ambiant_temp) - - sense_current = item[3][0][0][0][0] # Current in sense branch (Amps)| Complexes - battery_current = item[3][0][0][1][0] # urrent in battery branch (Amps)| Complexes - current_ratio = item[3][0][0][2][0] # Ratio of the above currents| Complexes - # Battery impedance (Ohms) computed from raw data| Complexes but multiple array of 1 complexe - battery_impedance = item[3][0][0][3] - # alibrated and smoothed battery impedance (Ohms)| Complexes but multiple array of 1 complexe - rectified_impedance = item[3][0][0][4] - # re = item[3][0][0][5][0][0] # Estimated electrolyte resistance (Ohms)| float_ - # rct = item[3][0][0][6][0][0] # Estimated charge transfer resistance (Ohms)| float_ - - percentage = idx / max_len - current_color = int(255 * percentage) - - plot("sense_current", sense_current, path, datetime, filename, current_color) - plot("battery_current", battery_current, path, datetime, filename, current_color) - plot("current_ratio", current_ratio, path, datetime, filename, current_color) - plot("battery_impedance", battery_impedance, path, datetime, filename, current_color) - plot("rectified_impedance", rectified_impedance, path, datetime, filename, current_color) - - plt.close('all') - - -def main(): - filepaths = [y for x in os.walk("./data/") for y in glob(os.path.join(x[0], '*.mat'))] - filepaths = sorted(filepaths) - - # TODO warning for for the [:1] - for filepath in filepaths[:1]: - filename = os.path.split(filepath)[-1].split(".")[0] - raw_mat = scipy.io.loadmat(filepath) - - mat = raw_mat[filename][0][0][0][0] - - impedance_items = filter_mat(mat, "impedance") - charge_items = filter_mat(mat, "charge") - discharge_items = filter_mat(mat, "discharge") - - charge_iteration(charge_items, filename) - discharge_iteration(discharge_items, filename) - impedance_iteration(impedance_items, filename) - - -if __name__ == "__main__": - main()