Skip to content

Commit

Permalink
Merge pull request #126 from observerly/feature/dusk/GetObjectHorizon…
Browse files Browse the repository at this point in the history
…talCoordinatesForDay

feat: Added GetObjectHorizontalCoordinatesForDay().
  • Loading branch information
michealroberts authored Jun 17, 2022
2 parents 1250a4c + aea7a06 commit 3151e80
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 82 deletions.
172 changes: 90 additions & 82 deletions coverage.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,77 @@
mode: atomic
github.com/observerly/dusk/pkg/dusk/solar.go:23.45,26.2 1 42
github.com/observerly/dusk/pkg/dusk/solar.go:35.50,38.2 1 32
github.com/observerly/dusk/pkg/dusk/solar.go:47.62,50.2 1 31
github.com/observerly/dusk/pkg/dusk/solar.go:60.74,62.2 1 27
github.com/observerly/dusk/pkg/dusk/solar.go:73.46,75.2 1 28
github.com/observerly/dusk/pkg/dusk/solar.go:83.47,88.11 2 12990
github.com/observerly/dusk/pkg/dusk/solar.go:92.2,92.10 1 12990
github.com/observerly/dusk/pkg/dusk/solar.go:88.11,90.3 1 10
github.com/observerly/dusk/pkg/dusk/solar.go:108.110,114.2 2 27
github.com/observerly/dusk/pkg/dusk/solar.go:125.146,133.16 4 3
github.com/observerly/dusk/pkg/dusk/solar.go:137.2,141.8 1 3
github.com/observerly/dusk/pkg/dusk/solar.go:133.16,135.3 1 0
github.com/observerly/dusk/pkg/dusk/solar.go:153.142,181.2 12 26
github.com/observerly/dusk/pkg/dusk/solar.go:189.70,200.2 4 4
github.com/observerly/dusk/pkg/dusk/solar.go:208.74,222.12 6 2
github.com/observerly/dusk/pkg/dusk/solar.go:226.2,229.3 1 2
github.com/observerly/dusk/pkg/dusk/solar.go:222.12,224.3 1 2
github.com/observerly/dusk/pkg/dusk/transit.go:23.77,31.2 3 27
github.com/observerly/dusk/pkg/dusk/transit.go:42.135,43.43 1 10
github.com/observerly/dusk/pkg/dusk/transit.go:52.2,75.3 9 10
github.com/observerly/dusk/pkg/dusk/transit.go:43.43,49.3 1 0
github.com/observerly/dusk/pkg/dusk/transit.go:87.164,96.16 4 1
github.com/observerly/dusk/pkg/dusk/transit.go:100.2,105.39 3 1
github.com/observerly/dusk/pkg/dusk/transit.go:129.2,129.43 1 1
github.com/observerly/dusk/pkg/dusk/transit.go:96.16,98.3 1 0
github.com/observerly/dusk/pkg/dusk/transit.go:105.39,108.12 2 1442
github.com/observerly/dusk/pkg/dusk/transit.go:126.3,126.25 1 1442
github.com/observerly/dusk/pkg/dusk/transit.go:108.12,116.4 1 1441
github.com/observerly/dusk/pkg/dusk/transit.go:116.9,124.4 1 1
github.com/observerly/dusk/pkg/dusk/transit.go:141.129,142.43 1 6
github.com/observerly/dusk/pkg/dusk/transit.go:150.2,153.62 2 5
github.com/observerly/dusk/pkg/dusk/transit.go:158.2,162.3 1 5
github.com/observerly/dusk/pkg/dusk/transit.go:142.43,148.3 1 1
github.com/observerly/dusk/pkg/dusk/transit.go:153.62,156.3 2 5
github.com/observerly/dusk/pkg/dusk/transit.go:174.134,175.43 1 7
github.com/observerly/dusk/pkg/dusk/transit.go:184.2,189.16 3 4
github.com/observerly/dusk/pkg/dusk/transit.go:193.2,203.8 4 4
github.com/observerly/dusk/pkg/dusk/transit.go:175.43,181.3 1 3
github.com/observerly/dusk/pkg/dusk/transit.go:189.16,191.3 1 0
github.com/observerly/dusk/pkg/dusk/transit.go:215.135,218.16 2 2
github.com/observerly/dusk/pkg/dusk/transit.go:222.2,222.47 1 2
github.com/observerly/dusk/pkg/dusk/transit.go:227.2,236.39 5 1
github.com/observerly/dusk/pkg/dusk/transit.go:255.2,255.20 1 1
github.com/observerly/dusk/pkg/dusk/transit.go:218.16,220.3 1 0
github.com/observerly/dusk/pkg/dusk/transit.go:222.47,224.3 1 1
github.com/observerly/dusk/pkg/dusk/transit.go:236.39,249.91 4 424
github.com/observerly/dusk/pkg/dusk/transit.go:249.91,251.9 2 1
github.com/observerly/dusk/pkg/dusk/transit.go:267.123,270.16 2 2
github.com/observerly/dusk/pkg/dusk/transit.go:274.2,274.47 1 2
github.com/observerly/dusk/pkg/dusk/transit.go:284.2,291.39 4 1
github.com/observerly/dusk/pkg/dusk/transit.go:310.2,315.8 1 1
github.com/observerly/dusk/pkg/dusk/transit.go:270.16,272.3 1 0
github.com/observerly/dusk/pkg/dusk/transit.go:274.47,281.3 1 1
github.com/observerly/dusk/pkg/dusk/transit.go:291.39,304.91 4 424
github.com/observerly/dusk/pkg/dusk/transit.go:304.91,306.9 2 1
github.com/observerly/dusk/pkg/dusk/trigonometry.go:10.30,12.2 1 285160
github.com/observerly/dusk/pkg/dusk/trigonometry.go:14.30,16.2 1 206358
github.com/observerly/dusk/pkg/dusk/trigonometry.go:18.44,20.2 1 541
github.com/observerly/dusk/pkg/dusk/trigonometry.go:22.30,24.2 1 13089
github.com/observerly/dusk/pkg/dusk/trigonometry.go:26.31,28.2 1 41274
github.com/observerly/dusk/pkg/dusk/trigonometry.go:30.31,32.2 1 15324
github.com/observerly/dusk/pkg/dusk/trigonometry.go:34.31,36.2 1 1
github.com/observerly/dusk/pkg/dusk/trigonometry.go:38.36,40.2 1 25976
github.com/observerly/dusk/pkg/dusk/utils.go:15.34,17.2 1 7
github.com/observerly/dusk/pkg/dusk/utils.go:26.55,31.12 2 12986
github.com/observerly/dusk/pkg/dusk/utils.go:35.2,35.11 1 12986
github.com/observerly/dusk/pkg/dusk/utils.go:31.12,33.3 1 0
github.com/observerly/dusk/pkg/dusk/utils.go:47.84,49.2 1 4
github.com/observerly/dusk/pkg/dusk/utils.go:60.84,62.2 1 12986
github.com/observerly/dusk/pkg/dusk/utils.go:72.85,74.2 1 21
github.com/observerly/dusk/pkg/dusk/utils.go:83.57,85.2 1 2
github.com/observerly/dusk/pkg/dusk/utils.go:93.51,95.2 1 3
github.com/observerly/dusk/pkg/dusk/utils.go:103.52,106.2 2 1
github.com/observerly/dusk/pkg/dusk/lunar.go:32.47,37.11 2 13006
github.com/observerly/dusk/pkg/dusk/lunar.go:41.2,41.10 1 13006
github.com/observerly/dusk/pkg/dusk/lunar.go:37.11,39.3 1 16
Expand Down Expand Up @@ -77,26 +150,26 @@ github.com/observerly/dusk/pkg/dusk/lunar.go:855.30,857.4 1 4
github.com/observerly/dusk/pkg/dusk/lunar.go:874.106,877.16 2 2
github.com/observerly/dusk/pkg/dusk/lunar.go:881.2,884.8 1 2
github.com/observerly/dusk/pkg/dusk/lunar.go:877.16,879.3 1 0
github.com/observerly/dusk/pkg/dusk/trigonometry.go:10.30,12.2 1 277950
github.com/observerly/dusk/pkg/dusk/trigonometry.go:14.30,16.2 1 199148
github.com/observerly/dusk/pkg/dusk/trigonometry.go:18.44,20.2 1 541
github.com/observerly/dusk/pkg/dusk/trigonometry.go:22.30,24.2 1 13089
github.com/observerly/dusk/pkg/dusk/trigonometry.go:26.31,28.2 1 39832
github.com/observerly/dusk/pkg/dusk/trigonometry.go:30.31,32.2 1 13882
github.com/observerly/dusk/pkg/dusk/trigonometry.go:34.31,36.2 1 1
github.com/observerly/dusk/pkg/dusk/trigonometry.go:38.36,40.2 1 25976
github.com/observerly/dusk/pkg/dusk/astrometry.go:14.52,18.12 2 13833
github.com/observerly/dusk/pkg/dusk/astrometry.go:22.2,22.11 1 13833
github.com/observerly/dusk/pkg/dusk/astrometry.go:18.12,20.3 1 2643
github.com/observerly/dusk/pkg/dusk/twilight.go:38.163,49.16 5 9
github.com/observerly/dusk/pkg/dusk/twilight.go:53.2,57.18 1 9
github.com/observerly/dusk/pkg/dusk/twilight.go:49.16,51.3 1 0
github.com/observerly/dusk/pkg/dusk/twilight.go:69.139,74.2 2 3
github.com/observerly/dusk/pkg/dusk/twilight.go:85.142,90.2 2 3
github.com/observerly/dusk/pkg/dusk/twilight.go:101.146,106.2 2 3
github.com/observerly/dusk/pkg/dusk/astrometry.go:14.52,18.12 2 15275
github.com/observerly/dusk/pkg/dusk/astrometry.go:22.2,22.11 1 15275
github.com/observerly/dusk/pkg/dusk/astrometry.go:18.12,20.3 1 2998
github.com/observerly/dusk/pkg/dusk/astrometry.go:34.73,42.2 4 4
github.com/observerly/dusk/pkg/dusk/coordinates.go:101.108,124.2 10 12982
github.com/observerly/dusk/pkg/dusk/coordinates.go:136.149,151.2 6 15273
github.com/observerly/dusk/pkg/dusk/epoch.go:31.56,33.2 1 22
github.com/observerly/dusk/pkg/dusk/epoch.go:41.48,46.2 2 118718
github.com/observerly/dusk/pkg/dusk/epoch.go:41.48,46.2 2 121602
github.com/observerly/dusk/pkg/dusk/epoch.go:53.45,55.2 1 79
github.com/observerly/dusk/pkg/dusk/epoch.go:63.60,93.13 15 13836
github.com/observerly/dusk/pkg/dusk/epoch.go:97.2,97.12 1 13836
github.com/observerly/dusk/pkg/dusk/epoch.go:93.13,95.3 1 4589
github.com/observerly/dusk/pkg/dusk/epoch.go:106.74,114.11 4 13834
github.com/observerly/dusk/pkg/dusk/epoch.go:118.2,118.17 1 13834
github.com/observerly/dusk/pkg/dusk/epoch.go:63.60,93.13 15 15278
github.com/observerly/dusk/pkg/dusk/epoch.go:97.2,97.12 1 15278
github.com/observerly/dusk/pkg/dusk/epoch.go:93.13,95.3 1 5097
github.com/observerly/dusk/pkg/dusk/epoch.go:106.74,114.11 4 15276
github.com/observerly/dusk/pkg/dusk/epoch.go:118.2,118.17 1 15276
github.com/observerly/dusk/pkg/dusk/epoch.go:114.11,116.3 1 0
github.com/observerly/dusk/pkg/dusk/epoch.go:127.65,138.2 4 36
github.com/observerly/dusk/pkg/dusk/epoch.go:146.76,154.2 3 77943
Expand Down Expand Up @@ -136,68 +209,3 @@ github.com/observerly/dusk/pkg/dusk/lawrence.go:152.58,160.2 3 12996
github.com/observerly/dusk/pkg/dusk/lawrence.go:170.70,178.14 3 12995
github.com/observerly/dusk/pkg/dusk/lawrence.go:182.2,182.11 1 12995
github.com/observerly/dusk/pkg/dusk/lawrence.go:178.14,180.3 1 0
github.com/observerly/dusk/pkg/dusk/twilight.go:38.163,49.16 5 9
github.com/observerly/dusk/pkg/dusk/twilight.go:53.2,57.18 1 9
github.com/observerly/dusk/pkg/dusk/twilight.go:49.16,51.3 1 0
github.com/observerly/dusk/pkg/dusk/twilight.go:69.139,74.2 2 3
github.com/observerly/dusk/pkg/dusk/twilight.go:85.142,90.2 2 3
github.com/observerly/dusk/pkg/dusk/twilight.go:101.146,106.2 2 3
github.com/observerly/dusk/pkg/dusk/utils.go:15.34,17.2 1 7
github.com/observerly/dusk/pkg/dusk/utils.go:26.55,31.12 2 12986
github.com/observerly/dusk/pkg/dusk/utils.go:35.2,35.11 1 12986
github.com/observerly/dusk/pkg/dusk/utils.go:31.12,33.3 1 0
github.com/observerly/dusk/pkg/dusk/utils.go:47.84,49.2 1 4
github.com/observerly/dusk/pkg/dusk/utils.go:60.84,62.2 1 12986
github.com/observerly/dusk/pkg/dusk/utils.go:72.85,74.2 1 21
github.com/observerly/dusk/pkg/dusk/utils.go:83.57,85.2 1 2
github.com/observerly/dusk/pkg/dusk/utils.go:93.51,95.2 1 3
github.com/observerly/dusk/pkg/dusk/utils.go:103.52,106.2 2 1
github.com/observerly/dusk/pkg/dusk/coordinates.go:101.108,124.2 10 12982
github.com/observerly/dusk/pkg/dusk/coordinates.go:136.149,151.2 6 13831
github.com/observerly/dusk/pkg/dusk/solar.go:23.45,26.2 1 42
github.com/observerly/dusk/pkg/dusk/solar.go:35.50,38.2 1 32
github.com/observerly/dusk/pkg/dusk/solar.go:47.62,50.2 1 31
github.com/observerly/dusk/pkg/dusk/solar.go:60.74,62.2 1 27
github.com/observerly/dusk/pkg/dusk/solar.go:73.46,75.2 1 28
github.com/observerly/dusk/pkg/dusk/solar.go:83.47,88.11 2 12990
github.com/observerly/dusk/pkg/dusk/solar.go:92.2,92.10 1 12990
github.com/observerly/dusk/pkg/dusk/solar.go:88.11,90.3 1 10
github.com/observerly/dusk/pkg/dusk/solar.go:108.110,114.2 2 27
github.com/observerly/dusk/pkg/dusk/solar.go:125.146,133.16 4 3
github.com/observerly/dusk/pkg/dusk/solar.go:137.2,141.8 1 3
github.com/observerly/dusk/pkg/dusk/solar.go:133.16,135.3 1 0
github.com/observerly/dusk/pkg/dusk/solar.go:153.142,181.2 12 26
github.com/observerly/dusk/pkg/dusk/solar.go:189.70,200.2 4 4
github.com/observerly/dusk/pkg/dusk/solar.go:208.74,222.12 6 2
github.com/observerly/dusk/pkg/dusk/solar.go:226.2,229.3 1 2
github.com/observerly/dusk/pkg/dusk/solar.go:222.12,224.3 1 2
github.com/observerly/dusk/pkg/dusk/transit.go:23.77,31.2 3 27
github.com/observerly/dusk/pkg/dusk/transit.go:42.135,43.43 1 10
github.com/observerly/dusk/pkg/dusk/transit.go:52.2,75.3 9 10
github.com/observerly/dusk/pkg/dusk/transit.go:43.43,49.3 1 0
github.com/observerly/dusk/pkg/dusk/transit.go:87.129,88.43 1 6
github.com/observerly/dusk/pkg/dusk/transit.go:96.2,99.62 2 5
github.com/observerly/dusk/pkg/dusk/transit.go:104.2,108.3 1 5
github.com/observerly/dusk/pkg/dusk/transit.go:88.43,94.3 1 1
github.com/observerly/dusk/pkg/dusk/transit.go:99.62,102.3 2 5
github.com/observerly/dusk/pkg/dusk/transit.go:120.134,121.43 1 7
github.com/observerly/dusk/pkg/dusk/transit.go:130.2,135.16 3 4
github.com/observerly/dusk/pkg/dusk/transit.go:139.2,149.8 4 4
github.com/observerly/dusk/pkg/dusk/transit.go:121.43,127.3 1 3
github.com/observerly/dusk/pkg/dusk/transit.go:135.16,137.3 1 0
github.com/observerly/dusk/pkg/dusk/transit.go:161.135,164.16 2 2
github.com/observerly/dusk/pkg/dusk/transit.go:168.2,168.47 1 2
github.com/observerly/dusk/pkg/dusk/transit.go:173.2,182.39 5 1
github.com/observerly/dusk/pkg/dusk/transit.go:201.2,201.20 1 1
github.com/observerly/dusk/pkg/dusk/transit.go:164.16,166.3 1 0
github.com/observerly/dusk/pkg/dusk/transit.go:168.47,170.3 1 1
github.com/observerly/dusk/pkg/dusk/transit.go:182.39,195.91 4 424
github.com/observerly/dusk/pkg/dusk/transit.go:195.91,197.9 2 1
github.com/observerly/dusk/pkg/dusk/transit.go:213.123,216.16 2 2
github.com/observerly/dusk/pkg/dusk/transit.go:220.2,220.47 1 2
github.com/observerly/dusk/pkg/dusk/transit.go:230.2,237.39 4 1
github.com/observerly/dusk/pkg/dusk/transit.go:256.2,261.8 1 1
github.com/observerly/dusk/pkg/dusk/transit.go:216.16,218.3 1 0
github.com/observerly/dusk/pkg/dusk/transit.go:220.47,227.3 1 1
github.com/observerly/dusk/pkg/dusk/transit.go:237.39,250.91 4 424
github.com/observerly/dusk/pkg/dusk/transit.go:250.91,252.9 2 1
54 changes: 54 additions & 0 deletions pkg/dusk/transit.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,60 @@ func GetObjectRiseObjectSetTimesInUTCForDay(datetime time.Time, eq EquatorialCoo
}
}

