# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3 (ipykernel)
#     language: python
#     name: python3
# ---

from os import path
import pandas as pd
import numpy as np
from eis.EISDataIO import eis_dataframe_from_csv, ECM_from_raw_strings
from sklearn import preprocessing

# +
# Load training data

# here = !pwd

train_data_path = path.join(path.dirname(here[0]), "train_data.csv")
eis_data = eis_dataframe_from_csv(train_data_path)

# +
# Drop ECM parameters from df for classification exercise

#sample = eis_data.loc[eis_data.Circuit=="L-R-RCPE"]
sample = eis_data
sample

# +
# Split X into Z_real and Z_imag

sample2 = sample
z_count = sample2.Z.size

sample2["Z_real"] = ""
sample2["Z_imag"] = ""

for x in range(z_count):
    
    z_real_x =  np.array(sample2.Z[x].real)
    sample2.Z_real[x] = z_real_x
    
    z_imag_x =  np.array(sample2.Z[x].imag)
    sample2.Z_imag[x] = z_imag_x

sample2 = sample2.drop(['Parameters','Z'], axis=1)
sample2 = sample2[['freq','Z_real','Z_imag','Circuit']]
sample2

# +
# Encode string labels to integers

le = preprocessing.LabelEncoder()
le.fit(sample2.Circuit)
print(list(le.classes_))
le.transform(sample2.Circuit)
sample2['Circuit_int']=""
Circuit_int = le.transform(sample2.Circuit)
sample2.Circuit_int = Circuit_int
sample2

# +
from eis.EISDataIO import eis_dataframe_from_csv, ECM_from_raw_strings
from eis.EISPlot import plot_eis

for x in range(len(le.classes_)):
    sample3 = eis_data.loc[eis_data.Circuit==list(le.classes_)[x]]
    print(list(le.classes_)[x])
    for y in range(5):
        sample_i = sample3.iloc[y]
        frequencies = sample_i.freq
        impedances = sample_i.Z
        plot_eis(frequencies, impedances)
# -



StarcoderdataJupyterScriptsDedupFiltered