def test_newton_fs_495(method, cec_module_fs_495): """test pvsystem.singlediode with different methods on FS495""" fs_495 = cec_module_fs_495 x = pvsystem.calcparams_desoto( effective_irradiance=POA, temp_cell=TCELL, alpha_sc=fs_495['alpha_sc'], a_ref=fs_495['a_ref'], I_L_ref=fs_495['I_L_ref'], I_o_ref=fs_495['I_o_ref'], R_sh_ref=fs_495['R_sh_ref'], R_s=fs_495['R_s'], EgRef=1.475, dEgdT=-0.0003) il, io, rs, rsh, nnsvt = x x += (101, ) pvs = pvsystem.singlediode(*x, method='lambertw') out = pvsystem.singlediode(*x, method=method) isc, voc, imp, vmp, pmp, ix, ixx, i, v = out.values() assert np.isclose(pvs['i_sc'], isc) assert np.isclose(pvs['v_oc'], voc) # the singlediode method doesn't actually get the MPP correct pvs_imp = pvsystem.i_from_v(rsh, rs, nnsvt, vmp, io, il, method='lambertw') pvs_vmp = pvsystem.v_from_i(rsh, rs, nnsvt, imp, io, il, method='lambertw') assert np.isclose(pvs_imp, imp) assert np.isclose(pvs_vmp, vmp) assert np.isclose(pvs['p_mp'], pmp) assert np.isclose(pvs['i_x'], ix) pvs_ixx = pvsystem.i_from_v(rsh, rs, nnsvt, (voc + vmp)/2, io, il, method='lambertw') assert np.isclose(pvs_ixx, ixx)
def test_brentq_spr_e20_327(): """test pvsystem.singlediode with Brent method on SPR-E20-327""" spr_e20_327 = CECMOD.SunPower_SPR_E20_327 x = pvsystem.calcparams_desoto( effective_irradiance=POA, temp_cell=TCELL, alpha_sc=spr_e20_327.alpha_sc, a_ref=spr_e20_327.a_ref, I_L_ref=spr_e20_327.I_L_ref, I_o_ref=spr_e20_327.I_o_ref, R_sh_ref=spr_e20_327.R_sh_ref, R_s=spr_e20_327.R_s, EgRef=1.121, dEgdT=-0.0002677) il, io, rs, rsh, nnsvt = x pvs = pvsystem.singlediode(*x, method='lambertw') out = pvsystem.singlediode(*x, method='brentq') isc, voc, imp, vmp, pmp, ix, ixx = out.values() assert np.isclose(pvs['i_sc'], isc) assert np.isclose(pvs['v_oc'], voc) # the singlediode method doesn't actually get the MPP correct pvs_imp = pvsystem.i_from_v(rsh, rs, nnsvt, vmp, io, il, method='lambertw') pvs_vmp = pvsystem.v_from_i(rsh, rs, nnsvt, imp, io, il, method='lambertw') assert np.isclose(pvs_imp, imp) assert np.isclose(pvs_vmp, vmp) assert np.isclose(pvs['p_mp'], pmp) assert np.isclose(pvs['i_x'], ix) pvs_ixx = pvsystem.i_from_v(rsh, rs, nnsvt, (voc + vmp)/2, io, il, method='lambertw') assert np.isclose(pvs_ixx, ixx) return isc, voc, imp, vmp, pmp, pvs
def test_method_spr_e20_327(method, cec_module_spr_e20_327): """test pvsystem.singlediode with different methods on SPR-E20-327""" spr_e20_327 = cec_module_spr_e20_327 x = pvsystem.calcparams_desoto( effective_irradiance=POA, temp_cell=TCELL, alpha_sc=spr_e20_327['alpha_sc'], a_ref=spr_e20_327['a_ref'], I_L_ref=spr_e20_327['I_L_ref'], I_o_ref=spr_e20_327['I_o_ref'], R_sh_ref=spr_e20_327['R_sh_ref'], R_s=spr_e20_327['R_s'], EgRef=1.121, dEgdT=-0.0002677) il, io, rs, rsh, nnsvt = x pvs = pvsystem.singlediode(*x, method='lambertw') out = pvsystem.singlediode(*x, method=method) isc, voc, imp, vmp, pmp, ix, ixx = out.values() assert np.isclose(pvs['i_sc'], isc) assert np.isclose(pvs['v_oc'], voc) # the singlediode method doesn't actually get the MPP correct pvs_imp = pvsystem.i_from_v(rsh, rs, nnsvt, vmp, io, il, method='lambertw') pvs_vmp = pvsystem.v_from_i(rsh, rs, nnsvt, imp, io, il, method='lambertw') assert np.isclose(pvs_imp, imp) assert np.isclose(pvs_vmp, vmp) assert np.isclose(pvs['p_mp'], pmp) assert np.isclose(pvs['i_x'], ix) pvs_ixx = pvsystem.i_from_v(rsh, rs, nnsvt, (voc + vmp)/2, io, il, method='lambertw') assert np.isclose(pvs_ixx, ixx)
def test_brentq_spr_e20_327(): """test pvsystem.singlediode with Brent method on SPR-E20-327""" spr_e20_327 = CECMOD.SunPower_SPR_E20_327 x = pvsystem.calcparams_desoto(effective_irradiance=POA, temp_cell=TCELL, alpha_sc=spr_e20_327.alpha_sc, a_ref=spr_e20_327.a_ref, I_L_ref=spr_e20_327.I_L_ref, I_o_ref=spr_e20_327.I_o_ref, R_sh_ref=spr_e20_327.R_sh_ref, R_s=spr_e20_327.R_s, EgRef=1.121, dEgdT=-0.0002677) il, io, rs, rsh, nnsvt = x pvs = pvsystem.singlediode(*x, method='lambertw') out = pvsystem.singlediode(*x, method='brentq') isc, voc, imp, vmp, pmp, ix, ixx = out.values() assert np.isclose(pvs['i_sc'], isc) assert np.isclose(pvs['v_oc'], voc) # the singlediode method doesn't actually get the MPP correct pvs_imp = pvsystem.i_from_v(rsh, rs, nnsvt, vmp, io, il, method='lambertw') pvs_vmp = pvsystem.v_from_i(rsh, rs, nnsvt, imp, io, il, method='lambertw') assert np.isclose(pvs_imp, imp) assert np.isclose(pvs_vmp, vmp) assert np.isclose(pvs['p_mp'], pmp) assert np.isclose(pvs['i_x'], ix) pvs_ixx = pvsystem.i_from_v(rsh, rs, nnsvt, (voc + vmp) / 2, io, il, method='lambertw') assert np.isclose(pvs_ixx, ixx) return isc, voc, imp, vmp, pmp, pvs
def test_newton_fs_495(): """test pvsystem.singlediode with Newton method on FS495""" fs_495 = CECMOD.First_Solar_FS_495 x = pvsystem.calcparams_desoto( effective_irradiance=POA, temp_cell=TCELL, alpha_sc=fs_495.alpha_sc, a_ref=fs_495.a_ref, I_L_ref=fs_495.I_L_ref, I_o_ref=fs_495.I_o_ref, R_sh_ref=fs_495.R_sh_ref, R_s=fs_495.R_s, EgRef=1.475, dEgdT=-0.0003) il, io, rs, rsh, nnsvt = x x += (101, ) pvs = pvsystem.singlediode(*x, method='lambertw') out = pvsystem.singlediode(*x, method='newton') isc, voc, imp, vmp, pmp, ix, ixx, i, v = out.values() assert np.isclose(pvs['i_sc'], isc) assert np.isclose(pvs['v_oc'], voc) # the singlediode method doesn't actually get the MPP correct pvs_imp = pvsystem.i_from_v(rsh, rs, nnsvt, vmp, io, il, method='lambertw') pvs_vmp = pvsystem.v_from_i(rsh, rs, nnsvt, imp, io, il, method='lambertw') assert np.isclose(pvs_imp, imp) assert np.isclose(pvs_vmp, vmp) assert np.isclose(pvs['p_mp'], pmp) assert np.isclose(pvs['i_x'], ix) pvs_ixx = pvsystem.i_from_v(rsh, rs, nnsvt, (voc + vmp)/2, io, il, method='lambertw') assert np.isclose(pvs_ixx, ixx) return isc, voc, imp, vmp, pmp, i, v, pvs
def test_i_from_v_from_i(fixture_v_from_i): # Solution set loaded from fixture Rsh = fixture_v_from_i['Rsh'] Rs = fixture_v_from_i['Rs'] nNsVth = fixture_v_from_i['nNsVth'] I = fixture_v_from_i['I'] I0 = fixture_v_from_i['I0'] IL = fixture_v_from_i['IL'] V = fixture_v_from_i['V_expected'] # Convergence criteria atol = 1.e-11 I_expected = pvsystem.i_from_v(Rsh, Rs, nNsVth, V, I0, IL, method='lambertw') assert_allclose(I, I_expected, atol=atol) I = pvsystem.i_from_v(Rsh, Rs, nNsVth, V, I0, IL) assert (isinstance(I, type(I_expected))) if isinstance(I, type(np.ndarray)): assert (isinstance(I.dtype, type(I_expected.dtype))) assert (I.shape == I_expected.shape) assert_allclose(I, I_expected, atol=atol)
def test_newton_fs_495(): """test pvsystem.singlediode with Newton method on FS495""" fs_495 = CECMOD.First_Solar_FS_495 x = pvsystem.calcparams_desoto(effective_irradiance=POA, temp_cell=TCELL, alpha_sc=fs_495.alpha_sc, a_ref=fs_495.a_ref, I_L_ref=fs_495.I_L_ref, I_o_ref=fs_495.I_o_ref, R_sh_ref=fs_495.R_sh_ref, R_s=fs_495.R_s, EgRef=1.475, dEgdT=-0.0003) il, io, rs, rsh, nnsvt = x x += (101, ) pvs = pvsystem.singlediode(*x, method='lambertw') out = pvsystem.singlediode(*x, method='newton') isc, voc, imp, vmp, pmp, ix, ixx, i, v = out.values() assert np.isclose(pvs['i_sc'], isc) assert np.isclose(pvs['v_oc'], voc) # the singlediode method doesn't actually get the MPP correct pvs_imp = pvsystem.i_from_v(rsh, rs, nnsvt, vmp, io, il, method='lambertw') pvs_vmp = pvsystem.v_from_i(rsh, rs, nnsvt, imp, io, il, method='lambertw') assert np.isclose(pvs_imp, imp) assert np.isclose(pvs_vmp, vmp) assert np.isclose(pvs['p_mp'], pmp) assert np.isclose(pvs['i_x'], ix) pvs_ixx = pvsystem.i_from_v(rsh, rs, nnsvt, (voc + vmp) / 2, io, il, method='lambertw') assert np.isclose(pvs_ixx, ixx) return isc, voc, imp, vmp, pmp, i, v, pvs
def test_singlediode_array(): # github issue 221 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, method='lambertw') expected = np.array([ 0., 0.54538398, 1.43273966, 2.36328163, 3.29255606, 4.23101358, 5.16177031, 6.09368251, 7.02197553, 7.96846051, 8.88220557 ]) assert_allclose(sd['i_mp'], expected, atol=0.01) sd = pvsystem.singlediode(photocurrent, saturation_current, resistance_series, resistance_shunt, nNsVth) expected = pvsystem.i_from_v(resistance_shunt, resistance_series, nNsVth, sd['v_mp'], saturation_current, photocurrent, method='lambertw') assert_allclose(sd['i_mp'], expected, atol=0.01)
def test_i_from_v(fixture_i_from_v, method, atol): # Solution set loaded from fixture Rsh = fixture_i_from_v['Rsh'] Rs = fixture_i_from_v['Rs'] nNsVth = fixture_i_from_v['nNsVth'] V = fixture_i_from_v['V'] I0 = fixture_i_from_v['I0'] IL = fixture_i_from_v['IL'] I_expected = fixture_i_from_v['I_expected'] I = pvsystem.i_from_v(Rsh, Rs, nNsVth, V, I0, IL, method=method) assert (isinstance(I, type(I_expected))) if isinstance(I, type(np.ndarray)): assert (isinstance(I.dtype, type(I_expected.dtype))) assert (I.shape == I_expected.shape) assert_allclose(I, I_expected, atol=atol)
def test_i_from_v(fixture_i_from_v): # Solution set loaded from fixture Rsh = fixture_i_from_v['Rsh'] Rs = fixture_i_from_v['Rs'] nNsVth = fixture_i_from_v['nNsVth'] V = fixture_i_from_v['V'] I0 = fixture_i_from_v['I0'] IL = fixture_i_from_v['IL'] I_expected = fixture_i_from_v['I_expected'] # Convergence criteria atol = 1.e-11 I = pvsystem.i_from_v(Rsh, Rs, nNsVth, V, I0, IL) assert(isinstance(I, type(I_expected))) if isinstance(I, type(np.ndarray)): assert(isinstance(I.dtype, type(I_expected.dtype))) assert(I.shape == I_expected.shape) assert_allclose(I, I_expected, atol=atol)
def test_i_from_v_size(): with pytest.raises(ValueError): pvsystem.i_from_v(20, [0.1] * 2, 0.5, [7.5] * 3, 6.0e-7, 7.0) with pytest.raises(ValueError): pvsystem.i_from_v(20, [0.1] * 2, 0.5, [7.5] * 3, 6.0e-7, 7.0, method='brentq') with pytest.raises(ValueError): pvsystem.i_from_v(20, 0.1, 0.5, [7.5] * 3, 6.0e-7, np.array([7., 7.]), method='newton')
def test_i_from_v(): output = pvsystem.i_from_v(20, .1, .5, 40, 6e-7, 7) assert_almost_equals(-299.746389916, output, 5)
def test_i_from_v(): output = pvsystem.i_from_v(20, .1, .5, 40, 6e-7, 7) assert_allclose(-299.746389916, output, atol=1e-5)
def test_singlediode_series_ivcurve(cec_module_params): times = pd.date_range(start='2015-06-01', periods=3, freq='6H') effective_irradiance = pd.Series([0.0, 400.0, 800.0], index=times) IL, I0, Rs, Rsh, nNsVth = pvsystem.calcparams_desoto( effective_irradiance, temp_cell=25, alpha_sc=cec_module_params['alpha_sc'], a_ref=cec_module_params['a_ref'], I_L_ref=cec_module_params['I_L_ref'], I_o_ref=cec_module_params['I_o_ref'], R_sh_ref=cec_module_params['R_sh_ref'], R_s=cec_module_params['R_s'], EgRef=1.121, dEgdT=-0.0002677) out = pvsystem.singlediode(IL, I0, Rs, Rsh, nNsVth, ivcurve_pnts=3, method='lambertw') expected = OrderedDict([ ('i_sc', array([0., 3.01054475, 6.00675648])), ('v_oc', array([0., 9.96886962, 10.29530483])), ('i_mp', array([0., 2.65191983, 5.28594672])), ('v_mp', array([0., 8.33392491, 8.4159707])), ('p_mp', array([0., 22.10090078, 44.48637274])), ('i_x', array([0., 2.88414114, 5.74622046])), ('i_xx', array([0., 2.04340914, 3.90007956])), ('v', array([[0., 0., 0.], [0., 4.98443481, 9.96886962], [0., 5.14765242, 10.29530483]])), ('i', array([[0., 0., 0.], [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(v, expected[k], atol=1e-2) out = pvsystem.singlediode(IL, I0, Rs, Rsh, nNsVth, ivcurve_pnts=3) expected['i_mp'] = pvsystem.i_from_v(Rsh, Rs, nNsVth, out['v_mp'], I0, IL, method='lambertw') expected['v_mp'] = pvsystem.v_from_i(Rsh, Rs, nNsVth, out['i_mp'], I0, IL, method='lambertw') expected['i'] = pvsystem.i_from_v(Rsh, Rs, nNsVth, out['v'].T, I0, IL, method='lambertw').T expected['v'] = pvsystem.v_from_i(Rsh, Rs, nNsVth, out['i'].T, I0, IL, method='lambertw').T for k, v in out.items(): assert_allclose(v, expected[k], atol=1e-2)
def test_i_from_v(): output = pvsystem.i_from_v(20, .1, .5, 40, 6e-7, 7) assert_almost_equals(-299.746389916, output, 5)
def test_i_from_v(): output = pvsystem.i_from_v(20, .1, .5, 40, 6e-7, 7) assert_allclose(-299.746389916, output, atol=1e-5)