|
| 1 | +import numpy as np |
| 2 | + |
| 3 | +import pytest |
| 4 | +from numpy.testing import assert_allclose |
| 5 | + |
| 6 | +from pvlib.ivtools.sdm._fit_desoto_pvsyst_sandia import ( |
| 7 | + _calc_theta_phi_exact, |
| 8 | + _update_rsh_fixed_pt, |
| 9 | + _update_io |
| 10 | +) |
| 11 | + |
| 12 | + |
| 13 | +@pytest.mark.parametrize('vmp, imp, iph, io, rs, rsh, nnsvth, expected', [ |
| 14 | + (2., 2., 2., 2., 2., 2., 2., np.nan), |
| 15 | + (2., 2., 0., 2., 2., 2., 2., np.nan), |
| 16 | + (2., 2., 2., 0., 2., 2., 2., np.nan), |
| 17 | + (2., 2., 2., 2., 0., 2., 2., np.nan), |
| 18 | + (2., 2., 2., 2., 2., 0., 2., np.nan), |
| 19 | + (2., 2., 2., 2., 2., 2., 0., np.nan)]) |
| 20 | +def test__update_rsh_fixed_pt_nans(vmp, imp, iph, io, rs, rsh, nnsvth, |
| 21 | + expected): |
| 22 | + outrsh = _update_rsh_fixed_pt(vmp, imp, iph, io, rs, rsh, nnsvth) |
| 23 | + assert np.all(np.isnan(outrsh)) |
| 24 | + |
| 25 | + |
| 26 | +def test__update_rsh_fixed_pt_vmp0(): |
| 27 | + outrsh = _update_rsh_fixed_pt(vmp=0., imp=2., iph=2., io=2., rs=2., |
| 28 | + rsh=2., nnsvth=2.) |
| 29 | + assert_allclose(outrsh, np.array([502.]), atol=.0001) |
| 30 | + |
| 31 | + |
| 32 | +def test__update_rsh_fixed_pt_vector(): |
| 33 | + outrsh = _update_rsh_fixed_pt(rsh=np.array([-1., 3, .5, 2.]), |
| 34 | + rs=np.array([1., -.5, 2., 2.]), |
| 35 | + io=np.array([.2, .3, -.4, 2.]), |
| 36 | + iph=np.array([-.1, 1, 3., 2.]), |
| 37 | + nnsvth=np.array([4., -.2, .1, 2.]), |
| 38 | + imp=np.array([.2, .2, -1., 2.]), |
| 39 | + vmp=np.array([0., -1, 0., 0.])) |
| 40 | + assert np.all(np.isnan(outrsh[0:3])) |
| 41 | + assert_allclose(outrsh[3], np.array([502.]), atol=.0001) |
| 42 | + |
| 43 | + |
| 44 | +@pytest.mark.parametrize('voc, iph, io, rs, rsh, nnsvth, expected', [ |
| 45 | + (2., 2., 2., 2., 2., 2., 0.5911), |
| 46 | + (2., 2., 2., 0., 2., 2., 0.5911), |
| 47 | + (2., 2., 0., 2., 2., 2., 0.), |
| 48 | + (2., 0., 2., 2., 2., 2., 1.0161e-4), |
| 49 | + (0., 2., 2., 2., 2., 2., 17.9436)]) |
| 50 | +def test__update_io(voc, iph, io, rs, rsh, nnsvth, expected): |
| 51 | + outio = _update_io(voc, iph, io, rs, rsh, nnsvth) |
| 52 | + assert_allclose(outio, expected, atol=.0001) |
| 53 | + |
| 54 | + |
| 55 | +@pytest.mark.parametrize('voc, iph, io, rs, rsh, nnsvth', [ |
| 56 | + (2., 2., 2., 2., 2., 0.), |
| 57 | + (-1., -1., -1., -1., -1., -1.)]) |
| 58 | +def test__update_io_nan(voc, iph, io, rs, rsh, nnsvth): |
| 59 | + outio = _update_io(voc, iph, io, rs, rsh, nnsvth) |
| 60 | + assert np.isnan(outio) |
| 61 | + |
| 62 | + |
| 63 | +@pytest.mark.parametrize('vmp, imp, iph, io, rs, rsh, nnsvth, expected', [ |
| 64 | + (2., 2., 2., 2., 2., 2., 2., (1.8726, 2.)), |
| 65 | + (2., 0., 2., 2., 2., 2., 2., (1.8726, 3.4537)), |
| 66 | + (2., 2., 0., 2., 2., 2., 2., (1.2650, 0.8526)), |
| 67 | + (0., 2., 2., 2., 2., 2., 2., (1.5571, 2.))]) |
| 68 | +def test__calc_theta_phi_exact(vmp, imp, iph, io, rs, rsh, nnsvth, expected): |
| 69 | + theta, phi = _calc_theta_phi_exact(vmp, imp, iph, io, rs, rsh, nnsvth) |
| 70 | + assert_allclose(theta, expected[0], atol=.0001) |
| 71 | + assert_allclose(phi, expected[1], atol=.0001) |
| 72 | + |
| 73 | + |
| 74 | +@pytest.mark.parametrize('vmp, imp, iph, io, rs, rsh, nnsvth', [ |
| 75 | + (2., 2., 2., 0., 2., 2., 2.), |
| 76 | + (2., 2., 2., 2., 2., 2., 0.), |
| 77 | + (2., 0., 2., 2., 2., 0., 2.)]) |
| 78 | +def test__calc_theta_phi_exact_both_nan(vmp, imp, iph, io, rs, rsh, nnsvth): |
| 79 | + theta, phi = _calc_theta_phi_exact(vmp, imp, iph, io, rs, rsh, nnsvth) |
| 80 | + assert np.isnan(theta) |
| 81 | + assert np.isnan(phi) |
| 82 | + |
| 83 | + |
| 84 | +def test__calc_theta_phi_exact_one_nan(): |
| 85 | + theta, phi = _calc_theta_phi_exact(imp=2., iph=2., vmp=2., io=2., |
| 86 | + nnsvth=2., rs=0., rsh=2.) |
| 87 | + assert np.isnan(theta) |
| 88 | + assert_allclose(phi, 2., atol=.0001) |
| 89 | + |
| 90 | + |
| 91 | +def test__calc_theta_phi_exact_vector(): |
| 92 | + theta, phi = _calc_theta_phi_exact(imp=np.array([1., -1.]), |
| 93 | + iph=np.array([-1., 1.]), |
| 94 | + vmp=np.array([1., -1.]), |
| 95 | + io=np.array([-1., 1.]), |
| 96 | + nnsvth=np.array([1., -1.]), |
| 97 | + rs=np.array([-1., 1.]), |
| 98 | + rsh=np.array([1., -1.])) |
| 99 | + assert np.isnan(theta[0]) |
| 100 | + assert np.isnan(theta[1]) |
| 101 | + assert np.isnan(phi[0]) |
| 102 | + assert_allclose(phi[1], 2.2079, atol=.0001) |
0 commit comments