Skip to content

Commit eb2e23a

Browse files
committed
rename spa.py to _spa.py
1 parent f02266f commit eb2e23a

File tree

6 files changed

+45
-22
lines changed

6 files changed

+45
-22
lines changed

docs/sphinx/source/reference/solarposition.rst

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,6 @@ Functions for calculating sunrise, sunset and transit times.
4343
solarposition.sun_rise_set_transit_geometric
4444

4545

46-
The spa module contains the implementation of the built-in NREL SPA
47-
algorithm.
48-
49-
.. autosummary::
50-
:toctree: generated/
51-
52-
spa
53-
5446
Correlations and analytical expressions for low precision solar position
5547
calculations.
5648

pvlib/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
snow,
2323
soiling,
2424
solarposition,
25-
spa,
2625
temperature,
2726
tools,
2827
tracking,

pvlib/spa.py renamed to pvlib/_spa.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1245,4 +1245,3 @@ def earthsun_distance(unixtime, delta_t, numthreads):
12451245

12461246
return R
12471247

1248-

pvlib/solarposition.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,10 @@ def spa_c(time, latitude, longitude, pressure=101325, altitude=0,
247247
def _spa_python_import(how):
248248
"""Compile spa.py appropriately"""
249249

250-
from pvlib import spa
250+
from pvlib import _spa
251251

252252
# check to see if the spa module was compiled with numba
253-
using_numba = spa.USE_NUMBA
253+
using_numba = _spa.USE_NUMBA
254254

255255
if how == 'numpy' and using_numba:
256256
# the spa module was compiled to numba code, so we need to
@@ -259,19 +259,19 @@ def _spa_python_import(how):
259259
# to not compile with numba
260260
warnings.warn('Reloading spa to use numpy')
261261
os.environ['PVLIB_USE_NUMBA'] = '0'
262-
spa = reload(spa)
262+
_spa = reload(_spa)
263263
del os.environ['PVLIB_USE_NUMBA']
264264
elif how == 'numba' and not using_numba:
265265
# The spa module was not compiled to numba code, so set
266266
# PVLIB_USE_NUMBA so it does compile to numba on reload.
267267
warnings.warn('Reloading spa to use numba')
268268
os.environ['PVLIB_USE_NUMBA'] = '1'
269-
spa = reload(spa)
269+
_spa = reload(_spa)
270270
del os.environ['PVLIB_USE_NUMBA']
271271
elif how != 'numba' and how != 'numpy':
272272
raise ValueError("how must be either 'numba' or 'numpy'")
273273

274-
return spa
274+
return _spa
275275

276276

277277
def spa_python(time, latitude, longitude,

pvlib/tests/test_solarposition.py

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import pytest
1111

1212
from pvlib.location import Location
13-
from pvlib import solarposition, spa
13+
from pvlib import solarposition, _spa
1414

1515
from .conftest import requires_ephem, requires_spa_c, requires_numba
1616

@@ -560,11 +560,11 @@ def test_declination():
560560
times = pd.date_range(start="1/1/2015 0:00", end="12/31/2015 23:00",
561561
freq="H")
562562
atmos_refract = 0.5667
563-
delta_t = spa.calculate_deltat(times.year, times.month)
563+
delta_t = solarposition.calculate_deltat(times.year, times.month)
564564
unixtime = np.array([calendar.timegm(t.timetuple()) for t in times])
565-
_, _, declination = spa.solar_position(unixtime, 37.8, -122.25, 100,
566-
1013.25, 25, delta_t, atmos_refract,
567-
sst=True)
565+
_, _, declination = _spa.solar_position(
566+
unixtime, 37.8, -122.25, 100, 1013.25, 25, delta_t, atmos_refract,
567+
sst=True)
568568
declination = np.deg2rad(declination)
569569
declination_rng = declination.max() - declination.min()
570570
declination_1 = solarposition.declination_cooper69(times.dayofyear)
@@ -769,3 +769,36 @@ def test_spa_python_numba_physical_dst(expected_solpos, golden):
769769
temperature=11, delta_t=67,
770770
atmos_refract=0.5667,
771771
how='numpy', numthreads=1)
772+
773+
774+
def test_calculate_deltat():
775+
year_array = np.array([-499, 500, 1000, 1500, 1800, 1860, 1900, 1950,
776+
1970, 1985, 1990, 2000, 2005, 2050, 2150])
777+
# `month_array` is used with `year_array` in `test_calculate_deltat`.
778+
# Both arrays need to have the same length for the test, hence the duplicates.
779+
month_array = np.array([1, 2, 3, 4, 5, 6, 6, 7, 8, 9, 10, 11, 12, 12, 12])
780+
dt_actual = 54.413442486
781+
dt_actual_array = np.array([1.7184831e+04, 5.7088051e+03, 1.5730419e+03,
782+
1.9801820e+02, 1.3596506e+01, 7.8316585e+00,
783+
-2.1171894e+00, 2.9289261e+01, 4.0824887e+01,
784+
5.4724581e+01, 5.7426651e+01, 6.4108015e+01,
785+
6.5038015e+01, 9.4952955e+01, 3.3050693e+02])
786+
year = 1985
787+
month = 2
788+
789+
mix_year_array = np.full((10), year)
790+
mix_month_array = np.full((10), month)
791+
mix_year_actual = np.full((10), dt_actual)
792+
mix_month_actual = mix_year_actual
793+
794+
result_mix_year = solarposition.calculate_deltat(mix_year_array, month)
795+
np.testing.assert_almost_equal(mix_year_actual, result_mix_year)
796+
797+
result_mix_month = solarposition.calculate_deltat(year, mix_month_array)
798+
np.testing.assert_almost_equal(mix_month_actual, result_mix_month)
799+
800+
result_array = solarposition.calculate_deltat(year_array, month_array)
801+
np.testing.assert_almost_equal(dt_actual_array, result_array, 3)
802+
803+
result_scalar = solarposition.calculate_deltat(year, month)
804+
np.testing.assert_almost_equal(dt_actual, result_scalar)

pvlib/tests/test_spa.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ class NumpySpaTest(unittest.TestCase, SpaBase):
378378
@classmethod
379379
def setUpClass(self):
380380
os.environ['PVLIB_USE_NUMBA'] = '0'
381-
import pvlib.spa as spa
381+
import pvlib._spa as spa
382382
spa = reload(spa)
383383
self.spa = spa
384384

@@ -398,7 +398,7 @@ class NumbaSpaTest(unittest.TestCase, SpaBase):
398398
def setUpClass(self):
399399
os.environ['PVLIB_USE_NUMBA'] = '1'
400400
if numba_version_int >= 17:
401-
import pvlib.spa as spa
401+
import pvlib._spa as spa
402402
spa = reload(spa)
403403
self.spa = spa
404404

0 commit comments

Comments
 (0)