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

Documentation #142

Closed rb3maker closed 3 years ago

rb3maker commented 3 years ago

The documentation does not appear to be correct for implementing pysolar

from pysolar.solar import *
import datetime
date = datetime.datetime.now()
print(get_altitude(42.206, -71.382, date))

I get the following error because date is not timezone-aware:

    raise NoTimeZoneInfoError(argname, dt)
pysolar.tzinfo_check.NoTimeZoneInfoError: datetime value '2021-03-02 17:19:37.150985' given for arg 'when' should be made timezone-aware.
You have to specify the 'tzinfo' attribute of 'datetime.datetime' objects.

The following code works and returns a datetime at UTC.

from pysolar.solar import *
import datetime
from datetime import timezone

date = datetime.datetime.now(timezone.utc)
print(get_altitude(42.206, -71.382, date))

Am I missing something?

pingswept commented 3 years ago

Ah, I actually just noticed that too a few days ago! Yes, I think you’re right. Pysolar used to be non-timezone aware, but now it is. I think your correction is right; I’ll fix that.

rb3maker commented 3 years ago

Thank you! This is such a useful library. My students will be using it for their solar trackers.

Could I also suggest that you pull the latitude and longitude arguments out of the function and assign them to variables so that it is clear which one is which.

~ Rich

date = datetime.datetime.now(datetime.timezone.utc) latitude = 42.206 longitude = -71.382print(get_altitude(latitude, longitude, date))date = datetime.datetime(2007, 2, 18, 15, 13, 1, 130320, tzinfo=datetime.timezone.utc)print(get_altitude(latitude, longitude, date))

On Fri, Mar 5, 2021 at 8:30 AM Brandon Stafford notifications@github.com wrote:

Ah, I actually just noticed that too a few days ago! Yes, I think you’re right. Pysolar used to be non-timezone aware, but now it is. I think your correction is right; I’ll fix that.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/pingswept/pysolar/issues/142#issuecomment-791531739, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJC2GGOKOEYCH6KYBPTDFRTTCEBLDANCNFSM4YQCBXFQ .

pingswept commented 3 years ago

Hi Rich,

That’s another good suggestion. I fixed it. Let me know if you see other deficiencies, or feel free to send pull requests with patches to fix stuff yourself.

pingswept commented 3 years ago

Hey, by the way, I was curious about your mention of students above, so I googled you, and it appears that we have basically the same job. I run the Nolop makerspace at Tufts University near Boston. Anyway, hello, fellow traveler!

rb3maker commented 3 years ago

Brandon,

Yes, I teach at Seattle University and run the Innovation Lab that is embedded in the electrical and computer engineering department. So very similar to you. We are also opening a campus wide space next fall that I am helping with.

The project that we are working on is for our Jr. Lab sequence. It is a solar tracker with a single solar cell. See attached photo. I use the project to teach electrical engineering fundamentals, lab skills, and design to our students.

Initially, we used light dependent resistors to track the sun. Spring quarter is a lot more open ended so I imagine that most students will switch to pysolar since it saves energy.

I really enjoy visiting other spaces, but that won't be happening for a while. And Boston is always a great city to visit.

My school email is bankhear@seattleu.edu. You can see some of my personal projects at @rb3.maker on Instagram.

~ Rich

On Mon, Mar 8, 2021 at 7:06 AM Brandon Stafford notifications@github.com wrote:

Hey, by the way, I was curious about your mention of students above, so I googled you, and it appears that we have basically the same job. I run the Nolop makerspace at Tufts University near Boston. Anyway, hello, fellow traveler!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/pingswept/pysolar/issues/142#issuecomment-792816607, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJC2GGI3ZRGAB3PGWXHZYKTTCTRXBANCNFSM4YQCBXFQ .