Skip to content

Commit

Permalink
Matching Python types for return values of pvsystem.calcparams_* (#…
Browse files Browse the repository at this point in the history
…1700)

* two decorators for renaming pd.Series in a function

* calcparams_* Rs return value to match temp_cell type

* adding tests for pd.Series naming and resistance_series type conversion

* methods for converting between numeric-type values

* adding more tests and clarifying documentation

* rename pdSeries clear name decorator and move it to pvlib.tools

* adding support for scalar to np.ndarray of any shape

* updating match_shape docstring

* fixing syntax error

* fix stickler issues

* different approach

* remove unnecessary asserts

* remove file

* update whatsnew

* add tests for all scalar inputs, and pass np.arrays to assert_allclose

* Update docs/sphinx/source/whatsnew/v0.10.0.rst

Co-authored-by: Cliff Hansen <cwhanse@sandia.gov>

* if condition swap, tests for tools.get_pandas_index, tests for returned Python type

* fix typo in docstring

* correct calcparams_cec test, and add test for calcparams_pvsyst all scalars

---------

Co-authored-by: Cliff Hansen <cwhanse@sandia.gov>
  • Loading branch information
reepoi and cwhanse committed Jun 23, 2023
1 parent 19467f3 commit 0bc5a53
Show file tree
Hide file tree
Showing 5 changed files with 343 additions and 64 deletions.
5 changes: 5 additions & 0 deletions docs/sphinx/source/whatsnew/v0.10.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ Deprecations

Enhancements
~~~~~~~~~~~~
* The return values of :py:func:`pvlib.pvsystem.calcparams_desoto`,
:py:func:`pvlib.pvsystem.calcparams_cec`, and
:py:func:`pvlib.pvsystem.calcparams_pvsyst` are all numeric types and have
the same Python type as the `effective_irradiance` and `temp_cell` parameters. (:issue:`1626`, :pull:`1700`)

* Added `map_variables` parameter to :py:func:`pvlib.iotools.read_srml`
and :py:func:`pvlib.iotools.read_srml_month_from_solardat` (:pull:`1773`)
* Allow passing keyword arguments to :py:func:`scipy:scipy.optimize.brentq` and
Expand Down
34 changes: 29 additions & 5 deletions pvlib/pvsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from pvlib import (atmosphere, iam, inverter, irradiance,
singlediode as _singlediode, spectrum, temperature)
from pvlib.tools import _build_kwargs, _build_args
import pvlib.tools as tools


# a dict of required parameter names for each DC power model
Expand Down Expand Up @@ -1540,7 +1541,7 @@ def calcparams_desoto(effective_irradiance, temp_cell,
saturation_current : numeric
Diode saturation curent in amperes
resistance_series : float
resistance_series : numeric
Series resistance in ohms
resistance_shunt : numeric
Expand Down Expand Up @@ -1663,9 +1664,21 @@ def calcparams_desoto(effective_irradiance, temp_cell,
# use errstate to silence divide by warning
with np.errstate(divide='ignore'):
Rsh = R_sh_ref * (irrad_ref / effective_irradiance)

Rs = R_s

return IL, I0, Rs, Rsh, nNsVth
numeric_args = (effective_irradiance, temp_cell)
out = (IL, I0, Rs, Rsh, nNsVth)

if all(map(np.isscalar, numeric_args)):
return out

index = tools.get_pandas_index(*numeric_args)

if index is None:
return np.broadcast_arrays(*out)

return tuple(pd.Series(a, index=index).rename(None) for a in out)


def calcparams_cec(effective_irradiance, temp_cell,
Expand Down Expand Up @@ -1744,7 +1757,7 @@ def calcparams_cec(effective_irradiance, temp_cell,
saturation_current : numeric
Diode saturation curent in amperes
resistance_series : float
resistance_series : numeric
Series resistance in ohms
resistance_shunt : numeric
Expand Down Expand Up @@ -1861,7 +1874,7 @@ def calcparams_pvsyst(effective_irradiance, temp_cell,
saturation_current : numeric
Diode saturation current in amperes
resistance_series : float
resistance_series : numeric
Series resistance in ohms
resistance_shunt : numeric
Expand Down Expand Up @@ -1920,7 +1933,18 @@ def calcparams_pvsyst(effective_irradiance, temp_cell,

Rs = R_s

return IL, I0, Rs, Rsh, nNsVth
numeric_args = (effective_irradiance, temp_cell)
out = (IL, I0, Rs, Rsh, nNsVth)

if all(map(np.isscalar, numeric_args)):
return out

index = tools.get_pandas_index(*numeric_args)

if index is None:
return np.broadcast_arrays(*out)

return tuple(pd.Series(a, index=index).rename(None) for a in out)


def retrieve_sam(name=None, path=None):
Expand Down

0 comments on commit 0bc5a53

Please sign in to comment.