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.
502 KiB
502 KiB
None
<html lang="en">
<head>
</head>
</html>
In [5]:
from pathlib import Path
import sys
PROJECT_ROOT = Path.cwd().parent
sys.path.insert(0, str(PROJECT_ROOT))
print("Project_Root:", PROJECT_ROOT)
from src.visualizacion import (plot_xy, comparar_rondas, comparar_experimentos, plot_con_ajuste
, plot_3D, plot_color_map, plot_dual_axis)
from src.data_loader import apply_filter
from src.data_loader import load_all
DATA_DIR = PROJECT_ROOT / "data"
data = load_all(DATA_DIR)
print("Datos Cargados:", len(data))
In [46]:
from pathlib import Path
from src.data_loader import apply_filter
import matplotlib.pyplot as plt
## Put the path for import the data
#PROJECT_ROOT = Path.cwd().parent
#DATA_DIR = PROJECT_ROOT / "data"
#data = load_all(DATA_DIR)
def plot_xy(df, x_col, y_col, label=None, ax=None):
if ax is None:
fig, ax = plt.subplots(figsize=(7,5))
ax.plot(df[x_col], df[y_col], marker='o', linestyle='-', label=label)
ax.set_xlabel(x_col)
ax.set_ylabel(y_col)
ax.grid(True)
if label:
ax.legend()
return ax
def comparar_rondas(data, ronda, experimento, x_col, y_col,
row_start=None, row_end=None,
t_min=None, t_max=None, title=None):
fig, ax = plt.subplots(figsize=(7,5))
if ronda == None:
rnd = [1,2]
else:
rnd = ronda
for ronda in rnd:
df = data[(ronda, experimento)]
# Data Filtering
df_f = apply_filter(df, row_start=row_start, row_end=row_end,
t_min=t_min, t_max=t_max)
plot_xy(df_f, x_col, y_col, label=f"Ronda {ronda}", ax=ax)
if title == None:
ax.set_title(f"Experiment {experimento} - Comparatives Rounds {rnd}")
else:
ax.set_title(title)
plt.show()
def comparar_experimentos(data, ronda, expe, x_col, y_col,
row_start=None, row_end=None,
t_min=None, t_max=None, title=None):
fig, ax = plt.subplots(figsize=(7,5))
if expe == None:
no_expe = [1,2,3,4]
else:
no_expe = expe
for exp in no_expe:
df = data[(ronda, exp)]
# Data Filtering
df_f = apply_filter(df, row_start=row_start, row_end=row_end,
t_min=t_min, t_max=t_max)
plot_xy(df_f, x_col, y_col, label=f"Experiment {exp}", ax=ax)
if title == None:
ax.set_title(f"Round {ronda} - Comparatives Experiments {no_expe}")
else:
ax.set_title(title)
plt.show()
expe_1 = [1,4]
comparar_rondas(data, ronda=None, experimento=1, x_col="Temperatura", y_col="Resistencia", row_start=35,
row_end=66, title="Comparative between Temperature vs Resistance in Experiment 1")
comparar_rondas(data, ronda=None, experimento=2, x_col="Voltaje Electrodos (V)", y_col="Temperatura",
row_start=35, row_end=66)
comparar_experimentos(data, ronda=1, expe=None, x_col="Voltaje Electrodos (V)", y_col="Resistencia",
row_start=35, row_end=66)
comparar_experimentos(data, ronda=1, expe=None, x_col="Voltaje Electrodos (V)", y_col="Corriente Electrodos (A)",
row_start=10, row_end=66)
comparar_experimentos(data, ronda=1, expe=expe_1, x_col="Voltaje Electrodos (V)",
y_col="Corriente Electrodos (A)", row_start=10, row_end=66)
comparar_experimentos(data, ronda=1, expe=expe_1, x_col="Voltaje Electrodos (V)",
y_col="Resistencia", row_start=35, row_end=66)
comparar_experimentos(data, ronda=1, expe=[2,3], x_col="Voltaje Electrodos (V)",
y_col="Resistencia", row_start=35, row_end=66)
In [ ]:
import numpy as np
def calcular_pendiente(df, x_col, y_col):
x = df[x_col].values
y = df[y_col].values
m, b = np.polyfit(x, y, 1)
return m, b
def comparar_pendientes(data, experimento, ronda,
x_col, y_col, row_start=None,
row_end=None):
resultados = {}
print(f"Items rondas: {ronda}")
print(f"Items experimento: {experimento}")
if len(ronda) > len(experimento):
mayor = False
else:
mayor = True
print(mayor)
for rnd in ronda:
for exp in experimento:
df = data[(rnd, exp)]
df_f = apply_filter(df, row_start=row_start, row_end=row_end)
m, _ = calcular_pendiente(df_f, x_col, y_col)
if mayor == False:
resultados[rnd] = m
else:
resultados[exp] = m
print("Pendientes:")
cont = 0
result = {}
for r, m in resultados.items():
cont = cont + 1
result[cont] = r
print(f"Ronda {r}: {m:.6f}")
print(result)
print(len(resultados))
cambio = ((resultados[result[2]] - resultados[result[1]]) / resultados[result[1]]) * 100
print(f"% Cambio Resultado 2 respecto Resultado 1: {cambio:.2f}%")
def plot_con_ajuste(data, x_col, y_col, ronda, exp,
row_start=None, row_end= None,
t_min=None, t_max=None):
df = data[(ronda, exp)]
df_f = apply_filter(df, row_start=row_start, row_end=row_end,
t_max=t_max, t_min=t_min)
x = df_f[x_col].values
y = df_f[y_col].values
m, b = np.polyfit(x, y, 1)
plt.figure(figsize=(7,5))
plt.scatter(x, y, label=f"Datos-Experimento {exp}")
plt.plot(x, m*x + b, color="red", label=f"Ajuste lineal (m={m:.4f})")
plt.xlabel(x_col)
plt.ylabel(y_col)
plt.legend()
plt.grid(True)
plt.show()
return m
plot_con_ajuste(data, x_col="Voltaje Electrodos (V)", y_col="Resistencia",
ronda=1, exp=1, row_start=36, row_end=66)
plot_con_ajuste(data, x_col="Voltaje Electrodos (V)", y_col="Corriente Electrodos (A)",
ronda=1, exp=1, row_start=10, row_end=66)
plot_con_ajuste(data, x_col="Voltaje Electrodos (V)", y_col="Corriente Electrodos (A)",
ronda=1, exp=4, row_start=10, row_end=66)
expr = [1,4]
rnd = [1]
comparar_pendientes(data, experimento=expr, ronda=rnd, x_col="Voltaje Electrodos (V)",
y_col="Corriente Electrodos (A)", row_start=10, row_end=66)
In [7]:
df = data[(1,1)]
plot_con_ajuste(df, x_col="Voltaje Electrodos (V)", y_col="Corriente Electrodos (A)")
comparar_rondas()
Out[7]:
In [ ]: