Skip to content

Pull Request for PVsyst_parameter_estimation #229

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

Closed
wants to merge 36 commits into from

Conversation

mattguttenberg
Copy link

This is the pull request for #227. Since the issue was opened, I have finished the singlediode port with accompanying tests and the Schumaker_QSpline port. I still need to write some tests to make sure that Schumaker_QSpline is fully functional; so far I have only tested it with out nose by using the python command console. Once the tests for Schumaker_QSpline are finished, I'll begin porting est_single_diode_param and write some tests for that code and then finish up with the PVsyst_parameter_estimation port with some accompanying tests. With that said, I wanted to start this pull request since this is such a large merge and wanted to start the feedback / discussion process.

Matt Guttenberg and others added 30 commits August 1, 2016 14:02
Added ported versions of calc_theta_phi_exact, lambertw, singlediode,
update_io_known_n, update_rsh_fixed_pt and associated tests to pvl-python.
Also added a __init__ file ot the tests folder to describe the file folder
and allow the tests to be called if necessary. PVsyst_parameter_estimation
and singlediode are not complete versions
Updated the lambertw and singlediode scripts to fix some small errors that
were found while testing. Added 38 tests for the singlediode script
functions althought more tests will be added.
Finished adding tests for singlediode that tests all of the
functionalities of the script, including properly raising errors. Updated
the singlediode script to fix any errors found while testing. Added a
statement to the lambertw function to make the calculations slightly
faster in the event a -inf case.
Adjusted all index references to be integer values to avoid the warnings
that were displayed. Fixed all logic errors. Fixed the sorting mechanism
for the final array.
Added a Schumaker_QSpline test (more to be added) and fixed the
singlediode_tests script to adhere to PEP8 standards
Added the est_single_diode_parameter ported script to pvlib. Fixed a typo
in the Schumaker_QSpline script that caused an error under a very
particular circumstance. Added brackets in the Schumaker_QSpline test
script to get rid of syntax errors.
Updated the imports in many of the regular and test scripts to fix some
ambiguity issues that might have been occurring during testing
Added a class to move on with the code for the PVsyst_paramter_estimation
script and added a class to the singlediode script to wrap up the answers
in a more succinct format. Adjusted the singlediode tests to reflect this
change.
Ported over some of the sections from PVsyst_parameter_estimation. Added
numdiff function to the PVsyst_parameter_estimation script. Since the
script uses matplotlib, added the requirement to the setup.
Finished porting PVsyst_parameter_estimation except for the section with
the robust_fit. Changed the outputs of this function and singlediode from
a class to a ordereddict and changed the inputs for
PVsyst_parameter_estimation from classes to ordereddicts as well.
Added the robust fit algorithm where it was needed to determine desired
information. Since this alrogithm used the statsmodels toolbox, the setup
was changed to reflect this addition.
Removed lambertw and associated test script since scipy.special already
had a working lambertw that has been tested and verified. Changed
associated scripts to reflect this change. Some bug fixes for
Pvsyst_paramter_estimation
Removed i_from_v, v_from_i and singlediode and used the already coded and
tested versions within pvlib. Updated PVsyst_parameter_estimation based on
some bug fixes.
Fixed additional typos and other errors that have prevented the code from
completing. Now that the code runs to completion, additional checks will
be run to determine whether the converged values are appropriate.
modified calc_theta_phi_exact to handle the edge case where nnsvth was
equal to 0.
Reintroduced lambertw script for use in update_rsh_fixed_pt since the
lambertw script was having problems for cases where rsh was extremely high
in calc_theta_phi_exact
Fixed an import error in update_io_known_n and removed v_from_i from the
tests since the code is using the code that already exists and has been
tested in pvsystem. Removed an unused import in update_rsh_fixed_pt
@wholmgren
Copy link
Member

Thanks @mattguttenberg! This looks great. I really appreciate that you wrote tests, too. Let's first address a few bigger and more general things. After that, I'll go through the code more carefully and make some line by line comments.

style: please install flake8 and pep8-naming and run them against all of your new code. This way I don't have to comment on every little style issue. Also run them against some of the existing modules so that you can get a feel for what to ignore. The big things that I see right now are line length and capitalization.

module structure: pvlib python prefers to consolidate similar functions into modules. We'll also want to make some (all?) of the helper functions into private methods. This is so that they don't become automatically documented by sphinx, and so that people don't rely on them for their own code.

lambertw: Is there a reason that you implemented lambertw instead of using the scipy lambertw? See e.g. pvsystem.v_from_i for an example of its usage in pvlib.

schumaker_qspline: I'm not familiar with this algorithm, but I'm wondering if scipy and/or statsmodels already has it (maybe under a different name or with the right parameters).

plotting: I'd like to see a better separation between plotting code and the rest of the code. Move the plotting stuff into a separate functions. You should also import matplotlib within those functions rather than at the top of the module. This way we don't need to make matplotlib a required dependency.

tests: put the calculations inside the test functions. numpy now recommends using assert_allclose instead of assert_array_almost_equal

documentation: Compare your documentation syntax to the numpydoc standard and/or the rest of pvlib.

@cwhanse
Copy link
Member

cwhanse commented Aug 17, 2016

Ø schumaker_qspline: I'm not familiar with this algorithm, but I'm wondering if scipy and/or statsmodels already has it (maybe under a different name or with the right parameters).
I very much doubt it. The algorithm produces a quadratic spline that preserves both monotonicity and concavity. I didn’t find any code when I looked 2 years ago. There’s a nascent R package now which might give us some ideas about making my matlab code more general and perhaps become a submission to a python package.

Cliff

@mattguttenberg
Copy link
Author

@wholmgren Thank you for all of the great feedback. I did notice that lambertw was already added to scipy and had made use of it in most of the scripts I had wrote. When I was running tests for calc_theta_phi_exact, however, I found that in some of the test cases I written, an edge case was observed were lambertw from scipy returned infinity while the lambertw script produced a very large value but not infinity which lead to an assertion error. Thus I had chosen to keep the function in on this port instead of 100% switching to the scipy version of the function to try and minimize discrepancy between the MATLAB version and ported version I had wrote.

@wholmgren
Copy link
Member

Can you use pvsystem.v_from_i instead?

@mattguttenberg
Copy link
Author

I thought I removed the v_from_i script I wrote and changed to using the pvsystem function in one of my latest commits.

@mattguttenberg
Copy link
Author

After double checking with my latest commit, I had already removed the v_from_i script I had written after I realized that pvsystem already had it and changed the scripts to use the one that already existed

Matt Guttenberg added 2 commits August 17, 2016 15:48
Modified all written scripts to adhere to the flake8 and pep8-naming
guidelines. Updated tests as suggested by Will
Updated script documentation for each of the written scripts to fit better
with the pvlib documentation
@wholmgren
Copy link
Member

It seemed to me that you could avoid the whole lambertw issue if you relied on pvsystem.v_from_i (which already handles overflow internally). Maybe I didn't read carefully enough, though.

@mattguttenberg
Copy link
Author

Oh I see. The error occurred in calc_theta_phi_exact. v_from_i could be used to calculated phi from the looks of it since they share the same argw formula but the formula for theta would still need the script as its argw formula is different from that of v_from_i and if I remember correctly, it was the theta term that was throwing the error mentioned above.

@wholmgren
Copy link
Member

Could we add similar code to pvsystem.i_from_v? If so, we might want to move the log solver into its own function that lives in, say, tools.py. Could be something like...

# in tools.py
def lambertw_maybe_log(argW, logargW):
    # scipy's result
    lambertwterm = lambertw(argW).real

    # Three iterations of Newton-Raphson method to solve
    # w+log(w)=logargW. The initial guess is w=logargW. Where direct
    # evaluation (above) results in NaN from overflow, 3 iterations
    # of Newton's method gives approximately 8 digits of precision.
    w = logargW
    for i in range(0, 3):
        w = w * (1 - np.log(w) + logargW) / (1 + w)
    lambertwterm_log = w

    lambertwterm = np.where(np.isfinite(lambertwterm), lambertwterm,
                            lambertwterm_log)

    return lambertwterm

