8000 Improved benchmark in solarposition.py by roger-lcc · Pull Request #1443 · pvlib/pvlib-python · GitHub
[go: up one dir, main page]

Skip to content

Improved benchmark in solarposition.py #1443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
76 changes: 64 additions & 12 deletions benchmarks/benchmarks/solarposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,20 @@
sun_rise_set_transit_spa = solarposition.get_sun_rise_set_transit


class SolarPosition:
class SolarPositionSlow:
params = [1, 10, 100] # number of days
param_names = ['ndays']

def setup(self, ndays):
self.times = pd.date_range(start='20180601', freq='1min',
periods=1440*ndays)
periods=1440 * ndays)
self.times_localized = self.times.tz_localize('Etc/GMT+7')
self.lat = 35.1
self.lon = -106.6
self.times_daily = pd.date_range(
start='20180601', freq='24h', periods=ndays, tz='Etc/GMT+7')

# GH 512
def time_ephemeris(self, ndays):
solarposition.ephemeris(self.times, self.lat, self.lon)
# def time_ephemeris(self, ndays):
# solarposition.ephemeris(self.times, self.lat, self.lon)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come these lines are commented out?


# GH 512
def time_ephemeris_localized(self, ndays):
Expand All @@ -43,13 +41,66 @@ def time_spa_python(self, ndays):
def time_pyephem(self, ndays):
solarposition.pyephem(self.times_localized, self.lat, self.lon)

def time_nrel_earthsun_distance(self, ndays):
solarposition.nrel_earthsun_distance(self.times_localized)

def time_pyephem_earthsun_distance(self, ndays):
solarposition.pyephem_earthsun_distance(self.times_localized)

def time_get_solarposition(self, ndays):
solarposition.get_solarposition(self.times_localized,
self.lat, self.lon)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure there's any need to benchmark get_solarposition -- since it's just a convenience wrapper around the various solar position algorithms, this is more or less a duplicate of the time_spa_python benchmark.



class SolarPositionFast:
params = [1, 365 * 10, 365 * 100]
param_names = ['ndays'] # provide informative names for the parameters

def setup(self, ndays):
self.lat = 35.1
self.lon = -106.6
self.times_daily = pd.date_range(
start='20180601', freq='24h', periods=ndays, tz='Etc/GMT+7')

def time_sun_rise_set_transit_geometric_full_comparison(self, ndays):
dayofyear = self.times_daily.dayofyear
declination = solarposition.declination_spencer71(dayofyear)
equationoftime = solarposition.equation_of_time_spencer71(dayofyear)
solarposition.sun_rise_set_transit_geometric(
self.times_daily, self.lat, self.lon, declination,
equationoftime)

def time__local_times_from_hours_full_comparison(self, ndays):
dayofyear = self.times_daily.dayofyear
equationoftime = solarposition.equation_of_time_spencer71(dayofyear)
hourangle = solarposition.hour_angle(self.times_daily,
self.lon, equationoftime)
solarposition._hour_angle_to_hours(self.times_daily,
hourangle, self.lon, equationoftime)

def time_solar_azimuth_analytical_full_comparison(self, nadys):
dayofyear = self.times_daily.dayofyear
equationoftime = solarposition.equation_of_time_spencer71(dayofyear)
declination = solarposition.declination_spencer71(dayofyear)
hourangle = solarposition.hour_angle(self.times_daily,
self.lon, equationoftime)
zenith = solarposition.solar_zenith_analytical(self.lat,
hourangle, declination)
solarposition.solar_azimuth_analytical(self.lat,
hourangle, declination, zenith)

def time_calculate_simple_day_angle(self, ndays):
solarposition._calculate_simple_day_angle(self.times_daily.dayofyear)

def time_equation_of_time_pvcdrom(self, ndays):
solarposition.equation_of_time_pvcdrom(self.times_daily.dayofyear)

def time_declination_cooper69(self, ndays):
solarposition.declination_cooper69(self.times_daily.dayofyear)

def time_sun_rise_set_transit_spa(self, ndays):
sun_rise_set_transit_spa(self.times_daily, self.lat, self.lon)

def time_sun_rise_set_transit_ephem(self, ndays):
solarposition.sun_rise_set_transit_ephem(
self.times_daily, self.lat, self.lon)

def time_sun_rise_set_transit_geometric_full_comparison(self, ndays):
dayofyear = self.times_daily.dayofyear
declination = solarposition.declination_spencer71(dayofyear)
Expand All @@ -58,8 +109,9 @@ def time_sun_rise_set_transit_geometric_full_comparison(self, ndays):
self.times_daily, self.lat, self.lon, declination,
equation_of_time)

def time_nrel_earthsun_distance(self, ndays):
solarposition.nrel_earthsun_distance(self.times_localized)
def time_sun_rise_set_transit_ephem(self, ndays):
solarposition.sun_rise_set_transit_ephem(
self.times_daily, self.lat, self.lon)


class SolarPositionCalcTime:
Expand Down
2 changes: 2 additions & 0 deletions docs/sphinx/source/whatsnew/v0.9.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ Documentation
Benchmarking
~~~~~~~~~~~~~
* Updated version of numba in asv.conf from 0.36.1 to 0.40.0 to solve numba/numpy conflict. (:issue:`1439`, :pull:`1440`)
* Improved the benchmark in solarposition.py (:issue:`1441`, :pull:`1443`)
Requirements
~~~~~~~~~~~~

Contributors
~~~~~~~~~~~~
* Naman Priyadarshi (:ghuser:`Naman-Priyadarshi`)
* Chencheng Luo (:ghuser:`roger-lcc`)
0