onekiloparsec / SwiftAA

The most comprehensive collection of accurate astronomical algorithms in (C++, Objective-C and) Swift.
http://www.onekiloparsec.dev/
MIT License
171 stars 31 forks source link

Rise / Transit / Set times for stars seem to be off by 1 hour #99

Closed stefanengel closed 3 years ago

stefanengel commented 3 years ago

Hi there,

thanks again for providing the api that calculates rise and set times for stars. I played around with it a little bit and compared the results to SkySafari. Of course the minutes do not exactly match since there might be small differences between the equatorial coordinates and the geographic coordinates in my code and in SkySafari, so that is fine. The strange thing is that all times seem to be off by one hour.

I picked two different locations and calculated rise/transit/set times for 3 Sagittarii on August the 24th, 2020. I am currently in UTC+2 so I created a DateFormatter with my current timezone and locale to get compareable results to SkySafari.

Here is my code:

        let timeZone = TimeZone.current
        let dateTimeFormatter = DateFormatter()
        dateTimeFormatter.dateStyle = .short
        dateTimeFormatter.timeStyle = .short
        dateTimeFormatter.timeZone = timeZone
        dateTimeFormatter.locale = Locale.current
        print("The current timezone is: \(timeZone)")
        print("Hours from GMT: \(timeZone.secondsFromGMT() / 60 / 60)")
        print("The current locale is: \(Locale.current)\n")

        let day = JulianDay(year: 2020, month: 8, day: 24, hour: 12, minute: 0, second: 0)

        let threeSgr = AstronomicalObject(
            name: "3 Sagittarii",
            coordinates: EquatorialCoordinates(rightAscension: Hour(.plus, 17, 47, 33.62), declination: Degree(.minus, 27, 49, 50.85)),
            julianDay: day
        )

        let rehbergTower = GeographicCoordinates(positivelyWestwardLongitude: Degree(7.970309), latitude: Degree(49.181973))
        let hoernumBeach = GeographicCoordinates(positivelyWestwardLongitude: Degree(8.279082), latitude: Degree(54.752388))

        let resultsForRehbergTower = threeSgr.riseTransitSetTimes(
            for: rehbergTower
        )

        let resultsForHoernumBeach = threeSgr.riseTransitSetTimes(
            for: hoernumBeach
        )

        print("Rehberg Tower")
        print("3 Sagittarii rises on \(dateTimeFormatter.string(from: resultsForRehbergTower.riseTime!.date))")
        print("3 Sagittarii transit occurs on \(dateTimeFormatter.string(from: resultsForRehbergTower.transitTime!.date))")
        print("3 Sagittarii sets on \(dateTimeFormatter.string(from: resultsForRehbergTower.setTime!.date))\n")
        print("Hörnum Beach")
        print("3 Sagittarii rises on \(dateTimeFormatter.string(from: resultsForHoernumBeach.riseTime!.date))")
        print("3 Sagittarii transit occurs on \(dateTimeFormatter.string(from: resultsForHoernumBeach.transitTime!.date))")
        print("3 Sagittarii sets on \(dateTimeFormatter.string(from: resultsForHoernumBeach.setTime!.date))")

Here is the output:

The current timezone is: Europe/Berlin (current)
Hours from GMT: 2
The current locale is: en (current)

Rehberg Tower
3 Sagittarii rises on 8/24/20, 6:30 PM
3 Sagittarii transit occurs on 8/24/20, 10:04 PM
3 Sagittarii sets on 8/25/20, 1:37 AM

Hörnum Beach
3 Sagittarii rises on 8/24/20, 7:12 PM
3 Sagittarii transit occurs on 8/24/20, 10:05 PM
3 Sagittarii sets on 8/25/20, 12:58 AM

And here are the results from SkySafari:

Rehberg Tower Rise: 5:29 PM Transit: 09:02 PM Set: 12:40 AM

Hörnum Beach Rise: 6:08 PM Transit: 9:01 PM Set: 11:54 PM

At first I thought that it was some kind of local date conversion problem so I looked at the results as JulianDay and they were off by one hour as well. Is this a bug or did I miss something that must be done before calling riseTransitSetTimes?

onekiloparsec commented 3 years ago

Hi. Thanks for the report, that's strange indeed. If I read well your message, the origin of the problem seems to lie in the JulianDay computation. Mine are well covered with tests, but who knows, I may have missed something.

Can you provide here a date and the corresponding JulianDays with SKySafari and SwiftAA ? We will compare with a third souce...

onekiloparsec commented 3 years ago

I reproduce your problem with SkySafari. Here are screenshots (sorry in French):

First show date, as in your code. JulianDay seems correct. It is also what we can obtain with SwiftAA: IMG_0702

Second shot shows site: Rehberg Tower IMG_0704

Last shows 3 Sagittarii infos. And rise, transit, set times are off. IMG_0703

"Se lève" = "rises": 7:34 PM, instead of 6:30 PM "Passe" = "transits": 10:04 PM, instead of 11:07 PM "Se couche" = "sets": 2:45 AM, instead of 01:37 AM (??)

onekiloparsec commented 3 years ago

But I just noticed that if you specify UT Offset for Rehberg Tower of one (1) hour instead of 2 (which usually accounts for summer time offset) inside SkySafari, you get correct values!

Rises: 6:34, Transits: 10:07 Sets: 01:45

That is, in SkySafari, the UT offset provided must be a purely geometric one, not something accounting already for summer offset.

onekiloparsec commented 3 years ago

In conclusion I would say, your setup of Rehberg Tower is wrong by one hour. Could you confirm ? (or not) :-D

stefanengel commented 3 years ago

Hi,

thank you for the hint. You are completely right, my location setup was messed up by one hour 🙈 I fixed the locations and now everything is fine, SwiftAA calculates the correct rise/transit/set times. I apologize for wasting your time, this issue can be closed :)