Skip to content

Commit 7b17d62

Browse files
cedricleroywholmgren
authored andcommitted
fix wrong deltat coefficient (#600)
* fix wrong deltat coefficient * include year 2150 in deltat calculation * add 2050 & 2150 for test_calculate_deltat * update whatsnew for calculate_deltat updates
1 parent 3e4b86d commit 7b17d62

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

docs/sphinx/source/whatsnew/v0.6.1.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ Enhancements
4343
Bug fixes
4444
~~~~~~~~~
4545
* Fix when building documentation using Matplotlib 3.0 or greater.
46+
* `~pvlib.spa.calculate_deltat`: Fix constant coefficient of the polynomial expression for years >= 1860
47+
and < 1900, fix year 2050 which was returning 0.
4648
* Fix and improve :func:`~pvlib.solarposition.hour_angle` (:issue:`598`)
4749
* Fix error in :func:`pvlib.clearsky.detect_clearsky` (:issue:`506`)
4850

@@ -56,6 +58,7 @@ Contributors
5658
~~~~~~~~~~~~
5759
* Will Holmgren (:ghuser:`wholmgren`)
5860
* Leland Boeman (:ghuser:`lboeman`)
61+
* Cedric Leroy (:ghuser:`cedricleroy`)
5962
* Ben Ellis (:ghuser:`bhellis725`)
6063
* Cliff Hansen (:ghuser:`cwhanse`)
6164
* Mark Mikofski (:ghuser:`mikofski`)

pvlib/spa.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,7 +1369,7 @@ def calculate_deltat(year, month):
13691369

13701370
deltat = np.where((1860 <= year) & (year < 1900),
13711371

1372-
7.6+0.5737*(y-1860)
1372+
7.62+0.5737*(y-1860)
13731373
- 0.251754*(y-1860)**2
13741374
+ 0.01680668*(y-1860)**3
13751375
- 0.0004473624*(y-1860)**4
@@ -1418,7 +1418,7 @@ def calculate_deltat(year, month):
14181418
-20+32*((y-1820)/100)**2
14191419
- 0.5628*(2150-y), deltat)
14201420

1421-
deltat = np.where(year > 2150,
1421+
deltat = np.where(year >= 2150,
14221422

14231423
-20+32*((y-1820)/100)**2, deltat)
14241424

pvlib/test/test_spa.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,17 @@
7979
Phi = 194.340241
8080
year = 1985
8181
month = 2
82-
year_array = np.array([-499, 500, 1000, 1500, 1800, 1900, 1950, 1970, 1985, 1990, 2000, 2005])
83-
month_array = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
82+
year_array = np.array([-499, 500, 1000, 1500, 1800, 1860, 1900, 1950,
83+
1970, 1985, 1990, 2000, 2005, 2050, 2150])
84+
# `month_array` is used with `year_array` in `test_calculate_deltat`.
85+
# Both arrays need to have the same length for the test, hence the duplicates.
86+
month_array = np.array([1, 2, 3, 4, 5, 6, 6, 7, 8, 9, 10, 11, 12, 12, 12])
8487
dt_actual = 54.413442486
8588
dt_actual_array = np.array([1.7184831e+04, 5.7088051e+03, 1.5730419e+03,
86-
1.9801820e+02, 1.3596506e+01, -2.1171894e+00,
87-
2.9289261e+01, 4.0824887e+01, 5.4724581e+01,
88-
5.7426651e+01, 6.4108015e+01, 6.5038015e+01])
89+
1.9801820e+02, 1.3596506e+01, 7.8316585e+00,
90+
-2.1171894e+00, 2.9289261e+01, 4.0824887e+01,
91+
5.4724581e+01, 5.7426651e+01, 6.4108015e+01,
92+
6.5038015e+01, 9.4952955e+01, 3.3050693e+02])
8993
mix_year_array = np.full((10), year)
9094
mix_month_array = np.full((10), month)
9195
mix_year_actual = np.full((10), dt_actual)
@@ -352,7 +356,7 @@ def test_calculate_deltat(self):
352356
result_array = self.spa.calculate_deltat(year_array, month_array)
353357
assert_almost_equal(dt_actual_array, result_array, 3)
354358

355-
result_scalar = self.spa.calculate_deltat(year,month)
359+
result_scalar = self.spa.calculate_deltat(year, month)
356360
assert_almost_equal(dt_actual, result_scalar)
357361

358362
class NumpySpaTest(unittest.TestCase, SpaBase):
@@ -417,4 +421,3 @@ def test_solar_position_multithreaded(self):
417421
, self.spa.solar_position(
418422
times, lat, lon, elev, pressure, temp, delta_t,
419423
atmos_refract, numthreads=8, sst=True)[:3], 5)
420-

0 commit comments

Comments
 (0)