def v_from_i(...):
    # ...
    argW = I0 * Rsh / nNsVth * np.exp(Rsh * (-I + IL + I0) / nNsVth)

    # Calculate using log(argW) in case argW is really big
    logargW = (np.log(I0) + np.log(Rsh) - np.log(nNsVth) +
               Rsh * (-I + IL + I0) / nNsVth)

    lambertwterm = tools.lambertw_maybe_log(argW, logargW)
    # ...

def i_from_v(...):
    # ...
    argW = (Rs*I0*Rsh *
            np.exp(Rsh*(Rs*(IL+I0)+V) / (nNsVth*(Rs+Rsh))) /
            (nNsVth*(Rs + Rsh)))

    logargW = np.log(...) + np.log(...) + ...

    lambertwterm = tools.lambertw_maybe_log(argW, logargW)
    # ...

@cwhanse
Copy link
Member

cwhanse commented Aug 18, 2016

Here's the IV curve data we provide with PVLib matlab, in csv format. Also, python code to read the data into a dict with the structure currently used by the parameter estimation code.
PVsyst_demo.txt

import numpy as np

specs = {key: None for key in ['ns', 'aisc','bvoc','type']}
keylist  = ['isc', 'imp', 'vmp', 'voc', 'poa', 'tc', 'ee']
ivcurves = {key: None for key in keylist}

with open('PVsyst_demo.txt', 'r') as f:

    Ns, aIsc, bVoc, descr = f.readline().split(',')

    specs['ns'] = int(float(Ns))
    specs['aisc'] = float(aIsc)
    specs['bvoc'] = float(bVoc)
    specs['type'] = descr

    strN, strM = f.readline().split(',')
    N = int(strN)
    M = int(strM)

    isc = np.empty(N)
    imp = np.empty_like(isc)
    vmp = np.empty_like(isc)
    voc = np.empty_like(isc)
    ee = np.empty_like(isc)
    poa = np.empty_like(isc)
    tc = np.empty_like(isc)
    v = np.empty((N, M))    
    i = np.empty_like(v)    

    for k in range(0,N):
        isc[k], imp[k], vmp[k], voc[k], poa[k], tc[k], ee[k] = f.readline().split(',')
        tmp = [str.strip(',') for str in f.readline().split()]
        while len(tmp)<M:
            tmp.append('NaN')
        v[k,] = [float(x) for x in tmp]
        tmp = [str.strip(',') for str in f.readline().split()]
        while len(tmp)<M:
            tmp.append('NaN')
        i[k,] = [float(x) for x in tmp]

ivcurves['v'] = v
ivcurves['i'] = i

@cwhanse
Copy link
Member

cwhanse commented Aug 18, 2016

Here's the solution for pvsyst from Matlab, and python code to read the csv file into an OrderedDict.

PVsyst_demo_model.txt

import numpy as np
from collections import OrderedDict


specs = {key: None for key in ['ns', 'aisc','bvoc','type']}
paramlist  = ['IL_ref', 'Io_ref', 'eG', 'Rsh_ref', 'Rsh0', 'Rshexp', 'Rs_ref', 'gamma_ref', 'mugamma']
varlist = ['Iph', 'Io', 'Rsh', 'Rs', 'u']
pvsyst = OrderedDict(key = paramlist + varlist)

with open('PVsyst_demo_model.txt', 'r') as f:

    Ns, aIsc, bVoc, descr = f.readline().split(',')

    specs['ns'] = int(float(Ns))
    specs['aisc'] = float(aIsc)
    specs['bvoc'] = float(bVoc)
    specs['type'] = descr

    IL_ref, Io_ref, eG, Rsh_ref, Rsh0, Rshexp, Rs_ref, gamma_ref, mugamma = f.readline().split(',')
    for key in paramlist:
        pvsyst[key] = float(eval(key))

    strN = f.readline()
    N = int(strN)

    Iph = np.empty(N)
    Io = np.empty_like(Iph)
    Rsh = np.empty_like(Iph)
    Rs = np.empty_like(Iph)
    u = np.empty_like(Iph)

    for k in range(0,N):
        Iph[k], Io[k], Rsh[k], Rs[k], u[k] = f.readline().split(',')

for var in varlist:
    pvsyst[var] = eval(var)

@wholmgren wholmgren added this to the 0.5.0 milestone Sep 13, 2016
@wholmgren
Copy link
Member

@mattguttenberg @cwhanse any plans for finishing this PR? Maybe someone else wants to pick it up? I don't personally have a need for this feature or the time to do it.

@mikofski
Copy link
Member

I will try to pick this up and fix it soon, maybe by the end of the year?

@cwhanse cwhanse mentioned this pull request Sep 21, 2018
@mikofski
Copy link
Member

mikofski commented Oct 4, 2018

continuing this in a new branch, also PV_LIB MATLAB works fine in Octave on Linux.

mikofski pushed a commit to mikofski/pvlib-python that referenced this pull request May 4, 2019
from PVLIB_MATLAB by Matt Guttenberg Aug-2016, see pvlib#229 and pvlib#227

Added ported functions and tests to pvlib

Added ported versions of calc_theta_phi_exact, lambertw, singlediode,
update_io_known_n, update_rsh_fixed_pt and associated tests to pvl-python.
Also added a __init__ file ot the tests folder to describe the file folder
and allow the tests to be called if necessary. PVsyst_parameter_estimation
and singlediode are not complete versions

Changed the tests to properly call the appropriate functions

Finished the singlediode script

Added Test script for singlediode

Added tests for singlediode functions and updated scripts

Updated the lambertw and singlediode scripts to fix some small errors that
were found while testing. Added 38 tests for the singlediode script
functions althought more tests will be added.

Finished singlediode and corresponding tests

Finished adding tests for singlediode that tests all of the
functionalities of the script, including properly raising errors. Updated
the singlediode script to fix any errors found while testing. Added a
statement to the lambertw function to make the calculations slightly
faster in the event a -inf case.

Added a new file for the Schumaker_QSpline script

Finished Schumaker_QSpline script

Fixed Schumaker_QSpline script based on test

Adjusted all index references to be integer values to avoid the warnings
that were displayed. Fixed all logic errors. Fixed the sorting mechanism
for the final array.

Added test file for Schumaker_QSpline script

Added a Schumaker_QSpline test

Added a Schumaker_QSpline test (more to be added) and fixed the
singlediode_tests script to adhere to PEP8 standards

Added a couple more tests for Schumaker_QSpline

Added the est_single_diode_parameter port and fixed typos

Added the est_single_diode_parameter ported script to pvlib. Fixed a typo
in the Schumaker_QSpline script that caused an error under a very
particular circumstance. Added brackets in the Schumaker_QSpline test
script to get rid of syntax errors.

Added tests for the est_single_diode_param script

Delete __init__.py

Changed one test case for lambertw

Fixed some ambiguities in the imports

Updated the imports in many of the regular and test scripts to fix some
ambiguity issues that might have been occurring during testing

Started adding code to the PVsyst_parameter_estimation script

Added Classes to singlediode and PVsyst_Parameter_estimation

Added a class to move on with the code for the PVsyst_paramter_estimation
script and added a class to the singlediode script to wrap up the answers
in a more succinct format. Adjusted the singlediode tests to reflect this
change.

Ported over some of the code for PVsyst_parameter_estimation

Ported over some of the sections from PVsyst_parameter_estimation. Added
numdiff function to the PVsyst_parameter_estimation script. Since the
script uses matplotlib, added the requirement to the setup.

Finished PVsyst_parameter_estimation and adjusted outputs of functions

Finished porting PVsyst_parameter_estimation except for the section with
the robust_fit. Changed the outputs of this function and singlediode from
a class to a ordereddict and changed the inputs for
PVsyst_parameter_estimation from classes to ordereddicts as well.

Changed the setup to include scipy as a required toolbox

Added robust fit algorithm to PVsyst_parameter_estimation

Added the robust fit algorithm where it was needed to determine desired
information. Since this alrogithm used the statsmodels toolbox, the setup
was changed to reflect this addition.

Removed lambertw since scipy already had a working copy. Script Changes

Removed lambertw and associated test script since scipy.special already
had a working lambertw that has been tested and verified. Changed
associated scripts to reflect this change. Some bug fixes for
Pvsyst_paramter_estimation

Removed some coded scripts and updated PVsyst_parameter_estimation

Removed i_from_v, v_from_i and singlediode and used the already coded and
tested versions within pvlib. Updated PVsyst_parameter_estimation based on
some bug fixes.

More bug fixes

Fixed additional typos and other errors that have prevented the code from
completing. Now that the code runs to completion, additional checks will
be run to determine whether the converged values are appropriate.

Updated calc_theta_phi_exact to handle an edge case

modified calc_theta_phi_exact to handle the edge case where nnsvth was
equal to 0.

Brought back lambertw script for use in update_rsh_fixed_pt

Reintroduced lambertw script for use in update_rsh_fixed_pt since the
lambertw script was having problems for cases where rsh was extremely high
in calc_theta_phi_exact

A couple mroe PVsyst_parameter_estimation bug fixes

Fixed import errors and removed unused lines

Fixed an import error in update_io_known_n and removed v_from_i from the
tests since the code is using the code that already exists and has been
tested in pvsystem. Removed an unused import in update_rsh_fixed_pt

Fixed typos / errors

Fixed an error in PVsyst_parameter_estimation in the numdiff function
where the summations were not occuring properly. Fixed a typo in pvsystem
where a parameter was accidentally changed.

Final bug fixes for PVsyst_parameter_estimation

Fixed a typo in one of the plots

Style Update

Modified all written scripts to adhere to the flake8 and pep8-naming
guidelines. Updated tests as suggested by Will

Documentation Update

Updated script documentation for each of the written scripts to fit better
with the pvlib documentation

Added Documents from Cliff
@mikofski
Copy link
Member

@wholmgren and @cwhanse do you want to close this in favor of #708

  • I've squashed all of these commits into c00d419 and rebased them on v0.4 then rebased that on master, to preserve the history
  • then isolated them in a new temporary folder until we decide what to do with them
  • then got them working in name only, there are some tests, all tests pass, but I think the testing is still insufficient

@wholmgren wholmgren closed this May 10, 2019
cwhanse added a commit that referenced this pull request Aug 28, 2020
* ENH: porting pvsyst and single diode param est

from PVLIB_MATLAB by Matt Guttenberg Aug-2016, see #229 and #227

Added ported functions and tests to pvlib

Added ported versions of calc_theta_phi_exact, lambertw, singlediode,
update_io_known_n, update_rsh_fixed_pt and associated tests to pvl-python.
Also added a __init__ file ot the tests folder to describe the file folder
and allow the tests to be called if necessary. PVsyst_parameter_estimation
and singlediode are not complete versions

Changed the tests to properly call the appropriate functions

Finished the singlediode script

Added Test script for singlediode

Added tests for singlediode functions and updated scripts

Updated the lambertw and singlediode scripts to fix some small errors that
were found while testing. Added 38 tests for the singlediode script
functions althought more tests will be added.

Finished singlediode and corresponding tests

Finished adding tests for singlediode that tests all of the
functionalities of the script, including properly raising errors. Updated
the singlediode script to fix any errors found while testing. Added a
statement to the lambertw function to make the calculations slightly
faster in the event a -inf case.

Added a new file for the Schumaker_QSpline script

Finished Schumaker_QSpline script

Fixed Schumaker_QSpline script based on test

Adjusted all index references to be integer values to avoid the warnings
that were displayed. Fixed all logic errors. Fixed the sorting mechanism
for the final array.

Added test file for Schumaker_QSpline script

Added a Schumaker_QSpline test

Added a Schumaker_QSpline test (more to be added) and fixed the
singlediode_tests script to adhere to PEP8 standards

Added a couple more tests for Schumaker_QSpline

Added the est_single_diode_parameter port and fixed typos

Added the est_single_diode_parameter ported script to pvlib. Fixed a typo
in the Schumaker_QSpline script that caused an error under a very
particular circumstance. Added brackets in the Schumaker_QSpline test
script to get rid of syntax errors.

Added tests for the est_single_diode_param script

Delete __init__.py

Changed one test case for lambertw

Fixed some ambiguities in the imports

Updated the imports in many of the regular and test scripts to fix some
ambiguity issues that might have been occurring during testing

Started adding code to the PVsyst_parameter_estimation script

Added Classes to singlediode and PVsyst_Parameter_estimation

Added a class to move on with the code for the PVsyst_paramter_estimation
script and added a class to the singlediode script to wrap up the answers
in a more succinct format. Adjusted the singlediode tests to reflect this
change.

Ported over some of the code for PVsyst_parameter_estimation

Ported over some of the sections from PVsyst_parameter_estimation. Added
numdiff function to the PVsyst_parameter_estimation script. Since the
script uses matplotlib, added the requirement to the setup.

Finished PVsyst_parameter_estimation and adjusted outputs of functions

Finished porting PVsyst_parameter_estimation except for the section with
the robust_fit. Changed the outputs of this function and singlediode from
a class to a ordereddict and changed the inputs for
PVsyst_parameter_estimation from classes to ordereddicts as well.

Changed the setup to include scipy as a required toolbox

Added robust fit algorithm to PVsyst_parameter_estimation

Added the robust fit algorithm where it was needed to determine desired
information. Since this alrogithm used the statsmodels toolbox, the setup
was changed to reflect this addition.

Removed lambertw since scipy already had a working copy. Script Changes

Removed lambertw and associated test script since scipy.special already
had a working lambertw that has been tested and verified. Changed
associated scripts to reflect this change. Some bug fixes for
Pvsyst_paramter_estimation

Removed some coded scripts and updated PVsyst_parameter_estimation

Removed i_from_v, v_from_i and singlediode and used the already coded and
tested versions within pvlib. Updated PVsyst_parameter_estimation based on
some bug fixes.

More bug fixes

Fixed additional typos and other errors that have prevented the code from
completing. Now that the code runs to completion, additional checks will
be run to determine whether the converged values are appropriate.

Updated calc_theta_phi_exact to handle an edge case

modified calc_theta_phi_exact to handle the edge case where nnsvth was
equal to 0.

Brought back lambertw script for use in update_rsh_fixed_pt

Reintroduced lambertw script for use in update_rsh_fixed_pt since the
lambertw script was having problems for cases where rsh was extremely high
in calc_theta_phi_exact

A couple mroe PVsyst_parameter_estimation bug fixes

Fixed import errors and removed unused lines

Fixed an import error in update_io_known_n and removed v_from_i from the
tests since the code is using the code that already exists and has been
tested in pvsystem. Removed an unused import in update_rsh_fixed_pt

Fixed typos / errors

Fixed an error in PVsyst_parameter_estimation in the numdiff function
where the summations were not occuring properly. Fixed a typo in pvsystem
where a parameter was accidentally changed.

Final bug fixes for PVsyst_parameter_estimation

Fixed a typo in one of the plots

Style Update

Modified all written scripts to adhere to the flake8 and pep8-naming
guidelines. Updated tests as suggested by Will

Documentation Update

Updated script documentation for each of the written scripts to fit better
with the pvlib documentation

Added Documents from Cliff

* change function name from est_single_diode_params

- to estimate_parameters() since it was the same as the module
- update imports and calls everywhere
- other modules still have functions shadowing them, like
pvsyst_parametre_estimation()

* use int indices, make docstring, test still fails

* isolate iv fitting and parameter generation

* TST: schumaker test is passing! Yoohoo!

* TST: fix imports and path to test data

* fix Io test sortof, some stickler

* fix tests, merge ivtools

- move ivtools.py to ivtools/__init__.py, all tests PASS
- fix Schmaker_QSpline again, boolean indexing in Numpy is different
 than MATLAB, size must be the same, so get just the first (n-1) indices
 first
- fix est_single_diode_param.py which uses np.tile, only works with
 integers, not floats, so remove periods from 1. to make it an int
