Skip to content

Commit 04a523f

Browse files
authored
more asv tests for solar position, fix fuentes asv bug (#1059)
* fix wind_speed typo in temperature.py * add ephem and geometric transet benchmarks * solarpositionnumba * add solarposition.ipynb benchmarks * pyephm and calc_time test * reload call * call a function * dont set envvar * commit * add numba to asv envs. duh * clean up * spec numba 0.36.1 * new calctime class, rename * add pull number to whatsnew * fix day typo and mistake * param ndays * add param_names
1 parent 30d784e commit 04a523f

File tree

6 files changed

+195
-53
lines changed

6 files changed

+195
-53
lines changed

benchmarks/asv.conf.json

+2
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
// Note: these don't have a minimum in setup.py
122122
"pytables": "3.6.1",
123123
"ephem": "3.7.6.0",
124+
"numba": "0.36.1",
124125
},
125126
// latest versions available
126127
{
@@ -130,6 +131,7 @@
130131
"scipy": "",
131132
"pytables": "",
132133
"ephem": "",
134+
"numba": ""
133135
},
134136
],
135137
"exclude": [

benchmarks/benchmarks/solarposition.py

+51-10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
ASV benchmarks for solarposition.py
33
"""
44

5+
import datetime
56
import pandas as pd
67
import pvlib
78
from pvlib import solarposition
@@ -16,28 +17,68 @@
1617

1718

1819
class SolarPosition:
20+
params = [1, 10, 100] # number of days
21+
param_names = ['ndays']
1922

20-
def setup(self):
23+
def setup(self, ndays):
2124
self.times = pd.date_range(start='20180601', freq='1min',
22-
periods=14400)
25+
periods=1440*ndays)
2326
self.times_localized = self.times.tz_localize('Etc/GMT+7')
2427
self.lat = 35.1
2528
self.lon = -106.6
29+
self.times_daily = pd.date_range(
30+
start='20180601', freq='24h', periods=ndays, tz='Etc/GMT+7')
2631

2732
# GH 512
28-
def time_ephemeris(self):
33+
def time_ephemeris(self, ndays):
2934
solarposition.ephemeris(self.times, self.lat, self.lon)
3035

3136
# GH 512
32-
def time_ephemeris_localized(self):
37+
def time_ephemeris_localized(self, ndays):
3338
solarposition.ephemeris(self.times_localized, self.lat, self.lon)
3439

35-
def time_spa_python(self):
36-
solarposition.spa_python(self.times_localized[::5], self.lat, self.lon)
40+
def time_spa_python(self, ndays):
41+
solarposition.spa_python(self.times_localized, self.lat, self.lon)
42+
43+
def time_pyephem(self, ndays):
44+
solarposition.pyephem(self.times_localized, self.lat, self.lon)
45+
46+
def time_sun_rise_set_transit_spa(self, ndays):
47+
sun_rise_set_transit_spa(self.times_daily, self.lat, self.lon)
3748

38-
def time_sun_rise_set_transit_spa(self):
39-
sun_rise_set_transit_spa(self.times_localized[::30],
40-
self.lat, self.lon)
49+
def time_sun_rise_set_transit_ephem(self, ndays):
50+
solarposition.sun_rise_set_transit_ephem(
51+
self.times_daily, self.lat, self.lon)
4152

42-
def time_nrel_earthsun_distance(self):
53+
def time_sun_rise_set_transit_geometric_full_comparison(self, ndays):
54+
dayofyear = self.times_daily.dayofyear
55+
declination = solarposition.declination_spencer71(dayofyear)
56+
equation_of_time = solarposition.equation_of_time_spencer71(dayofyear)
57+
solarposition.sun_rise_set_transit_geometric(
58+
self.times_daily, self.lat, self.lon, declination,
59+
equation_of_time)
60+
61+
def time_nrel_earthsun_distance(self, ndays):
4362
solarposition.nrel_earthsun_distance(self.times_localized)
63+
64+
65+
class SolarPositionCalcTime:
66+
67+
def setup(self):
68+
# test calc_time for finding times at which sun is 3 degrees
69+
# above the horizon.
70+
# Tucson 2020-09-14 sunrise at 6:08 AM MST, 13:08 UTC
71+
# according to google.
72+
self.start = datetime.datetime(2020, 9, 14, 12)
73+
self.end = datetime.datetime(2020, 9, 14, 15)
74+
self.value = 0.05235987755982988
75+
self.lat = 32.2
76+
self.lon = -110.9
77+
self.attribute = 'alt'
78+
79+
def time_calc_time(self):
80+
# datetime.datetime(2020, 9, 14, 13, 24, 13, 861913, tzinfo=<UTC>)
81+
solarposition.calc_time(
82+
self.start, self.end, self.lat, self.lon, self.attribute,
83+
self.value
84+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"""ASV benchmarks for solarposition.py using numba.
2+
3+
We use a separate module so that we can control the pvlib import process
4+
using an environment variable. This will force pvlib to compile the numba
5+
code during setup.
6+
7+
Try to keep relevant sections in sync with benchmarks/solarposition.py
8+
"""
9+
10+
from pkg_resources import parse_version
11+
import pandas as pd
12+
13+
import os
14+
os.environ['PVLIB_USE_NUMBA'] = '1'
15+
16+
17+
import pvlib # NOQA: E402
18+
from pvlib import solarposition # NOQA: E402
19+
20+
21+
if parse_version(pvlib.__version__) >= parse_version('0.6.1'):
22+
sun_rise_set_transit_spa = solarposition.sun_rise_set_transit_spa
23+
else:
24+
sun_rise_set_transit_spa = solarposition.get_sun_rise_set_transit
25+
26+
27+
class SolarPositionNumba:
28+
params = [1, 10, 100] # number of days
29+
param_names = ['ndays']
30+
31+
def setup(self, ndays):
32+
self.times = pd.date_range(start='20180601', freq='1min',
33+
periods=1440*ndays)
34+
self.times_localized = self.times.tz_localize('Etc/GMT+7')
35+
self.lat = 35.1
36+
self.lon = -106.6
37+
self.times_daily = pd.date_range(
38+
start='20180601', freq='24h', periods=ndays, tz='Etc/GMT+7')
39+
40+
def time_spa_python(self, ndays):
41+
solarposition.spa_python(
42+
self.times_localized, self.lat, self.lon, how='numba')
43+
44+
def time_sun_rise_set_transit_spa(self, ndays):
45+
sun_rise_set_transit_spa(
46+
self.times_daily, self.lat, self.lon, how='numba')

benchmarks/benchmarks/temperature.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def set_weather_data(obj):
1313
periods=14400)
1414
obj.poa = pd.Series(1000, index=obj.times)
1515
obj.tamb = pd.Series(20, index=obj.times)
16-
obj.windspeed = pd.Series(2, index=obj.times)
16+
obj.wind_speed = pd.Series(2, index=obj.times)
1717

1818

1919
class SAPM:
@@ -35,7 +35,7 @@ def sapm_cell_wrapper(poa_global, temp_air, wind_speed):
3535

3636
def time_sapm_cell(self):
3737
# use version-appropriate wrapper
38-
self.sapm_cell_wrapper(self.poa, self.tamb, self.windspeed)
38+
self.sapm_cell_wrapper(self.poa, self.tamb, self.wind_speed)
3939

4040

4141
class Fuentes:

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Bug fixes
2222
Testing
2323
~~~~~~~
2424
* Add airspeed velocity performance testing configuration and a few benchmarks.
25-
(:issue:`419`, :pull:`1049`)
25+
(:issue:`419`, :pull:`1049`, :pull:`1059`)
2626

2727
Documentation
2828
~~~~~~~~~~~~~

docs/tutorials/solarposition.ipynb

+93-40
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)