Skip to content

Single diode model helper function to wrap Lambert w and other methods #410

Closed

Description

@mikofski

I propose the following:

Activity

  1. markcampanelli commented on Jan 29, 2018

    @markcampanelli
    Contributor

    It appears that singlediode() does not expose a way to compute i-from-v at an arbitrary array of v. One would use i_from_v() for that. Also, singlediode() makes a choice for i_from_v(), v_from_i(), and the maximum power computation.

    Also, I have vectorized max power and fill factor functions that I think can be very useful for plotting max power and ff as a function of temperature and/or photocurrent, for example.

    I think this will first and foremost require some careful thinking about what the current API definition is and what we want it to be going forward with alternative implementations.

  2. cwhanse commented on Jan 29, 2018

    @cwhanse
    Member
  3. wholmgren commented on Jan 30, 2018

    @wholmgren
    Member

    Makes sense to me. We can do this without any breaking API changes, right?

  4. added this to the 0.6.0 milestone on Jan 30, 2018
  5. mikofski commented on Jan 30, 2018

    @mikofski
    MemberAuthor

    Yes, that's my view - the api will remain the same. Is it okay to make bishop88 and it's related i_from_v, v_from_i, etc. methods the defaults?

  6. wholmgren commented on Jan 30, 2018

    @wholmgren
    Member

    I need to review the paper and probably see a clean PR before I can recommend a default.

  7. markcampanelli commented on Jan 31, 2018

    @markcampanelli
    Contributor

    I'd really like to know where pandas support starts and ends in the API. I was told earlier that I didn't need to match output to pandas input in i_from_v() and v_from_i(). I realize folks love pandas, but it's hard enough just wrangling numpy types into some sort of consistency (esp. python scalar vs. numpy scalar vs. dim-0 array vs. dimensioned array)!

  8. wholmgren commented on Jan 31, 2018

    @wholmgren
    Member

    The rule of thumb is pandas in, pandas out. Beyond that, I'd just say don't remove pandas consistency from functions that do already support it. *_from_* does not, singlediode does.

    I'm guessing that most users would consider pandas consistency to be more important than numpy type consistency.

  9. markcampanelli commented on Jan 31, 2018

    @markcampanelli
    Contributor

    Thanks. I think the i_from_v() and v_from_i() docstrings indicate that pandas.Series are ok inputs, but won't be the output. I propose removing that promise on the inputs and leave it to higher level functions.

  10. wholmgren commented on Jan 31, 2018

    @wholmgren
    Member

    In general, it's ok with me to remove it as a promise on the inputs of a function if it's not also a promise on the outputs. In most cases I think it's much better to have a feature that only supports numpy than a feature that doesn't exist.

  11. markcampanelli commented on Jan 31, 2018

    @markcampanelli
    Contributor

    @mikofski Note the above pandas support discussion for #409.

  12. markcampanelli commented on Jan 31, 2018

    @markcampanelli
    Contributor

    @wholmgren Is numba used in pvlib-python yet? If not, then are there remaining blockers to using it?

  13. wholmgren commented on Jan 31, 2018

    @wholmgren
    Member

    @thunderfish24 yes, numba can be used in solar position calculations. See spa.py and get_solarposition(method='nrel_numba').

  14. 10 remaining items

  15. mikofski commented on Feb 1, 2018

    @mikofski
    MemberAuthor

    ✔️ the Ix and Ixx values are returned using any method: ('lambertw', 'fast', default: 'gold')

    Exact expressions for gradients from bishop88(gradients=True)

    ✔️ both dynamic resistances: dI/dV @ (V, I) = (0, Isc), and dI/dV @ (V, I) = (Voc, 0) can both be evaluated using exact expressions from pvsystem.bishop88(gradients=True):

    >>> from pvlib import pvsystem
    >>> IL, I0, Rs, Rsh, nNsVth = (7, 6e-7, .1, 20, .5)
    >>> out = singlediode(IL, I0, Rs, Rsh, nNsVth)
    >>> vd_sc = out['i_sc']*Rs  # diode voltage at short circuit
    >>> short_circuit = bishop88(vd_sc, IL, I0, Rs, Rsh, nNsVth, gradients=True)
    >>> short_circuit
    (6.965172322158323,        # i_sc,       idx=0
     -9.9920072216264089e-16,  # v_sc,       idx=1
     -6.9596052142878349e-15,  # p_sc,       idx=2
     -0.05000483246177085,     # di/dvd,     idx=3
     1.0050004832461772,       # dv/dvd,     idx=4
     -0.049756028275980489,    # di/dv,      idx=5
     6.965172322158323,        # dp/dv,      idx=6
     -0.1000096649235417)      # d2p/dv/dvd, idx=7
    >>> grad_sc = short_circuit[5]
    >>> -1 / grad_sc
    20.098067202095102  # super close to Rsh = 20.
    

    etc.

    The important thing to note is that Bishop expected the diode voltage, vd, not the cell voltage, that's how it's explicit, but it's easy to convert between them, and I suppose we could make a conversion method if required:

    def diode_voltage(i, v, rs):
        """calculate diode voltage"""
        return v + i * rs
    
    def v_from_vd(vd, i, rs):
        """calculate cell voltage from diode voltage"""
        return vd - i * rs
    
  16. markcampanelli commented on Feb 1, 2018

    @markcampanelli
    Contributor

    So #412 offers alternatives to working with vd. There is some groundwork to do before I would try to add them to pvlib (i.e., #411), but if they test and benchmark well, I will offer them up. Note that the idea in #412 for (1) brentq is to upper bound the 1st quadrant I-V curve with the corresponding ideal-device curve, and (2) newton/halley is to use a partially ideal device as the initial condition (all quadrants). I suspect that (2) may not converge globally, esp. for really poor quality devices. I'd also like to try out numba on both of these methods.

    nit: I prefer p_mp and p_mp() for maximum power variable and function-that-computes maximum power names, respectively. Jibes better with i_sc and v_oc in my own mind.

  17. mikofski commented on Feb 1, 2018

    @mikofski
    MemberAuthor

    nit: I prefer p_mp and p_mp() for maximum power variable and function-that-computes maximum power names, respectively. Jibes better with i_sc and v_oc in my own mind.

    Are you referring to mpp()? The output is already p_mp as you suggest. Personally, I don't think that the function that calculates an output and the output itself should have the same name, unless it's a property, but that's just my opinion. So I'm okay with it as it is. Is that okay with you?

    I am starting to feel for sanity sake that we should probably start to think of a class to hold all of these single diode model methods and attributes, but let's save that for another day.

  18. cwhanse commented on Feb 1, 2018

    @cwhanse
    Member

    Agree with the class idea, but not now. I suspect it will break the current API.

  19. cwhanse commented on Jun 13, 2018

    @cwhanse
    Member

    @mikofski @thunderfish24 do you have any updates on this and related issues #409 #411? Will and I are campaigning to get pvlib to 0.6.0 and to clear up the backlog of issues and pull requests.

  20. markcampanelli commented on Jun 14, 2018

    @markcampanelli
    Contributor

    I'm supposed to have a considerable chunk of free time on Saturday, so if all goes well I can address the reviews on PR #426 for issue #411 and it should then be ready to go in. IIRC, #411 has two additional pieces after #426: (1) Adding gold data for Isc, Ix, Pmp, Ixx, and Voc, and (2) Adding unit tests that actually fail if the pvsystem functions don't produce values sufficiently close to the gold values. (A further followup could add logging/tracking of the benchmarks in CI.) Of course, I see no reason that these additional items cannot happen after 0.6.0.

  21. mikofski commented on Jun 14, 2018

    @mikofski
    MemberAuthor

    @cwhanse I have been waiting for SciPy pr8357 to merge. It's almost there. The last reviewers remaining issue pr8907 / gh8904 was merged today, coincidentally, I can work on it tomorrow and then we should see vectorized Newton in SciPy-1.2.0 but when will that be released? Is it okay for us to use a vendorized version until SciPy is updated? Or should we do some Numba hack in the meantime? Or just add Bishop explicit method but leave everything else the same. Sorry, I don't have a good answer. I will try to wrap this up as soon as possible

  22. wholmgren commented on Jun 14, 2018

    @wholmgren
    Member

    I recommend copying the vectorized newton function into _tools.py for now.

  23. mikofski commented on Jun 27, 2018

    @mikofski
    MemberAuthor

    @wholmgren you mean tools.py no underscore right?

  24. wholmgren commented on Jun 27, 2018

    @wholmgren
    Member

    Yes. But I think the function should be private.

  25. mikofski commented on Jun 27, 2018

    @mikofski
    MemberAuthor

    OK if I move _golden_sect_DataFrame to tools.py also? no changes to API. makes it easier to not have circular references. thanks! You'll probably dislike this, but I'm calling that instead of brentq until I get scipy/scipy#8431

  26. wholmgren commented on Jun 27, 2018

    @wholmgren
    Member

    OK if I move _golden_sect_DataFrame to tools.py also?

    Sure.

    You'll probably dislike this, but I'm calling that instead of brentq until I get scipy/scipy#8431

    I am confused. What will I dislike? And I thought you were going to use your new vectorized newton for single diode.

  27. mikofski commented on Jun 27, 2018

    @mikofski
    MemberAuthor

    #409 is long and convoluted. We agreed in the end to have 3 methods:

    • Newton
    • Bisection or "gold" - we used Brent for this
    • Lambert W
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions