The Standards of Fundamental Astronomy (SOFA) is a collection of algorithms creates by the International Astronomical Union (IAU). The IAU has implemented these algorithms in two programming languages: Fortran and C. However, there are implementations in other languages by other people or organizations. For example, ERFA (Essential Routines for Fundamental Astronomy) is the python implementation of SOFA and it is a prerequisite for astropy.

Fundamental Astronomy With Swift

Swift is a very powerful language. It is 8.4x faster thay python and up to 2.6x faster than C. But it is a very young langauage. It was released for the first time in 2014. There is no important astronomical package in Swift, yet. But in the future everything may change. Currently, Swift supports all major platforms, such as macOS, Linux and Windows. So, I have created a Swift package, named FAWS (Fundamental Astronomy With Swift), that is the full implementation of SOFA. It can be the basis of any astronomical library in the future.

With a mac computer you can simply use XCode to add the library. In other platforms, you have to download the package and compile the files alongside your own script. For example, suppose that you have written your code in a file named MyFile.swift and you want to run it in Windows. You can type this line in the command line, then run MyFile.exe:

swiftc -o MyFile.exe Basics.swift Matrix.swift CalTime.swift PrecNutPol.swift GeoGnoEclGalHor.swift Ephemerides.swift Astrometry.swift CatalogConv.swift MyFile.swift

How to use

All the SOFA constants, functions and structures have been implemented in FAWS. They can be accessed as an attribute or method of the main faws struct. For example, the constant DR2D in SOFA is a constant for converting radians to degrees. To use it in FAWS, you should write faws.DR2D.

When using SOFA/FAWS you haveto pay attention to units. Some useful constants for unit conversions are:

DR2D: Radians to degrees
DD2R: Degrees to radians
DAS2R: Arcseconds to radians
DMAS2R: Milliarcseconds to radians

Example: Convert Catalog ICRS to observed

Let’s say we want to find the observed coordinates of a star called Gliese 555. The Hipparcos identifier of this star is 71253 and it’s SIMBAD main_id is “BD-11 3759”. It’s basic catalog data from SIMBAD is:

ra             218.57004859310788
dec           -12.519559582093887
pmra                     -355.138
pmdec                      593.04
plx_value                159.9225
rvz_radvel                  -1.28

We have choosen the observation site in Strasbourg, France and the UTC date and time is 10th Feb 2024 at 22:32:37. The Earth Orientation Parameters have been obtained from IERS website.

import FAWS

let faws = Faws()

// Star data
let rc = 218.57004859310788 * faws.DD2R
let dc = -12.519559582093887 * faws.DD2R
let pr = -355.138 * faws.DMAS2R
let pd = 593.04 * faws.DMAS2R
let px = 159.9225 * 0.001
let rv = -1.28

// Time of observation
let (utc1, utc2) = faws.dtf2d("UTC", 2024, 2, 10, 22, 32, 37.0)

// Earth Orientation Parameters
let dut1 = 0.00261476
let xp = 0.0473476 * faws.DAS2R
let yp = 0.2368623 * faws.DAS2R

// Observation site (coordinates and conditions)
let elong = 7.744083817548831 * faws.DD2R //longitude (radians)
let phi = 48.58313582900411 * faws.DD2R   //latitude (radians)
let hm = 140.0                            //height (m)
let phpa = 987.0 //Ambient pressure (HPa)
let tc = 15.0    //Temperature (C)
let rh = 0.92    //Relative humidity (frac)
let wl = 0.55    //Effective color (microns)

let (aob, zob, hob, dob, rob, eo) = faws.atco13(
        rc, dc, pr, pd, px, rv,
        utc1, utc2, dut1,
        elong, phi, hm,
        xp, yp,
        phpa, tc, rh, wl
        )
        
    
print("Azimuth                 : \(aob * faws.DR2D)")
print("Zenith Distance         : \(zob * faws.DR2D)")
print("Hour Angle              : \(hob * faws.DR2D)")
print("Declination             : \(dob * faws.DR2D)")
print("Right Ascension         : \(rob * faws.DR2D)")
print("equation of the origins : \(eo  * faws.DR2D)")

The output (all in degrees):

Azimuth                 : 96.59548514831307
Zenith Distance         : 100.89938985767792
Hour Angle              : -92.37778736685267
Declination             : -12.498270592129632
Right Ascension         : 218.47147240846533
equation of the origins : -0.3079588055596707

The FAWS package can be accessed via this link. For the list of all functions and some examples, see this link.