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.
 
 
 
 

72 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 dumper
  21. import json
  22. # Fixes the "TypeError: Object of type int64 is not JSON serializable"
  23. # See https://stackoverflow.com/a/50577730
  24. def json_default(o):
  25. if isinstance(o, numpy.int64):
  26. return int(o)
  27. raise TypeError('Object of type ' + str(type(o)) + ' could not be integrated in the JSON')
  28. def main():
  29. args = get_args()
  30. year = args.year
  31. month = args.month
  32. day = args.date
  33. position = {'lat': args.latitude, 'lon': args.longitude, 'alt': args.altitude}
  34. if day is not None and month is None:
  35. month = date.today().month
  36. ephemeris = Ephemeris(position)
  37. e = ephemeris.compute_ephemeris(year, month, day)
  38. d = dumper.TextDumper(e)
  39. print(d.to_string())
  40. def get_args():
  41. parser = argparse.ArgumentParser(description='Compute the ephemeris for a given day/month/year.',
  42. epilog='By default, the observer will be set at position (0,0) with an altitude'
  43. ' of 0. You will more likely want to change that.')
  44. parser.add_argument('--latitude', '-lat', type=float, default=0., help="The observer's position on Earth"
  45. " (latitude)")
  46. parser.add_argument('--longitude', '-lon', type=float, default=0., help="The observer's position on Earth"
  47. " (longitude)")
  48. parser.add_argument('--altitude', '-alt', type=float, default=0., help="The observer's position on Earth"
  49. " (altitude)")
  50. parser.add_argument('--date', '-d', type=int, help='A number between 1 and 28, 29, 30 or 31 (depending on the'
  51. ' month). The date you want to compute the ephemeris for')
  52. parser.add_argument('--month', '-m', type=int, help='A number between 1 and 12. The month you want to compute the'
  53. ' ephemeris for (defaults to the current month if the day is'
  54. ' defined)')
  55. parser.add_argument('year', type=int, help='The year you want to compute the ephemeris for')
  56. return parser.parse_args()
  57. if '__main__' == __name__:
  58. main()