Skip to content

Commit c78d2c1

Browse files
committed
add ModelChain temperature comparison example to system-models gallery
1 parent 4c3f770 commit c78d2c1

File tree

1 file changed

+168
-0
lines changed

1 file changed

+168
-0
lines changed
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
"""
2+
Varying Model Components in ModelChain
3+
======================================
4+
5+
This example demonstrates how changing modeling components
6+
within ``pvlib.modelchain.ModelChain`` affects simulation results.
7+
8+
Using the same PV system and weather data, we create two
9+
ModelChain instances that differ only in their temperature
10+
model. By comparing the resulting cell temperature and AC
11+
power output, we can see how changing a single modeling
12+
component affects overall system behavior.
13+
"""
14+
15+
# %%
16+
# Varying ModelChain components
17+
# ------------------------------
18+
#
19+
# Below, we create two ModelChain objects with identical system
20+
# definitions and weather inputs. The only difference between them
21+
# is the selected temperature model. This highlights how individual
22+
# modeling components in ``ModelChain`` can be swapped while keeping
23+
# the overall workflow unchanged.
24+
25+
import pvlib
26+
import pandas as pd
27+
import matplotlib.pyplot as plt
28+
29+
# %%
30+
# Define location
31+
# ---------------
32+
#
33+
# We select Tucson, Arizona, a location frequently used in pvlib
34+
# examples due to its strong solar resource and available TMY data.
35+
latitude = 32.2
36+
longitude = -110.9
37+
location = pvlib.location.Location(latitude, longitude)
38+
39+
# %%
40+
# Create simple synthetic weather data
41+
# -------------------------------------
42+
#
43+
# To keep this example lightweight and fully reproducible,
44+
# we generate a small synthetic weather dataset instead of
45+
# downloading data from an external source.
46+
#
47+
# The weather values are kept constant so that any differences
48+
# in results arise solely from the chosen temperature model.
49+
50+
times = pd.date_range(
51+
"2019-06-01 00:00",
52+
"2019-06-07 23:00",
53+
freq="1h",
54+
tz="Etc/GMT+7",
55+
)
56+
57+
weather_subset = pd.DataFrame({
58+
"ghi": 800,
59+
"dni": 600,
60+
"dhi": 200,
61+
"temp_air": 25,
62+
"wind_speed": 1,
63+
}, index=times)
64+
65+
# %%
66+
# Define a simple PV system
67+
# -------------------------
68+
#
69+
# To keep the focus on the temperature model comparison,
70+
# we define a minimal PV system using the PVWatts DC and AC models.
71+
# These models require only a few high-level parameters.
72+
#
73+
# The module DC rating (pdc0) represents the array capacity at
74+
# reference conditions, and gamma_pdc describes the power
75+
# temperature coefficient.
76+
#
77+
# For the temperature model parameters, we use the sapm values
78+
# for an open-rack, glass-glass module configuration. These
79+
# parameters describe how heat is transferred from the module
80+
# to the surrounding environment.
81+
module_parameters = dict(pdc0=5000, gamma_pdc=-0.003)
82+
inverter_parameters = dict(pdc0=4000)
83+
84+
temperature_model_parameters = (
85+
pvlib.temperature.TEMPERATURE_MODEL_PARAMETERS["sapm"]
86+
["open_rack_glass_glass"]
87+
)
88+
89+
system = pvlib.pvsystem.PVSystem(
90+
surface_tilt=30,
91+
surface_azimuth=180,
92+
module_parameters=module_parameters,
93+
inverter_parameters=inverter_parameters,
94+
temperature_model_parameters=temperature_model_parameters,
95+
)
96+
97+
# %%
98+
# ModelChain using the sapm temperature model
99+
# --------------------------------------------
100+
#
101+
# First, we construct a ModelChain that uses the sapm
102+
# temperature model. All other modeling components remain
103+
# identical between simulations.
104+
#
105+
# This ensures that any differences in the results arise
106+
# solely from the temperature model choice.
107+
mc_sapm = pvlib.modelchain.ModelChain(
108+
system,
109+
location,
110+
dc_model="pvwatts",
111+
ac_model="pvwatts",
112+
temperature_model="sapm",
113+
)
114+
115+
mc_sapm.run_model(weather_subset)
116+
117+
# %%
118+
# ModelChain using the Faiman temperature model
119+
# ----------------------------------------------
120+
#
121+
# Next, we repeat the same simulation but replace the
122+
# temperature model with the Faiman model.
123+
#
124+
# No other system or weather parameters are changed.
125+
# This illustrates how individual components within
126+
# ModelChain can be varied independently.
127+
mc_faiman = pvlib.modelchain.ModelChain(
128+
system,
129+
location,
130+
dc_model="pvwatts",
131+
ac_model="pvwatts",
132+
temperature_model="faiman",
133+
)
134+
135+
mc_faiman.run_model(weather_subset)
136+
137+
# %%
138+
# Compare modeled cell temperature
139+
# ---------------------------------
140+
#
141+
# Since module temperature directly affects DC power
142+
# through the temperature coefficient, differences
143+
# between temperature models can propagate into
144+
# performance results.
145+
fig, ax = plt.subplots(figsize=(10, 4))
146+
mc_sapm.results.cell_temperature.plot(ax=ax, label="SAPM")
147+
mc_faiman.results.cell_temperature.plot(ax=ax, label="Faiman")
148+
149+
ax.set_ylabel("Cell Temperature (°C)")
150+
ax.set_title("Comparison of Temperature Models")
151+
ax.legend()
152+
plt.tight_layout()
153+
154+
# %%
155+
# Compare AC power output
156+
# ------------------------
157+
#
158+
# Finally, we compare the resulting AC power. Even small
159+
# differences in temperature modeling can lead to noticeable
160+
# differences in predicted energy production.
161+
fig, ax = plt.subplots(figsize=(10, 4))
162+
mc_sapm.results.ac.plot(ax=ax, label="SAPM")
163+
mc_faiman.results.ac.plot(ax=ax, label="Faiman")
164+
165+
ax.set_ylabel("AC Power (W)")
166+
ax.set_title("AC Output with Different Temperature Models")
167+
ax.legend()
168+
plt.tight_layout()

0 commit comments

Comments
 (0)