/*
GetObjectHorizontalCoordinatesForDay()
@param datetime - the datetime of the observer (in UTC)
@params eq - the EquatorialCoordinate{} of the object to calculate the rise and set times for
@param longitude - is the longitude (west is negative, east is positive) in degrees of some observer on Earth
@param latitude - is the latitude (south is negative, north is positive) in degrees of some observer on Earth
@returns the horizontal coordinates of the target object for every minute of a given day.
*/
func GetObjectHorizontalCoordinatesForDay(datetime time.Time, eq EquatorialCoordinate, longitude float64, latitude float64) ([]TransitHorizontalCoordinate, error) {
// create an empty list of horizontalCoordinate structs:
horizontalCoordinates := make([]TransitHorizontalCoordinate, 1442)

// get the corresponding timezone for the longitude and latitude provided:
timezone := tzm.LatLngToTimezoneString(latitude, longitude)

location, err := time.LoadLocation(timezone)

if err != nil {
return horizontalCoordinates, err
}

var d = time.Date(datetime.Year(), datetime.Month(), datetime.Day(), 0, 0, 0, 0, location).In(time.UTC)

// Subtract one minute to ensure we are not over looking the rise time to be
d = d.Add(time.Minute * -1)

for i := range horizontalCoordinates {
var hz HorizontalCoordinate = ConvertEquatorialCoordinateToHorizontal(d, longitude, latitude, eq)

if i > 0 {
horizontalCoordinates[i] = TransitHorizontalCoordinate{
Datetime: d.In(location),
Altitude: hz.Altitude,
Azimuth: hz.Azimuth,
IsRise: hz.Altitude > 0 && horizontalCoordinates[i-1].Altitude <= 0,
IsSet: hz.Altitude < 0 && horizontalCoordinates[i-1].Altitude >= 0,
}
} else {
horizontalCoordinates[i] = TransitHorizontalCoordinate{
Datetime: d.In(location),
Altitude: hz.Altitude,
Azimuth: hz.Azimuth,
IsRise: false,
IsSet: false,
}
}

d = d.Add(time.Minute)
}

return horizontalCoordinates[1:1441], nil
}

