Browse Source

Return the ephemeris in a nice table 🤩

tags/v0.1.0
Jérôme Deuchnord 4 years ago
parent
commit
d444e4e727
No known key found for this signature in database GPG Key ID: BC6F3C345B7D33B0
6 changed files with 77 additions and 9 deletions
  1. +1
    -0
      Pipfile
  2. +8
    -1
      Pipfile.lock
  3. +19
    -0
      README.md
  4. +39
    -0
      dumper.py
  5. +7
    -7
      ephemeris.py
  6. +3
    -1
      kosmorro.py

+ 1
- 0
Pipfile View File

@@ -8,6 +8,7 @@ pylintfileheader = "*"

[packages]
skyfield = ">=1.13.0,<2.0.0"
tabulate = "*"

[requires]
python_version = "3.7"

+ 8
- 1
Pipfile.lock View File

@@ -1,7 +1,7 @@
{
"_meta": {
"hash": {
"sha256": "87e49f26ac5fcddb454c1ec4233406938f06ba68534ee464a1b1c2398f2d1d26"
"sha256": "2567979765f3ac22ecdbf4c6fbaf6e20c75bc83173db4f43d961e7a405804685"
},
"pipfile-spec": 6,
"requires": {
@@ -60,6 +60,13 @@
],
"index": "pypi",
"version": "==1.13"
},
"tabulate": {
"hashes": [
"sha256:d0097023658d4dea848d6ae73af84532d1e86617ac0925d1adf1dd903985dac3"
],
"index": "pypi",
"version": "==0.8.5"
}
},
"develop": {


+ 19
- 0
README.md View File

@@ -51,4 +51,23 @@ optional arguments:

By default, the observer will be set at position (0,0) with an altitude of 0.
You will more likely want to change that.
```

For instance, if you want the ephemeris of October 31th, 2019 in Paris, France:

```console
$ python kosmorro.py --latitude 48.8032 --longitude 2.3511 -m 10 -d 31 2019
Planet Rise time Maximum time Set time
-------- ----------- -------------- ----------
SUN 06:35 - 16:32
MERCURY 08:44 13:01 16:59
VENUS 08:35 13:01 17:18
MARS 04:48 10:20 15:51
JUPITER 10:40 15:01 18:46
SATURN 12:12 16:20 20:26
URANUS 16:23 - 06:22
NEPTUNE 14:53 20:23 01:56
PLUTO 12:36 17:01 20:50

Moon phase: New Moon
```

+ 39
- 0
dumper.py View File

@@ -0,0 +1,39 @@
from abc import ABC, abstractmethod
from tabulate import tabulate
from skyfield import almanac


class Dumper(ABC):
def __init__(self, ephemeris):
self.ephemeris = ephemeris

@abstractmethod
def to_string(self):
pass


class TextDumper(Dumper):
def to_string(self):
s = '\n\n'.join([self.get_planets(self.ephemeris['planets'], self.ephemeris['sun']),
self.get_moon(self.ephemeris['moon'])])
return s

@staticmethod
def get_planets(planets, sun):
s = [['SUN', sun['rise'].utc_strftime('%H:%M'), '-', sun['set'].utc_strftime('%H:%M')]]
for planet in planets:
name = planet
planet_data = planets[planet]
planet_rise = planet_data['rise'].utc_strftime('%H:%M') if planet_data['rise'] is not None else ' -'
planet_maximum = planet_data['maximum'].utc_strftime('%H:%M') if planet_data['maximum'] is not None\
else ' -'
planet_set = planet_data['set'].utc_strftime('%H:%M') if planet_data['set'] is not None else ' -'

s.append([name, planet_rise, planet_maximum, planet_set])

return tabulate(s, headers=['Planet', 'Rise time', 'Maximum time', 'Set time'], tablefmt='simple',
stralign='center', colalign=('left',))

@staticmethod
def get_moon(moon):
return 'Moon phase: %s' % almanac.MOON_PHASES[moon['phase']]

+ 7
- 7
ephemeris.py View File

@@ -39,7 +39,7 @@ class Ephemeris:
sunrise = t[0] if y[0] else t[1]
sunset = t[1] if not y[1] else t[0]

return {'rise': sunrise.utc_iso(), 'set': sunset.utc_iso()}
return {'rise': sunrise, 'set': sunset}

def get_moon(self, year, month, day) -> dict:
time1 = self.timescale.utc(year, month, day - 10)
@@ -138,16 +138,16 @@ class Ephemeris:
if rise_time is not None and set_time is not None and maximum_time is not None:
return {
'name': o['planet'],
'rise': rise_time.utc_iso(),
'maximum': maximum_time.utc_iso(),
'set': set_time.utc_iso()
'rise': rise_time,
'maximum': maximum_time,
'set': set_time
}

return {
'name': o['planet'],
'rise': rise_time.utc_iso() if rise_time is not None else None,
'maximum': maximum_time.utc_iso() if maximum_time is not None else None,
'set': set_time.utc_iso() if set_time is not None else None
'rise': rise_time if rise_time is not None else None,
'maximum': maximum_time if maximum_time is not None else None,
'set': set_time if set_time is not None else None
}

def compute_ephemeris_for_month(self, year: int, month: int) -> list:


+ 3
- 1
kosmorro.py View File

@@ -18,6 +18,7 @@ import argparse
import numpy
from datetime import date
from ephemeris import Ephemeris
import dumper
import json


@@ -42,7 +43,8 @@ def main():
ephemeris = Ephemeris(position)
e = ephemeris.compute_ephemeris(year, month, day)

print(json.dumps(e, default=json_default, indent=4, separators=(',', ': ')))
d = dumper.TextDumper(e)
print(d.to_string())


def get_args():


Loading…
Cancel
Save