@@ -304,3 +304,36 @@ def test_fit_pvsyst_iec61853_sandia_optional(pvsyst_iec61853_table3,
304304 min_Rsh_irradiance = 500 )
305305 assert not np .isclose (fitted_params ['R_sh_ref' ], expected ['R_sh_ref' ],
306306 atol = 0 , rtol = 1e-3 )
307+
308+
309+ @requires_statsmodels
310+ def test_fit_pvsyst_iec61853_sandia_tolerance (pvsyst_iec61853_table3 ,
311+ iec61853_conditions ):
312+ # verify that the *_tolerance parameters allow non-"perfect" irradiance
313+ # and temperature values
314+ ee , tc = iec61853_conditions
315+ ee [ee == 1000 ] = 999
316+ tc [tc == 25 ] = 25.1
317+ case = pvsyst_iec61853_table3 ['high current' ]
318+ true_params = case ['true' ]
319+ expected = case ['estimated' ]
320+ sde_params = pvsystem .calcparams_pvsyst (ee , tc , ** true_params )
321+ iv = pvsystem .singlediode (* sde_params )
322+
323+ inputs = dict (
324+ effective_irradiance = ee , temp_cell = tc , i_sc = iv ['i_sc' ],
325+ v_oc = iv ['v_oc' ], i_mp = iv ['i_mp' ], v_mp = iv ['v_mp' ],
326+ cells_in_series = true_params ['cells_in_series' ]
327+ )
328+ fitted_params = sdm .fit_pvsyst_iec61853_sandia (** inputs )
329+ # still get approximately the expected values
330+ for key in expected .keys ():
331+ assert np .isclose (fitted_params [key ], expected [key ], atol = 0 , rtol = 1e-2 )
332+
333+ # but if the changes exceed the specified tolerance, then error:
334+ with pytest .raises (ValueError , match = 'Coefficient array is empty' ):
335+ sdm .fit_pvsyst_iec61853_sandia (** inputs , irradiance_tolerance = 0.1 )
336+
337+ with pytest .raises (ValueError , match = 'can only convert an array of size 1' ):
338+ sdm .fit_pvsyst_iec61853_sandia (** inputs , temperature_tolerance = 0.1 )
339+
0 commit comments