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.
 
 
 
 

70 lines
3.2 KiB

  1. # Kosmorro - Compute The Next Ephemeris
  2. # Copyright (C) 2019 Jérôme Deuchnord <jerome@deuchnord.fr>
  3. #
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU Affero General Public License as
  6. # published by the Free Software Foundation, either version 3 of the
  7. # License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU Affero General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Affero General Public License
  15. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. import argparse
  17. import numpy
  18. from datetime import date
  19. from ephemeris import Ephemeris
  20. import json
  21. # Fixes the "TypeError: Object of type int64 is not JSON serializable"
  22. # See https://stackoverflow.com/a/50577730
  23. def json_default(o):
  24. if isinstance(o, numpy.int64):
  25. return int(o)
  26. raise TypeError('Object of type ' + str(type(o)) + ' could not be integrated in the JSON')
  27. def main():
  28. args = get_args()
  29. year = args.year
  30. month = args.month
  31. day = args.date
  32. position = {'lat': args.latitude, 'lon': args.longitude, 'alt': args.altitude}
  33. if day is not None and month is None:
  34. month = date.today().month
  35. ephemeris = Ephemeris(position)
  36. e = ephemeris.compute_ephemeris(year, month, day)
  37. print(json.dumps(e, default=json_default, indent=4, separators=(',', ': ')))
  38. def get_args():
  39. parser = argparse.ArgumentParser(description='Compute the ephemeris for a given day/month/year.',
  40. epilog='By default, the observer will be set at position (0,0) with an altitude'
  41. ' of 0. You will more likely want to change that.')
  42. parser.add_argument('--latitude', '-lat', type=float, default=0., help="The observer's position on Earth"
  43. " (latitude)")
  44. parser.add_argument('--longitude', '-lon', type=float, default=0., help="The observer's position on Earth"
  45. " (longitude)")
  46. parser.add_argument('--altitude', '-alt', type=float, default=0., help="The observer's position on Earth"
  47. " (altitude)")
  48. parser.add_argument('--date', '-d', type=int, help='A number between 1 and 28, 29, 30 or 31 (depending on the'
  49. ' month). The date you want to compute the ephemeris for')
  50. parser.add_argument('--month', '-m', type=int, help='A number between 1 and 12. The month you want to compute the'
  51. ' ephemeris for (defaults to the current month if the day is'
  52. ' defined)')
  53. parser.add_argument('year', type=int, help='The year you want to compute the ephemeris for')
  54. return parser.parse_args()
  55. if '__main__' == __name__:
  56. main()