Skip to content

Commit

Permalink
use mean, move _gamma, make sure _gamma is frac not percentage
Browse files Browse the repository at this point in the history
  • Loading branch information
alorenzo175 committed Mar 12, 2021
1 parent 6d7a3c7 commit a8cb3da
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
12 changes: 7 additions & 5 deletions api/solarperformanceinsight_api/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from itertools import zip_longest
import json
import logging
from statistics import mean
from typing import Callable, Generator, Union, List, Tuple, Optional
from uuid import UUID

Expand Down Expand Up @@ -621,7 +622,8 @@ def _calculate_weather_adjusted_predicted_performance(
pac0 = inv.inverter_parameters._pac0
num_arrays = len(chain.system.arrays)
gammas = [
arr._gamma for arr in job.definition.system_definition.inverters[i].arrays
arr.module_parameters._gamma
for arr in job.definition.system_definition.inverters[i].arrays
]
if any([g is None for g in gammas]):
raise TypeError(
Expand Down Expand Up @@ -753,19 +755,19 @@ def compare_monthly_predicted_and_actual(
pac0 = sum([inv.inverter_parameters._pac0 for inv in inverters])
G_0 = 1000

gammas = [arr._gamma for inv in inverters for arr in inv.arrays]
gammas = [arr.module_parameters._gamma for inv in inverters for arr in inv.arrays]
if any([g is None for g in gammas]):
raise TypeError(
"Currently unable to compare predicted and actual performance for "
"PVsyst specified arrays."
)

avg_gamma = sum(
avg_gamma = mean(
[
sum([arr._gamma for arr in inv.arrays]) / len(inv.arrays) # type: ignore
mean([arr.module_parameters._gamma for arr in inv.arrays])
for inv in inverters
]
) / len(inverters)
)
poa_insol_rat = (
actual_weather["total_poa_insolation"] / ref_weather["total_poa_insolation"]
)
Expand Down
16 changes: 11 additions & 5 deletions api/solarperformanceinsight_api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ class PVsystModuleParameters(PVLibBase):
gt=0,
)
_modelchain_dc_model: str = PrivateAttr("pvsyst")
_gamma: Optional[float] = PrivateAttr(None)


class PVWattsModuleParameters(PVLibBase):
Expand All @@ -220,6 +221,11 @@ class PVWattsModuleParameters(PVLibBase):
),
)
_modelchain_dc_model: str = PrivateAttr("pvwatts")
_gamma: float = PrivateAttr()

def __init__(self, **data):
super().__init__(**data)
self._gamma = self.gamma_pdc / 100

def pvlib_dict(self):
"""Convert to a dict pvlib understands for `module_parameters`
Expand Down Expand Up @@ -300,6 +306,11 @@ class CECModuleParameters(PVLibBase):
),
)
_modelchain_dc_model: str = PrivateAttr("cec")
_gamma: float = PrivateAttr()

def __init__(self, **data):
super().__init__(**data)
self._gamma = self.gamma_r / 100

def pvlib_dict(self):
"""Convert to a dict pvlib understands for `module_parameters` by removing
Expand Down Expand Up @@ -382,7 +393,6 @@ class PVArray(SPIBase):
..., description="Number of parallel strings in the array", gt=0
)
_modelchain_models: Tuple[Tuple[str, str], ...] = PrivateAttr()
_gamma: Optional[float] = PrivateAttr(None)

def __init__(self, **data):
super().__init__(**data)
Expand All @@ -393,10 +403,6 @@ def __init__(self, **data):
self.temperature_model_parameters._modelchain_temperature_model,
),
)
if isinstance(self.module_parameters, PVWattsModuleParameters):
self._gamma = self.module_parameters.gamma_pdc
elif isinstance(self.module_parameters, CECModuleParameters):
self._gamma = self.module_parameters.gamma_r


class PVWattsLosses(SPIBase):
Expand Down
8 changes: 4 additions & 4 deletions api/solarperformanceinsight_api/tests/test_compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,9 +832,9 @@ def test_compare_monthly_predicted_and_actual(
assert len(ser) == 5
assert ser.loc["month"] == "July"
assert ser.loc["actual_energy"] == 60000
assert ser.loc["weather_adjusted_energy"] == 56212.5
assert ser.loc["difference"] == 3787.5
assert (ser.loc["ratio"] - 1.0673783) < 1e-7
assert ser.loc["weather_adjusted_energy"] == 56249.625
assert ser.loc["difference"] == 3750.375
assert (ser.loc["ratio"] - 1.0666738) < 1e-10


@pytest.fixture(params=list(models.TemperatureTypeEnum))
Expand Down Expand Up @@ -1091,7 +1091,7 @@ def test_compare_predicted_and_actual(
)
assert ser["weather_adjusted_energy"] > 0
assert "difference" in ser
assert 0.5 < ser["ratio"] < 1.5
assert 0.5 < ser["ratio"] < 1.8


@pytest.mark.parametrize(
Expand Down
6 changes: 3 additions & 3 deletions api/solarperformanceinsight_api/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,12 +711,12 @@ def test_array_gamma(system_def):
)
arrd = deepcopy(system_def.inverters[0].arrays[0].dict())
mod = models.PVArray(**arrd)
assert mod._gamma is None # PVsyst
assert mod.module_parameters._gamma is None # PVsyst

arrd["module_parameters"] = cec
mod = models.PVArray(**arrd)
assert mod._gamma == -0.487
assert mod.module_parameters._gamma == -4.87e-3

arrd["module_parameters"] = {"pdc0": 100, "gamma_pdc": -0.328}
mod = models.PVArray(**arrd)
assert mod._gamma == -0.328
assert mod.module_parameters._gamma == -3.28e-3

0 comments on commit a8cb3da

Please sign in to comment.