A PoC of Kosmorro, before Kosmorro became cool.
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
Questo repository è archiviato. Puoi vedere i file e clonarli, ma non puoi effettuare richieste di pushj o aprire problemi/richieste di pull.

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()