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
4
4
from skyfield .api import EarthSatellite , wgs84 , load
5
- import pytz
5
+ from pytz import timezone as py_tz
6
6
from mods .import_sat import import_satellites
7
7
from mods .get_keps import get_keps
8
8
@@ -15,19 +15,18 @@ def get_sat(norad_id:int, usr_lat:float, usr_lon:float, usr_minalt:float):
15
15
sat_import = import_satellites ()
16
16
file_path = get_keps (sat_group = 'amateur' , file_format = 'csv' )
17
17
with load .open (file_path , mode = 'r' ) as f :
18
- data = list (csv . DictReader (f ))
18
+ data = list (DictReader (f ))
19
19
# 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 ))
26
25
# 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 ]
28
27
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 )
31
30
# Using parsed kep-data to make a few lists to allow easier access to the information.
32
31
sat_data = []
33
32
sat_info = []
@@ -40,27 +39,24 @@ def get_sat(norad_id:int, usr_lat:float, usr_lon:float, usr_minalt:float):
40
39
}
41
40
sat_data .append (sat_dict )
42
41
# 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 )
44
43
event_names = 'Rises' , 'Culminates' , 'Sets'
45
44
pass_limit = 1
46
45
format_str = "%b %d, %Y at %I:%M:%S %p"
47
46
# For loop to loop through data and grab only what we want based on pass_limit
48
47
# Default: Next pass that rises above set min. elevation
49
48
# 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
59
55
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"
64
60
}
65
61
sat_info .append (pass_dict )
66
62
if pass_limit == 3 : break
0 commit comments