- rename calc_theta_phi_exact and lambertw to be prefixed with test so that
 pytest actually runs them, both PASS
- start fixing test_PVsyst_parameter_estimation, FAIL

* fixing test_PVsyst_parameter_estimation

- in calc_theta_phi_exactly, replace if-then with
 np.where(nnsvth is zero, use inf, or calculate)
- restrict arrays to dtype=float where they're created from arrays, this
 prevents arrays of arrays with dtype=object, which FAILS with
 np.isnan(doesn't work on dtype=object, only float)
 TODO: fix this!
- in lambertw b/c any(must be an iterable) is called on z which is
 scalar when called from PVsyst_parameter_estimation then need to make z
at least a 1d array, even tho this causes problems later, oh well
 TODO: fix this!
- in pvsyst_parameter_estimation, replace enumerate with zip(),
 and more importantly in rectify_IV_curve() remove any nan's which were
 added to the ivcurves
- the old tests are still PASSING, but test-pvsyst is a WIP

* include statsmodels and mpl in ci/conda-envs

* stickler fixes, long lines, code tweaks

- ignore w503,w504 break before/after binary operator
- add logging to pvsyst_parameter_estimation
- add latex $math$ to graphics output
- replace repeated len(f) with n

* rename update io and rsh tests so they run

- use concise indexing notation in numdiff

* concise indexing in Schumaker QSpline

* add test for numdiff

- add test data from original MATLAB, based on pvsyst demo
- more concise indices in numdiff

* move pvsyst parameter estimation tests

- to pvlib.test

* use maximum not max in estRsh

- add verbosity to least_squares
- limit to 100 ivcurves

* fudge tolerance for pvsyst_parameter_estimation for fun

* restrict pvsyst estimation test to first 3000 points

- the last 500 points seem to cause a problem that I need more time to pin down
- instead of testing against the matlab generated pvsyst coefficients, which
 seem to be different from `pvlib.pvsystem.calcparams` works, also test the
 actual iv curve points (isc, voc, imp, vmp, pmp) generate from the coefficients in
 pvlib with the original data
- set tolerances to match the test data

* rename pvsyst parameter estimation tests folder

- suffix with _tests instead of prefix
- remove matplotlib from pvsyst_parameter_estimation, I save all of the
 snippets so maybe they can go in the tests folder?
- removes graphic & convergeparamsfig args from check_converge and the
 graphic arg from pvsyst_parameter_estimation funcs
- safely import scipy and statsmodels inside pvsyst_parameter_estimation so
 bare linux tests can run on CI, add comment at top
- also remove mpl from setup optional requires
- add pvsyst_parameter_estimation to api docs
- raise runtime error if doesn't converge instead of the oflag
- remove oflag arg from pvsyst_param_est everywhere
- add decorator for requires_statsmodels in conftest and apply to
 test_pvsyst_parameter_estimation
- rename Schmaker_QSpline and est_single_diode_param tests

Signed-off-by: Mark Mikofski <[email protected]>

* move test_numdiff inside test_pvsyst_parameter_estimation.py

* add requires_scipy to update_io_know_n tests

- remove TODO's to delete old code replaced by np.where in
 calc_theta_phi_exact
- stickler fixes:
  * overindented lines and continutation characters in calc_theta
  * long line in docstring of estimate_single_diode
  * over indentation in pvsyst_param_est
  * extra line after function check_converge before fun_rsh
- also add TODO to change convergence relative ratios

* pycodestyle passing, rm xtra sp, fix indent

* shuffle functions into different modules. Rename to fit_sdX_ pattern

* fix import names

* fix import in ivtools

* refactor deux: rm old files

- remove PVsyst_parameter_estimation.py with 7 methods, and the module
attribute `const_default`
    1. numdiff -> utility.numdiff
    2. rectify_iv_curve -> utility.rectify_iv_curve
    3. estrsh -> fit_sdm._rsh_pvsyst
    4. filter_params -> fit_sdm._filter_params
    5. check_converge -> fit_sdm._check_converge
    6. const_default -> utility.constants
    7. fun_rsh -> local to fit_pvsyst_sandia
    8. pvsyst_parameter_estimation -> fit_sdm.fit_pvsyst_sandia
- remove calc_theta_phi_exact with only 1 method which is in fit_sdm.py
now
- ditto for update_io_to_known_n & update_rsh_fixed_pt.py
- ditto remove est_single_diode_param.py
- remove lambertw, using scipy
- remove Schumaker_QSpline in favor do you even like music.
- fix some typos

Signed-off-by: Mark Mikofski <[email protected]>

* remove old pvsyst parma estimation tests

* stickler fixes

* using lambertw requires scipy in tests

- for calc_theta_phi_exact
- and update_rsh_fixed_pt

* align with scipy.intepolate pattern

* refactor fit_sde_cocontent, change argument order

* stickler

* fix argument order in fit_pvsyst_sandia

* fix rectify function, add test

* stickler

* corrections, add rcond=None

* more corrections

* undo change in rs, rsh order

* fix test for rectify_iv_curve, use np.expm1

* exclude curve #2540

* fix expected outcome for test_rectify_

* messed up csv

* exclude curve #2540

* correct rounding for test_rectify_

* move exclude to line 2540 was on 2536

* create exclude mask for individual curves

* use umask

* helper functions, some streamlining

* rename _update_io_known_n

* docstring improvements

* split _calc_theta_phi_exact, overhaul tests

* remove unused lines

* stickler

* remove test_ivtools.py

* renaming, update api.rst

* update name

* improve _update_rsh_fixed_pt

* fix typo

* fix error

* correct convergence in _update_rsh_fixed_pt

* flake8

* docstring for fit_sdm

* docstring for fit_sdm

* docstring for fit_sdm

* docstring for fit_sdm

* docstring for fit_sde, utility

* update api.rst

* add helper to deal with numpy<1.14

* fix workaround for numpy version

* rename modules and functions, move tests to ivtools/test

* move tests from ivtools/test to pvlib/tests/ivtools

* remove old test folder

* remove old pvlib/test folder

* name correction, remove old test files

* fix test, move test_fit_sde_cocontent into test_sde

* move test_schumaker_qspline to test_utility

* docstring work

* docstring work

* test corrections

* fix order in parametrize

* one comma

* corrections

* remove old files, update api.rst

* update names in ivtools\__init__.py

* docstring work, rename outputs from fit_pvsyst_sandia to be consistent with pvlib.pvsystem functions

* docstring work, use cells_in_series throughout

* docstring work, use mu_gamma instead of mugamma

* missed one

* sort of Rs vs R_s vs R_s_ref

* refactor to prepare for adding desoto, cec estimation; remove logging

* add fit_desoto_sandia

* correct argument order, lint

* change to pvlib-consistent key names

* add test for fit_desoto_sandia

* corrections

* more corrections

* use canonical order iph, io, rs, rsh, n

* convert update_rsh test, move to test_sdm.py

* fix update_rsh tests, improve function

* remove old update_rsh test file

* convert tests for _update_io

* remove old tests for _update_io

* convert tests for calc_theta_phi

* remove old test for calc_theta

* take care of float div by 0 test failures

* move sde functions to canonical argument order

* fix bugs

* more raid for bugs

* die bugs die

* maintain order of variables in the text file

* test repair

* minor editing

* pin pysam version to 1.2.1

* pysam to current version, patch over numpy 1.14 change

* module docstring

* remove ivtools.py

* separate sam_estimate_failure into its own function

* fix stickler

* 'mispelling'

* fix error in _calc_I0

* more fixing of that error

* improvements from review

* another fix for mistake in _calc_I0

* docstring edits

* improve coverage

* tpo

* use the correct error Class

* improvements from review

* changes from review: helper functions for test, _numdiff and _schum private, move and rename data files

* whatsnew

* add renamed and moved data files

* use pathlib.Path.open()

* duh

* add return, doing three things at once = poor quality

* add statsmodels for py38, fix dict declarations

* ()

Co-authored-by: Matt Guttenberg <[email protected]>
Co-authored-by: Cliff Hansen <[email protected]>
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.

4 participants