You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
py-data-analysis/Experimental_Analysis.ipynb

355 KiB

None <html lang="en"> <head> </head>

Experimental Data-Analysis

In [ ]:
!pip install pandas
!pip install matplotlib
In [24]:
import  pandas      as      pd
import  numpy       as      np
from    pathlib     import  Path
from    dataclasses import  dataclass
import  math
import  matplotlib.pyplot as plt    

class   Experimento:
    def __init__(self, volt_iny, volt_elec, corr_elec, resistencia):
        self.volt_iny    =   volt_iny
        self.volt_elec   =   volt_elec
        self.corr_elec   =   corr_elec
        self.resistencia =   resistencia
In [62]:
path_1  =   Path("/home/mgph/Desktop/?/MAESTRIA/HYDROGEN_PROJ/Data/Experimental-Data/EXP-A_20250917_163949.csv")    # Path for the experiment 20250917
path_2  =   Path("/home/mgph/Desktop/?/MAESTRIA/HYDROGEN_PROJ/Data/Experimental-Data/EXP-A_20250922_100524.csv")     # Path for the experiment 20250922
# Import the experiment "20250917"
df_1    =   pd.read_csv(path_1, encoding="latin-1")
# Import the experiment "20250922"
df_2    =   pd.read_csv(path_2, encoding="latin-1")
#df_1.head() 
#df_1.head()

cols_extract    =   ["Voltaje Inyectado (V)", "Voltaje Electrodos (V)", "Corriente Electrodos (A)", "Resistencia"]
dt_exp1         =   df_1[cols_extract].copy()   #Exp 20250917
dt_exp2         =   df_2[cols_extract].copy()   #Exp 20250922

exp_1   =   Experimento(
    volt_iny    =   dt_exp1["Voltaje Inyectado (V)"], 
    volt_elec   =   dt_exp1["Voltaje Electrodos (V)"],
    corr_elec   =   dt_exp1["Corriente Electrodos (A)"],
    resistencia =   dt_exp1["Resistencia"],
)

exp_2   =   Experimento(
    volt_iny    =   dt_exp2["Voltaje Inyectado (V)"], 
    volt_elec   =   dt_exp2["Voltaje Electrodos (V)"],
    corr_elec   =   dt_exp2["Corriente Electrodos (A)"],
    resistencia =   dt_exp2["Resistencia"],
)

min_val_exp1    =   min(exp_1.volt_iny)
min_val_exp2    =   min(exp_2.volt_iny)

print(f"The min value of the exp_1 are: {min_val_exp1} V, length: {len(exp_1.volt_iny)}")
print(f"The min value of the exp_2 are: {min_val_exp2} V, length: {len(exp_2.volt_iny)}")

# Now we filter the data for extract only the values that we need to work with
min_value       =   0.6
min_val_curr    =   1.2
max_value       =   8.0

# Voltage from the both experiments 
volt_iny_20250917   =   exp_1.volt_iny.to_list()   #   voltage supply for exp_1
volt_iny_20250922   =   exp_2.volt_iny.to_list()   #   voltage supply for exp_2
volt_elec_20250917  =   exp_1.volt_elec.to_list()  #   from exp_1
volt_elec_20250922  =   exp_2.volt_elec.to_list()  #   from exp_2

#Current from the both experiments 
curr_elec_20250917  =   exp_1.corr_elec.to_list()   # Current electrodes from the exp_1
curr_elec_20250922  =   exp_2.corr_elec.to_list()   # Current electrodes from the exp_2

#Resistance from the both experiments
res_20250917        =   exp_1.resistencia.to_list() #   Resistance from the exp_1
res_20250922        =   exp_2.resistencia.to_list() #   Resistance from the exp_2

print(len(volt_iny_20250917), len(volt_iny_20250922))
print(len(volt_elec_20250917))
print(len(volt_elec_20250922))

volt_iny_filt_20250917  =   []      # Variable for the volt_iny filtered values
volt_elec_filt_20250917 =   []      # Variable for the volt_elec filtered values from the exp_1
volt_elec_filt_20250922 =   []      # Variable for the volt_elec filtered values from the exp_2
curr_elec_filt_20250917 =   []      # Variable for the curr_elec filtered values from the exp_1
curr_elec_filt_20250922 =   []      # Variable for the curr_elec filtered values from the exp_2

for x in range(len(volt_iny_20250917)):
    if min_value    <=  volt_iny_20250917[x]  <=  max_value:
        volt_iny_filt_20250917.append(volt_iny_20250917[x])
        volt_elec_filt_20250917.append(volt_elec_20250917[x])
        curr_elec_filt_20250917.append(curr_elec_20250917[x])

for x in range(len(volt_iny_20250922)):
    if min_value    <=  volt_iny_20250922[x]    <=  max_value:
        volt_elec_filt_20250922.append(volt_elec_20250922[x])
        curr_elec_filt_20250922.append(curr_elec_20250922[x])

if len(volt_iny_filt_20250917) == len(volt_elec_filt_20250917) and len(volt_iny_filt_20250917) == len(volt_elec_filt_20250922):
    print(True)
else:
    print(False)

print(volt_elec_filt_20250917)
print(volt_elec_filt_20250922)
print(volt_iny_filt_20250917)
print(curr_elec_filt_20250917)
print(curr_elec_filt_20250922)


curr_elec_filt_20250917 =   []      # Variable for the curr_elec filtered values from the exp_1
curr_elec_filt_20250922 =   []      # Variable for the curr_elec filtered values from the exp_2
res_filt_20250917       =   []
res_filt_20250922       =   []

for x in range(len(volt_iny_20250917)):
    if min_val_curr <=  volt_iny_20250917[x]  <=  max_value:
        curr_elec_filt_20250917.append(curr_elec_20250917[x])
        res_filt_20250917.append(res_20250917[x])

for x in range(len(volt_iny_20250922)):
    if min_val_curr <=  volt_iny_20250922[x]  <=  max_value:
        curr_elec_filt_20250922.append(curr_elec_20250922[x])
        res_filt_20250922.append(res_20250922[x])

print(curr_elec_filt_20250917)
print(curr_elec_filt_20250922)
print(res_filt_20250917)
print(res_filt_20250922)
The min value of the exp_1 are: 0.6 V, length: 77
The min value of the exp_2 are: 0.3 V, length: 85
77 85
77
85
True
[0.573808, 0.668549, 0.772401, 0.869213, 0.973349, 1.071694, 1.173009, 1.27474, 1.372375, 1.471467, 1.568757, 1.672959, 1.776859, 1.8776, 1.965347, 2.064571, 2.151419, 2.243739, 2.32795, 2.419784, 2.508601, 2.592741, 2.677183, 2.768261, 2.852988, 2.93498, 3.019871, 3.10941, 3.193848, 3.277706, 3.360108, 3.445992, 3.533107, 3.616832, 3.679116, 3.766311, 3.8489, 3.934223, 4.016886, 4.090264, 4.178369, 4.247341, 4.296629, 4.383905, 4.464879, 4.5511, 4.644093, 4.728928, 4.781434, 4.892725, 4.971322, 5.060052, 5.185251, 5.194691, 5.262038, 5.357256, 5.458388, 5.544996, 5.60318, 5.675927, 5.757613, 5.844239, 5.910516, 6.025117, 6.090627, 6.175911, 6.266985, 6.351973, 6.424481, 6.592911, 6.674127, 6.741563, 6.831755, 6.913147, 7.000398]
[0.573853, 0.667522, 0.773055, 0.872369, 0.97355, 1.074186, 1.167853, 1.272827, 1.3683, 1.472672, 1.569552, 1.675805, 1.769356, 1.86589, 1.944208, 2.018332, 2.088197, 2.15909, 2.220222, 2.275156, 2.355009, 2.439813, 2.553364, 2.649481, 2.717847, 2.788432, 2.873282, 2.976466, 3.050858, 3.131146, 3.22697, 3.317778, 3.398386, 3.487932, 3.575035, 3.661309, 3.763909, 3.864253, 3.941614, 4.043282, 4.12081, 4.20273, 4.280082, 4.37163, 4.440561, 4.539856, 4.623924, 4.683808, 4.75006, 4.844785, 4.948401, 5.019534, 5.09199, 5.184119, 5.246069, 5.346119, 5.423541, 5.508804, 5.592692, 5.677811, 5.766302, 5.8584, 5.936311, 6.080866, 6.150302, 6.232371, 6.324351, 6.402649, 6.494829, 6.574733, 6.642314, 6.733614, 6.813686, 6.892127, 6.970774]
[0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3.0, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 4.0, 4.1, 4.2, 4.3, 4.4, 4.5, 4.6, 4.7, 4.8, 4.9, 5.0, 5.1, 5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 5.9, 6.0, 6.1, 6.2, 6.3, 6.4, 6.5, 6.6, 6.7, 6.8, 6.9, 7.0, 7.1, 7.2, 7.3, 7.4, 7.5, 7.6, 7.7, 7.8, 7.9, 8.0]
[4e-05, 2.5e-05, 2.9e-05, 4e-06, -1.5e-05, 0.0, 0.000116, 0.000189, 0.000338, 0.000466, 0.000768, 0.001142, 0.003504, 0.015547, 0.043751, 0.094182, 0.154819, 0.229686, 0.305378, 0.39451, 0.483181, 0.572389, 0.664283, 0.765462, 0.861482, 0.95772, 1.057778, 1.166856, 1.271295, 1.373711, 1.477331, 1.58443, 1.695818, 1.803364, 1.893588, 2.013072, 2.135011, 2.281549, 2.418617, 2.567917, 2.696063, 2.801837, 2.898538, 3.038538, 3.175038, 3.304268, 3.463134, 3.626114, 3.75665, 3.961792, 4.170739, 4.331041, 4.558776, 4.633475, 4.795757, 4.982659, 5.196361, 5.369012, 5.50799, 5.665349, 5.829409, 6.032178, 6.162864, 6.371677, 6.537258, 6.734802, 6.922025, 7.115891, 7.279034, 7.601211, 7.841906, 8.070398, 8.251828, 8.409674, 8.641052]
[-4e-05, 4e-06, 7e-06, -7e-06, 7e-06, 2.2e-05, 0.000135, 0.000229, 0.00028, 0.000433, 0.000619, 0.000946, 0.003798, 0.018141, 0.042834, 0.07729, 0.116835, 0.164013, 0.208107, 0.252116, 0.317086, 0.389082, 0.490479, 0.578236, 0.643377, 0.712517, 0.794274, 0.895377, 0.971699, 1.054093, 1.153973, 1.251328, 1.339532, 1.439558, 1.541803, 1.644073, 1.757055, 1.872176, 1.965919, 2.093101, 2.188167, 2.296594, 2.387163, 2.501815, 2.619785, 2.7534, 2.872021, 3.215351, 3.322893, 3.454194, 3.664167, 3.778408, 3.897527, 4.042425, 4.163778, 4.333649, 4.460923, 4.601108, 4.747941, 4.893745, 5.049223, 5.226894, 5.369962, 5.601626, 5.747484, 5.909402, 6.080099, 6.246463, 6.431688, 6.600529, 6.827111, 7.043618, 7.243291, 7.452209, 7.645198]
[0.000116, 0.000189, 0.000338, 0.000466, 0.000768, 0.001142, 0.003504, 0.015547, 0.043751, 0.094182, 0.154819, 0.229686, 0.305378, 0.39451, 0.483181, 0.572389, 0.664283, 0.765462, 0.861482, 0.95772, 1.057778, 1.166856, 1.271295, 1.373711, 1.477331, 1.58443, 1.695818, 1.803364, 1.893588, 2.013072, 2.135011, 2.281549, 2.418617, 2.567917, 2.696063, 2.801837, 2.898538, 3.038538, 3.175038, 3.304268, 3.463134, 3.626114, 3.75665, 3.961792, 4.170739, 4.331041, 4.558776, 4.633475, 4.795757, 4.982659, 5.196361, 5.369012, 5.50799, 5.665349, 5.829409, 6.032178, 6.162864, 6.371677, 6.537258, 6.734802, 6.922025, 7.115891, 7.279034, 7.601211, 7.841906, 8.070398, 8.251828, 8.409674, 8.641052]
[0.000135, 0.000229, 0.00028, 0.000433, 0.000619, 0.000946, 0.003798, 0.018141, 0.042834, 0.07729, 0.116835, 0.164013, 0.208107, 0.252116, 0.317086, 0.389082, 0.490479, 0.578236, 0.643377, 0.712517, 0.794274, 0.895377, 0.971699, 1.054093, 1.153973, 1.251328, 1.339532, 1.439558, 1.541803, 1.644073, 1.757055, 1.872176, 1.965919, 2.093101, 2.188167, 2.296594, 2.387163, 2.501815, 2.619785, 2.7534, 2.872021, 3.215351, 3.322893, 3.454194, 3.664167, 3.778408, 3.897527, 4.042425, 4.163778, 4.333649, 4.460923, 4.601108, 4.747941, 4.893745, 5.049223, 5.226894, 5.369962, 5.601626, 5.747484, 5.909402, 6.080099, 6.246463, 6.431688, 6.600529, 6.827111, 7.043618, 7.243291, 7.452209, 7.645198]
[10112.1469, 6744.657778, 4060.281183, 3157.653562, 2042.652917, 1464.938144, 507.094521, 120.76927, 44.921195, 21.921082, 13.896348, 9.768722, 7.623177, 6.133644, 5.191846, 4.529684, 4.030185, 3.616458, 3.311721, 3.06455, 2.85492, 2.664776, 2.512279, 2.386023, 2.274445, 2.17491, 2.083423, 2.005603, 1.942933, 1.870927, 1.802754, 1.724365, 1.660819, 1.592834, 1.549804, 1.515913, 1.482344, 1.442768, 1.406244, 1.37734, 1.341009, 1.304131, 1.272792, 1.234978, 1.191952, 1.168322, 1.137422, 1.121122, 1.097228, 1.07518, 1.050425, 1.032778, 1.017282, 1.001867, 0.987684, 0.968844, 0.959054, 0.945609, 0.931679, 0.917014, 0.905369, 0.892646, 0.882601, 0.86735, 0.851085, 0.835345, 0.827908, 0.822047, 0.810133]
[8650.759704, 5558.194585, 4886.786857, 3401.091178, 2535.625719, 1771.464186, 465.865276, 102.854881, 45.389367, 26.11376, 17.873047, 13.164137, 10.668656, 9.024241, 7.427035, 6.270691, 5.205857, 4.582006, 4.224346, 3.913495, 3.617495, 3.32426, 3.139715, 2.970464, 2.7964, 2.651406, 2.536995, 2.422919, 2.318736, 2.226975, 2.142169, 2.064044, 2.004973, 1.931718, 1.883224, 1.829984, 1.792958, 1.747383, 1.69501, 1.648818, 1.60999, 1.456702, 1.429495, 1.402581, 1.350484, 1.328478, 1.306467, 1.282428, 1.25993, 1.23363, 1.215789, 1.197278, 1.17792, 1.160218, 1.142018, 1.120819, 1.105466, 1.085554, 1.070086, 1.054653, 1.040172, 1.025004, 1.009817, 0.996092, 0.972932, 0.955988, 0.940689, 0.924843, 0.911785]
In [63]:
def _minlen(*list):
    return  min(len(lst) for lst in list)

# Ploting "volt_iny_filt_20250917 (x)" vs "volt_elec_20250917" - "volt_elec_20250922" (y)

n1  =   _minlen(volt_iny_filt_20250917, volt_elec_filt_20250917, volt_elec_filt_20250922)
x1  =   volt_iny_filt_20250917[:n1]
#y1  =   [volt_elec_filt_20250917[i] - volt_elec_filt_20250922[i] for i in range(n1)]
y1  =   volt_elec_filt_20250917
y2  =   volt_elec_filt_20250922

plt.figure()
plt.plot(x1, y1, marker='o', linestyle='-', color='tab:blue', label='V_elec_20250917')
plt.plot(x1, y2, marker='o', linestyle='-', color='tab:red', label='V_elec_20250922')
plt.title('Comparative between the Voltage Electrodes and Voltage Supply')
plt.xlabel('Suply Voltage (V)')
plt.ylabel('ΔVoltage Electrodes (V)')
plt.grid(True)
plt.legend()
plt.show()

n1  =   _minlen(volt_iny_filt_20250917, curr_elec_filt_20250917, curr_elec_filt_20250922)
x1  =   volt_iny_filt_20250917[:n1]
#y1  =   [volt_elec_filt_20250917[i] - volt_elec_filt_20250922[i] for i in range(n1)]
y1  =   curr_elec_filt_20250917
y2  =   curr_elec_filt_20250922

plt.figure()
plt.plot(x1, y1, marker='o', linestyle='-', color='tab:blue', label='C_elec_20250917')
plt.plot(x1, y2, marker='o', linestyle='-', color='tab:red', label='C_elec_20250922')
plt.title('Comparative between the Current Electrodes and Voltage Supply')
plt.xlabel('Suply Voltage (V)')
plt.ylabel('ΔCurrent Electrodes (A)')
plt.grid(True)
plt.legend()
plt.show()

n1  =   _minlen(volt_iny_filt_20250917, res_filt_20250917, res_filt_20250922)
x1  =   volt_iny_filt_20250917[:n1]
#y1  =   [volt_elec_filt_20250917[i] - volt_elec_filt_20250922[i] for i in range(n1)]
y1  =   res_filt_20250917
y2  =   res_filt_20250922

plt.figure()
plt.plot(x1, y1, marker='o', linestyle='-', color='tab:blue', label='Resistance_20250917')
plt.plot(x1, y2, marker='o', linestyle='-', color='tab:red', label='Resistance_20250922')
plt.title('Comparative between the Resistance and Voltage Supply')
plt.xlabel('Suply Voltage (V)')
plt.ylabel('Δ Resistance (Ohms)')
plt.grid(True)
plt.legend()
plt.show()