/*
GetObjectRiseObjectSetTimesInUTC()
Expand Down
18 changes: 18 additions & 0 deletions pkg/dusk/transit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,24 @@ func TestGetDoesObjectRiseOrSetArcturusSouthernHemisphere(t *testing.T) {
}
}

func TestGetObjectHorizontalCoordinatesForDay(t *testing.T) {
var datetime time.Time = time.Date(2022, 5, 14, 0, 0, 0, 0, time.UTC)

var got, err = GetObjectHorizontalCoordinatesForDay(datetime, EquatorialCoordinate{RightAscension: 88.7929583, Declination: 7.4070639}, -155.468094, 19.798484)

if err != nil {
t.Errorf("got %q", err)
}

if got[518].Datetime.String() == "2022-05-14 08:37:00 -1000 HST" && !got[860].IsRise {
t.Errorf("We're expecting Betelgeuse to rise at 8:37am on 14th May 2022")
}

if got[1257].Datetime.String() == "2022-05-14 20:56:00 -1000 HST" && !got[135].IsSet {
t.Errorf("We're expecting Betelgeuse to set at 8:56pm on 14th May 2022")
}
}

func TestGetObjectRiseObjectSetTimesInUTCLawrenceChapter5Exercise1(t *testing.T) {
var datetime time.Time = time.Date(2015, 6, 6, 0, 0, 0, 0, time.UTC)

Expand Down

0 comments on commit 3151e80

Please sign in to comment.