From bc04953bacad98358acedbae5160b57a7f4c3436 Mon Sep 17 00:00:00 2001 From: Kevin Anderson Date: Tue, 28 Jan 2020 19:38:56 -0700 Subject: [PATCH 1/8] Create plot_singlediode.py --- docs/examples/plot_singlediode.py | 140 ++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 docs/examples/plot_singlediode.py diff --git a/docs/examples/plot_singlediode.py b/docs/examples/plot_singlediode.py new file mode 100644 index 0000000000..e93a70237a --- /dev/null +++ b/docs/examples/plot_singlediode.py @@ -0,0 +1,140 @@ +""" +Single-diode equation +===================== + +Examples of modeling IV curves using a single-diode circuit equivalent model. +""" + +#%% +# Calculating a module IV curve for certain operating conditions is a two-step +# process. Multiple methods exist for both parts of the process. Here we use +# the De Soto 5-parameter model to calculate the electrical characteristics +# of a PV module at a certain irradiance and temperature using the module's +# base characteristics at reference conditions. Those parameters are then used +# to calculate the module's IV curve by solving the single-diode equation using +# the Lambert W method. +# +# The single-diode equation is a circuit-equivalent model of a PV +# cell and has five electrical parameters that depend on the operating +# conditions. For more details on the single-diode equation and the five +# parameters, see the `PVPMC single diode page +# `_. +# +# Calculating IV Curves +# ----------------------- +# This example uses :py:meth:`pvlib.pvsystem.calcparams_desoto` to calculate +# the 5 electrical parameters needed to solve the single-diode equation. +# :py:meth:`pvlib.pvsystem.singlediode` is then used to generate the IV curves. + +from pvlib import pvsystem +import pandas as pd +import matplotlib.pyplot as plt + +# Example module parameters for the Canadian Solar CS5P-220M: +parameters = { + 'Name': 'Canadian Solar CS5P-220M', + 'BIPV': 'N', + 'Date': '10/5/2009', + 'T_NOCT': 42.4, + 'A_c': 1.7, + 'N_s': 96, + 'I_sc_ref': 5.1, + 'V_oc_ref': 59.4, + 'I_mp_ref': 4.69, + 'V_mp_ref': 46.9, + 'alpha_sc': 0.004539, + 'beta_oc': -0.22216, + 'a_ref': 2.6373, + 'I_L_ref': 5.114, + 'I_o_ref': 8.196e-10, + 'R_s': 1.065, + 'R_sh_ref': 381.68, + 'Adjust': 8.7, + 'gamma_r': -0.476, + 'Version': 'MM106', + 'PTC': 200.1, + 'Technology': 'Mono-c-Si', +} + +base_case = {'Geff': 400, 'Tcell': 80} + +cases = [base_case] +for i in range(1, 3): + case = {'Geff': base_case['Geff'], 'Tcell': base_case['Tcell'] - i * 25} + cases.append(case) + +for i in range(1, 4): + case = {'Geff': base_case['Geff'] + i * 200, 'Tcell': base_case['Tcell']} + cases.append(case) + +conditions = pd.DataFrame(cases) + +# adjust the reference parameters according to the operating +# conditions using the De Soto model: +IL, I0, Rs, Rsh, nNsVth = pvsystem.calcparams_desoto( + conditions['Geff'], + conditions['Tcell'], + alpha_sc=parameters['alpha_sc'], + a_ref=parameters['a_ref'], + I_L_ref=parameters['I_L_ref'], + I_o_ref=parameters['I_o_ref'], + R_sh_ref=parameters['R_sh_ref'], + R_s=parameters['R_s'], + EgRef=1.121, + dEgdT=-0.0002677 +) + +# plug the parameters into the SDE and solve for IV curves: +curve_info = pvsystem.singlediode( + photocurrent=IL, + saturation_current=I0, + resistance_series=Rs, + resistance_shunt=Rsh, + nNsVth=nNsVth, + ivcurve_pnts=100, + method='lambertw' +) + +# plot the calculated curves: +plt.figure() +for i, case in enumerate(cases): + label = ( + "$G_{eff}$ " + f"{case['Geff']} $W/m^2$\n" + "$T_{cell}$ " + f"{case['Tcell']} $C$" + ) + plt.plot(curve_info['v'][i], curve_info['i'][i], label=label) + v_mp = curve_info['v_mp'][i] + i_mp = curve_info['i_mp'][i] + # mark the MPP + plt.plot([v_mp], [i_mp], ls='', marker='o', c='k') + +plt.legend(loc=(1.0, 0)) +plt.xlabel('Module voltage [V]') +plt.ylabel('Module current [A]') +plt.title(parameters['Name']) +plt.show() +plt.gcf().set_tight_layout(True) + + +# draw trend arrows +def draw_arrow(ax, label, x0, y0, rotation, size, direction): + style = direction + 'arrow' + bbox_props = dict(boxstyle=style, fc=(0.8, 0.9, 0.9), ec="b", lw=1) + t = ax.text(x0, y0, label, ha="left", va="bottom", rotation=rotation, + size=size, bbox=bbox_props, zorder=-1) + + bb = t.get_bbox_patch() + bb.set_boxstyle(style, pad=0.6) + + +ax = plt.gca() +draw_arrow(ax, 'Irradiance', 20, 2.5, 90, 15, 'r') +draw_arrow(ax, 'Temperature', 35, 1, 0, 15, 'l') + +print(pd.DataFrame({ + 'i_sc': curve_info['i_sc'], + 'v_oc': curve_info['v_oc'], + 'i_mp': curve_info['i_mp'], + 'v_mp': curve_info['v_mp'], + 'p_mp': curve_info['p_mp'], +})) From e0870466a9c98854a36a6e7b958208d6399fba2f Mon Sep 17 00:00:00 2001 From: Kevin Anderson <57452607+kanderso-nrel@users.noreply.github.com> Date: Wed, 29 Jan 2020 18:47:44 -0700 Subject: [PATCH 2/8] Apply suggestions from code review Co-Authored-By: Cliff Hansen --- docs/examples/plot_singlediode.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/examples/plot_singlediode.py b/docs/examples/plot_singlediode.py index e93a70237a..cef292c20e 100644 --- a/docs/examples/plot_singlediode.py +++ b/docs/examples/plot_singlediode.py @@ -1,5 +1,5 @@ """ -Single-diode equation +Calculating a module's IV curves ===================== Examples of modeling IV curves using a single-diode circuit equivalent model. @@ -8,7 +8,7 @@ #%% # Calculating a module IV curve for certain operating conditions is a two-step # process. Multiple methods exist for both parts of the process. Here we use -# the De Soto 5-parameter model to calculate the electrical characteristics +# the De Soto model [DeSoto]_ to calculate the electrical parameters for an IV curve at a certain irradiance``` # of a PV module at a certain irradiance and temperature using the module's # base characteristics at reference conditions. Those parameters are then used # to calculate the module's IV curve by solving the single-diode equation using @@ -19,7 +19,12 @@ # conditions. For more details on the single-diode equation and the five # parameters, see the `PVPMC single diode page # `_. -# + References + ---------- +# .. [1] W. De Soto et al., "Improvement and validation of a model for + photovoltaic array performance", Solar Energy, vol 80, pp. 78-88, + 2006. + # Calculating IV Curves # ----------------------- # This example uses :py:meth:`pvlib.pvsystem.calcparams_desoto` to calculate From b85ca7a26b7cb5800b6eaf9a243969891374ec9e Mon Sep 17 00:00:00 2001 From: Kevin Anderson Date: Wed, 29 Jan 2020 18:56:13 -0700 Subject: [PATCH 3/8] RST cleanup, reorder legend entries --- docs/examples/plot_singlediode.py | 37 +++++++++++++++---------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/docs/examples/plot_singlediode.py b/docs/examples/plot_singlediode.py index cef292c20e..0d38c39a15 100644 --- a/docs/examples/plot_singlediode.py +++ b/docs/examples/plot_singlediode.py @@ -8,8 +8,8 @@ #%% # Calculating a module IV curve for certain operating conditions is a two-step # process. Multiple methods exist for both parts of the process. Here we use -# the De Soto model [DeSoto]_ to calculate the electrical parameters for an IV curve at a certain irradiance``` -# of a PV module at a certain irradiance and temperature using the module's +# the De Soto model [DeSoto]_ to calculate the electrical parameters for an IV +# curve at a certain irradiance and temperature using the module's # base characteristics at reference conditions. Those parameters are then used # to calculate the module's IV curve by solving the single-diode equation using # the Lambert W method. @@ -19,11 +19,12 @@ # conditions. For more details on the single-diode equation and the five # parameters, see the `PVPMC single diode page # `_. - References - ---------- -# .. [1] W. De Soto et al., "Improvement and validation of a model for - photovoltaic array performance", Solar Energy, vol 80, pp. 78-88, - 2006. +# +# References +# ---------- +# .. [1] W. De Soto et al., "Improvement and validation of a model for +# photovoltaic array performance", Solar Energy, vol 80, pp. 78-88, +# 2006. # Calculating IV Curves # ----------------------- @@ -61,18 +62,16 @@ 'Technology': 'Mono-c-Si', } -base_case = {'Geff': 400, 'Tcell': 80} - -cases = [base_case] -for i in range(1, 3): - case = {'Geff': base_case['Geff'], 'Tcell': base_case['Tcell'] - i * 25} - cases.append(case) - -for i in range(1, 4): - case = {'Geff': base_case['Geff'] + i * 200, 'Tcell': base_case['Tcell']} - cases.append(case) +cases = [ + (1000, 55), + (800, 55), + (600, 55), + (400, 25), + (400, 40), + (400, 55) +] -conditions = pd.DataFrame(cases) +conditions = pd.DataFrame(cases, columns=['Geff', 'Tcell']) # adjust the reference parameters according to the operating # conditions using the De Soto model: @@ -102,7 +101,7 @@ # plot the calculated curves: plt.figure() -for i, case in enumerate(cases): +for i, case in conditions.iterrows(): label = ( "$G_{eff}$ " + f"{case['Geff']} $W/m^2$\n" "$T_{cell}$ " + f"{case['Tcell']} $C$" From ac870662b4435b6fda839939269f5a95f092b013 Mon Sep 17 00:00:00 2001 From: Kevin Anderson Date: Wed, 29 Jan 2020 19:10:49 -0700 Subject: [PATCH 4/8] Formatting fixes --- docs/examples/plot_singlediode.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/examples/plot_singlediode.py b/docs/examples/plot_singlediode.py index 0d38c39a15..e9cade85d9 100644 --- a/docs/examples/plot_singlediode.py +++ b/docs/examples/plot_singlediode.py @@ -8,7 +8,7 @@ #%% # Calculating a module IV curve for certain operating conditions is a two-step # process. Multiple methods exist for both parts of the process. Here we use -# the De Soto model [DeSoto]_ to calculate the electrical parameters for an IV +# the De Soto model [1]_ to calculate the electrical parameters for an IV # curve at a certain irradiance and temperature using the module's # base characteristics at reference conditions. Those parameters are then used # to calculate the module's IV curve by solving the single-diode equation using @@ -23,8 +23,7 @@ # References # ---------- # .. [1] W. De Soto et al., "Improvement and validation of a model for -# photovoltaic array performance", Solar Energy, vol 80, pp. 78-88, -# 2006. +# photovoltaic array performance", Solar Energy, vol 80, pp. 78-88, 2006. # Calculating IV Curves # ----------------------- From b3f7b9ba4ddd68a4fb18622ec9ca1e89ab531463 Mon Sep 17 00:00:00 2001 From: Kevin Anderson Date: Thu, 30 Jan 2020 20:38:34 -0700 Subject: [PATCH 5/8] whatsnew --- docs/sphinx/source/whatsnew/v0.7.2.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/sphinx/source/whatsnew/v0.7.2.rst b/docs/sphinx/source/whatsnew/v0.7.2.rst index abd4771101..5f4a90d545 100644 --- a/docs/sphinx/source/whatsnew/v0.7.2.rst +++ b/docs/sphinx/source/whatsnew/v0.7.2.rst @@ -17,6 +17,7 @@ Bug fixes Documentation ~~~~~~~~~~~~~ * Add NumFOCUS affiliation to Sphinx documentation :pull:`862` +* Add example of IV curve generation :pull:`872` Contributors ~~~~~~~~~~~~ From 81e8d60381883c26a59e6bf54f1a67674f479f31 Mon Sep 17 00:00:00 2001 From: Kevin Anderson Date: Thu, 30 Jan 2020 20:40:11 -0700 Subject: [PATCH 6/8] whatsnewer --- docs/sphinx/source/whatsnew/v0.7.2.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/sphinx/source/whatsnew/v0.7.2.rst b/docs/sphinx/source/whatsnew/v0.7.2.rst index 5f4a90d545..323b6f04b4 100644 --- a/docs/sphinx/source/whatsnew/v0.7.2.rst +++ b/docs/sphinx/source/whatsnew/v0.7.2.rst @@ -22,3 +22,4 @@ Documentation Contributors ~~~~~~~~~~~~ * Mark Mikofski (:ghuser:`mikofski`) +* Kevin Anderson (:ghuser:`kanderso-nrel`) From 80d9a6481e42667ce71528e5037a2ad0a54655c7 Mon Sep 17 00:00:00 2001 From: Kevin Anderson Date: Fri, 31 Jan 2020 13:38:57 -0700 Subject: [PATCH 7/8] sorry, one formatting fix --- docs/examples/plot_singlediode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/examples/plot_singlediode.py b/docs/examples/plot_singlediode.py index e9cade85d9..a5ee60e024 100644 --- a/docs/examples/plot_singlediode.py +++ b/docs/examples/plot_singlediode.py @@ -24,7 +24,7 @@ # ---------- # .. [1] W. De Soto et al., "Improvement and validation of a model for # photovoltaic array performance", Solar Energy, vol 80, pp. 78-88, 2006. - +# # Calculating IV Curves # ----------------------- # This example uses :py:meth:`pvlib.pvsystem.calcparams_desoto` to calculate From 9b131ec3d5ed1f9b132d7eaa00abe53d3e7ec621 Mon Sep 17 00:00:00 2001 From: Kevin Anderson Date: Wed, 12 Feb 2020 21:23:23 -0700 Subject: [PATCH 8/8] stickler --- docs/examples/plot_singlediode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/examples/plot_singlediode.py b/docs/examples/plot_singlediode.py index a5ee60e024..0bf78a9cf6 100644 --- a/docs/examples/plot_singlediode.py +++ b/docs/examples/plot_singlediode.py @@ -5,7 +5,7 @@ Examples of modeling IV curves using a single-diode circuit equivalent model. """ -#%% +# %% # Calculating a module IV curve for certain operating conditions is a two-step # process. Multiple methods exist for both parts of the process. Here we use # the De Soto model [1]_ to calculate the electrical parameters for an IV