Skip to content

Villalva Algorithm Pull Request - #2878

Open
JFrederico2022 wants to merge 10 commits into
pvlib:mainfrom
JFrederico2022:main
Open

JFrederico2022 wants to merge 10 commits into
pvlib:mainfrom
JFrederico2022:main

Conversation

@JFrederico2022

@JFrederico2022 JFrederico2022 commented Oct 3, 2026 •

Copy link
Copy Markdown
  • Closes #xxxx
  • I am familiar with the contributing guidelines
  • I attest that all AI-generated material has been vetted for accuracy and is in compliance with the pvlib license
  • Tests added
  • Updates entries in docs/sphinx/source/reference for API changes.
  • Adds description and name entries in the appropriate "what's new" file in docs/sphinx/source/whatsnew for all changes. Includes link to the GitHub Issue with :issue:`num` or this Pull Request with :pull:`num`. Includes contributor name and/or GitHub username (link with :ghuser:`user`).
  • New code is fully documented. Includes numpydoc compliant docstrings, examples, and comments where necessary.
  • Pull request is nearly complete and ready for detailed review.
  • Maintainer: Appropriate GitHub Labels (including remote-data) and Milestone are assigned to the Pull Request and linked Issue.

@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown

Hey @JFrederico2022! 🎉

Thanks for opening your first pull request! We appreciate your
contribution. Please ensure you have reviewed and understood the
contributing guidelines.

If AI is used for any portion of this PR, you must vet the content
for technical accuracy.

Finally, be sure the PR description includes the PR
checklist,
and complete the items you are able to.

@cwhanse

cwhanse commented Oct 4, 2026

Copy link
Copy Markdown
Member

@JFrederico2022 pvlib should get only the functions, not the notebook. It has been a while since we discussed that: #2754 (comment) "In pvlib, a calcparams_villalva function would go into pvlib.pvsystem. Code for fitting would go into pvlib.ivtools.sdm in a new module villalva.py"

If you want, you can convert the notebook to a python script and add to the Example Gallery. Just start the script name with "plot_" and use docstrings where you want text to appear.

@JFrederico2022

Copy link
Copy Markdown
Author

Hello, @cwhanse

I updated the docs. Please, let me know if they are all right.

Best regards,
João Frederico

Comment thread pvlib/ivtools/sdm/villalva.py Outdated
Comment thread pvlib/ivtools/sdm/villalva.py Outdated
rows = []
rs_values = np.arange(0.0, rs_max + 0.5 * rs_step, rs_step)

for resistance_series in rs_values:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks to me that the helper function will operate on a vector rs_values. I think this for loop could go away. I'd set the numpy error state is set to ignore division by zero, then filter the output values to exclude NaN and negative parameters before finding the values at minimum power error.

Comment thread pvlib/pvsystem.py

References
----------
.. [1] M. G. Villalva, PhD thesis, Chapter 3 and Appendix A.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a DOI for both of these references?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! Here are the full references alongside their DOIs:

[1] M. G. Villalva, "Three-phase electronic power converter for a grid-connected photovoltaic system," PhD Thesis, Unicamp, 2010. DOI: 10.47749/T/UNICAMP.2010.781324

[2] M. G. Villalva, J. R. Gazoli, and E. Ruppert Filho, "Comprehensive Approach to Modeling and Simulation of Photovoltaic Arrays," IEEE Transactions on Power Electronics, 2009. DOI: 10.1109/TPEL.2009.2013862

JFrederico2022 and others added 3 commits October 6, 2026 21:09
Co-authored-by: Cliff Hansen <cwhanse@sandia.gov>
Co-authored-by: Cliff Hansen <cwhanse@sandia.gov>
@ramaroesilva

Copy link
Copy Markdown
Contributor

Hi @JFrederico2022, great initiative!

In my opinion, I think it would be nice for your PR to have a corresponding issue which includes a description of what you are adding to pvlib (e.g., what do you see is missing that a PR would add and include sources). That way reviewers and curious people can have a quick outlook of what's happening.

@RDaxini

RDaxini commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

Hi @JFrederico2022, great initiative!

In my opinion, I think it would be nice for your PR to have a corresponding issue which includes a description of what you are adding to pvlib (e.g., what do you see is missing that a PR would add and include sources). That way reviewers and curious people can have a quick outlook of what's happening.

