Skip to content

Commit 407798c

Browse files
change gamma_pdc to units of %/C (#125)
* change gamma_pdc to units of %/C closes #106 * Update api/solarperformanceinsight_api/models.py Co-authored-by: Will Holmgren <[email protected]> * line lenght Co-authored-by: Will Holmgren <[email protected]>
1 parent a9ca93c commit 407798c

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

api/solarperformanceinsight_api/models.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@ def UserString(default: Any = Undefined, *, title: str = None, description: str
9090
)
9191

9292

93+
class PVLibBase(BaseModel):
94+
"""Provide a `pvlib_dict` method to convert parameters if needed
95+
for using in pvlib. Child classes may implement model-specific conversions
96+
as needed."""
97+
98+
def pvlib_dict(self):
99+
return self.dict()
100+
101+
93102
class FixedTracking(BaseModel):
94103
"""Parameters for a fixed tilt array"""
95104

@@ -135,7 +144,7 @@ class SingleAxisTracking(BaseModel):
135144
)
136145

137146

138-
class PVsystModuleParameters(BaseModel):
147+
class PVsystModuleParameters(PVLibBase):
139148
"""Parameters for the modules that make up an array in a PVsyst-like model"""
140149

141150
alpha_sc: float = Field(
@@ -191,7 +200,7 @@ class PVsystModuleParameters(BaseModel):
191200
_modelchain_dc_model: str = PrivateAttr("pvsyst")
192201

193202

194-
class PVWattsModuleParameters(BaseModel):
203+
class PVWattsModuleParameters(PVLibBase):
195204
"""Parameters for the modules that make up an array in a PVWatts-like model"""
196205

197206
pdc0: float = Field(
@@ -201,12 +210,17 @@ class PVWattsModuleParameters(BaseModel):
201210
gamma_pdc: float = Field(
202211
...,
203212
description=(
204-
"Temperature coefficient of power in units of 1/C. "
205-
"Typically -0.002 to -0.005 per degree C"
213+
"Temperature coefficient of power in units of %/C. "
214+
"Typically -0.2 to -0.5 % per degree C"
206215
),
207216
)
208217
_modelchain_dc_model: str = PrivateAttr("pvwatts")
209218

219+
def pvlib_dict(self):
220+
"""Convert to a dict pvlib understands for `module_parameters`
221+
i.e. scale gamma_pdc to 1/C"""
222+
return {k: v / 100 if k == "gamma_pdc" else v for k, v in self.dict().items()}
223+
210224

211225
class PVsystTemperatureParameters(BaseModel):
212226
"""Parameters for the cell temperature model of the modules in a

api/solarperformanceinsight_api/pvmodeling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def construct_pvsystem(inverter: models.Inverter) -> Union[PVSystem, SingleAxisT
4141
dict(
4242
albedo=array.albedo,
4343
module=array.make_model,
44-
module_parameters=array.module_parameters.dict(),
44+
module_parameters=array.module_parameters.pvlib_dict(),
4545
temperature_model_parameters=array.temperature_model_parameters.dict(),
4646
modules_per_string=array.modules_per_string,
4747
strings=array.strings,

api/solarperformanceinsight_api/tests/test_models.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,3 +429,9 @@ def test_inverter_multiple_arrays(system_def):
429429
arrays=[track0],
430430
inverter_parameters=system_def.inverters[0].inverter_parameters,
431431
)
432+
433+
434+
def test_pvwatts_module_temp_scaling():
435+
mod = models.PVWattsModuleParameters(pdc0=100, gamma_pdc=-0.2)
436+
assert mod.dict() == {"pdc0": 100, "gamma_pdc": -0.2}
437+
assert mod.pvlib_dict() == {"pdc0": 100, "gamma_pdc": -0.002}

dashboard/tests/unit/openapi.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)