Calculate daylight hours Based on gegraphical coordinates

前端 未结 4 942
日久生厌
日久生厌 2021-02-03 13:28

I want to calculate Daylight hours based on given Latitude and Longitude and DateTime
I mean calculate the time of sunrise and the time of sunset in a specefic Date and bas

4条回答
  •  闹比i
    闹比i (楼主)
    2021-02-03 14:04

    Here is a python function that returns the number of hours of daylight with arguments of latitude and day of the year(number between 1-356):

    import math
    def Daylight(latitude,day):
    P = math.asin(0.39795 * math.cos(0.2163108 + 2 * math.atan(0.9671396 * math.tan(.00860 * (day - 186)))))
    pi = math.pi
    daylightamount = 24 - (24 / pi) * math.acos(
        (math.sin((0.8333 * pi / 180) + math.sin(latitude * pi / 180) * math.sin(P)) / (math.cos(latitude * pi / 180) * math.cos(P))))
    return daylightamount
    

提交回复
热议问题