summaryrefslogtreecommitdiff
path: root/iss/tests/test_predictions.py
blob: 6af32d3ea667c6e15641f72886422185bf553e13 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from pathlib import Path
from skyfield.api import Topos

from ..predictions import Predictions

DATA_DIR = Path(__file__).parent / "data"
STATIONS = DATA_DIR / "stations.txt"


def test_get_timescales():
    days = 5
    p = Predictions(lat=32.0853, lng=34.7817, days=days)
    t0, t1 = p.get_next_days()
    delta = t1.ut1 - t0.ut1
    assert delta == days


def test_custom_start():
    start = 2459117.245895914
    p = Predictions(lat=32.0853, lng=34.7817, start=start)
    t0, _t1 = p.get_next_days()
    assert t0.ut1 == start


def test_get_location():
    p = Predictions(lat=32.0853, lng=34.7817)
    tlv = Topos("32.0853 N", "34.7817 E")
    location = p.location
    assert location.latitude.degrees == tlv.latitude.degrees
    assert location.longitude.degrees == tlv.longitude.degrees


def test_get_prediction_events():
    start = 2459117.245895914

    p = Predictions(
        lat=32.0853, lng=34.7817, tz="Asia/Jerusalem", start=start, tle_file=STATIONS
    )
    preds = p.get_prediction_events()
    assert len(preds) == 77
    preds = [[t.ut1 for t in pred] for pred in preds]
    assert preds[0] == [2459117.2606692477, 2459117.261888149, 2459117.263112468]

    p = Predictions(
        lat=32.0853,
        lng=34.7817,
        tz="Asia/Jerusalem",
        altitude=0,
        start=start,
        days=5,
        tle_file=STATIONS,
    )
    preds = p.get_prediction_events()
    assert len(preds) == 39


def test_get_predictions():
    start = 2459117.245895914
    p = Predictions(
        lat=32.0853, lng=34.7817, tz="Asia/Jerusalem", start=start, tle_file=STATIONS
    )
    preds = p.get_predictions()
    assert len(preds) == 77
    assert preds[0]["rise"]["time"] == "2020-09-24T18:15:22Z"
    assert preds[0]["rise"]["azimuth"] == 347
    assert preds[0]["culminate"]["degrees"] == 1
    assert preds[0]["set"]["distance"] == 2364


def test_get_grouped_predictions():
    start = 2459117.245895914
    p = Predictions(
        lat=32.0853, lng=34.7817, tz="Asia/Jerusalem", start=start, tle_file=STATIONS
    )
    preds = p.get_grouped_predictions()
    assert "2020-09-28" in preds
    assert preds["2020-09-28"][0]["rise"]["time"] == "10:14:43"
    assert preds["2020-09-28"][1]["culminate"]["time"] == "11:51:14"
    assert preds["2020-09-28"][1]["set"]["time"] == "11:56:36"