Skip to content

Create inverter.py #886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 36 commits into from
Jul 7, 2020
Merged

Create inverter.py #886

merged 36 commits into from
Jul 7, 2020

Conversation

cwhanse
Copy link
Member

@cwhanse cwhanse commented Feb 11, 2020

  • I am familiar with the contributing guidelines
  • Tests added
  • Updates entries to docs/sphinx/source/api.rst 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 and Milestone are assigned to the Pull Request and linked Issue.

Creates inverter.py

  • pvsystem.snlinverter to inverter.sandia
  • pvsystem.adrinverter to inverter.adr
  • pvsystem.pvwatts_ac to inverter.pvwatts

@cwhanse cwhanse added the api label Feb 11, 2020
@cwhanse cwhanse added this to the 0.8.0 milestone Feb 11, 2020
@adriesse
Copy link
Member

I fully support the new module, but I wonder about the naming. Perhaps 'efficiency' or 'power' should be part of it, since that's what the current functions model? I can imagine inverter-related functions that model other aspects.

@cwhanse cwhanse mentioned this pull request Mar 9, 2020
@cwhanse cwhanse mentioned this pull request Apr 23, 2020
@cwhanse cwhanse changed the title WIP: create inverter.py Create inverter.py Jun 10, 2020
@cwhanse
Copy link
Member Author

cwhanse commented Jun 10, 2020

Ready for review

@@ -447,22 +447,29 @@ def acdc(mc):
mc.ac = mc.dc


# TODO in v0.9: remove 'snlinverter', 'adrinverter', 'pvwatts'
Copy link
Member

Choose a reason for hiding this comment

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

Same here about 'pvwatts' being removed

Copy link
Member Author

Choose a reason for hiding this comment

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

I've edited the TODO comment to drop the 'snlinverter' and 'adrinverter' values for ModelChain.ac_model.

There's a loose thread outside of this PR, in that PVSystem.snlinverter, PVSystem.adrinverter and PVSystem.pvwatts_ac methods aren't renamed. I couldn't come up with a naming scheme for the PVSystem methods that I liked, when the methods wrap functions in a different module. The method name needs to package both the method purpose (inverter model) and the model (snl, adr, pvwatts).

@cwhanse
Copy link
Member Author

cwhanse commented Jun 15, 2020

Test failures are unrelated (NREL server not responding), otherwise I think I've addressed the review comments (thanks @kanderso-nrel )

@cwhanse
Copy link
Member Author

cwhanse commented Jun 25, 2020

@kanderso-nrel can you see if the NSRDB PSM3 data service is offline? Looks that way to me.

Test are passing except get_psm3_key

@kandersolar
Copy link
Member

I'm getting tests passing except for get_psm3_tmy too. On first glance, it seems like a few of the data columns have changed for that TMY dataset, possibly the date labeling too. Not sure what to make of that -- I had the impression that tmy-2017 was static and should never change. I'll open an issue on the NREL github to see if this was an unintentional change.

Copy link
Member

@kandersolar kandersolar left a comment

Choose a reason for hiding this comment

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

A few more comments. I wish github would allow comments on code that wasn't changed in the PR, but absent that here is a list:

  • lines 2444, 2446 in pvsystem.py still reference pvsystem.pvwatts_ac.
  • git grep -n snlinverter shows a handful of docs files still referencing pvsystem.snlinverter. I checked the other two and didn't see any offenders.
docs/sphinx/source/introtutorial.rst:99:        ac = pvlib.pvsystem.snlinverter(dc['v_mp'], dc['p_mp'], inverter)
docs/sphinx/source/introtutorial.rst:245:        ac = localized_system.snlinverter(dc['v_mp'], dc['p_mp'])
docs/tutorials/forecast.ipynb:8162:       "  ac_model: snlinverter\n",
docs/tutorials/forecast_to_power.ipynb:879:    "p_ac = pvsystem.snlinverter(sapm_out.v_mp, sapm_out.p_mp, sapm_inverter)\n",
docs/tutorials/pvsystem.ipynb:576:    "### snlinverter"
docs/tutorials/pvsystem.ipynb:1359:    "pacs = pvsystem.snlinverter(vdcs, pdcs, inverters['ABB__MICRO_0_25_I_OUTD_US_208_208V__CEC_2014_'])\n",
docs/tutorials/tmy_to_power.ipynb:1187:    "p_acs['sapm'] = pvlib.pvsystem.snlinverter(sapm_out.v_mp, sapm_out.p_mp, sapm_inverter)\n",
docs/tutorials/tmy_to_power.ipynb:1188:    "p_acs['sd'] = pvlib.pvsystem.snlinverter(single_diode_out.v_mp, single_diode_out.p_mp, sapm_inverter)\n",

Pnt AC power consumed by inverter at night (night tare) to
maintain circuitry required to sense PV array voltage. [W]

======= ============================================================
Copy link
Member

Choose a reason for hiding this comment

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

Sphinx still doesn't like this. I'm not if all of these steps are necessary, but I got it working locally for me by:

  1. Adding spacing between terms and definitions so that there is no overlap between columns (the ADRCoefficients term sticks out pretty far)
  2. Extending the left ==== strings so that they completely cover the column width
  3. Removing the empty line between Pnt and the trailing line.

Here's the text that works for me (with some text reflows to stay under 80 chars):

    ===============   ========================================================
    Column            Description
    ===============   ========================================================
    Pnom              Nominal DC power, typically the DC power needed to
                      produce maximum AC power output. [W]
    Vnom              Nominal DC input voltage. Typically the level at which
                      the highest efficiency is achieved. [V]
    Vmax              Maximum DC input voltage. [V]
    Vmin              Minimum DC input voltage. [V]
    Vdcmax            . [V]
    MPPTHi            Maximum DC voltage for MPPT range. [V]
    MPPTLow           Minimum DC voltage for MPPT range. [V]
    Pacmax            Maximum AC output power, used to clip the output power
                      if needed. [W]
    ADRCoefficients   A list of 9 coefficients that capture the influence
                      of input voltage and power on inverter losses, and
                      thereby efficiency. Corresponds to terms from [1]_
                      (in order): :math:`b_{0,0}, b_{1,0}, b_{2,0}, b_{0,1},
                      b_{1,1}, b_{2,1}, b_{0,2}, b_{1,2}, b_{1,2}`. See [1]_
                      for the use of each coefficient and the associated unit.
    Pnt               AC power consumed by inverter at night (night tare) to
                      maintain circuitry required to sense PV array voltage.
                      [W]
    ===============   ========================================================

Pnt AC power consumed by inverter at night (night tare) to
maintain circuitry required to sense PV array voltage. [W]

======= ============================================================
Copy link
Member

Choose a reason for hiding this comment

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

Two more notes: Vdcmax is still undefined and b_{1,2} is repeated in ADRCoefficients, presumably should be b_{2,2}?

@cwhanse
Copy link
Member Author

cwhanse commented Jun 26, 2020

git grep -n snlinverter shows a handful of docs files still referencing pvsystem.snlinverter. I checked the other two and didn't see any offenders.

Many thanks for checking this. I've made these corrections where the function is referenced; other instances are references to PVSystem and ModelChain methods that aren't being renamed in this PR.

Copy link
Member

@kandersolar kandersolar left a comment

Choose a reason for hiding this comment

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

Agreed that most of the output of git grep -n snlinverter is from ModelChain or the PVSystem method, but I think this subset is still the pvsystem function:

docs/tutorials/forecast_to_power.ipynb:879:    "p_ac = pvsystem.snlinverter(sapm_out.v_mp, sapm_out.p_mp, sapm_inverter)\n",
docs/tutorials/pvsystem.ipynb:576:    "### snlinverter"
docs/tutorials/pvsystem.ipynb:1359:    "pacs = pvsystem.snlinverter(vdcs, pdcs, inverters['ABB__MICRO_0_25_I_OUTD_US_208_208V__CEC_2014_'])\n",

Otherwise LGTM!

@cwhanse
Copy link
Member Author

cwhanse commented Jun 26, 2020

docs/tutorials/pvsystem.ipynb:576: "### snlinverter"

What does the ### formatting do? I assumed this was just an internal label or link.

@kandersolar
Copy link
Member

docs/tutorials/pvsystem.ipynb:576: "### snlinverter"

What does the ### formatting do? I assumed this was just an internal label or link.

That's inside a markdown cell, just making a small header:

image

It's not code so nbd to leave as-is.

@cwhanse
Copy link
Member Author

cwhanse commented Jul 1, 2020

@wholmgren ok to merge?

Copy link
Member

@wholmgren wholmgren left a comment

Choose a reason for hiding this comment

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

Sorry for the delay @cwhanse. A handful of minor things but looks very close.

Thanks @kanderso-nrel for the detailed review.

- :py:func:`pvlib.pvsystem.snlinverter` is now :py:func:`pvlib.inverter.sandia`
- :py:func:`pvlib.pvsystem.pvwatts_ac` is now :py:func:`pvlib.inverter.pvwatts`
- :py:func:`pvlib.pvsystem.adrinverter` is now :py:func:`pvlib.inverter.adr`
* ModelChain.ac_model now accepts `'sandia'`, `'pvwatts'` and `'adr'` for the
Copy link
Member

Choose a reason for hiding this comment

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

does this line render as you intend it to?

Copy link
Member Author

Choose a reason for hiding this comment

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

'sandia' is intended to display as a string value. Should it be marked differently?

Copy link
Member

Choose a reason for hiding this comment

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

The current rendering is fine with me (shown below), but the meaning of single backticks is context dependent in rst. If you want to keep these in italics, I prefer *'sandia'*. Also fine to format as code (e.g. double backtick 'sandia' double backtick)

Screen Shot 2020-07-06 at 8 07 48 AM

@@ -56,7 +56,7 @@ def basic_chain(times, latitude, longitude,
See temperature.sapm_cell for details.

inverter_parameters : None, dict or Series
Inverter parameters as defined by the CEC. See pvsystem.snlinverter for
Inverter parameters as defined by the CEC. See inverter.sandia for
Copy link
Member

Choose a reason for hiding this comment

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

noting the open comment that may have been buried

'sandia': 'snlinverter',
'adrinverter': 'adrinverter',
'adr': 'adrinverter',
'pvwatts': 'pvwatts_ac'}
system = ac_systems[ac_model]

Copy link
Member

Choose a reason for hiding this comment

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

Ideally we would test that the deprecation warning is raised if the ac method name is snlinverter or adrinverter. Ok with me to skip it though since the code looks correct and is not too complicated.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll add a test for the deprecation warning if ModelChain.ac_model is assigned 'snlinverter' or 'adrinverter'

The ModelChain and PVSystem methods are still snlinverter and adrinverter. Do we want to rename those as well? I favor doing that, but in a separate PR.

Copy link
Member

Choose a reason for hiding this comment

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

I agree we should rename the methods in a separate PR.

Copy link
Member

@wholmgren wholmgren left a comment

Choose a reason for hiding this comment

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

minor doc comments then ready to merge

@@ -3,15 +3,25 @@
v0.8.0 (Month day, year)
-------------------------

API Changes with Deprecations
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Moved functions related to inverters from `pvsystem.py` to `inverter.py`.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Moved functions related to inverters from `pvsystem.py` to `inverter.py`.
* Moved functions related to inverters from ``pvsystem.py`` to ``inverter.py``.

Comment on lines 13 to 14
* Attribute :py:attribute:`modelchain.ModelChain.ac_model` now accepts ``sandia``,
``pvwatts`` and ``adr`` for the inverter models. (:pull:`886`)
Copy link
Member

Choose a reason for hiding this comment

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

I'm guessing the vast majority of people set this through the ac_model kwarg rather than the attribute. So I would link to :py:class:`pvlib.modelchain.ModelChain` instead. Also suggest adding ' within the code blocks.

@@ -23,6 +33,8 @@ Testing
~~~~~~~
* Decorator :py:func:`pvlib.conftest.fail_on_pvlib_version` can now be
applied to functions that require args or kwargs. (:pull:`973`)
* Test added for :py:meth:`ModelChain` to confirm ValueError when
Copy link
Member

Choose a reason for hiding this comment

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

use same link code as commented above

def adr(v_dc, p_dc, inverter, vtol=0.10):
r'''
Converts DC power and voltage to AC power using Anton Driesse's
Grid-Connected PV Inverter efficiency model
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Grid-Connected PV Inverter efficiency model
Grid-Connected PV Inverter efficiency model.

Copy link
Member

Choose a reason for hiding this comment

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

grid-connected inverter?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants