A PoC of Kosmorro, before Kosmorro became cool.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import argparse
  2. import numpy
  3. from datetime import date
  4. from ephemeris import Ephemeris
  5. import json
  6. # Fixes the "TypeError: Object of type int64 is not JSON serializable"
  7. # See https://stackoverflow.com/a/50577730
  8. def json_default(o):
  9. if isinstance(o, numpy.int64):
  10. return int(o)
  11. raise TypeError('Object of type ' + str(type(o)) + ' could not be integrated in the JSON')
  12. def main():
  13. args = get_args()
  14. year = args.year
  15. month = args.month
  16. day = args.date
  17. position = {'lat': args.latitude, 'lon': args.longitude, 'alt': args.altitude}
  18. if day is not None and month is None:
  19. month = date.today().month
  20. ephemeris = Ephemeris(position)
  21. e = ephemeris.compute_ephemeris(year, month, day)
  22. print(json.dumps(e, default=json_default, indent=4, separators=(',', ': ')))
  23. def get_args():
  24. parser = argparse.ArgumentParser(description='Compute the ephemeris for a given day/month/year, by default for'
  25. ' Paris, France.', epilog='By default, the observer will be set at'
  26. ' position (0,0) with an altitude of 0.'
  27. ' You will more likely want to change that.')
  28. parser.add_argument('--latitude', '-lat', type=float, default=0., help="The observer's position on Earth"
  29. " (latitude)")
  30. parser.add_argument('--longitude', '-lon', type=float, default=0., help="The observer's position on Earth"
  31. " (longitude)")
  32. parser.add_argument('--altitude', '-alt', type=float, default=0., help="The observer's position on Earth"
  33. " (altitude)")
  34. parser.add_argument('--date', '-d', type=int, help='A number between 1 and 28, 29, 30 or 31 (depending on the'
  35. ' month). The date you want to compute the ephemeris for')
  36. parser.add_argument('--month', '-m', type=int, help='A number between 1 and 12. The month you want to compute the'
  37. ' ephemeris for (defaults to the current month if the day is'
  38. ' defined)')
  39. parser.add_argument('year', type=int, help='The year you want to compute the ephemeris for')
  40. return parser.parse_args()
  41. if '__main__' == __name__:
  42. main()