From cb22bd40eb0094238b6c3ee1c064d70cb00a4172 Mon Sep 17 00:00:00 2001 From: Don Cross Date: Sat, 10 Aug 2019 18:02:15 -0400 Subject: [PATCH] Added culminate.py demo program. --- demo/c/culminate.c | 8 +++--- demo/c/test/test | 2 +- demo/python/culminate.py | 34 ++++++++++++++++++++++++++ demo/python/test/culminate_correct.txt | 16 ++++++------ demo/python/test/test | 11 ++++----- 5 files changed, 52 insertions(+), 19 deletions(-) create mode 100755 demo/python/culminate.py diff --git a/demo/c/culminate.c b/demo/c/culminate.c index 0942b24a..0500fd4f 100644 --- a/demo/c/culminate.c +++ b/demo/c/culminate.c @@ -11,9 +11,9 @@ each body's "hour angle" is 0. Having an hour angle of 0 is another way of saying that the body is - crossing the meridian, the imaginary semicircle in the sky that passes - from due north on the horizon, through the zenith (straight up), - toward due south on the horizon. At this moment the body appears to + crossing the meridian, the imaginary semicircle in the sky that passes + from due north on the horizon, through the zenith (straight up), + toward due south on the horizon. At this moment the body appears to have an azimuth of either 180 degrees (due south) or 0 (due north). */ @@ -38,7 +38,7 @@ int PrintEvent(const char *name, astro_hour_angle_t evt) int main(int argc, const char *argv[]) { - static const astro_body_t bodies[] = + static const astro_body_t bodies[] = { BODY_SUN, BODY_MOON, BODY_MERCURY, BODY_VENUS, BODY_MARS, BODY_JUPITER, BODY_SATURN, BODY_URANUS, BODY_NEPTUNE, BODY_PLUTO diff --git a/demo/c/test/test b/demo/c/test/test index 2f40fb6f..02a79701 100755 --- a/demo/c/test/test +++ b/demo/c/test/test @@ -5,7 +5,7 @@ Fail() exit 1 } -rm -f moonphase positions +rm -f moonphase positions riseset seasons culminate test/{moonphase,positions,riseset,seasons,culminate}.txt ./build || Fail "Error building example programs." echo "Testing example: moonphase.c" diff --git a/demo/python/culminate.py b/demo/python/culminate.py new file mode 100755 index 00000000..b079726f --- /dev/null +++ b/demo/python/culminate.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 +# +# culminate.py - Don Cross - 2019-08-10 +# +# Example program for Astronomy Engine: +# https://github.com/cosinekitty/astronomy +# +# This example program shows how to calculate the time +# the Sun, Moon, and planets will next reach their highest point in the sky +# as seen by an observer at a given location on the Earth. +# This is called culmination, and is found by finding when +# each body's "hour angle" is 0. +# +# Having an hour angle of 0 is another way of saying that the body is +# crossing the meridian, the imaginary semicircle in the sky that passes +# from due north on the horizon, through the zenith (straight up), +# toward due south on the horizon. At this moment the body appears to +# have an azimuth of either 180 degrees (due south) or 0 (due north). + +import sys +from astronomy import Body, SearchHourAngle +from astro_demo_common import ParseArgs + +if __name__ == '__main__': + observer, time = ParseArgs(sys.argv) + body_list = [ + Body.Sun, Body.Moon, Body.Mercury, Body.Venus, Body.Mars, + Body.Jupiter, Body.Saturn, Body.Uranus, Body.Neptune, Body.Pluto + ] + print('search :', time) + for body in body_list: + evt = SearchHourAngle(body, observer, 0.0, time) + print('{:<8s} : {} altitude={:6.2f} azimuth={:7.2f}'.format(body.name, evt.time, evt.hor.altitude, evt.hor.azimuth)) + sys.exit(0) diff --git a/demo/python/test/culminate_correct.txt b/demo/python/test/culminate_correct.txt index c54f79f4..8a621563 100644 --- a/demo/python/test/culminate_correct.txt +++ b/demo/python/test/culminate_correct.txt @@ -1,11 +1,11 @@ search : 2015-02-28T00:00:00.000Z Sun : 2015-02-28T18:12:32.330Z altitude= 52.13 azimuth= 180.00 Moon : 2015-02-28T01:58:15.580Z altitude= 77.88 azimuth= 180.00 -Mercury : 2015-02-28T16:31:18.913Z altitude= 42.57 azimuth= 180.00 -Venus : 2015-02-28T20:03:56.863Z altitude= 63.24 azimuth= 180.00 -Mars : 2015-02-28T19:52:21.650Z altitude= 62.24 azimuth= 180.00 -Jupiter : 2015-02-28T04:40:04.004Z altitude= 77.29 azimuth= 180.00 -Saturn : 2015-02-28T11:40:53.866Z altitude= 40.96 azimuth= 180.00 -Uranus : 2015-02-28T20:20:51.250Z altitude= 65.12 azimuth= 180.00 -Neptune : 2015-02-28T18:04:23.941Z altitude= 50.53 azimuth= 180.00 -Pluto : 2015-02-28T14:31:39.410Z altitude= 39.51 azimuth= 180.00 +Mercury : 2015-02-28T16:31:18.914Z altitude= 42.57 azimuth= 180.00 +Venus : 2015-02-28T20:03:56.864Z altitude= 63.24 azimuth= 180.00 +Mars : 2015-02-28T19:52:21.651Z altitude= 62.24 azimuth= 180.00 +Jupiter : 2015-02-28T04:40:04.005Z altitude= 77.29 azimuth= 180.00 +Saturn : 2015-02-28T11:40:53.867Z altitude= 40.96 azimuth= 180.00 +Uranus : 2015-02-28T20:20:51.251Z altitude= 65.12 azimuth= 180.00 +Neptune : 2015-02-28T18:04:23.942Z altitude= 50.53 azimuth= 180.00 +Pluto : 2015-02-28T14:31:39.411Z altitude= 39.51 azimuth= 180.00 diff --git a/demo/python/test/test b/demo/python/test/test index f09fedd4..c67d49e7 100755 --- a/demo/python/test/test +++ b/demo/python/test/test @@ -5,6 +5,8 @@ Fail() exit 1 } +rm -f test/{moonphase,positions,riseset,seasons,culminate}.txt + echo "Testing example: moonphase.py" ./moonphase.py 2019-06-15T09:15:32.987Z > test/moonphase.txt || Fail "Error running moonphase.py." diff test/moonphase.txt test/moonphase_correct.txt || Fail "Error comparing moonphase.py output." @@ -21,12 +23,9 @@ echo "Testing example: seasons.py" ./seasons.py 2019 > test/seasons.txt || Fail "Error running seasons.py." diff test/seasons.txt test/seasons_correct.txt || Fail "Error comparing seasons.py output." -if false; then - - echo "Testing example: culminate.py" - ./culminate +30 -90 2015-02-28T00:00Z > test/culminate.txt || Fail "Error running culminate.py." - diff test/culminate.txt test/culminate_correct.txt || Fail "Error comparing culminate.py output." -fi +echo "Testing example: culminate.py" +./culminate.py +30 -90 2015-02-28T00:00:00Z > test/culminate.txt || Fail "Error running culminate.py." +diff test/culminate.txt test/culminate_correct.txt || Fail "Error comparing culminate.py output." echo "PASS: Python examples" exit 0