Skip to content

critical error in singlediode p_mp calculation #221

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
wholmgren opened this issue Jul 20, 2016 · 6 comments
Closed

critical error in singlediode p_mp calculation #221

wholmgren opened this issue Jul 20, 2016 · 6 comments
Labels
Milestone

Comments

@wholmgren
Copy link
Member

wholmgren commented Jul 20, 2016

Bad news. I discovered a major error in the singlediode p_mp calculation: given a time series input, the numerical solver exits if the solution for any single time is within the error tolerance, rather than requiring that the solution for all times be close enough. The error is in this line.

Here's some sample code:

photocurrent = np.linspace(0, 10, 11)
resistance_shunt = 16
resistance_series = 0.094
nNsVth = 0.473
saturation_current = 1.943e-09

sd = pvsystem.singlediode(photocurrent, saturation_current, resistance_series, resistance_shunt, nNsVth)

sd['i_mp']
array([ 0.        ,  0.59453544,  1.56145498,  2.54105091,  3.52353436,
        4.50658749,  5.4890739 ,  6.47016579,  7.44909413,  8.42504244,
        9.39708533])

# change .all() to .any()

pvsystem = reload(pvlib.pvsystem)

sd_any = pvsystem.singlediode(photocurrent, saturation_current, resistance_series, resistance_shunt, nNsVth)

sd_any['i_mp']
array([ 0.        ,  0.54538398,  1.43273966,  2.36328163,  3.29255606,
        4.23101358,  5.16177031,  6.09368251,  7.02197553,  7.96846051,
        8.88220557])

sd['i_mp']/sd_any['i_mp']
array([        nan,  1.09012266,  1.0898386 ,  1.07522137,  1.07015167,
        1.06513189,  1.06340917,  1.06178256,  1.06082599,  1.05729864,
        1.05796756])

sd['p_mp']/sd_any['p_mp']
array([        nan,  0.98250248,  0.92482996,  0.91242588,  0.91052337,
        0.91256532,  0.9165425 ,  0.92159883,  0.92731275,  0.93339723,
        0.93974898])

So the error here is on the order of 5 to 10%, but the results will depend on your exact input.

The blue dots on the IV curve below show the p_mp points in the old code. The black dots show the p_mp points in fixed code. These IV curves are generated using a fix for #83 that I'll make a PR for soon. They're also what led me to discovering the problem.

ivcurves

On a related note, someone should put more effort into verifying that the matlab and python libraries give the same results. Not me.

@jforbess
Copy link
Contributor

Wow. Good catch.

On Wed, Jul 20, 2016 at 4:49 PM, Will Holmgren [email protected]
wrote:

Bad news. I discovered a major error in the singlediode p_mp calculation:
given a time series input, the numerical solver exits if the solution for
any single time is within the error tolerance, rather than requiring that
the solution for all times be close enough. The error is in this line

errflag = (abs(err) > .01).all()
.

Here's some sample code:

photocurrent = np.linspace(0, 10, 11)
resistance_shunt = 16
resistance_series = 0.094
nNsVth = 0.473
saturation_current = 1.943e-09

sd = pvsystem.singlediode(photocurrent, saturation_current, resistance_series, resistance_shunt, nNsVth)

sd['i_mp']
array([ 0. , 0.59453544, 1.56145498, 2.54105091, 3.52353436,
4.50658749, 5.4890739 , 6.47016579, 7.44909413, 8.42504244,
9.39708533])

change .all() to .any()

pvsystem = reload(pvlib.pvsystem)

sd_any = pvsystem.singlediode(photocurrent, saturation_current, resistance_series, resistance_shunt, nNsVth)

sd_any['i_mp']
array([ 0. , 0.54538398, 1.43273966, 2.36328163, 3.29255606,
4.23101358, 5.16177031, 6.09368251, 7.02197553, 7.96846051,
8.88220557])

sd['i_mp']/sd_any['i_mp']
array([ nan, 1.09012266, 1.0898386 , 1.07522137, 1.07015167,
1.06513189, 1.06340917, 1.06178256, 1.06082599, 1.05729864,
1.05796756])

So the error here is on the order of 5 to 10%, but the results will depend
on your exact input.

The blue dots on the IV curve below show the p_mp points in the old code.
The black dots show the p_mp points in fixed code. These IV curves are
generated using a fix for #83
#83 that I'll make a PR for
soon. They're also what led me to discovering the problem.

[image: ivcurves]
https://cloud.githubusercontent.com/assets/4383303/17006598/cedaa96c-4e96-11e6-9e9a-64ed1377536c.png

On a related note, someone should put more effort into verifying that the
matlab and python libraries give the same results. Not me.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#221, or mute the thread
https://github.com/notifications/unsubscribe-auth/AH66Afta3YTqPeH7OEr-gdqHaSaAfLiDks5qXrQLgaJpZM4JRUWz
.

@jforbess
Copy link
Contributor

Also, will this fix trigger a new release 0.3.4? Seems pretty important.

On Thu, Jul 21, 2016 at 9:39 AM, Jessica Forbess [email protected] wrote:

Wow. Good catch.

On Wed, Jul 20, 2016 at 4:49 PM, Will Holmgren [email protected]
wrote:

Bad news. I discovered a major error in the singlediode p_mp calculation:
given a time series input, the numerical solver exits if the solution for
any single time is within the error tolerance, rather than requiring that
the solution for all times be close enough. The error is in this line

errflag = (abs(err) > .01).all()
.

Here's some sample code:

photocurrent = np.linspace(0, 10, 11)
resistance_shunt = 16
resistance_series = 0.094
nNsVth = 0.473
saturation_current = 1.943e-09

sd = pvsystem.singlediode(photocurrent, saturation_current, resistance_series, resistance_shunt, nNsVth)

sd['i_mp']
array([ 0. , 0.59453544, 1.56145498, 2.54105091, 3.52353436,
4.50658749, 5.4890739 , 6.47016579, 7.44909413, 8.42504244,
9.39708533])

change .all() to .any()

pvsystem = reload(pvlib.pvsystem)

sd_any = pvsystem.singlediode(photocurrent, saturation_current, resistance_series, resistance_shunt, nNsVth)

sd_any['i_mp']
array([ 0. , 0.54538398, 1.43273966, 2.36328163, 3.29255606,
4.23101358, 5.16177031, 6.09368251, 7.02197553, 7.96846051,
8.88220557])

sd['i_mp']/sd_any['i_mp']
array([ nan, 1.09012266, 1.0898386 , 1.07522137, 1.07015167,
1.06513189, 1.06340917, 1.06178256, 1.06082599, 1.05729864,
1.05796756])

So the error here is on the order of 5 to 10%, but the results will
depend on your exact input.

The blue dots on the IV curve below show the p_mp points in the old code.
The black dots show the p_mp points in fixed code. These IV curves are
generated using a fix for #83
#83 that I'll make a PR
for soon. They're also what led me to discovering the problem.

[image: ivcurves]
https://cloud.githubusercontent.com/assets/4383303/17006598/cedaa96c-4e96-11e6-9e9a-64ed1377536c.png

On a related note, someone should put more effort into verifying that the
matlab and python libraries give the same results. Not me.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#221, or mute the thread
https://github.com/notifications/unsubscribe-auth/AH66Afta3YTqPeH7OEr-gdqHaSaAfLiDks5qXrQLgaJpZM4JRUWz
.

@wholmgren
Copy link
Member Author

I want to release 0.4 next week, but I am sympathetic to the fact that people may not be happy about dealing with a lot of API changes just so that they can get this fix. So, I figured that I'd wait to see if anyone requested it.

@jforbess
Copy link
Contributor

Ok. I have a project I'm dealing with this week, but I can make the
individual fix myself. I didn't realize 0.4.0 was so close. I can accept
the API changes as well as the fix, so I'll let others request if they need
it.

On Thu, Jul 21, 2016 at 10:05 AM, Will Holmgren [email protected]
wrote:

I want to release 0.4 next week, but I am sympathetic to the fact that
people may not be happy about dealing with a lot of API changes just so
that they can get this fix. So, I figured that I'd wait to see if anyone
requested it.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#221 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AH66AYTjlmSqib_96YGMD9r9zUAE1trUks5qX6bjgaJpZM4JRUWz
.

@cwhanse
Copy link
Member

cwhanse commented Jul 21, 2016

Will,

I'll take this on - test case for single diode functions.

Can you point me to an example of a test implemented as you like it?

Cliff

Sent from my iPhone

On Jul 20, 2016, at 5:49 PM, Will Holmgren <[email protected]mailto:[email protected]> wrote:

