SergeyO7 commited on
Commit
b6bb994
·
verified ·
1 Parent(s): 5a2f1ac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -18
app.py CHANGED
@@ -8,6 +8,8 @@ from PIL import Image
8
  from geopy.geocoders import Nominatim
9
  from timezonefinder import TimezoneFinder
10
  import pytz
 
 
11
 
12
  # Russian translations for planets
13
  planet_ru = {
@@ -74,33 +76,32 @@ def lon_to_sign(lon):
74
  return f"{signs[sign_index]} {degrees}°{minutes}'"
75
 
76
  def PLadder_ZSizes(utc_dt, lat, lon):
77
- """Calculate Planetary Ladder and Zone Sizes."""
78
  if not 1900 <= utc_dt.year <= 2050:
79
  return {"error": "Date out of range (1900–2050)."}
80
 
81
- # Load the JPL ephemeris (DE421)
82
- planets = load('de421.bsp')
83
- earth = planets['earth']
84
 
85
- # Define planet objects (using barycenters for Jupiter and Saturn)
86
  planet_objects = {
87
- 'Sun': planets['sun'], 'Moon': planets['moon'], 'Mercury': planets['mercury'],
88
- 'Venus': planets['venus'], 'Mars': planets['mars'],
89
- 'Jupiter': planets['jupiter barycenter'], 'Saturn': planets['saturn barycenter']
90
  }
91
 
92
- # Create a timescale and convert the UTC datetime to a Skyfield time object
93
- ts = load.timescale()
94
- t = ts.from_datetime(utc_dt)
95
-
96
  # Calculate geocentric ecliptic longitudes for each planet
97
  longitudes = {}
98
- for planet, obj in planet_objects.items():
99
- # Geocentric position from Earth's center
100
- astrometric = earth.at(t).observe(obj)
101
- apparent = astrometric.apparent()
102
- _, lon, _ = apparent.ecliptic_latlon()
103
- longitudes[planet] = lon.degrees
104
 
105
  # Sort planets by their ecliptic longitude
106
  sorted_planets = sorted(longitudes.items(), key=lambda x: x[1])
 
8
  from geopy.geocoders import Nominatim
9
  from timezonefinder import TimezoneFinder
10
  import pytz
11
+ import swisseph as swe
12
+
13
 
14
  # Russian translations for planets
15
  planet_ru = {
 
76
  return f"{signs[sign_index]} {degrees}°{minutes}'"
77
 
78
  def PLadder_ZSizes(utc_dt, lat, lon):
79
+ """Calculate Planetary Ladder and Zone Sizes using Swiss Ephemeris."""
80
  if not 1900 <= utc_dt.year <= 2050:
81
  return {"error": "Date out of range (1900–2050)."}
82
 
83
+ # Initialize Swiss Ephemeris
84
+ swe.set_ephe_path(None) # Use default ephemeris path
 
85
 
86
+ # Map planet names to Swiss Ephemeris constants
87
  planet_objects = {
88
+ 'Sun': swe.SUN, 'Moon': swe.MOON, 'Mercury': swe.MERCURY,
89
+ 'Venus': swe.VENUS, 'Mars': swe.MARS,
90
+ 'Jupiter': swe.JUPITER, 'Saturn': swe.SATURN
91
  }
92
 
93
+ # Convert datetime to Julian Day
94
+ jd = swe.julday(utc_dt.year, utc_dt.month, utc_dt.day,
95
+ utc_dt.hour + utc_dt.minute/60 + utc_dt.second/3600)
96
+
97
  # Calculate geocentric ecliptic longitudes for each planet
98
  longitudes = {}
99
+ for planet, planet_id in planet_objects.items():
100
+ # Calculate position (geocentric, apparent, with light-time correction)
101
+ flags = swe.FLG_SWIEPH | swe.FLG_SPEED
102
+ xx, _ = swe.calc_ut(jd, planet_id, flags)
103
+ lon = xx[0] # ecliptic longitude in degrees
104
+ longitudes[planet] = lon % 360 # ensure 0-360 range
105
 
106
  # Sort planets by their ecliptic longitude
107
  sorted_planets = sorted(longitudes.items(), key=lambda x: x[1])