diff --git a/.github/workflows/asv_check.yml b/.github/workflows/asv_check.yml new file mode 100644 index 0000000000..2a645c35e3 --- /dev/null +++ b/.github/workflows/asv_check.yml @@ -0,0 +1,39 @@ +name: CI ASV check + +# CI ASV CHECK is aimed to verify that the benchmarks execute without error. +on: [pull_request, push] + +jobs: + test: + runs-on: ubuntu-latest + defaults: + run: + shell: bash -el {0} + + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Install Python + uses: actions/setup-python@v3 + with: + python-version: '3.9.7' + + - name: Install asv + run: | + pip install . + pip install ephem==3.7.6.0 + pip install numba==0.40.0 + pip install asv==0.4.2 + + - name: Run asv benchmarks + run: | + cd benchmarks + asv machine --yes + asv run --quick --dry-run --show-stderr --python=same\ + | sed "/failed$/ s/^/##[error]/" | tee benchmarks.log + if grep "failed" benchmarks.log > /dev/null ; then + exit 1 + fi + diff --git a/benchmarks/benchmarks/solarposition.py b/benchmarks/benchmarks/solarposition.py index 4fac0ea470..71bc307076 100644 --- a/benchmarks/benchmarks/solarposition.py +++ b/benchmarks/benchmarks/solarposition.py @@ -16,22 +16,16 @@ 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) - self.times_localized = self.times.tz_localize('Etc/GMT+7') + self.times_localized = pd.date_range( + start='20180601', freq='1min', + periods=1440 * ndays, tz='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) # GH 512 def time_ephemeris_localized(self, ndays): @@ -43,23 +37,73 @@ 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) + + +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) - equation_of_time = solarposition.equation_of_time_spencer71(dayofyear) + equationoftime = solarposition.equation_of_time_spencer71(dayofyear) solarposition.sun_rise_set_transit_geometric( self.times_daily, self.lat, self.lon, declination, - equation_of_time) + equationoftime) - 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: diff --git a/docs/sphinx/source/whatsnew/v0.9.2.rst b/docs/sphinx/source/whatsnew/v0.9.2.rst index 1982759bf5..f676bde632 100644 --- a/docs/sphinx/source/whatsnew/v0.9.2.rst +++ b/docs/sphinx/source/whatsnew/v0.9.2.rst @@ -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`)