Giter Club home page Giter Club logo

onekiloparsec / swiftaa Goto Github PK

View Code? Open in Web Editor NEW
165.0 16.0 32.0 34.73 MB

The most comprehensive collection of accurate astronomical algorithms in (C++, Objective-C and) Swift.

Home Page: http://www.onekiloparsec.dev/

License: MIT License

C 0.02% C++ 96.80% CSS 0.01% Objective-C 0.21% Objective-C++ 0.01% Swift 1.06% CMake 0.02% Ruby 0.01% HTML 1.88%
astronomy swift framework algorithm cplusplus objective-c astronomical-algorithms swift-4 ios-swift ios-sdk

swiftaa's Introduction

SwiftAAaa-jsQLFitsFITSImporterObjCFITSIO

SwiftAA

Travis Codecov Carthage compatible FOSSA Status

The most comprehensive collection of accurate astronomical algorithms, in C++ and Swift, all in one place.

(Available through all distribution mechanisms: Swift Package Manager, Cocoapods and Carthage.)

Other implementations: JavaScript (aa-js), C# (AASharp).

Description

SwiftAA provides everything you need to build our Solar System, compute length of seasons, moon phases, determine rise, transit and set times, get positions of large planetary moons, transform coordinates, determine physical details of planets, their illumination, distance etc. With a professional-grade accuracy.

SwiftAA is already used in production apps. In particular, MeteorActive, a carefully crafted iOS app to get everything about meteors.

SwiftAA is first built with a C(++) layer atop the C++ implementation by P.J. Naughter of the reference textbook Astronomical Algorithms, by Jean Meeus (2nd ed., Amazon). This C++ package is called AA+ (see below). AA+ also includes additional algorithms of the VSOP87 framework, and includes the complete support for the ELP/MPP02 theory. Thus, SwiftAA, thanks to AA+, is the most complete and accurate collection of algorithms for all things astronomical in Swift.

But SwiftAA provides more modern and a lot more readable APIs, taking advantage of the expressiveness of Swift and its various syntax elements, making it fun and easy of use. In fact, you simply can't use AA+ without having the AA book. While SwiftAA is precisely made to be accessible by anyone. Additional functions and algorithms are added to improve even more the completeness and ease of use. In particular, SwiftAA provides units safety a lot stronger compared to C++ APIs.

Moreover, SwiftAA has a much larger unit tests coverage (>90% for the Swift code!). In fact, unit tests are being carefully written with data directly taken from Jean Meeus' textbook, AA+ own tests, USNO, SkySafari and Xephem (and thus trying to achieve a probably hypothetical consistency between these sources).

Documentation

The documentation generated from the code itself is available at http://onekiloparsec.github.io/SwiftAA.

Installation

Using the Swift Package Manager: either through Xcode > File > Swift Packages > Add Package Dependency... and enter this repo URL (including the .git extension), , then choose SwiftAA target. Or add the line .package(url: "https://github.com/onekiloparsec/SwiftAA.git", from: "3.0.0") in the dependencies section of your Package.swift file.

Using Carthage: add github "onekiloparsec/SwiftAA" to your Cartfile, then run carthage update, and finally add the newly built SwiftAA-macOS.framework or SwiftAA-iOS.framework into your project (in embedded binaries).

Using CocoaPods: add pod 'SwiftAA' to your Podfile and then run pod update.

Notes

AABridge

The AABridge library is simply a bridge between the C++ codebase provided by AA+ and the Swift code in SwiftAA. It's implemented entirely in C. It's recommended that you use either the A++ C++ code directly or the SwiftAA Swift wrapper.

For a long time, all the C++, (Objective-)C(++) and Swift code was bundled together. But in order to distribute SwiftAA through the SPM, it was necessary to split the sources into seperate folders. Then, three different libraries were declared in the Package.swift file and built separatedly, each of them depending on the previous one (AA+, then AABridge, and finally SwiftAA).

During that evolution, we chose to create a specific AABridge target inside the Xcode project. The consequence is that AABridge must be imported in SwiftAA source files that need it. Not a big deal, expect for Cocoapods which doesn't understand the subtelty. Hence, we created a specific AABridge pod, which will follow the versioning numbers of the main package.

In summary, we have:

  • Three targets available through the Swift Package Manager: AA+, AABridge and SwiftAA. Embed only the last level you intend to use in your project.
  • Three targets available through Carthage, inside the Xcode project: AABridge (including AA+), SwiftAA-iOS and SwiftAA-macOS.
  • Two pods available through Cocoapods: AABridge and SwiftAA.

AA+

The AA+ framework, written in C++ by PJ Naughter (Visual C++ MVP) is certainly the best and most complete implementation of the "Astronomical Algorithms", found in the reference textbook by Jean Meeus. To make the most of this code specifically, you have to have a copy of the book with you (APIs and method names are hardly understandable without knowing what they refer to).

Pull requests are accepted only about the C(++) and Swift code. The AA+ code changes must be directed (as I will personnaly do if I need to) to the original source (see the AA+ website).

Today's version of AA+ used in SwiftAA is 2.50 (released 16 April 2023).

Caution on Coordinates

The coordinates computations are key for modern astronomy. However, there is no mention to modern conventions (like ICRS) in the textbook of Jean Meeus, therefore in the AA+ code. Awaiting for such improvement, any user wanting to compute coordinates transformations should be careful. For a good example of a complete implementation of such transformations, see the AstroPy excellent package.

Prefixes & Conventions

Needless to say how different the syntax is between C, C++, Objective-C and Swift. The main guideline in writting SwiftAA was to build a C(++) layer that follow strictly the methods and interfaces of the underlying C++ library. Only the name of some variables were a bit "Objective-C-fied" (to avoid prefix them with the one-letter type, 'b' for boolean etc').

As C lacks namespaces, everything must be prefixed. It is a convention to use 3-letters prefixes in Objective-C. KPC stands for "kiloparsec" and is "my" usual prefix. I chose to keep the AA prefix that belongs to the C++ library as well. Hence the (rather long) 5-letters KPCAA prefix of all methods.

The constraint of having an C layer first comes from the fact that no C++ code can be written directly alongside Swift code (in the same file). And Swift doesn't have the header/implementation split into different files. Hence one must write a Objective-C++/C wrapper around it, with name prefixes. Additionally, this codebase is compatible with Swift on Linux, and Objective-C is largely unavailable there - and thus the AABridge layer is built in C.

Branches

For Swift4, see the swift4 branch. Likewise for Swift3 (unmaintained).

Author

Cédric Foellmi, a.k.a. @onekiloparsec (website).
(Ph.D. in astrophysics, and former support astronomer at the European Southern Observatory in Chile).
I am the author of the app iObserve (for macOS (and formerly in [iOS/iPad]) and arcsecond.io.

Support

You can help me spend more time on Open-Source software for astronomers by supporting me on Patreon!

Licence

The licence of this software is the MIT licence, which allows you to use it freely in open-source or commercial products. But it does not apply to the AA+ Framework, which retains its own licence. Quoting the original:

AA+ Copyright :

  • You are allowed to include the source code in any product (commercial, shareware, freeware or otherwise) when your product is released in binary form.
  • You are allowed to modify the source code in any way you want except you cannot modify the copyright details at the top of each module.
  • If you want to distribute source code with your application, then you are only allowed to distribute versions released by the author. This is to maintain a single distribution point for the source code.

FOSSA

FOSSA Status

swiftaa's People

Contributors

alex-vasenin avatar andris-zalitis avatar fossabot avatar ikenndac avatar onekiloparsec avatar ruslankmlv avatar sbenitezb avatar treaves avatar vincentneo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swiftaa's Issues

Compiling for Catalyst app

Hello,

Long time lurker for this project. I'm currently using this framework in one of my apps and was wondering if there was a way to build a Catalyst version of this framework (currently using Carthage). Seems like Carthage should be able to generate one since it already builds both iOS and Mac versions.
Appreciate the help and sorry if I'm asking in the wrong place.

'SignedNumber' is unavailable: Please use 'SignedNumeric & Comparable' instead.

using xcode 9.1 or even latest beta 9.3

/// Base protocol for all numeric types of SwiftAA
public protocol NumericType: _NumericType, SignedNumber, ExpressibleByFloatLiteral, Hashable { /* intentionally left blank */ }

this seems to fix it
public protocol NumericType: _NumericType, SignedNumeric & Comparable, ExpressibleByFloatLiteral, Hashable { /* intentionally left blank */ }

Swift use in an iOS App

Hi there,

I'm looking for an algorithm witch give the sun position (Azimuth & Altitude) for a specific position at a specific date & hour. Your code looks very cool :) May be it can to the job ? Can you take a part of your time to help me found the right functions to use for my goal ?

Regards

Cannot compile SwiftAA with Swift4

Even with SWIFT_VERSION=3.2, due to the changes in Swift Standard Library, Xcode 9 says .../SwiftAA/Angles.swift:96:15: Type 'ArcMinute' does not conform to protocol 'Numeric' for all NumericTypes

RiseTransitSetTimes is broken

RiseTransitSetTimes is broken because it uses CelestialBody.equatorialCoordinates which are heliocentric coordinates instead of geocentric coordinates (related to issue #24)

JulianDate implementation is flawed

This code

let date = Date(timeIntervalSinceReferenceDate: 503975049.303508)
print(date)
print(date.julianDay().date())

Results in

2016-12-21 01:04:09 +0000
2016-12-21 01:09:12 +0000 // ???

Compile Errors with Xcode 11.4 Update NumericType does not conform to protocol 'AdditiveArithmetic'

I updated my Xcode to 11.4 and got all below errors:

Type 'Magnitude' does not conform to protocol 'AdditiveArithmetic'
Type 'Day' does not conform to protocol 'AdditiveArithmetic'
Type 'Hour' does not conform to protocol 'AdditiveArithmetic'
Type 'Minute' does not conform to protocol 'AdditiveArithmetic'
Type 'Second' does not conform to protocol 'AdditiveArithmetic'
Type 'AstronomicalUnit' does not conform to protocol 'AdditiveArithmetic'
Type 'Parsec' does not conform to protocol 'AdditiveArithmetic'
Type 'Meter' does not conform to protocol 'AdditiveArithmetic'
Type 'Kilometer' does not conform to protocol 'AdditiveArithmetic'
Type 'JulianDay' does not conform to protocol 'AdditiveArithmetic'
Type 'Degree' does not conform to protocol 'AdditiveArithmetic'
Type 'ArcMinute' does not conform to protocol 'AdditiveArithmetic'
Type 'ArcSecond' does not conform to protocol 'AdditiveArithmetic'
Type 'Radian' does not conform to protocol 'AdditiveArithmetic'

Can't get ecliptic to equatorial transformation working

Here is the test code:

let now = Date().julianDay()
let sun = Sun.init(julianDay: now)
print(now) // OK
print(sun.eclipticCoordinates) // OK
print(sun.equatorialCoordinates) // RA is OK, but DEC should be -23°, not +55°

And here is the output:

JulianDay(value: 2457742.6550525003)
EclipticCoordinates(celestialLongitude: SwiftAA.Degree(value: 268.6910301599379), celestialLatitude: SwiftAA.Degree(value: -1.8868903201079716e-05), epoch: SwiftAA.JulianDay(value: 2451545.0))
EquatorialCoordinates(rightAscension: SwiftAA.Hour(value: 17.847912733146728), declination: SwiftAA.Degree(value: 54.978633717748345), epoch: SwiftAA.JulianDay(value: 2451545.0))

What I'm doing wrong?

CocoaPods

This would make a library integration a lot more easier

Failed to build for SwiftUI preview

Hello,

when I add the SwiftAA lib to my SwiftUI app, the live canvas preview fails to build:

symbol(s) not found for architecture x86_64

Here is the full error log:
build-error-swift-UI.txt

From what I understand, it looks like the ObjcAA framework is not built for x86_64 which the SwiftUI preview uses.

Did anyone run into the same problem ?
Since I am new to iOS development and struggled to just get the lib to work in a normal build, it is quite possible that I misconfigured something, so any advice would be appreciated :)

Thanks

Edit: forgot to mention the lib was added in Xcode via the Swift Package Manager (full disclosure: tried with Carthage but got another kind of error at runtime)

Incorrect results for some calls to Moon.time

I am getting some incorrect results when trying to fetch the next full moon time when using Moon.time - public func time inside Moon.swift.

Here is some code

            print ("loop begin")
            for index in 1...20 {
                calculationDate = Calendar.current.date(byAdding: .day, value: index, to: Date())!
                print("calcdate, next fullmoon",calculationDate, Moon(julianDay:JulianDay(calculationDate)).time(of: .fullMoon, forward: true, mean: false).date)
            }
            print ("end loop")

and here is the result

loop begin
calcdate, next fullmoon 2019-02-09 09:01:26 +0000 2019-02-19 15:54:38 +0000
calcdate, next fullmoon 2019-02-10 09:01:26 +0000 2019-02-19 15:54:38 +0000
calcdate, next fullmoon 2019-02-11 09:01:26 +0000 2019-02-19 15:54:38 +0000
calcdate, next fullmoon 2019-02-12 09:01:26 +0000 2019-02-19 15:54:38 +0000
calcdate, next fullmoon 2019-02-13 09:01:26 +0000 2019-02-19 15:54:38 +0000
calcdate, next fullmoon 2019-02-14 09:01:26 +0000 2019-03-21 01:44:00 +0000 <<incorrect
calcdate, next fullmoon 2019-02-15 09:01:26 +0000 2019-03-21 01:44:00 +0000 <<incorrect
calcdate, next fullmoon 2019-02-16 09:01:26 +0000 2019-03-21 01:44:00 +0000 <<incorrect
calcdate, next fullmoon 2019-02-17 09:01:26 +0000 2019-03-21 01:44:00 +0000 <<incorrect
calcdate, next fullmoon 2019-02-18 09:01:26 +0000 2019-03-21 01:44:00 +0000 <<incorrect
calcdate, next fullmoon 2019-02-19 09:01:26 +0000 2019-03-21 01:44:00 +0000 <<incorrect
calcdate, next fullmoon 2019-02-20 09:01:26 +0000 2019-03-21 01:44:00 +0000
calcdate, next fullmoon 2019-02-21 09:01:26 +0000 2019-03-21 01:44:00 +0000
calcdate, next fullmoon 2019-02-22 09:01:26 +0000 2019-03-21 01:44:00 +0000
calcdate, next fullmoon 2019-02-23 09:01:26 +0000 2019-03-21 01:44:00 +0000
calcdate, next fullmoon 2019-02-24 09:01:26 +0000 2019-03-21 01:44:00 +0000
calcdate, next fullmoon 2019-02-25 09:01:26 +0000 2019-03-21 01:44:00 +0000
calcdate, next fullmoon 2019-02-26 09:01:26 +0000 2019-03-21 01:44:00 +0000
calcdate, next fullmoon 2019-02-27 09:01:26 +0000 2019-03-21 01:44:00 +0000
calcdate, next fullmoon 2019-02-28 09:01:26 +0000 2019-03-21 01:44:00 +0000
end loop

I have marked some lines as incorrect above, they show the next full moon as being on the 21st March, whereas the next full moon is actually still to come on 19th February.
I haven't worked out the root cause of the issue yet, whether it is in SwiftAA or AA+, but I thought I would report it here. Cheers.

Planet aspects /conjunction - clarification on methods for PlanetaryPhenomena

http://onekiloparsec.github.io/SwiftAA/Protocols/PlanetaryPhenomena.html

inferiorConjunction(mean:) Default implementation
superiorConjunction(mean:) Default implementation
opposition(mean:) Default implementation
conjunction(mean:) Default implementation
easternElongation(mean:) Default implementation
westernElongation(mean:) Default implementation
station1(mean:) Default implementation
station2(mean:) Default implementation
elongationValue(eastern:) Default implementation

this website
http://www.theastrologer.com/wap/todaysaspect.php?aspect=yesterday

can determine aspects for today's date.

eg. Dec 2nd 2017
Mercury Conjunct Saturn ( )
Mars Opposite Uranus ( )
Jupiter Trine Neptune ( )

screen shot 2017-12-02 at 7 20 58 pm

Forgive the newbie question - but can that be inferred from methods above?
Did you ever implement these methods in your code?
Do you have a gist you could share?

Calculate Moonphase for Date

Hi,
I just stumbled over this great repo.
I'm looking for a function to calculate the moon phase for a specific Date. I'm pretty sure this task can be solved with your code, but I'm a absolute beginner at this topic.
Could you please tell me which functions I need ?

enhancement - scenekit / arkit helpers to display planet locations based off user location / JD

I get that this is pushing limits of responsibility for the port - but swift + astronomy naturally leads to question - "how do I use this with iphone frameworks....."

Here's an AR app for planes - determining location / bearing of plane.
Perhaps we can cherry pick some of the code / logic from @calda .

https://github.com/HTN-2017/AR-Planes

https://www.youtube.com/watch?v=dnYHQ-7wlag
screen shot 2018-03-09 at 11 18 31 am

I'm looking for something as trivial as

here's my date / time / coordinate - where is the corresponding planet pluto / mars / etc.

https://github.com/HTN-2017/AR-Planes/blob/master/AR%20Planes/Model/Flight.swift

struct Flight {
    
    // MARK: - Properties
    
    let icao: String
    let callsign: String
    let longitude: Double
    let latitude: Double
    let altitude: Double
    let noseHeading: Double
    let groundVelocity: Double
    let verticalVelocity: Double
    
    var location: CLLocation {
        let coordinate = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
        
        //note: CLLocation also accepts heading and speed, could be useful?
        return CLLocation(
            coordinate: coordinate,
            altitude: altitude,
            horizontalAccuracy: 1,
            verticalAccuracy: 1,
            timestamp: Date())
    }

func sceneKitCoordinate(relativeTo userLocation: CLLocation) -> SCNVector3 {
        let distance = location.distance(from: userLocation)
        let heading = userLocation.coordinate.getHeading(toPoint: location.coordinate)
        let headingRadians = heading * (.pi/180)
        
        let distanceScale: Double = 1/140
        let eastWestOffset = distance * sin(headingRadians) * distanceScale
        let northSouthOffset = distance * cos(headingRadians)  * distanceScale
        
        let altitudeScale: Double = 1/140 //1/20
        let upDownOffset = altitude * altitudeScale
        
        //in .gravityAndHeading, (1, 1, 1) is (east, up, south)
        return SCNVector3(eastWestOffset, upDownOffset, -northSouthOffset)
    }

Fix localMidnight

In some cases localMidnight(longitude:) returns wrong value.

let jd = JulianDay(year: 2016, month: 12, day: 20, hour: 3, minute: 5, second: 3.5)

let longitude4 = 90.0.degrees
print(jd.localMidnight(longitude: longitude4).date)
// Prints 2016-12-20 06:00:00 +0000

If we're on longitude W 90, and current time is December 20th, 03:05 UTC, then the date is not actually December 20th for us yet. December 20th will come when time is December 20th, 06:00 UTC.

  • So what is December 20th, 03:05 UTC on longitude W 90?
    • It's evening of December 19th. I.e. by local time it would be December 19th, 21:05.
  • So which date is it?
    • December 19th.
  • So what's the UTC time of local midnight?
    • December 19th, 06:00 UTC.

Pluto

Pluto: Astronomers took it out from being a planet, but very important for astrology. I haven't found a way in SwiftAA to see in what degree it is located. I use
the "apparentEclipticCoordinates" to see in what degree are the planets, but not available for Pluto or Dwarf Planet. Im I looking in the wrong place or its simply not available?

Saturn magnitude is still buggy in some cases

Saturn magnitude is still buggy in some cases:

    let jd = JulianDay(year: 2018, month: 1, day: 1) // Could be any date
    let jupiter = Jupiter(julianDay: jd)
    let saturn = Saturn(julianDay: jd)
    let uranus = Uranus(julianDay: jd)
    let neptune = Neptune(julianDay: jd)
    let gasGiants = [jupiter, saturn, uranus, neptune]
    print(saturn.magnitude.value) // Prints 0.479, as expected
    print(gasGiants[1].magnitude.value) // Prints nan !!!

This is one of the very few cases where Swift language itself falls short. Saturn's object is both Planet and Saturn. Planet has it's own magnitude as default implementation of IlluminatedFraction protocol. Saturn has it's own magnitude as computed property. Due to static dispatch Swift calls wrong implementation for magnitude in some cases. More info in SR-103.

BUG calculating illuminated fraction and phase angle

let today = Date()
for i in 1...35 {
    let date = Calendar.current.date(byAdding: .day, value: i, to: today)!
    let moon = Moon(julianDay: JulianDay(date))
    print("\ndate: ", date)
    print("illuminated: ", moon.illuminatedFraction())
    print("phase angle: ", moon.phaseAngle().inRadians)
}

...
date: 2020-06-20 07:58:09 +0000
illuminated: 0.009716656259011525
phase angle: 2.944 rad

-> BUG calculating illuminated fraction and phase angle
date: 2020-06-21 07:58:09 +0000
illuminated: 3.156544325816357e-05
phase angle: 3.130 rad

date: 2020-06-22 07:58:09 +0000
illuminated: 0.012492466021575277
phase angle: 2.918 rad
...

// Use this to reproduce the error
if let date = Calendar.current.date(from: DateComponents(timeZone: TimeZone(secondsFromGMT: 0), year: 2020, month: 06, day: 21, hour: 08, minute: 00, second: 00)) {
    let moon = Moon(julianDay: JulianDay(date))
    print("date: ", date)
    print("illuminated: ", moon.illuminatedFraction())
    print("phase angle: ", moon.phaseAngle().inRadians)
}

Calculate RiseTransitSet based on timezone

When calculating RiseTransitSet we need to have a base date. Resulting rise, transit, set values are from a time range of (base date ..< base date + 24h).

Currently the base date is calculated like this:

    private lazy var riseTransiteSetTimesDetails: RiseTransitSetTimesDetails = {
        [unowned self] in
        let midnight = self.celestialBody.julianDay.midnight

Let's say we'd like to print moonrise/moonset for year 2017 in Sydney. Even if we pass correct dates (midnights by Sydney timezone) to let moon = Moon(julianDay: JulianDay(date)) we will still get wrong result because we discard local midnight in our code and so we'll return rise/set for 24h window based on GMT.

This code:

    func testPrintMoonriseMoonset() {
        let sydney = GeographicCoordinates(positivelyWestwardLongitude: Degree(.minus, 151, 12, 0), latitude: Degree(.minus, 33, 52, 0), altitude: Meter(0))

        var gregorianCalendar = Calendar(identifier: .gregorian)
        let timeZone = TimeZone(identifier: "Australia/Sydney")!
        gregorianCalendar.timeZone = timeZone
        let dateComponents = DateComponents(timeZone: timeZone, year: 2017, month: 1, day: 1)

        var date = gregorianCalendar.date(from: dateComponents)!

        let dateFormatter = DateFormatter()
        dateFormatter.dateFormat = DateFormatter.dateFormat(fromTemplate: "d MMM, HH mm ss, z", options: 0, locale: nil)
        dateFormatter.timeZone = timeZone

        for _ in 1...365 {

            let moon = Moon(julianDay: JulianDay(date))

            let riseTransitSetTimes = RiseTransitSetTimes(celestialBody: moon, geographicCoordinates: sydney, riseSetAltitude: 0.125)

            let riseString = riseTransitSetTimes.riseTime != nil ? dateFormatter.string(from: riseTransitSetTimes.riseTime!.date) : "----"
            let setString = riseTransitSetTimes.setTime != nil ? dateFormatter.string(from: riseTransitSetTimes.setTime!.date) : "----"
            print("rise: \(riseString) | set: \(setString)")

            date = gregorianCalendar.date(byAdding: .day, value: 1, to: date)!
        }
    }

Prints:

rise: Jan 1 08:18:48 GMT+11 | set: Dec 31 21:25:11 GMT+11
rise: Jan 2 09:16:49 GMT+11 | set: Jan 1 22:07:07 GMT+11
rise: Jan 3 10:16:11 GMT+11 | set: Jan 2 22:46:33 GMT+11
rise: ---- | set: Jan 3 23:24:09 GMT+11
rise: Jan 4 11:16:39 GMT+11 | set: Jan 5 00:00:51 GMT+11
rise: Jan 5 12:18:14 GMT+11 | set: Jan 6 00:37:43 GMT+11
rise: Jan 6 13:21:14 GMT+11 | set: Jan 7 01:15:56 GMT+11
rise: Jan 7 14:25:51 GMT+11 | set: Jan 8 01:56:48 GMT+11
rise: Jan 8 15:32:00 GMT+11 | set: Jan 9 02:41:35 GMT+11

Notice how rise and set are usually in different dates by Sydney time.

This is how it should look instead.

Compile Error with XCode 11, Swift 4.x

Hi,

I am getting several compile errors:
Type 'Day' does not conform to protocol 'AdditiveArithmetic'...
Type 'Degree' does not conform to protocol 'AdditiveArithmetic'....

Thank you

Ascendant

Is their a way to calculate the Ascendant
("The ascendant ( , Asc or As), is the zodiacal sign and degree that is ascending on the eastern horizon at the specific time and location of an event").
Getting the degree that is in the eastern horizon at any given time.

NumericType suggestion

I think NumericType.value should be immutable. We don't actually use this mutability anywhere, but it makes implementations a bit more complicated. What you think?

Getting coordinates of stars

Can I use this library to get positions of the brightest stars (Regulus, etc.)? If so, how would I get started?

Fix twilights API to return correct results

Here is a code that I used to print astronomical dawn and dusk times for each day in 2017 for a location in Paris:

    func calculateTwilights() {
        let paris = GeographicCoordinates(CLLocation(latitude: 48.866667, longitude: 2.350000)) 

        let gregorianCalendar = Calendar(identifier: .gregorian)
        var date = JulianDay(year: 2017, month: 1, day: 1).date

        for _ in 1...365 {
            let earth = Earth(julianDay: JulianDay(date))

            let twilights = earth.twilights(forSunAltitude: TwilightSunAltitude.astronomical.rawValue, coordinates: paris)

            if let rise = twilights.rise {
                print("dawn: \(rise.date)")
            } else {
                print("dawn: ---")
            }
            if let set = twilights.set {
                print("dusk: \(set.date)")
            } else {
                print("dusk: ---")
            }

            date = gregorianCalendar.date(byAdding: .day, value: 1, to: date)!
        }
    }

Location coordinates (latitude: 48.866667, longitude: 2.350000) correspond to the following in the degrees: 48°52'00.0"N 2°21'00.0"E
(that can be checked here)

This is the setup that I use for checking the data at http://aa.usno.navy.mil/:
screen shot 2017-02-17 at 13 22 15

Here is a peek into the results that I got from SwiftAA:

dawn: 2017-01-01 05:54:31 +0000
dusk: 2017-01-01 18:07:15 +0000
dawn: 2017-01-02 05:54:31 +0000
dusk: 2017-01-02 18:08:10 +0000
dawn: 2017-01-03 05:54:28 +0000
dusk: 2017-01-03 18:09:07 +0000
dawn: 2017-01-04 05:54:23 +0000
dusk: 2017-01-04 18:10:05 +0000
dawn: 2017-01-05 05:54:16 +0000
dusk: 2017-01-05 18:11:05 +0000
dawn: 2017-01-06 05:54:06 +0000
dusk: 2017-01-06 18:12:06 +0000
dawn: 2017-01-07 05:53:54 +0000
dusk: 2017-01-07 18:13:08 +0000
dawn: 2017-01-08 05:53:39 +0000
dusk: 2017-01-08 18:14:12 +0000
dawn: 2017-01-09 05:53:21 +0000
dusk: 2017-01-09 18:15:17 +0000
dawn: 2017-01-10 05:53:02 +0000
....

Here is what USNO gives:
http://aa.usno.navy.mil/cgi-bin/aa_rstablew.pl?ID=AA&year=2017&task=4&place=&lon_sign=1&lon_deg=2&lon_min=21&lat_sign=1&lat_deg=48&lat_min=52&tz=0&tz_sign=-1

So it looks like we're a little bit off.

Calculating the rise and set times for a star

Hi there,

thank you for this awesome framework!
Is it possible to use SwiftAA to calculate when a star will rise and set for a given date and location on earth?

I tried the following:

        let star = AstronomicalObject(
            name: "Sirius",
            coordinates: EquatorialCoordinates(
                rightAscension: Hour(.plus, 6, 45, 9.25),
                declination: Degree(.minus, 16, 42, 47.3)
            ),
            julianDay: JulianDay(Date())
        )
        let result = star.riseTransitSetTimes(
            for: GeographicCoordinates(
                positivelyWestwardLongitude: Degree(.plus, 7, 46, 42),
                latitude: Degree(.plus, 49, 9, 3),
                altitude: 210)
        )

Unfortunately it doesn't work since riseTransitSetTimes will call the unimplemented initializer of AstronomicalObject and cause a fatalError. Is there another way to get the rise and set times of a star?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.