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
372 stars 125 forks source link

`get_azimuth_fast`: Issue with get_azimuth_fast in near equatorial countries #143

Closed pjayathissa closed 1 year ago

pjayathissa commented 3 years ago

I was cross-referencing a basic radiation equation to your source code and was getting issues in near-equatorial countries (singapore), which I think is related to this logic. I was wondering what the reason for this boolean logic is?

Below is a graph of azimuth hourly profiles during the year, which I found to look a little strange. x axis is the hour of a year, and the y axis is the angle.

Screen Shot 2021-03-21 at 15 45 18

Zoomed into the the middle months:

Screen Shot 2021-03-21 at 16 02 14

https://github.com/pingswept/pysolar/blob/177b283eb8ed588d1241ecd1885d260b567d8da6/pysolar/solar.py#L175-L178

Code to regenerate the plots

import pysolar
import datetime
import pytz
import matplotlib.pyplot as plt

# The size of each step in days
hour_delta = datetime.timedelta(hours=1)

start_date = datetime.datetime(2007, 1, 1, 0, 0, 0, 0)
end_date = start_date + 8760*hour_delta

Azimuths = []

for ii in range(8760):
    hour = (start_date + ii*hour_delta).replace(tzinfo = pytz.timezone("Asia/Singapore"))
    azimuth = pysolar.solar.get_azimuth_fast(1.37,1.112828,hour)
    Azimuths.append(azimuth)

plt.scatter(range(8760),Azimuths)
plt.show()
pjayathissa commented 3 years ago

I don't have sufficient experience in equatorial countries to know if this is a normal pattern.

pingswept commented 3 years ago

I haven't looked at this really closely, but I'm not sure that it's wrong. Your second chart looks like a sine wave centered around 0, but the negative parts are wrapped around to the top. Maybe you just need to subtract 360 degrees from the values above 180 to make it look sensibly continuous?

It would also be interesting to know if get_azimuth() returns the same values as get_azimuth_fast() for the values you're testing.

pingswept commented 1 year ago

Closing this for now. Please reopen if I’m in error here.