Bad news. I discovered a major error in the singlediode p_mp calculation: given a time series input, the numerical solver exits if the solution for any single time is within the error tolerance, rather than requiring that the solution for all times be close enough. The error is in this linehttps://github.com/pvlib/pvlib-python/blob/5218c9d3dd2d5a4e410140de3180b7ef00e8b1ee/pvlib/pvsystem.py#L1728.

Here's some sample code:

photocurrent = np.linspace(0, 10, 11)
resistance_shunt = 16
resistance_series = 0.094
nNsVth = 0.473
saturation_current = 1.943e-09

sd = pvsystem.singlediode(photocurrent, saturation_current, resistance_series, resistance_shunt, nNsVth)

sd['i_mp']
array([ 0. , 0.59453544, 1.56145498, 2.54105091, 3.52353436,
4.50658749, 5.4890739 , 6.47016579, 7.44909413, 8.42504244,
9.39708533])

change .all() to .any()

pvsystem = reload(pvlib.pvsystem)

sd_any = pvsystem.singlediode(photocurrent, saturation_current, resistance_series, resistance_shunt, nNsVth)

sd_any['i_mp']
array([ 0. , 0.54538398, 1.43273966, 2.36328163, 3.29255606,
4.23101358, 5.16177031, 6.09368251, 7.02197553, 7.96846051,
8.88220557])

sd['i_mp']/sd_any['i_mp']
array([ nan, 1.09012266, 1.0898386 , 1.07522137, 1.07015167,
1.06513189, 1.06340917, 1.06178256, 1.06082599, 1.05729864,
1.05796756])

So the error here is on the order of 5 to 10%, but the results will depend on your exact input.

The blue dots on the IV curve below show the p_mp points in the old code. The black dots show the p_mp points in fixed code. These IV curves are generated using a fix for #83#83 that I'll make a PR for soon. They're also what led me to discovering the problem.

[ivcurves]https://cloud.githubusercontent.com/assets/4383303/17006598/cedaa96c-4e96-11e6-9e9a-64ed1377536c.png

On a related note, someone should put more effort into verifying that the matlab and python libraries give the same results. Not me.

You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHubhttps://github.com//issues/221, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AFJNL8QHFLEBDsIwVzBZAJkVsD2ruKNYks5qXrQLgaJpZM4JRUWz.

@wholmgren
Copy link
Member Author

Thanks, Cliff.

You could base your test on the example above, but you probably don't need as many points.

For slightly more realistic input, you could base your test on something similar to the test suite's test_singlediode_series_ivcurve function.

def test_singlediode_series_ivcurve(cec_module_params):
    times = pd.DatetimeIndex(start='2015-06-01', periods=3, freq='6H')
    poa_data = pd.Series([0, 400, 800], index=times)
    IL, I0, Rs, Rsh, nNsVth = pvsystem.calcparams_desoto(
                                         poa_data,
                                         temp_cell=25,
                                         alpha_isc=cec_module_params['alpha_sc'],
                                         module_parameters=cec_module_params,
                                         EgRef=1.121,
                                         dEgdT=-0.0002677)

    out = pvsystem.singlediode(IL, I0, Rs, Rsh, nNsVth, ivcurve_pnts=3)

    expected = OrderedDict([('i_sc', array([        nan,  3.01054475,  6.00675648])),
             ('v_oc', array([         nan,   9.96886962,  10.29530483])),
             ('i_mp', array([        nan,  2.65191983,  5.28594672])),
             ('v_mp', array([        nan,  8.33392491,  8.4159707 ])),
             ('p_mp', array([         nan,  22.10090078,  44.48637274])),
             ('i_x', array([        nan,  2.88414114,  5.74622046])),
             ('i_xx', array([        nan,  2.04340914,  3.90007956])),
             ('v',
              array([[         nan,          nan,          nan],
       [  0.        ,   4.98443481,   9.96886962],
       [  0.        ,   5.14765242,  10.29530483]])),
             ('i',
              array([[             nan,              nan,              nan],
       [  3.01079860e+00,   2.88414114e+00,   3.10862447e-14],
       [  6.00726296e+00,   5.74622046e+00,   0.00000000e+00]]))])

    for k, v in out.items():
        assert_allclose(expected[k], v, atol=1e-2)

The function is called with the 'Example_Module' parameters. Note that the numbers above are generated using the corrected solver.

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

No branches or pull requests

3 participants