From a6be60afa8023c3a7857414fb9f1cf77e0c8fb21 Mon Sep 17 00:00:00 2001 From: Lakshya Garg <72099449+Lakshyadevelops@users.noreply.github.com> Date: Fri, 24 Mar 2023 02:02:41 +0530 Subject: [PATCH 01/16] added pvl_louche --- pvlib/irradiance.py | 48 ++++++++++++++++++++++++++++++++++ pvlib/tests/test_irradiance.py | 15 +++++++++++ 2 files changed, 63 insertions(+) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index 83527c7604..5ff68ccc8e 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -3117,3 +3117,51 @@ def complete_irradiance(solar_zenith, 'dhi': dhi, 'dni': dni}) return component_sum_df + + +def pvl_louche(ghi, zenith, datetime_or_doy): + """ + Determine DNI and GHI from GHI using louche model. + + Parameters + ---------- + ghi : Series + Global horizontal irradiance. + + zenith : Series + True (not refraction-corrected) zenith angles in decimal + degrees. Angles must be >=0 and <=180. + + datetime_or_doy : numeric, pandas.DatetimeIndex + Day of year or array of days of year e.g. + pd.DatetimeIndex.dayofyear, or pd.DatetimeIndex. + + Returns + ------- + dni : Series + The modeled direct normal irradiance. + + dhi : Series + The modeled diffused horizontal irradiance + + kt : Series + Clearness index + + References + ------- + .. [1] Louche A, Notton G, Poggi P, Simmonnot G. Correlations for direct normal and global horizontal irradiation on French Mediterranean site. Solar Energy 1991;46:261-6 + + """ + # this is the I0 calculation from the reference + # SSC uses solar constant = 1366.1 + I0 = get_extra_radiation(datetime_or_doy) + + I0h = I0*tools.cosd(zenith) + Kt = ghi/I0h + pd.Series.clip(Kt, 0, inplace=True) + kb = -10.627*Kt**5 + 15.307*Kt**4 - 5.205 * \ + Kt**3 + 0.994*Kt**2 - 0.059*Kt + 0.002 + dni = kb*I0 + dhi = ghi-dni*tools.cosd(zenith) + + return dni, dhi, Kt diff --git a/pvlib/tests/test_irradiance.py b/pvlib/tests/test_irradiance.py index cffdd23e40..b39b1e432d 100644 --- a/pvlib/tests/test_irradiance.py +++ b/pvlib/tests/test_irradiance.py @@ -1203,3 +1203,18 @@ def test_complete_irradiance(): dhi=None, dni=i.dni, dni_clear=clearsky.dni) + + +def test_pvl_louche(): + times = pd.DatetimeIndex(['2016-07-19 06:11:00'], tz='America/Phoenix') + out_dni,out_dhi,out_kt = irradiance.pvl_louche(ghi=1.0, zenith=89.99, + datetime_or_doy=times) + expected_dni=pd.Series(np.array([0.00000000e+00]),index=times) + # expected_dhi=pd.Series(np.array([8.72544336e+02]),index=times) + expected_kt=pd.Series(np.array([1.16046346e-02]),index=times) + assert_series_equal(out_dni,expected_dni) + # assert_series_equal(out_dhi,expected_dhi) + assert_series_equal(out_kt,expected_kt) + + + \ No newline at end of file From 125a6ad2d036b3266f829c6d816b4ad555813c41 Mon Sep 17 00:00:00 2001 From: Lakshya Garg <72099449+Lakshyadevelops@users.noreply.github.com> Date: Fri, 24 Mar 2023 02:09:13 +0530 Subject: [PATCH 02/16] stickler --- pvlib/tests/test_irradiance.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/pvlib/tests/test_irradiance.py b/pvlib/tests/test_irradiance.py index b39b1e432d..e7f456c4e6 100644 --- a/pvlib/tests/test_irradiance.py +++ b/pvlib/tests/test_irradiance.py @@ -246,6 +246,7 @@ def test_haydavies_components(irrad_data, ephem_data, dni_et): assert_allclose(result['horizon'], expected['horizon'][-1], atol=1e-4) assert isinstance(result, dict) + def test_reindl(irrad_data, ephem_data, dni_et): result = irradiance.reindl( 40, 180, irrad_data['dhi'], irrad_data['dni'], irrad_data['ghi'], @@ -903,8 +904,12 @@ def test_dirindex(times): assert np.allclose(out, expected_out, rtol=tolerance, atol=0, equal_nan=True) tol_dirint = 0.2 - assert np.allclose(out.values, dirint_close_values, rtol=tol_dirint, atol=0, - equal_nan=True) + assert np.allclose( + out.values, + dirint_close_values, + rtol=tol_dirint, + atol=0, + equal_nan=True) def test_dirindex_min_cos_zenith_max_zenith(): @@ -1207,14 +1212,11 @@ def test_complete_irradiance(): def test_pvl_louche(): times = pd.DatetimeIndex(['2016-07-19 06:11:00'], tz='America/Phoenix') - out_dni,out_dhi,out_kt = irradiance.pvl_louche(ghi=1.0, zenith=89.99, - datetime_or_doy=times) - expected_dni=pd.Series(np.array([0.00000000e+00]),index=times) + out_dni, out_dhi, out_kt = irradiance.pvl_louche(ghi=1.0, zenith=89.99, + datetime_or_doy=times) + expected_dni = pd.Series(np.array([0.00000000e+00]), index=times) # expected_dhi=pd.Series(np.array([8.72544336e+02]),index=times) - expected_kt=pd.Series(np.array([1.16046346e-02]),index=times) - assert_series_equal(out_dni,expected_dni) + expected_kt = pd.Series(np.array([1.16046346e-02]), index=times) + assert_series_equal(out_dni, expected_dni) # assert_series_equal(out_dhi,expected_dhi) - assert_series_equal(out_kt,expected_kt) - - - \ No newline at end of file + assert_series_equal(out_kt, expected_kt) From d0cb26d2d4faea04ba49ccedba5398efb8fd5642 Mon Sep 17 00:00:00 2001 From: Lakshya Garg <72099449+Lakshyadevelops@users.noreply.github.com> Date: Tue, 28 Mar 2023 03:12:51 +0530 Subject: [PATCH 03/16] add tests --- pvlib/irradiance.py | 44 +++++++++++++++++++++++----------- pvlib/tests/test_irradiance.py | 25 ++++++++++++------- 2 files changed, 46 insertions(+), 23 deletions(-) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index 5ff68ccc8e..81b3f5ae55 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -3119,14 +3119,14 @@ def complete_irradiance(solar_zenith, return component_sum_df -def pvl_louche(ghi, zenith, datetime_or_doy): +def pvl_louche(ghi, solar_zenith, datetime_or_doy): """ Determine DNI and GHI from GHI using louche model. Parameters ---------- ghi : Series - Global horizontal irradiance. + Global horizontal irradiance. [W/m^2] zenith : Series True (not refraction-corrected) zenith angles in decimal @@ -3135,33 +3135,49 @@ def pvl_louche(ghi, zenith, datetime_or_doy): datetime_or_doy : numeric, pandas.DatetimeIndex Day of year or array of days of year e.g. pd.DatetimeIndex.dayofyear, or pd.DatetimeIndex. - + Returns ------- - dni : Series - The modeled direct normal irradiance. - - dhi : Series - The modeled diffused horizontal irradiance - - kt : Series - Clearness index + data: OrderedDict or DataFrame + Contains the following keys/columns: + + * ``dni``: the modeled direct normal irradiance in W/m^2. + * ``dhi``: the modeled diffuse horizontal irradiance in + W/m^2. + * ``kt``: Ratio of global to extraterrestrial irradiance + on a horizontal plane. References ------- .. [1] Louche A, Notton G, Poggi P, Simmonnot G. Correlations for direct normal and global horizontal irradiation on French Mediterranean site. Solar Energy 1991;46:261-6 """ + bool=np.logical_or(solar_zenith>180,solar_zenith < 0) + solar_zenith=np.where(bool,np.NaN,solar_zenith) + + if np.isscalar(datetime_or_doy): + bool=(np.any(datetime_or_doy>366 or datetime_or_doy < 1,axis=0)) + print(bool) + datetime_or_doy=np.where(bool,np.NaN,datetime_or_doy) + # this is the I0 calculation from the reference # SSC uses solar constant = 1366.1 I0 = get_extra_radiation(datetime_or_doy) - I0h = I0*tools.cosd(zenith) + I0h = I0*tools.cosd(solar_zenith) Kt = ghi/I0h pd.Series.clip(Kt, 0, inplace=True) kb = -10.627*Kt**5 + 15.307*Kt**4 - 5.205 * \ Kt**3 + 0.994*Kt**2 - 0.059*Kt + 0.002 dni = kb*I0 - dhi = ghi-dni*tools.cosd(zenith) + dhi = ghi-dni*tools.cosd(solar_zenith) - return dni, dhi, Kt + data=OrderedDict() + data['dni']=dni + data['dhi']=dhi + data['kt']=Kt + + if isinstance(datetime_or_doy, pd.DatetimeIndex): + data = pd.DataFrame(data, index=datetime_or_doy) + + return data diff --git a/pvlib/tests/test_irradiance.py b/pvlib/tests/test_irradiance.py index e7f456c4e6..0c721cd2eb 100644 --- a/pvlib/tests/test_irradiance.py +++ b/pvlib/tests/test_irradiance.py @@ -1211,12 +1211,19 @@ def test_complete_irradiance(): def test_pvl_louche(): - times = pd.DatetimeIndex(['2016-07-19 06:11:00'], tz='America/Phoenix') - out_dni, out_dhi, out_kt = irradiance.pvl_louche(ghi=1.0, zenith=89.99, - datetime_or_doy=times) - expected_dni = pd.Series(np.array([0.00000000e+00]), index=times) - # expected_dhi=pd.Series(np.array([8.72544336e+02]),index=times) - expected_kt = pd.Series(np.array([1.16046346e-02]), index=times) - assert_series_equal(out_dni, expected_dni) - # assert_series_equal(out_dhi,expected_dhi) - assert_series_equal(out_kt, expected_kt) + + index = pd.DatetimeIndex(['20190101']*3 + ['20190620']*3) + ghi = pd.Series([0, 50, 1000, 1000, 1000, 1000], index=index) + zenith = pd.Series([120, 85, 10, 10, 182, -2], index=index) + expected = pd.DataFrame(np.array( + [[2.827964, 1.413982, 0.000000], + [130.089669, 38.661938, 0.405724], + [828.498650, 184.088106, 0.718133], + [887.407348, 126.074364, 0.768214], + [np.NaN, np.NaN, np.NaN], + [np.NaN, np.NaN, np.NaN]]), + columns=['dni', 'dhi', 'kt'], index=index) + + out = irradiance.pvl_louche(ghi, zenith, index) + + assert np.allclose(out, expected) From f790fb3a19085390780af43649d0abdec560e996 Mon Sep 17 00:00:00 2001 From: Lakshya Garg <72099449+Lakshyadevelops@users.noreply.github.com> Date: Tue, 28 Mar 2023 03:58:40 +0530 Subject: [PATCH 04/16] stickler --- pvlib/irradiance.py | 20 ++++++++++---------- pvlib/tests/test_irradiance.py | 6 +++--- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index 81b3f5ae55..b7cc47cfc7 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -3135,12 +3135,12 @@ def pvl_louche(ghi, solar_zenith, datetime_or_doy): datetime_or_doy : numeric, pandas.DatetimeIndex Day of year or array of days of year e.g. pd.DatetimeIndex.dayofyear, or pd.DatetimeIndex. - + Returns ------- data: OrderedDict or DataFrame Contains the following keys/columns: - + * ``dni``: the modeled direct normal irradiance in W/m^2. * ``dhi``: the modeled diffuse horizontal irradiance in W/m^2. @@ -3152,13 +3152,13 @@ def pvl_louche(ghi, solar_zenith, datetime_or_doy): .. [1] Louche A, Notton G, Poggi P, Simmonnot G. Correlations for direct normal and global horizontal irradiation on French Mediterranean site. Solar Energy 1991;46:261-6 """ - bool=np.logical_or(solar_zenith>180,solar_zenith < 0) - solar_zenith=np.where(bool,np.NaN,solar_zenith) + bool = np.logical_or(solar_zenith > 180, solar_zenith < 0) + solar_zenith = np.where(bool, np.NaN, solar_zenith) if np.isscalar(datetime_or_doy): - bool=(np.any(datetime_or_doy>366 or datetime_or_doy < 1,axis=0)) + bool = (np.any(datetime_or_doy > 366 or datetime_or_doy < 1, axis=0)) print(bool) - datetime_or_doy=np.where(bool,np.NaN,datetime_or_doy) + datetime_or_doy = np.where(bool, np.NaN, datetime_or_doy) # this is the I0 calculation from the reference # SSC uses solar constant = 1366.1 @@ -3172,10 +3172,10 @@ def pvl_louche(ghi, solar_zenith, datetime_or_doy): dni = kb*I0 dhi = ghi-dni*tools.cosd(solar_zenith) - data=OrderedDict() - data['dni']=dni - data['dhi']=dhi - data['kt']=Kt + data = OrderedDict() + data['dni'] = dni + data['dhi'] = dhi + data['kt'] = Kt if isinstance(datetime_or_doy, pd.DatetimeIndex): data = pd.DataFrame(data, index=datetime_or_doy) diff --git a/pvlib/tests/test_irradiance.py b/pvlib/tests/test_irradiance.py index 0c721cd2eb..8d6b051575 100644 --- a/pvlib/tests/test_irradiance.py +++ b/pvlib/tests/test_irradiance.py @@ -1211,12 +1211,12 @@ def test_complete_irradiance(): def test_pvl_louche(): - + index = pd.DatetimeIndex(['20190101']*3 + ['20190620']*3) ghi = pd.Series([0, 50, 1000, 1000, 1000, 1000], index=index) zenith = pd.Series([120, 85, 10, 10, 182, -2], index=index) expected = pd.DataFrame(np.array( - [[2.827964, 1.413982, 0.000000], + [[2.827964, 1.413982, -0.000000], [130.089669, 38.661938, 0.405724], [828.498650, 184.088106, 0.718133], [887.407348, 126.074364, 0.768214], @@ -1226,4 +1226,4 @@ def test_pvl_louche(): out = irradiance.pvl_louche(ghi, zenith, index) - assert np.allclose(out, expected) + assert assert_frame_equal(out, expected) is None From 66f9c813712433b7ea5f58c06cb9fe13f620121f Mon Sep 17 00:00:00 2001 From: Lakshya Garg <72099449+Lakshyadevelops@users.noreply.github.com> Date: Tue, 28 Mar 2023 04:10:01 +0530 Subject: [PATCH 05/16] stickler --- pvlib/irradiance.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index b7cc47cfc7..d6df51ac68 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -3149,7 +3149,10 @@ def pvl_louche(ghi, solar_zenith, datetime_or_doy): References ------- - .. [1] Louche A, Notton G, Poggi P, Simmonnot G. Correlations for direct normal and global horizontal irradiation on French Mediterranean site. Solar Energy 1991;46:261-6 + .. [1] Louche A, Notton G, Poggi P, Simmonnot G. Correlations for direct + normal and global horizontal irradiation on French Mediterranean site. + Solar Energy + 1991;46:261-6 """ bool = np.logical_or(solar_zenith > 180, solar_zenith < 0) From ff8eb59eb952392eb1915ab6ed842a2f7c3f9240 Mon Sep 17 00:00:00 2001 From: Lakshya Garg <72099449+Lakshyadevelops@users.noreply.github.com> Date: Sat, 1 Apr 2023 02:14:48 +0530 Subject: [PATCH 06/16] made suggested changes --- pvlib/irradiance.py | 17 +++++++---------- pvlib/tests/test_irradiance.py | 9 ++++----- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index d6df51ac68..2d0f82e347 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -3121,14 +3121,14 @@ def complete_irradiance(solar_zenith, def pvl_louche(ghi, solar_zenith, datetime_or_doy): """ - Determine DNI and GHI from GHI using louche model. + Determine DNI and GHI from GHI using Louche model. Parameters ---------- ghi : Series Global horizontal irradiance. [W/m^2] - zenith : Series + solar_zenith : Series True (not refraction-corrected) zenith angles in decimal degrees. Angles must be >=0 and <=180. @@ -3151,29 +3151,26 @@ def pvl_louche(ghi, solar_zenith, datetime_or_doy): ------- .. [1] Louche A, Notton G, Poggi P, Simmonnot G. Correlations for direct normal and global horizontal irradiation on French Mediterranean site. - Solar Energy - 1991;46:261-6 + Solar Energy 1991;46:261-6 """ - bool = np.logical_or(solar_zenith > 180, solar_zenith < 0) + bool = np.logical_or(solar_zenith > 90, solar_zenith < 0) solar_zenith = np.where(bool, np.NaN, solar_zenith) if np.isscalar(datetime_or_doy): bool = (np.any(datetime_or_doy > 366 or datetime_or_doy < 1, axis=0)) - print(bool) datetime_or_doy = np.where(bool, np.NaN, datetime_or_doy) # this is the I0 calculation from the reference # SSC uses solar constant = 1366.1 I0 = get_extra_radiation(datetime_or_doy) - I0h = I0*tools.cosd(solar_zenith) - Kt = ghi/I0h - pd.Series.clip(Kt, 0, inplace=True) + Kt = clearness_index(ghi, solar_zenith, I0) + kb = -10.627*Kt**5 + 15.307*Kt**4 - 5.205 * \ Kt**3 + 0.994*Kt**2 - 0.059*Kt + 0.002 dni = kb*I0 - dhi = ghi-dni*tools.cosd(solar_zenith) + dhi = ghi - dni*tools.cosd(solar_zenith) data = OrderedDict() data['dni'] = dni diff --git a/pvlib/tests/test_irradiance.py b/pvlib/tests/test_irradiance.py index 8d6b051575..8ecbf03e1b 100644 --- a/pvlib/tests/test_irradiance.py +++ b/pvlib/tests/test_irradiance.py @@ -1212,15 +1212,14 @@ def test_complete_irradiance(): def test_pvl_louche(): - index = pd.DatetimeIndex(['20190101']*3 + ['20190620']*3) - ghi = pd.Series([0, 50, 1000, 1000, 1000, 1000], index=index) - zenith = pd.Series([120, 85, 10, 10, 182, -2], index=index) + index = pd.DatetimeIndex(['20190101']*3 + ['20190620']*2) + ghi = pd.Series([0, 50, 1000, 1000, 1000], index=index) + zenith = pd.Series([91, 85, 10, 10, -2], index=index) expected = pd.DataFrame(np.array( - [[2.827964, 1.413982, -0.000000], + [[np.NaN, np.NaN, np.NaN], [130.089669, 38.661938, 0.405724], [828.498650, 184.088106, 0.718133], [887.407348, 126.074364, 0.768214], - [np.NaN, np.NaN, np.NaN], [np.NaN, np.NaN, np.NaN]]), columns=['dni', 'dhi', 'kt'], index=index) From 4cbb2bc1e7f909b3d5c91e747f15c99f428373e9 Mon Sep 17 00:00:00 2001 From: Lakshya Garg <72099449+Lakshyadevelops@users.noreply.github.com> Date: Sat, 1 Apr 2023 03:46:34 +0530 Subject: [PATCH 07/16] updated what's new, doc API changes & added notes --- docs/sphinx/source/reference/irradiance/decomposition.rst | 1 + docs/sphinx/source/whatsnew/v0.9.6.rst | 2 +- pvlib/irradiance.py | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/sphinx/source/reference/irradiance/decomposition.rst b/docs/sphinx/source/reference/irradiance/decomposition.rst index f0d1495889..90ef0fa3e2 100644 --- a/docs/sphinx/source/reference/irradiance/decomposition.rst +++ b/docs/sphinx/source/reference/irradiance/decomposition.rst @@ -15,3 +15,4 @@ DNI estimation models irradiance.boland irradiance.campbell_norman irradiance.gti_dirint + irradiance.pvl_louche diff --git a/docs/sphinx/source/whatsnew/v0.9.6.rst b/docs/sphinx/source/whatsnew/v0.9.6.rst index 06e7049a28..e8801b9c24 100644 --- a/docs/sphinx/source/whatsnew/v0.9.6.rst +++ b/docs/sphinx/source/whatsnew/v0.9.6.rst @@ -11,7 +11,7 @@ Deprecations Enhancements ~~~~~~~~~~~~ - +* Lakshya Garg (:ghuser:`Lakshyadevelops` :pull:`1705`) Bug fixes ~~~~~~~~~ diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index 2d0f82e347..fc0bf2f853 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -3146,6 +3146,10 @@ def pvl_louche(ghi, solar_zenith, datetime_or_doy): W/m^2. * ``kt``: Ratio of global to extraterrestrial irradiance on a horizontal plane. + Notes + ----- + solar_zenith angles should be between 0 and 90 degrees else NaN will be + returned. doy should be between 1 and 366 else NaN will be returned. References ------- From 1562111cc22a1923a8c731c077ffa7e099123cdd Mon Sep 17 00:00:00 2001 From: Lakshya Garg <72099449+Lakshyadevelops@users.noreply.github.com> Date: Sat, 1 Apr 2023 23:27:03 +0530 Subject: [PATCH 08/16] correct comments --- pvlib/irradiance.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index fc0bf2f853..a89dfa3432 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -3130,7 +3130,7 @@ def pvl_louche(ghi, solar_zenith, datetime_or_doy): solar_zenith : Series True (not refraction-corrected) zenith angles in decimal - degrees. Angles must be >=0 and <=180. + degrees. Angles must be >=0 and <=90. datetime_or_doy : numeric, pandas.DatetimeIndex Day of year or array of days of year e.g. From 12a52a251508378d6baf8ff6b894a568d6f473cf Mon Sep 17 00:00:00 2001 From: Lakshya Garg <72099449+Lakshyadevelops@users.noreply.github.com> Date: Mon, 3 Apr 2023 20:36:07 +0530 Subject: [PATCH 09/16] Update pvlib/irradiance.py Co-authored-by: Cliff Hansen --- pvlib/irradiance.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index a89dfa3432..9e6568d8cd 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -3148,8 +3148,8 @@ def pvl_louche(ghi, solar_zenith, datetime_or_doy): on a horizontal plane. Notes ----- - solar_zenith angles should be between 0 and 90 degrees else NaN will be - returned. doy should be between 1 and 366 else NaN will be returned. + `solar_zenith` angles should be between 0 and 90 degrees else NaN will be + returned. Day of year (doy) should be between 1 and 366 else NaN will be returned. References ------- From c111d69ad32c76ef3653a1db8af6a818cdbc1ce3 Mon Sep 17 00:00:00 2001 From: Lakshya Garg <72099449+Lakshyadevelops@users.noreply.github.com> Date: Mon, 3 Apr 2023 20:42:30 +0530 Subject: [PATCH 10/16] complete PR with formatting changes --- pvlib/irradiance.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index 9e6568d8cd..3ae1c67b52 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -3154,8 +3154,8 @@ def pvl_louche(ghi, solar_zenith, datetime_or_doy): References ------- .. [1] Louche A, Notton G, Poggi P, Simmonnot G. Correlations for direct - normal and global horizontal irradiation on French Mediterranean site. - Solar Energy 1991;46:261-6 + normal and global horizontal irradiation on French Mediterranean site. + Solar Energy 1991;46:261-6 """ bool = np.logical_or(solar_zenith > 90, solar_zenith < 0) From 65d27ce003a6101a72b4c694880c626898eb755f Mon Sep 17 00:00:00 2001 From: Lakshya Garg <72099449+Lakshyadevelops@users.noreply.github.com> Date: Mon, 3 Apr 2023 20:54:35 +0530 Subject: [PATCH 11/16] stickler --- pvlib/irradiance.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index 3ae1c67b52..9c45928b00 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -3149,7 +3149,8 @@ def pvl_louche(ghi, solar_zenith, datetime_or_doy): Notes ----- `solar_zenith` angles should be between 0 and 90 degrees else NaN will be - returned. Day of year (doy) should be between 1 and 366 else NaN will be returned. + returned. Day of year (doy) should be between 1 and 366 else NaN will be + returned. References ------- From c14c735b9beccd9527f7cd93cad21552da00137c Mon Sep 17 00:00:00 2001 From: Lakshya Garg <72099449+Lakshyadevelops@users.noreply.github.com> Date: Sat, 27 May 2023 23:26:00 +0530 Subject: [PATCH 12/16] Update pvlib/irradiance.py Co-authored-by: Kevin Anderson --- pvlib/irradiance.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index 9c45928b00..0f207a87eb 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -3154,9 +3154,9 @@ def pvl_louche(ghi, solar_zenith, datetime_or_doy): References ------- - .. [1] Louche A, Notton G, Poggi P, Simmonnot G. Correlations for direct - normal and global horizontal irradiation on French Mediterranean site. - Solar Energy 1991;46:261-6 + .. [1] Louche A, Notton G, Poggi P, Simonnot G. Correlations for direct + normal and global horizontal irradiation on a French Mediterranean site. + Solar Energy 1991;46:261-6. :doi:`10.1016/0038-092X(91)90072-5` """ bool = np.logical_or(solar_zenith > 90, solar_zenith < 0) From 1bcdd19baa7d89ac581a9ada4e3e94d0a1dda28d Mon Sep 17 00:00:00 2001 From: Lakshya Garg <72099449+Lakshyadevelops@users.noreply.github.com> Date: Sun, 28 May 2023 00:25:12 +0530 Subject: [PATCH 13/16] done necessary changes --- docs/sphinx/source/whatsnew/v0.9.6.rst | 3 ++- pvlib/irradiance.py | 17 ++++++++--------- pvlib/tests/test_irradiance.py | 15 +++++++-------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/docs/sphinx/source/whatsnew/v0.9.6.rst b/docs/sphinx/source/whatsnew/v0.9.6.rst index e8801b9c24..9178e38045 100644 --- a/docs/sphinx/source/whatsnew/v0.9.6.rst +++ b/docs/sphinx/source/whatsnew/v0.9.6.rst @@ -11,7 +11,7 @@ Deprecations Enhancements ~~~~~~~~~~~~ -* Lakshya Garg (:ghuser:`Lakshyadevelops` :pull:`1705`) +* Added a new irradiance decomposition model :py:func:`pvlib.irradiance.louche`. (:pull:`1705`) Bug fixes ~~~~~~~~~ @@ -35,4 +35,5 @@ Requirements Contributors ~~~~~~~~~~~~ +* Lakshya Garg (:ghuser:`Lakshyadevelops` :pull:`1705`) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index 0f207a87eb..c984a469f2 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -3119,16 +3119,16 @@ def complete_irradiance(solar_zenith, return component_sum_df -def pvl_louche(ghi, solar_zenith, datetime_or_doy): +def louche(ghi, solar_zenith, datetime_or_doy, max_zenith=90): """ Determine DNI and GHI from GHI using Louche model. Parameters ---------- - ghi : Series + ghi : numeric Global horizontal irradiance. [W/m^2] - solar_zenith : Series + solar_zenith : numeric True (not refraction-corrected) zenith angles in decimal degrees. Angles must be >=0 and <=90. @@ -3159,12 +3159,6 @@ def pvl_louche(ghi, solar_zenith, datetime_or_doy): Solar Energy 1991;46:261-6. :doi:`10.1016/0038-092X(91)90072-5` """ - bool = np.logical_or(solar_zenith > 90, solar_zenith < 0) - solar_zenith = np.where(bool, np.NaN, solar_zenith) - - if np.isscalar(datetime_or_doy): - bool = (np.any(datetime_or_doy > 366 or datetime_or_doy < 1, axis=0)) - datetime_or_doy = np.where(bool, np.NaN, datetime_or_doy) # this is the I0 calculation from the reference # SSC uses solar constant = 1366.1 @@ -3177,6 +3171,11 @@ def pvl_louche(ghi, solar_zenith, datetime_or_doy): dni = kb*I0 dhi = ghi - dni*tools.cosd(solar_zenith) + bad_values = (solar_zenith > max_zenith) | (ghi < 0) | (dni < 0) + dni = np.where(bad_values, 0, dni) + # ensure that closure relationship remains valid + dhi = np.where(bad_values, ghi, dhi) + data = OrderedDict() data['dni'] = dni data['dhi'] = dhi diff --git a/pvlib/tests/test_irradiance.py b/pvlib/tests/test_irradiance.py index 8ecbf03e1b..1755ac06b1 100644 --- a/pvlib/tests/test_irradiance.py +++ b/pvlib/tests/test_irradiance.py @@ -1210,19 +1210,18 @@ def test_complete_irradiance(): dni_clear=clearsky.dni) -def test_pvl_louche(): +def test_louche(): - index = pd.DatetimeIndex(['20190101']*3 + ['20190620']*2) - ghi = pd.Series([0, 50, 1000, 1000, 1000], index=index) - zenith = pd.Series([91, 85, 10, 10, -2], index=index) + index = pd.DatetimeIndex(['20190101']*3 + ['20190620']*1) + ghi = pd.Series([0, 50, 1000, 1000], index=index) + zenith = pd.Series([91, 85, 10, 10], index=index) expected = pd.DataFrame(np.array( - [[np.NaN, np.NaN, np.NaN], + [[0, 0, 0], [130.089669, 38.661938, 0.405724], [828.498650, 184.088106, 0.718133], - [887.407348, 126.074364, 0.768214], - [np.NaN, np.NaN, np.NaN]]), + [887.407348, 126.074364, 0.768214]]), columns=['dni', 'dhi', 'kt'], index=index) - out = irradiance.pvl_louche(ghi, zenith, index) + out = irradiance.louche(ghi, zenith, index) assert assert_frame_equal(out, expected) is None From bf61e972a51ed2d3132875c3b139aa2e208cd6db Mon Sep 17 00:00:00 2001 From: Lakshya Garg <72099449+Lakshyadevelops@users.noreply.github.com> Date: Tue, 30 May 2023 16:04:17 +0530 Subject: [PATCH 14/16] Update docs/sphinx/source/reference/irradiance/decomposition.rst Co-authored-by: Cliff Hansen --- docs/sphinx/source/reference/irradiance/decomposition.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/sphinx/source/reference/irradiance/decomposition.rst b/docs/sphinx/source/reference/irradiance/decomposition.rst index 90ef0fa3e2..0677d6ac95 100644 --- a/docs/sphinx/source/reference/irradiance/decomposition.rst +++ b/docs/sphinx/source/reference/irradiance/decomposition.rst @@ -15,4 +15,5 @@ DNI estimation models irradiance.boland irradiance.campbell_norman irradiance.gti_dirint - irradiance.pvl_louche + irradiance.louche + From 3abbc7933cead78bdc8c349ed6ab9fa73a1ed6fd Mon Sep 17 00:00:00 2001 From: Lakshya Garg <72099449+Lakshyadevelops@users.noreply.github.com> Date: Tue, 30 May 2023 16:08:36 +0530 Subject: [PATCH 15/16] removed SSC comment --- pvlib/irradiance.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index c984a469f2..f457d1fa7d 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -3160,8 +3160,6 @@ def louche(ghi, solar_zenith, datetime_or_doy, max_zenith=90): """ - # this is the I0 calculation from the reference - # SSC uses solar constant = 1366.1 I0 = get_extra_radiation(datetime_or_doy) Kt = clearness_index(ghi, solar_zenith, I0) From 57b6af096e1a227b81ec42445491f6493f1966c8 Mon Sep 17 00:00:00 2001 From: Kevin Anderson Date: Tue, 30 May 2023 09:27:30 -0400 Subject: [PATCH 16/16] Apply suggestions from code review --- pvlib/irradiance.py | 7 +------ pvlib/tests/test_irradiance.py | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index f457d1fa7d..af983e47b9 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -3121,7 +3121,7 @@ def complete_irradiance(solar_zenith, def louche(ghi, solar_zenith, datetime_or_doy, max_zenith=90): """ - Determine DNI and GHI from GHI using Louche model. + Determine DNI and DHI from GHI using the Louche model. Parameters ---------- @@ -3146,11 +3146,6 @@ def louche(ghi, solar_zenith, datetime_or_doy, max_zenith=90): W/m^2. * ``kt``: Ratio of global to extraterrestrial irradiance on a horizontal plane. - Notes - ----- - `solar_zenith` angles should be between 0 and 90 degrees else NaN will be - returned. Day of year (doy) should be between 1 and 366 else NaN will be - returned. References ------- diff --git a/pvlib/tests/test_irradiance.py b/pvlib/tests/test_irradiance.py index 1755ac06b1..d0158dad1a 100644 --- a/pvlib/tests/test_irradiance.py +++ b/pvlib/tests/test_irradiance.py @@ -1224,4 +1224,4 @@ def test_louche(): out = irradiance.louche(ghi, zenith, index) - assert assert_frame_equal(out, expected) is None + assert_frame_equal(out, expected)