From 6da6eaa34286984df06565acddfb62af29917446 Mon Sep 17 00:00:00 2001 From: Kevin Anderson Date: Fri, 3 Dec 2021 22:00:09 -0500 Subject: [PATCH 1/6] add test --- pvfactors/tests/test_engine.py | 38 ++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/pvfactors/tests/test_engine.py b/pvfactors/tests/test_engine.py index e537534..d486216 100644 --- a/pvfactors/tests/test_engine.py +++ b/pvfactors/tests/test_engine.py @@ -562,6 +562,44 @@ def test_check_direct_shading_continuity(): np.testing.assert_allclose(out, expected_out) +def test_check_tilt_zero_discontinuity(): + """ + Before version 1.5.2, surface_tilt=0 with certain combinations of + surface_azimuth and axis_azimuth showed anomolous behavior where + the irradiance at zero tilt was significantly different from the + irradiance at very small but nonzero tilts. See GH #125 + """ + # expected value calculated for surface_tilt=0.001, so should + # not be significantly different from result for surface_tilt=0 + rear_qinc_expected = 76.10 + + timestamps = np.array([dt.datetime(2019, 6, 1, 10)]) + solar_azimuth = np.array([135]) + solar_zenith = np.array([45]) + dni = np.array([200]) + dhi = np.array([400]) + albedo = np.array([0.2]) + surface_tilt = np.array([0.0]) + + # the discontinuity did not occur for all combinations of + # (surface_azimuth, axis_azimuth), so test all four "primary" pairs: + for surface_azimuth in [90, 270]: + surface_azimuth = np.array([surface_azimuth]) + for axis_azimuth in [0, 180]: + params = dict(n_pvrows=3, axis_azimuth=axis_azimuth, + pvrow_height=2, pvrow_width=1, gcr=0.4) + + pvarray = OrderedPVArray.init_from_dict(params) + eng = PVEngine(pvarray) + eng.fit(timestamps, dni, dhi, solar_zenith, solar_azimuth, + surface_tilt, surface_azimuth, albedo) + + # Run simulation and get output + eng.run_full_mode() + out = pvarray.ts_pvrows[1].back.get_param_weighted('qinc') + assert rear_qinc_expected == pytest.approx(out[0], abs=1e-2) + + def test_create_engine_with_rho_init(params, pvmodule_canadian): """Check that can create PV engine with rho initialization from faoi functions""" From a13db323c6312eec9c0988ed0bbe4e2aac467438 Mon Sep 17 00:00:00 2001 From: Kevin Anderson Date: Fri, 3 Dec 2021 22:00:21 -0500 Subject: [PATCH 2/6] add weird bug fix --- pvfactors/geometry/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pvfactors/geometry/base.py b/pvfactors/geometry/base.py index a390bab..7b19577 100644 --- a/pvfactors/geometry/base.py +++ b/pvfactors/geometry/base.py @@ -122,7 +122,7 @@ def _get_rotation_from_tilt_azimuth(surface_azimuth, axis_azimuth, tilt): # Calculate rotation of PV row (signed tilt angle) is_pointing_right = ((surface_azimuth - axis_azimuth) % 360.) > 180. rotation = np.where(is_pointing_right, tilt, -tilt) - + rotation = np.where(tilt == 0, -0.0, rotation) # GH 125 return rotation From 28326221e12f550621154c0b29ee5ab80bd47501 Mon Sep 17 00:00:00 2001 From: Kevin Anderson Date: Sat, 4 Dec 2021 08:06:29 -0500 Subject: [PATCH 3/6] assert vf values in [0, 1] --- pvfactors/tests/test_engine.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pvfactors/tests/test_engine.py b/pvfactors/tests/test_engine.py index d486216..609d7fd 100644 --- a/pvfactors/tests/test_engine.py +++ b/pvfactors/tests/test_engine.py @@ -597,6 +597,8 @@ def test_check_tilt_zero_discontinuity(): # Run simulation and get output eng.run_full_mode() out = pvarray.ts_pvrows[1].back.get_param_weighted('qinc') + assert np.all(pvarray.ts_vf_matrix >= 0) + assert np.all(pvarray.ts_vf_matrix <= 1) assert rear_qinc_expected == pytest.approx(out[0], abs=1e-2) From 0d545950135200b74799a056cf6e31d582ad2cf9 Mon Sep 17 00:00:00 2001 From: Kevin Anderson Date: Sat, 4 Dec 2021 08:07:08 -0500 Subject: [PATCH 4/6] update comment --- pvfactors/tests/test_engine.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pvfactors/tests/test_engine.py b/pvfactors/tests/test_engine.py index 609d7fd..7560471 100644 --- a/pvfactors/tests/test_engine.py +++ b/pvfactors/tests/test_engine.py @@ -567,7 +567,8 @@ def test_check_tilt_zero_discontinuity(): Before version 1.5.2, surface_tilt=0 with certain combinations of surface_azimuth and axis_azimuth showed anomolous behavior where the irradiance at zero tilt was significantly different from the - irradiance at very small but nonzero tilts. See GH #125 + irradiance at very small but nonzero tilts. Additionally, the + calculated VF matrix could have values outside [0, 1]. See GH #125 """ # expected value calculated for surface_tilt=0.001, so should # not be significantly different from result for surface_tilt=0 From 4fdfbbce206b74d8d96aa9ccffff5d157965617e Mon Sep 17 00:00:00 2001 From: Kevin Anderson Date: Sat, 4 Dec 2021 10:07:13 -0500 Subject: [PATCH 5/6] whatsnew --- docs/sphinx/whatsnew/v1.5.2.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/sphinx/whatsnew/v1.5.2.rst b/docs/sphinx/whatsnew/v1.5.2.rst index 0bf7281..ce9df6f 100644 --- a/docs/sphinx/whatsnew/v1.5.2.rst +++ b/docs/sphinx/whatsnew/v1.5.2.rst @@ -16,9 +16,11 @@ Fixes output moving forward, the pvlib dependency is updated from ``pvlib>=0.7.0,<0.9.0`` to ``pvlib>=0.9.0,<0.10.0``. This will likely change the results of irradiance simulations. According to the - [pvlib release notes](https://pvlib-python.readthedocs.io/en/v0.9.0/whatsnew.html#bug-fixes), + `pvlib release notes `_, the differences are "expected to be small and primarily occur at low irradiance conditions". (:ghpull:`121`) +* Fixed a bug that affected some irradiance simulations when `surface_tilt` is exactly zero. + See `GH #125 `_ for details. (:ghpull:`128`) Contributors From 0c96ce036aee9e2350b9130670d2cda872692ee7 Mon Sep 17 00:00:00 2001 From: Kevin Anderson Date: Tue, 7 Dec 2021 13:28:52 -0500 Subject: [PATCH 6/6] switch to in-place editing instead of np.where --- pvfactors/geometry/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pvfactors/geometry/base.py b/pvfactors/geometry/base.py index 7b19577..4cc7d1d 100644 --- a/pvfactors/geometry/base.py +++ b/pvfactors/geometry/base.py @@ -122,7 +122,7 @@ def _get_rotation_from_tilt_azimuth(surface_azimuth, axis_azimuth, tilt): # Calculate rotation of PV row (signed tilt angle) is_pointing_right = ((surface_azimuth - axis_azimuth) % 360.) > 180. rotation = np.where(is_pointing_right, tilt, -tilt) - rotation = np.where(tilt == 0, -0.0, rotation) # GH 125 + rotation[tilt == 0] = -0.0 # GH 125 return rotation