Add local time conversion to satellite ephemeris computation
Browse files- Imported pytz for timezone handling.
- Updated compute_ephemeris function to accept a timezone string and convert UTC times to local times.
- Modified app.py to pass the local timezone string to the compute_ephemeris function.
- Adjusted ephemeris data to display local time instead of UTC.
- app.py +2 -0
- utils/satellite_utils.py +9 -3
app.py
CHANGED
@@ -82,6 +82,7 @@ def main():
|
|
82 |
timezone = local_timezone
|
83 |
else:
|
84 |
timezone = local_timezone
|
|
|
85 |
timezone_abbr = timezone.tzname(datetime.now())
|
86 |
st.write(f"Using local time zone: {timezone} ({timezone_abbr})")
|
87 |
|
@@ -107,6 +108,7 @@ def main():
|
|
107 |
satellite_url, float(latitude), float(longitude),
|
108 |
start_datetime_utc.strftime('%Y-%m-%d'),
|
109 |
start_datetime_utc.time(), end_datetime_utc.time(),
|
|
|
110 |
custom_tle
|
111 |
)
|
112 |
if not ephemeris_df.empty:
|
|
|
82 |
timezone = local_timezone
|
83 |
else:
|
84 |
timezone = local_timezone
|
85 |
+
timezone_str = str(timezone)
|
86 |
timezone_abbr = timezone.tzname(datetime.now())
|
87 |
st.write(f"Using local time zone: {timezone} ({timezone_abbr})")
|
88 |
|
|
|
108 |
satellite_url, float(latitude), float(longitude),
|
109 |
start_datetime_utc.strftime('%Y-%m-%d'),
|
110 |
start_datetime_utc.time(), end_datetime_utc.time(),
|
111 |
+
timezone_str, # Pass the timezone string to the function
|
112 |
custom_tle
|
113 |
)
|
114 |
if not ephemeris_df.empty:
|
utils/satellite_utils.py
CHANGED
@@ -5,6 +5,7 @@ import requests
|
|
5 |
import pandas as pd
|
6 |
import numpy as np
|
7 |
from datetime import datetime
|
|
|
8 |
|
9 |
def get_cardinal_direction(azimuth_degrees):
|
10 |
"""
|
@@ -14,9 +15,9 @@ def get_cardinal_direction(azimuth_degrees):
|
|
14 |
index = int((azimuth_degrees + 22.5) // 45)
|
15 |
return directions[index % 8]
|
16 |
|
17 |
-
def compute_ephemeris(satellite_url, latitude, longitude, start_date_utc, start_time, end_time, custom_tle=None):
|
18 |
"""
|
19 |
-
Computes the ephemeris for the satellite.
|
20 |
"""
|
21 |
try:
|
22 |
ts = load.timescale()
|
@@ -40,6 +41,7 @@ def compute_ephemeris(satellite_url, latitude, longitude, start_date_utc, start_
|
|
40 |
|
41 |
# Prepare the ephemeris data
|
42 |
ephemeris_data = []
|
|
|
43 |
for satellite in satellites:
|
44 |
difference = satellite - observer
|
45 |
for ti in times:
|
@@ -50,8 +52,12 @@ def compute_ephemeris(satellite_url, latitude, longitude, start_date_utc, start_
|
|
50 |
if alt.degrees > 0: # Check if the satellite is above the horizon
|
51 |
azimuth_degrees = az.degrees
|
52 |
cardinal_direction = get_cardinal_direction(azimuth_degrees)
|
|
|
|
|
|
|
|
|
53 |
ephemeris_data.append({
|
54 |
-
"Date (
|
55 |
"R.A.": str(ra),
|
56 |
"Dec": str(dec),
|
57 |
"Altitude": f"{alt.degrees:.2f}°",
|
|
|
5 |
import pandas as pd
|
6 |
import numpy as np
|
7 |
from datetime import datetime
|
8 |
+
import pytz
|
9 |
|
10 |
def get_cardinal_direction(azimuth_degrees):
|
11 |
"""
|
|
|
15 |
index = int((azimuth_degrees + 22.5) // 45)
|
16 |
return directions[index % 8]
|
17 |
|
18 |
+
def compute_ephemeris(satellite_url, latitude, longitude, start_date_utc, start_time, end_time, timezone_str, custom_tle=None):
|
19 |
"""
|
20 |
+
Computes the ephemeris for the satellite and converts times to local time.
|
21 |
"""
|
22 |
try:
|
23 |
ts = load.timescale()
|
|
|
41 |
|
42 |
# Prepare the ephemeris data
|
43 |
ephemeris_data = []
|
44 |
+
local_tz = pytz.timezone(timezone_str)
|
45 |
for satellite in satellites:
|
46 |
difference = satellite - observer
|
47 |
for ti in times:
|
|
|
52 |
if alt.degrees > 0: # Check if the satellite is above the horizon
|
53 |
azimuth_degrees = az.degrees
|
54 |
cardinal_direction = get_cardinal_direction(azimuth_degrees)
|
55 |
+
|
56 |
+
# Convert UTC time to local time
|
57 |
+
local_time = ti.utc_datetime().replace(tzinfo=pytz.utc).astimezone(local_tz)
|
58 |
+
|
59 |
ephemeris_data.append({
|
60 |
+
"Date (Local Time)": local_time.strftime('%Y-%m-%d %H:%M:%S'),
|
61 |
"R.A.": str(ra),
|
62 |
"Dec": str(dec),
|
63 |
"Altitude": f"{alt.degrees:.2f}°",
|