|
2 | 2 | ASV benchmarks for solarposition.py
|
3 | 3 | """
|
4 | 4 |
|
| 5 | +import datetime |
5 | 6 | import pandas as pd
|
6 | 7 | import pvlib
|
7 | 8 | from pvlib import solarposition
|
|
16 | 17 |
|
17 | 18 |
|
18 | 19 | class SolarPosition:
|
| 20 | + params = [1, 10, 100] # number of days |
| 21 | + param_names = ['ndays'] |
19 | 22 |
|
20 |
| - def setup(self): |
| 23 | + def setup(self, ndays): |
21 | 24 | self.times = pd.date_range(start='20180601', freq='1min',
|
22 |
| - periods=14400) |
| 25 | + periods=1440*ndays) |
23 | 26 | self.times_localized = self.times.tz_localize('Etc/GMT+7')
|
24 | 27 | self.lat = 35.1
|
25 | 28 | self.lon = -106.6
|
| 29 | + self.times_daily = pd.date_range( |
| 30 | + start='20180601', freq='24h', periods=ndays, tz='Etc/GMT+7') |
26 | 31 |
|
27 | 32 | # GH 512
|
28 |
| - def time_ephemeris(self): |
| 33 | + def time_ephemeris(self, ndays): |
29 | 34 | solarposition.ephemeris(self.times, self.lat, self.lon)
|
30 | 35 |
|
31 | 36 | # GH 512
|
32 |
| - def time_ephemeris_localized(self): |
| 37 | + def time_ephemeris_localized(self, ndays): |
33 | 38 | solarposition.ephemeris(self.times_localized, self.lat, self.lon)
|
34 | 39 |
|
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) |
37 | 48 |
|
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) |
41 | 52 |
|
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): |
43 | 62 | 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 | + ) |
0 commit comments