pysolar
pysolar copied to clipboard
Argument to asin() above 1 in get_azimuth_fast?
As previously reported this method returns an error:
This fails using
import pysolar
import datetime
az=pysolar.solar.get_azimuth_fast(48, 14, datetime.datetime(2015, 3, 10, 16, 30))
print('{}'.format(az))
The reason for there failure is the asin function is being given a value of (1.1); Which is out of bounds... This can be resolved by using %1.
The solution is to change the line in Solar.py
From:
azimuth_rad = math.asin(math.cos(declination_rad) * math.sin(hour_angle_rad) / math.cos(altitude_rad))
To: azimuth_rad = math.asin( (math.cos(declination_rad) * math.sin(hour_angle_rad) / math.cos(altitude_rad))%1)
I have not checked to see if this may occur in the get_azimuth method.
I suspect you're on the right track here. Any thoughts on when or why asin is getting called with values above 1? I'm hesitant to just wipe out values above 1 without understanding why they're appearing in the first place.
Brandon, I too am not sure just why the adjustment should be required….
So this morning in a little spare time - I sat down to try and replicate this issue. I have had issues in the past when dealing with GPS data, having to “adjust” E/W and N/S functions. So I suspect that this is the issue …. BUT I have not seen that.
New virtual python environment; And I tried to replicate the work I was doing the other day.
Generate 10 minute “sun plots” for a position…. This time, I added a structure to have multiple locations.
After generating these values - then some pyplot to check the sense of the Altitude and Az values.
I could not create any issues at all … I was however using the code
alt = sol.get_altitude(loc[0], loc[1], aware_datetime)
az = sol.get_azimuth(loc[0], loc[1], aware_datetime)
If I change this to
alt = sol.get_altitude_fast(loc[0], loc[1], aware_datetime)
az = sol.get_azimuth_fast(loc[0], loc[1], aware_datetime)
Then data loss and exceptions are thrown. So 100% the issue is in the “fast” algorithm section.
Please find attached, an iPython notebook. Which I hope you can find useful - Python 3.5.
Regards
Tim
On Jul 10, 2017, at 8:36 PM, Brandon Stafford [email protected] wrote:
I suspect you're on the right track here. Any thoughts on when or why asin is getting called with values above 1? I'm hesitant to just wipe out values above 1 without understanding why they're appearing in the first place.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/pingswept/pysolar/issues/52#issuecomment-314162030, or mute the thread https://github.com/notifications/unsubscribe-auth/AKtOMwnXwtxD8RQq0p95nm0emNGSe5ktks5sMlL5gaJpZM4ORtUm.
If anyone can replicate this, I'd be interested in the details.