Skip to content

Instantly share code, notes, and snippets.

@soniakeys
Last active March 22, 2018 19:31
Show Gist options
  • Save soniakeys/b066347d58a59ac6f3b4 to your computer and use it in GitHub Desktop.
Save soniakeys/b066347d58a59ac6f3b4 to your computer and use it in GitHub Desktop.
Meeus sunrise, sunset example
Sunrise: 6ʰ45ᵐ28ˢ
Sunset: 17ʰ11ᵐ46ˢ
package main
import (
"fmt"
"math"
"github.com/soniakeys/meeus/base"
"github.com/soniakeys/meeus/globe"
"github.com/soniakeys/meeus/julian"
"github.com/soniakeys/meeus/rise"
"github.com/soniakeys/meeus/sidereal"
"github.com/soniakeys/meeus/solar"
)
// a quick check against values from USNO as computed at
// http://aa.usno.navy.mil/data/docs/RS_OneDay.php
//
// U.S. Naval Observatory
// Astronomical Applications Department
//
// Sun and Moon Data for One Day
//
// The following information is provided for Boston, Suffolk County,
// Massachusetts (longitude W71.1, latitude N42.3):
//
// Wednesday
// 12 February 2014 Eastern Standard Time
//
// SUN
// Begin civil twilight 6:16 a.m.
// Sunrise 6:45 a.m.
// Sun transit 11:59 a.m.
// Sunset 5:13 p.m.
// End civil twilight 5:42 p.m.
var (
// USNO gives the coordiates it uses in decimal degrees, so I do a simple
// conversion to radians like this rather than use base.NewAngle as in
// examples in the package doc.
bostonLon = 71.1 * math.Pi / 180
bostonLat = 42.3 * math.Pi / 180
h0 = rise.Stdh0Solar // events of interest are sunrise, sunset
jd = julian.CalendarGregorianToJD(2014, 2, 12) // date of interest
tz = -5 * 3600. // EST time zone correction, in seconds
)
func main() {
p := globe.Coord{bostonLat, bostonLon}
Th0 := sidereal.Apparent0UT(jd)
ra, dec := solar.ApparentEquatorial(jd) // position of sun
mRise, _, mSet, err := rise.ApproxTimes(p, h0, Th0, ra, dec)
if err != nil {
fmt.Println(err)
return
}
fmt.Println("Sunrise: ", base.NewFmtTime(mRise+tz))
fmt.Println("Sunset: ", base.NewFmtTime(mSet+tz))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment