pingswept / pysolar

Pysolar is a collection of Python libraries for simulating the irradiation of any point on earth by the sun. It includes code for extremely precise ephemeris calculations.
http://pysolar.org
GNU General Public License v3.0
375 stars 125 forks source link

Discontinuity just after sunset #155

Open martinmCGG opened 1 year ago

martinmCGG commented 1 year ago

PySolar seems to produce discontinuous sun elevation/altitude around sunset (and also near sunrise): there is a ~0.6deg jump in the following test case. May be related to #115.

Minimal example showing the issue:

import pysolar.solar as solar
import datetime
import matplotlib.pyplot as plt
import numpy as np

lat, long = 37.249870621332086, -115.81458511013524 # a randomly picked position
strange_timestamp = 1565491275.92175
epsilon = 420 #3600*12 #0.00008 # <- scale
x = np.linspace(strange_timestamp - epsilon, strange_timestamp + epsilon, 100)
y = [solar.get_altitude(lat, long, datetime.datetime.fromtimestamp(t).astimezone(datetime.timezone.utc)) for t in x]
plt.scatter(x, y, label='pysolar')

# optional, for comparison (pip install pysolar suncalc)
import suncalc
y2 = [np.rad2deg(suncalc.get_position(datetime.datetime.fromtimestamp(t).astimezone(datetime.timezone.utc), long, lat)['altitude']) for t in x]
plt.scatter(x, y2, label='suncalc')
plt.legend()
plt.show()

pysolar

pingswept commented 1 year ago

Interesting. That certainly looks like a bug. Thanks for the test case.

My guess is that some correction factor is blowing up as altitude nears zero.

I’d welcome more details from anyone who wanted to dig into the details.