n1  =   _minlen(volt_iny_filt_20250917, res_filt_20250917, res_filt_20250922)
x1  =   volt_iny_filt_20250917[:n1]
y1  =   [res_filt_20250917[i] - res_filt_20250922[i] for i in range(n1)]

plt.figure()
plt.plot(x1, y1, marker='o', linestyle='-', color='tab:blue', label='ΔResistance = Resistance_20250917 - Resistance_20250922')
plt.title('Comparative between the Resistance and Voltage Supply')
plt.xlabel('Suply Voltage (V)')
plt.ylabel('ΔResistance (Ohms)')
plt.grid(True)
plt.legend()
plt.show()

res_filt_20250917       =   []
res_filt_20250922       =   []
volt_iny_filt_20250917  =   []
min_val_curr            =   2.5

for x in range(len(volt_iny_20250917)):
    if min_val_curr <=  volt_iny_20250917[x]  <=  max_value:
        volt_iny_filt_20250917.append(volt_iny_20250917[x])
        res_filt_20250917.append(res_20250917[x])

for x in range(len(volt_iny_20250922)):
    if min_val_curr <=  volt_iny_20250922[x]  <=  max_value:
        res_filt_20250922.append(res_20250922[x])

n1  =   _minlen(volt_iny_filt_20250917, res_filt_20250917, res_filt_20250922)
x1  =   volt_iny_filt_20250917[:n1]
#y1  =   [volt_elec_filt_20250917[i] - volt_elec_filt_20250922[i] for i in range(n1)]
y1  =   res_filt_20250917
y2  =   res_filt_20250922        

plt.figure()
plt.plot(x1, y1, marker='o', linestyle='-', color='tab:blue', label='Resistance_20250917')
plt.plot(x1, y2, marker='o', linestyle='-', color='tab:red', label='Resistance_20250922')
plt.title('Comparative between the Resistance and Voltage Supply')
plt.xlabel('Suply Voltage (V)')
plt.ylabel('Δ Resistance (Ohms)')
plt.grid(True)
plt.legend()
plt.show()

n1  =   _minlen(volt_iny_filt_20250917, res_filt_20250917, res_filt_20250922)
x1  =   volt_iny_filt_20250917[:n1]
y1  =   [res_filt_20250922[i] - res_filt_20250917[i] for i in range(n1)]

plt.figure()
plt.plot(x1, y1, marker='o', linestyle='-', color='tab:blue', label='ΔResistance = Resistance_20250917 - Resistance_20250922')
plt.title('Comparative between the Resistance and Voltage Supply')
plt.xlabel('Suply Voltage (V)')
plt.ylabel('ΔResistance (Ohms)')
plt.grid(True)
plt.legend()
plt.show()

pwr_consup_20250917         =   []
pwr_consup_20250922         =   []
volt_iny_filt_20250917_1    =   []
min_val_curr_1              =   1.2
val_aux                     =   0

n   =   _minlen(volt_iny_20250917, volt_elec_filt_20250917, curr_elec_filt_20250917)

for x in range(n):
    if min_val_curr_1 <= volt_iny_20250917[x]    <=  max_value:
        volt_iny_filt_20250917_1.append(volt_iny_20250917[x])
        pwr_consup_20250917.append((volt_elec_filt_20250917[x]*curr_elec_filt_20250917[x]))

n   =   _minlen(volt_iny_20250917, volt_elec_filt_20250922, curr_elec_filt_20250922)

for x in range(n):
    if min_val_curr_1 <= volt_iny_20250922[x]    <=  max_value:
        pwr_consup_20250922.append((volt_elec_filt_20250922[x]*curr_elec_filt_20250922[x]))

n1  =   _minlen(volt_iny_filt_20250917_1, pwr_consup_20250917, pwr_consup_20250922)
x1  =   volt_iny_filt_20250917_1[:n1]
#y1  =   [volt_elec_filt_20250917[i] - volt_elec_filt_20250922[i] for i in range(n1)]
y1  =   pwr_consup_20250917[:n1]
y2  =   pwr_consup_20250922      


plt.figure()
plt.plot(x1, y1, marker='o', linestyle='-', color='tab:blue', label='Power_Consumption_20250917')
plt.plot(x1, y2, marker='o', linestyle='-', color='tab:red', label='Power_Consumption_20250922')
plt.title('Comparative the Power Consumption (W) of both experiments')
plt.xlabel('Suply Voltage (V)')
plt.ylabel('Δ Power (W)')
plt.grid(True)
plt.legend()
plt.show()
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
</html>