Skip to content

Commit 35ebf7b

Browse files
author
Jan Pecinovsky
committed
Implement code changes to enhance functionality and improve performance
1 parent 489dac2 commit 35ebf7b

2 files changed

Lines changed: 139 additions & 1316 deletions

File tree

openenergyid/pvsim/pvlib/main.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
"""
2+
PVLib-based simulator implementation.
3+
4+
Defines a PVSimulator subclass that uses PVLib's ModelChain and weather data
5+
to simulate PV system performance.
6+
"""
7+
18
import pandas as pd
29
import pvlib
310

@@ -7,13 +14,33 @@
714

815

916
class PVLibSimulator(PVSimulator):
17+
"""
18+
Simulator for PV systems using PVLib's ModelChain and weather data.
19+
"""
20+
1021
def __init__(self, modelchain: pvlib.modelchain.ModelChain, weather: pd.DataFrame):
22+
"""
23+
Initialize the simulator with a ModelChain and weather DataFrame.
24+
25+
Args:
26+
modelchain: An instance of pvlib.modelchain.ModelChain.
27+
weather: Weather data as a pandas DataFrame.
28+
"""
1129
super().__init__()
1230

1331
self.modelchain = modelchain
1432
self.weather = weather
1533

1634
def simulate(self, **kwargs) -> pd.Series:
35+
"""
36+
Run the simulation and return the resulting AC energy series.
37+
38+
Returns:
39+
pd.Series: Simulated AC energy in kWh for each timestep.
40+
41+
Raises:
42+
ValueError: If the AC power result is None.
43+
"""
1744
# Run model
1845
self.modelchain.run_model(self.weather)
1946

@@ -26,10 +53,21 @@ def simulate(self, **kwargs) -> pd.Series:
2653
# Convert W to kWh
2754
energy = ac * 0.25 / 1000
2855

56+
energy.name = None
57+
2958
return energy
3059

3160
@classmethod
3261
def from_pydantic(cls, modelchain: PVLibModelChain) -> "PVLibSimulator":
62+
"""
63+
Create a PVLibSimulator instance from a PVLibModelChain model.
64+
65+
Args:
66+
modelchain: A PVLibModelChain instance.
67+
68+
Returns:
69+
PVLibSimulator: An initialized simulator.
70+
"""
3371
mc = modelchain.create_modelchain()
3472
weather = modelchain.get_weather()
3573

0 commit comments

Comments
 (0)