Skip to content

Commit

Permalink
Add simple sdm fit to performance matrix to demo
Browse files Browse the repository at this point in the history
  • Loading branch information
markcampanelli committed Jan 15, 2024
1 parent 12b18f2 commit 0ad4f56
Showing 1 changed file with 35 additions and 31 deletions.
66 changes: 35 additions & 31 deletions pvfit/modeling/dc/single_diode/model/demos/getting_started.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Copyright 2023 Intelligent Measurement Systems LLC
"""

import pprint
from pprint import pprint

from matplotlib import pyplot
import numpy
Expand All @@ -13,47 +13,49 @@
import pvfit.modeling.dc.single_diode.equation.simulation as sde_sim
import pvfit.modeling.dc.single_diode.model.demos.data as data
import pvfit.modeling.dc.single_diode.model.simple.auxiliary_equations as ae
from pvfit.modeling.dc.single_diode.model.simple.types import ModelParameters
import pvfit.modeling.dc.single_diode.model.simple.inference_matrix as sdm_simple_inf_matrix
import pvfit.modeling.dc.single_diode.model.simple.types as sdm_simple_types


# By convention, variable names for numeric values include the units.

N_s = data.HIT_MODULE["N_s"]
material = data.HIT_MODULE["material"]
iv_performance_matrix = data.HIT_MODULE["matrix"]
model_parameters_unfittable = sdm_simple_types.ModelParametersUnfittable(
N_s=data.HIT_MODULE["N_s"],
T_degC_0=iv_performance_matrix.T_degC_0,
)
material = data.HIT_MODULE["material"]
ivft_data = iv_performance_matrix.ivft_data

print(f"Performance matrix for HIT module with {N_s} cells in series:")
print(iv_performance_matrix)

print(f"HIT module with {model_parameters_unfittable['N_s']} cells in series:")
print(f"I_sc_A_0_data = {iv_performance_matrix.I_sc_A_0}")
print(f"I_A_data =\n{ivft_data.I_A}")
print(f"V_V_data =\n{ivft_data.V_V}")
print(f"F_data =\n{ivft_data.F}")
print(f"T_degC_data =\n{ivft_data.T_degC}")

# TODO Demonstrate how to fit these parameters to data.
model_parameters_fit = ModelParameters(
N_s=N_s,
T_degC_0=iv_performance_matrix.T_degC_0,
I_sc_A_0=5.531975277850156,
I_rs_A_0=7.739216483430394e-11,
n_0=1.086322575846391,
R_s_Ohm_0=0.5948166451105333,
G_p_S_0=0.00134157981991618,
E_g_eV_0=1.1557066550514934,
# Fit simple SDM to matrix data. Additional outputs can be useful, but ignored here.
# model_parameters has both fittable and unfittable parameters, which can be
# used convienently in downstream functions, e.g., for power simulation.
model_parameters, _, _ = sdm_simple_inf_matrix.fit(
iv_performance_matrix=iv_performance_matrix,
model_parameters_unfittable=model_parameters_unfittable,
material=material,
)

print("model_parameters from fit to performance matrix:")
pprint(model_parameters)

# Compute parameters for I-V curve at STC.
iv_curve_parameters_0 = sde_sim.iv_curve_parameters(
model_parameters=ae.compute_sde_model_parameters(
ft_data=FTData(F=1, T_degC=iv_performance_matrix.T_degC_0),
model_parameters=model_parameters_fit,
ft_data=FTData(F=1.0, T_degC=iv_performance_matrix.T_degC_0),
model_parameters=model_parameters,
)
)

print("I-V curve parameters at STC:")
pprint.pprint(iv_curve_parameters_0)
pprint(iv_curve_parameters_0)

# Save some I-V curve values for later.
I_sc_A_0 = iv_curve_parameters_0["I_sc_A"]
Expand All @@ -64,15 +66,15 @@
# Compute an alternative operating condition.
F_alt = 0.5
T_degC_alt = 35.0
iv_params_alt = sde_sim.iv_curve_parameters(
iv_parameters_alt = sde_sim.iv_curve_parameters(
model_parameters=ae.compute_sde_model_parameters(
ft_data=FTData(F=F_alt, T_degC=T_degC_alt),
model_parameters=model_parameters_fit,
model_parameters=model_parameters,
)
)

print(f"Alternative operating condition: F={F_alt}, T={T_degC_alt} °C")
pprint.pprint(iv_params_alt)
pprint(iv_parameters_alt)

# F and/or T_degC can be vectorized, such as for a time-series of weather data.
F_series = numpy.array([0.95, 0.97, 0.99, 1.01, 0.97, 0.98])
Expand All @@ -81,7 +83,7 @@
P_mp_W_series, _, _, _ = sde_sim.P_mp(
model_parameters=ae.compute_sde_model_parameters(
ft_data=FTData(F=F_series, T_degC=T_degC_series),
model_parameters=model_parameters_fit,
model_parameters=model_parameters,
)
)

Expand All @@ -90,7 +92,9 @@
# Now make a nice plot.
fig, ax = pyplot.subplots(figsize=(8, 6))
# Plot the data fits.
for idx, (F, T_degC) in enumerate(zip(iv_performance_matrix.F, iv_performance_matrix.T_degC)):
for idx, (F, T_degC) in enumerate(
zip(iv_performance_matrix.F, iv_performance_matrix.T_degC)
):
# Plot Isc, Pmp, and Voc with same colors as fit lines.
color = next(ax._get_lines.prop_cycler)["color"]
ax.plot(
Expand All @@ -106,7 +110,7 @@
V_V=V_V,
model_parameters=ae.compute_sde_model_parameters(
ft_data=FTData(F=F, T_degC=T_degC),
model_parameters=model_parameters_fit,
model_parameters=model_parameters,
),
),
label=f"F={F:.2f} suns, T={T_degC:.0f} °C",
Expand All @@ -115,26 +119,26 @@
# Plot the LIC.
color = next(ax._get_lines.prop_cycler)["color"]
ax.plot(
[0.0, iv_params_alt["V_mp_V"], iv_params_alt["V_oc_V"]],
[iv_params_alt["I_sc_A"], iv_params_alt["I_mp_A"], 0.0],
[0.0, iv_parameters_alt["V_mp_V"], iv_parameters_alt["V_oc_V"]],
[iv_parameters_alt["I_sc_A"], iv_parameters_alt["I_mp_A"], 0.0],
"*",
color=color,
)
V_V = numpy.linspace(0, iv_params_alt["V_oc_V"], 101)
V_V = numpy.linspace(0, iv_parameters_alt["V_oc_V"], 101)
ax.plot(
V_V,
sde_sim.I_at_V(
V_V=V_V,
model_parameters=ae.compute_sde_model_parameters(
ft_data=FTData(F=F_alt, T_degC=T_degC_alt),
model_parameters=model_parameters_fit,
model_parameters=model_parameters,
),
),
"--",
label=f"F={F_alt:.2f} suns, T={T_degC_alt:.0f} °C",
color=color,
)
ax.set_title("6-Parameter SDM Fit to IEC 61853-1 Data", fontdict={"fontsize": 14})
ax.set_title("6-Parameter SDM Fit to Performance Matrix", fontdict={"fontsize": 14})
ax.set_xlabel("V (V)")
ax.set_ylabel("I (A)")
fig.legend(loc="center")
Expand Down

0 comments on commit 0ad4f56

Please sign in to comment.