Skip to content

Commit 0f04457

Browse files
committed
Last Sync: 2025-06-27 13:07 (Mobile)
1 parent b89196e commit 0f04457

File tree

1 file changed

+24
-28
lines changed

1 file changed

+24
-28
lines changed

mods/get_sat.py

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import csv
2-
import time
3-
from datetime import datetime
1+
from csv import DictReader
2+
from time import time
3+
from datetime import datetime as dt
44
from skyfield.api import EarthSatellite, wgs84, load
5-
import pytz
5+
from pytz import timezone as py_tz
66
from mods.import_sat import import_satellites
77
from mods.get_keps import get_keps
88

@@ -15,19 +15,18 @@ def get_sat(norad_id:int, usr_lat:float, usr_lon:float, usr_minalt:float):
1515
sat_import = import_satellites()
1616
file_path = get_keps(sat_group='amateur', file_format='csv')
1717
with load.open(file_path, mode='r') as f:
18-
data = list(csv.DictReader(f))
18+
data = list(DictReader(f))
1919
# Setting Timescale/Datetime/Timezone
20-
t_s = load.timescale()
21-
local_tz = pytz.timezone('America/Detroit')
22-
epoch_now = time.time()
23-
epoch_then = epoch_now + 86400.00
24-
t0 = t_s.from_datetime(datetime.fromtimestamp(epoch_now, tz=local_tz))
25-
t1 = t_s.from_datetime(datetime.fromtimestamp(epoch_then, tz=local_tz))
20+
ts = load.timescale()
21+
l_tz = py_tz('America/Detroit')
22+
t0 = ts.from_datetime(dt.fromtimestamp(time(), tz=l_tz))
23+
ep_24 = time() + 86400.00
24+
t1 = ts.from_datetime(dt.fromtimestamp(ep_24, tz=l_tz))
2625
# Parsing Keps and returning easily callable data.
27-
earth_sats = [EarthSatellite.from_omm(t_s, fields) for fields in data]
26+
earth_sats = [EarthSatellite.from_omm(ts, fields) for fields in data]
2827
by_number = {sat.model.satnum: sat for sat in earth_sats}
29-
main_satellite = by_number[norad_id]
30-
my_pos = wgs84.latlon(usr_lat, usr_lon)
28+
main_sat = by_number[norad_id]
29+
pos = wgs84.latlon(usr_lat, usr_lon)
3130
# Using parsed kep-data to make a few lists to allow easier access to the information.
3231
sat_data = []
3332
sat_info = []
@@ -40,27 +39,24 @@ def get_sat(norad_id:int, usr_lat:float, usr_lon:float, usr_minalt:float):
4039
}
4140
sat_data.append(sat_dict)
4241
# Finding events using the two set timescales (Current time + 24hours)
43-
t, sat_events = main_satellite.find_events(my_pos, t0, t1, altitude_degrees=usr_minalt)
42+
t, sat_events = main_sat.find_events(pos, t0, t1, altitude_degrees=usr_minalt)
4443
event_names = 'Rises', 'Culminates', 'Sets'
4544
pass_limit = 1
4645
format_str = "%b %d, %Y at %I:%M:%S %p"
4746
# For loop to loop through data and grab only what we want based on pass_limit
4847
# Default: Next pass that rises above set min. elevation
4948
# Returns Rise/Max/Set elevation, datetime and satellite distance (in miles)
50-
for t_i, event in zip(t, sat_events):
51-
event_name = event_names[event]
52-
utc_datetime = t_i.astimezone(local_tz)
53-
format_datetime = utc_datetime.strftime(format_str)
54-
pos_diff = main_satellite - my_pos
55-
topocentric = pos_diff.at(t_i)
56-
alt_el, _, sat_dx = topocentric.altaz()
57-
km_mile = float(sat_dx.km) * 0.621371
58-
dx_format = str(km_mile)[:6]
49+
for ti, event in zip(t, sat_events):
50+
utc_datetime = ti.astimezone(l_tz)
51+
dt_fm = utc_datetime.strftime(format_str)
52+
pos_diff = main_sat - pos
53+
alt, _, dx = pos_diff.at(ti).altaz()
54+
km_mile = float(dx.km) * 0.621371
5955
pass_dict = {
60-
"Event": f"{event_name}",
61-
"When": f"{format_datetime}",
62-
"Elev": f"{str(alt_el)[:2]}°",
63-
"Distance": f"{dx_format}mi"
56+
"Event": f"{event_names[event]}",
57+
"When": f"{dt_fm}",
58+
"Elev": f"{str(alt)[:2]}°",
59+
"Distance": f"{str(km_mile)[:6]}mi"
6460
}
6561
sat_info.append(pass_dict)
6662
if pass_limit == 3: break

0 commit comments

Comments
 (0)