Kleinigkeiten und Monatsvoschrau angefangen

This commit is contained in:
2026-04-03 11:31:01 +02:00
parent f4bc622c47
commit dfd65b16e3
16 changed files with 5922 additions and 23 deletions
+135 -6
View File
@@ -1,4 +1,5 @@
#!/usr/bin/env python3
import base64
import json
import math
import os
@@ -261,6 +262,128 @@ def action_planet_rise_set(args: list[str]) -> dict:
}
def serialize_body_position(
key: str,
label: str,
body: astronomy.Body,
time_value: astronomy.Time,
observer: astronomy.Observer,
) -> dict:
eq = astronomy.Equator(body, time_value, observer, True, True)
hor = astronomy.Horizon(time_value, observer, eq.ra, eq.dec, astronomy.Refraction.Normal)
payload = {
"key": key,
"label": label,
"ra_hours": float(eq.ra),
"dec_deg": float(eq.dec),
"azimuth_deg": float(hor.azimuth),
"altitude_deg": float(hor.altitude),
"visible": float(hor.altitude) >= 0.0,
}
try:
illum = astronomy.Illumination(body, time_value)
payload["distance_au"] = float(illum.geo_dist)
payload["phase_fraction"] = float(illum.phase_fraction)
payload["magnitude"] = float(illum.mag)
except Exception:
pass
return payload
def action_month_sky_context(args: list[str]) -> dict:
if len(args) != 8:
fail(
"Aktion month_sky_context erwartet 8 Argumente: latitude longitude elevation year month hour minute timezone",
extra={"argv": args},
)
latitude = parse_float(args[0], "Latitude")
longitude = parse_float(args[1], "Longitude")
elevation = parse_float(args[2], "Elevation")
try:
year = int(args[3])
month = int(args[4])
hour = int(args[5])
minute = int(args[6])
except ValueError as exc:
fail("Jahr, Monat oder Uhrzeit sind ungueltig.", extra={"details": str(exc), "argv": args})
if month < 1 or month > 12:
fail("Monat muss zwischen 1 und 12 liegen.", extra={"month": month})
if hour < 0 or hour > 23:
fail("Stunde muss zwischen 0 und 23 liegen.", extra={"hour": hour})
if minute < 0 or minute > 59:
fail("Minute muss zwischen 0 und 59 liegen.", extra={"minute": minute})
timezone_name = args[7]
try:
tz = ZoneInfo(timezone_name)
except Exception as exc:
fail("Zeitzone ist ungueltig oder auf dem Server nicht verfuegbar.", extra={"details": str(exc)})
local_dt = datetime(year, month, 15, hour, minute, 0, tzinfo=tz)
utc_dt = local_dt.astimezone(timezone.utc)
time_value = dt_to_time(utc_dt)
observer = astronomy.Observer(latitude, longitude, elevation)
gst_hours = float(astronomy.SiderealTime(time_value))
lst_hours = normalize_degrees(gst_hours * 15.0 + longitude) / 15.0
sun = serialize_body_position("sun", "Sonne", astronomy.Body.Sun, time_value, observer)
moon = serialize_body_position("moon", "Mond", astronomy.Body.Moon, time_value, observer)
moon_phase_angle = normalize_degrees(astronomy.MoonPhase(time_value))
moon_age_days = moon_phase_angle / 360.0 * SYNODIC_MONTH
moon["phase_angle_deg"] = float(moon_phase_angle)
moon["phase_label"] = get_phase_label(moon_age_days)
moon["age_days"] = float(moon_age_days)
moon["waxing"] = moon_phase_angle <= 180.0
planets = [
serialize_body_position("mercury", "Merkur", astronomy.Body.Mercury, time_value, observer),
serialize_body_position("venus", "Venus", astronomy.Body.Venus, time_value, observer),
serialize_body_position("mars", "Mars", astronomy.Body.Mars, time_value, observer),
serialize_body_position("jupiter", "Jupiter", astronomy.Body.Jupiter, time_value, observer),
serialize_body_position("saturn", "Saturn", astronomy.Body.Saturn, time_value, observer),
serialize_body_position("uranus", "Uranus", astronomy.Body.Uranus, time_value, observer),
serialize_body_position("neptune", "Neptun", astronomy.Body.Neptune, time_value, observer),
]
return {
"ok": True,
"action": "month_sky_context",
"selected": {
"year": year,
"month": month,
"day": 15,
"hour": hour,
"minute": minute,
"timezone": timezone_name,
"local_iso": local_dt.isoformat(),
"utc_iso": utc_dt.isoformat().replace("+00:00", "Z"),
"local_label": local_dt.strftime("%d.%m.%Y %H:%M") + f" {timezone_name}",
},
"observer": {
"latitude": latitude,
"longitude": longitude,
"elevation": elevation,
},
"sidereal": {
"greenwich_hours": gst_hours,
"local_hours": lst_hours,
},
"bodies": {
"sun": sun,
"moon": moon,
"planets": planets,
},
}
def classify_visibility(sun_alt_deg: float) -> dict:
if sun_alt_deg > -5:
return {"key": "day", "label": "Tag"}
@@ -1032,7 +1155,7 @@ def _bisect_crossing(satrec, obs_ecef, lat_rad, lon_rad, t1: datetime, t2: datet
def action_satellite_passes(args: list[str]) -> dict:
if len(args) != 7:
fail(
"Aktion satellite_passes erwartet 7 Argumente: latitude longitude elevation timezone window_start_iso window_end_iso satellites_json",
"Aktion satellite_passes erwartet 7 Argumente: latitude longitude elevation timezone window_start_iso window_end_iso satellites_payload",
extra={"argv": args},
)
@@ -1042,7 +1165,7 @@ def action_satellite_passes(args: list[str]) -> dict:
timezone_name = args[3]
window_start_iso = args[4]
window_end_iso = args[5]
satellites_json = args[6]
satellites_payload = args[6]
try:
tz = ZoneInfo(timezone_name)
@@ -1056,9 +1179,10 @@ def action_satellite_passes(args: list[str]) -> dict:
fail("Zeitfenster-ISO ungueltig.", extra={"details": str(exc)})
try:
satellites_json = base64.b64decode(satellites_payload.encode("ascii")).decode("utf-8")
satellites = json.loads(satellites_json)
except json.JSONDecodeError as exc:
fail("satellites_json ist kein gueltiges JSON.", extra={"details": str(exc)})
except (ValueError, UnicodeDecodeError, json.JSONDecodeError) as exc:
fail("satellites_payload ist ungueltig.", extra={"details": str(exc)})
try:
import os as _os
@@ -1261,7 +1385,7 @@ def action_satellite_passes(args: list[str]) -> dict:
def main() -> None:
if len(sys.argv) < 2:
fail("Es wurde keine Aktion uebergeben.", extra={"available_actions": ["sun_moon_rise_set", "moon_star_occultations", "moon_phase_details", "satellite_passes"]})
fail("Es wurde keine Aktion uebergeben.", extra={"available_actions": ["sun_moon_rise_set", "moon_star_occultations", "moon_phase_details", "satellite_passes", "planet_rise_set", "month_sky_context"]})
action = sys.argv[1]
args = sys.argv[2:]
@@ -1291,7 +1415,12 @@ def main() -> None:
print(json.dumps(result, ensure_ascii=False))
return
fail("Unbekannte Aktion.", extra={"action": action, "available_actions": ["sun_moon_rise_set", "moon_star_occultations", "moon_phase_details", "satellite_passes", "planet_rise_set"]})
if action == "month_sky_context":
result = action_month_sky_context(args)
print(json.dumps(result, ensure_ascii=False))
return
fail("Unbekannte Aktion.", extra={"action": action, "available_actions": ["sun_moon_rise_set", "moon_star_occultations", "moon_phase_details", "satellite_passes", "planet_rise_set", "month_sky_context"]})
if __name__ == "__main__":