The issue exists (#2754) but, @JFrederico2022, please tag this in the PR template

References
----------
.. [1] M. G. Villalva, "Three-phase electronic power converter for a grid-connected photovoltaic system,"
PhD Thesis, Unicamp, 2010. DOI: 10.47749/T/UNICAMP.2010.781324

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
PhD Thesis, Unicamp, 2010. DOI: 10.47749/T/UNICAMP.2010.781324
PhD Thesis, Unicamp, 2010. :doi:`10.47749/T/UNICAMP.2010.781324`

Apply this DOI formatting to calcparams_villalba too.

PhD Thesis, Unicamp, 2010. DOI: 10.47749/T/UNICAMP.2010.781324
.. [2] M. G. Villalva, J. R. Gazoli, and E. Ruppert Filho,
"Comprehensive Approach to Modeling and Simulation of Photovoltaic Arrays,"
IEEE Transactions on Power Electronics, 2009. DOI: 10.1109/TPEL.2009.2013862

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
IEEE Transactions on Power Electronics, 2009. DOI: 10.1109/TPEL.2009.2013862
IEEE Transactions on Power Electronics, 2009. :doi:`10.1109/TPEL.2009.2013862`

Same as above.

@echedey-ls

Copy link
Copy Markdown
Member

Remember to list the new functions in https://github.com/pvlib/pvlib-python/blob/main/docs/sphinx/source/reference/pv_modeling/sdm.rst?plain=1

@cwhanse cwhanse added this to the v0.16.2 milestone Oct 7, 2026

@RDaxini RDaxini left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have suggested a few basic docstring revisions. You can implement changes recommended by reviewers either by committing them individually or, under the Files changed tab, adding the suggestions to a batch and committing them all at once.

Happy to look more in depth at the core implementation in the coming days

Comment on lines +86 to +87
The dimensionless diode ideality factor :math:`n` is supplied by the user. The
modified ideality factor at reference conditions is calculated as

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The dimensionless diode ideality factor :math:`n` is supplied by the user. The
modified ideality factor at reference conditions is calculated as
The dimensionless diode ideality factor :math:`n` is supplied by the user.
The modified ideality factor at reference conditions is calculated as

Comment on lines +79 to +84
Villalva's basic parameter-extraction method increments the series
resistance from zero. For each candidate :math:`R_s`, the corresponding
:math:`R_{sh}`, :math:`I_L`, and :math:`I_0` are calculated and the
maximum power of the resulting single-diode model is evaluated. The
selected solution minimizes the absolute difference between modeled and
reference maximum power.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Villalva's basic parameter-extraction method increments the series
resistance from zero. For each candidate :math:`R_s`, the corresponding
:math:`R_{sh}`, :math:`I_L`, and :math:`I_0` are calculated and the
maximum power of the resulting single-diode model is evaluated. The
selected solution minimizes the absolute difference between modeled and
reference maximum power.
Villalva's parameter-extraction method is described in [1]_ and [2]. This
approach increments the series resistance from zero. For each candidate
:math:`R_s`, the corresponding :math:`R_{sh}`, :math:`I_L`, and :math:`I_0`
are calculated and the maximum power of the resulting single-diode
model is evaluated. The selected solution minimizes the absolute
difference between modeled and reference maximum power.

cells_in_series : int
Effective number of cells or junctions connected in series.
diode_factor : float
Dimensionless diode ideality factor used by the Villalva model.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Dimensionless diode ideality factor used by the Villalva model.
Dimensionless diode ideality factor. [unitless]

temp_ref : float, default 25
Reference cell temperature. [°C]
irrad_ref : float, default 1000
Reference irradiance. [W/m²]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Reference irradiance. [W/m²]
Reference irradiance. [Wm⁻²]

Comment on lines +146 to +153
References
----------
.. [1] M. G. Villalva, "Three-phase electronic power converter for a grid-connected photovoltaic system,"
PhD Thesis, Unicamp, 2010. DOI: 10.47749/T/UNICAMP.2010.781324
.. [2] M. G. Villalva, J. R. Gazoli, and E. Ruppert Filho,
"Comprehensive Approach to Modeling and Simulation of Photovoltaic Arrays,"
IEEE Transactions on Power Electronics, 2009. DOI: 10.1109/TPEL.2009.2013862
"""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@echedey-ls's suggestion to use the :doi sphinx role is correct but these lines are also >79 characters so will fail the flake8 checks. I am unsure why the failure isn't already marked in the diff. The references are also missing some bibliographic information (eg pages/volume), which need to be included in the IEEE format. I recommend the following:

Suggested change
References
----------
.. [1] M. G. Villalva, "Three-phase electronic power converter for a grid-connected photovoltaic system,"
PhD Thesis, Unicamp, 2010. DOI: 10.47749/T/UNICAMP.2010.781324
.. [2] M. G. Villalva, J. R. Gazoli, and E. Ruppert Filho,
"Comprehensive Approach to Modeling and Simulation of Photovoltaic Arrays,"
IEEE Transactions on Power Electronics, 2009. DOI: 10.1109/TPEL.2009.2013862
"""
References
----------
.. [1] M. G. Villalva, "Conversor eletrônico de potência trifásico para
sistema fotovoltaico conectado à rede elétrica," Ph.D. dissertation,
Faculdade de Engenharia Elétrica e de Computação, Universidade Estadual
de Campinas (UNICAMP), Campinas, Brazil, 2010.
:doi:`10.47749/T/UNICAMP.2010.781324`
.. [2] M. G. Villalva, J. R. Gazoli, and E. Ruppert Filho, "Comprehensive
approach to modeling and simulation of photovoltaic arrays," IEEE Trans.
Power Electron., vol. 24, no. 5, pp. 1198-1208, May 2009.
:doi:`10.1109/TPEL.2009.2013862`
"""

Comment thread pvlib/pvsystem.py
Comment on lines 1679 to +1682
return tracking_data

def calcparams_villalva(
effective_irradiance,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two blank lines needed for flake8

Suggested change
return tracking_data
def calcparams_villalva(
effective_irradiance,
return tracking_data
def calcparams_villalva(
effective_irradiance,

Comment thread pvlib/pvsystem.py
Parameters
----------
effective_irradiance : numeric
Effective irradiance converted to photocurrent. [W/m²]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can format like this throughout the docs

Suggested change
Effective irradiance converted to photocurrent. [W/m²]
Effective irradiance converted to photocurrent. [Wm⁻²]

best_idx = history["abs_power_error"].idxmin()
best = history.loc[best_idx]

print(f"Best R_s = {best['R_s']:.6f} ohm")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

false positive flake8 failure, I think. Don't add a space here (or on any of the other instances)

Comment on lines +22 to +26

from pvlib.ivtools.sdm.villalva import ( # noqa: F401
_villalva_params_at_rs,
fit_villalva,
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the flake8 error by adding a space. I don't think we need to list the private helper here either

Suggested change
from pvlib.ivtools.sdm.villalva import ( # noqa: F401
_villalva_params_at_rs,
fit_villalva,
)
from pvlib.ivtools.sdm.villalva import ( # noqa: F401
_villalva_params_at_rs,
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants