SergeyO7 commited on
Commit
7f6411d
·
verified ·
1 Parent(s): bcae291

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +91 -30
app.py CHANGED
@@ -1,7 +1,8 @@
1
  import gradio as gr
2
  import matplotlib.pyplot as plt
3
  from datetime import datetime
4
- from dateutil import parser
 
5
  from io import BytesIO
6
  from PIL import Image
7
  from geopy.geocoders import Nominatim
@@ -75,51 +76,111 @@ def lon_to_sign(lon):
75
  minutes = int((lon % 1) * 60)
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("https://github.com/aloistr/swisseph/tree/master/ephe") # 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])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  PLadder = [p for p, _ in sorted_planets]
109
- sorted_lons = [lon for _, lon in sorted_planets]
110
-
111
- # Calculate zone sizes (angular distances between consecutive planets)
112
- zone_sizes = [sorted_lons[0]] + [sorted_lons[i+1] - sorted_lons[i] for i in range(6)] + [360 - sorted_lons[6]]
113
- bordering = [[PLadder[0]]] + [[PLadder[i-1], PLadder[i]] for i in range(1, 7)] + [[PLadder[6]]]
 
 
 
 
 
 
 
 
 
 
 
114
  ZSizes = []
115
  for i, size in enumerate(zone_sizes):
116
  bord = bordering[i]
117
- X = 7 if any(p in ['Sun', 'Moon'] for p in bord) else 6 if any(p in ['Mercury', 'Venus', 'Mars'] for p in bord) else 5
118
- classification = ('Swallowed' if size <= 1 else 'Tiny' if size <= X else 'Small' if size <= 40 else
119
- 'Ideal' if 50 <= size <= 52 else 'Normal' if size < 60 else 'Big')
120
- d, m = int(size), int((size - int(size)) * 60)
121
- ZSizes.append((f"{d}°{m}'", classification))
122
- return {'PLadder': PLadder, 'ZSizes': ZSizes, 'longitudes': longitudes}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
 
124
  def plot_pladder(PLadder):
125
  fig, ax = plt.subplots()
 
1
  import gradio as gr
2
  import matplotlib.pyplot as plt
3
  from datetime import datetime
4
+ from
5
+ dateutil import parser
6
  from io import BytesIO
7
  from PIL import Image
8
  from geopy.geocoders import Nominatim
 
76
  minutes = int((lon % 1) * 60)
77
  return f"{signs[sign_index]} {degrees}°{minutes}'"
78
 
79
+ import swisseph as swe
80
+ from datetime import datetime
81
+
82
  def PLadder_ZSizes(utc_dt, lat, lon):
83
  """Calculate Planetary Ladder and Zone Sizes using Swiss Ephemeris."""
 
 
 
 
 
84
 
85
+ # Updated time range check (Swiss Ephemeris supports -13000 to +17000)
86
+ if not -13000 <= utc_dt.year <= 17000:
87
+ return {"error": "Date out of Swiss Ephemeris range (-13,000–17,000 CE)."}
88
+
89
+ # Configure Swiss Ephemeris for high precision
90
+ swe.set_ephe_path(None) # Use default ephemeris path
91
+ swe.set_jpl_file('de441.eph') # Use DE441 for best modern accuracy (optional)
92
+
93
+ # Planet mapping (Swiss Ephemeris constants)
94
  planet_objects = {
95
  'Sun': swe.SUN, 'Moon': swe.MOON, 'Mercury': swe.MERCURY,
96
  'Venus': swe.VENUS, 'Mars': swe.MARS,
97
  'Jupiter': swe.JUPITER, 'Saturn': swe.SATURN
98
  }
99
 
100
+ # Convert datetime to Julian Day (high precision)
101
+ jd_utc = swe.julday(
102
+ utc_dt.year, utc_dt.month, utc_dt.day,
103
+ utc_dt.hour + utc_dt.minute/60 + utc_dt.second/3600
104
+ )
105
 
106
+ # Calculate geocentric ecliptic longitudes (with light-time correction)
107
  longitudes = {}
108
  for planet, planet_id in planet_objects.items():
109
+ flags = swe.FLG_SWIEPH | swe.FLG_SPEED # High-precision mode
110
+ xx, _ = swe.calc_ut(jd_utc, planet_id, flags)
111
+ lon = xx[0] % 360 # Normalize to 0-360°
112
+
113
+ # Convert to degrees, minutes, seconds (DMS)
114
+ d = int(lon)
115
+ m = int((lon - d) * 60)
116
+ s = round(((lon - d) * 60 - m) * 60)
117
+
118
+ # Handle rounding (e.g., 59.999" → 60" → increment minute)
119
+ if s >= 60:
120
+ s -= 60
121
+ m += 1
122
+ if m >= 60:
123
+ m -= 60
124
+ d += 1
125
+
126
+ longitudes[planet] = f"{d}°{m:02d}'{s:02d}\""
127
+
128
+ # Sort planets by longitude (for PLadder and ZSizes)
129
+ sorted_planets = sorted(
130
+ longitudes.items(),
131
+ key=lambda x: float(x[1].split('°')[0]) # Sort by degrees
132
+ )
133
  PLadder = [p for p, _ in sorted_planets]
134
+ sorted_lons = [float(lon.split('°')[0]) for _, lon in sorted_planets]
135
+
136
+ # Calculate zone sizes (angular distances)
137
+ zone_sizes = (
138
+ [sorted_lons[0]] +
139
+ [sorted_lons[i+1] - sorted_lons[i] for i in range(6)] +
140
+ [360 - sorted_lons[6]]
141
+ )
142
+
143
+ # Classify zone sizes (with exact DMS)
144
+ bordering = (
145
+ [[PLadder[0]]] +
146
+ [[PLadder[i-1], PLadder[i]] for i in range(1, 7)] +
147
+ [[PLadder[6]]]
148
+ )
149
+
150
  ZSizes = []
151
  for i, size in enumerate(zone_sizes):
152
  bord = bordering[i]
153
+ X = (7 if any(p in ['Sun', 'Moon'] for p in bord)
154
+ else 6 if any(p in ['Mercury', 'Venus', 'Mars'] for p in bord)
155
+ else 5)
156
+
157
+ # Exact DMS for zone size
158
+ d = int(size)
159
+ m = int((size - d) * 60)
160
+ s = round(((size - d) * 60 - m) * 60)
161
+ if s >= 60:
162
+ s -= 60
163
+ m += 1
164
+ if m >= 60:
165
+ m -= 60
166
+ d += 1
167
+
168
+ classification = (
169
+ 'Swallowed' if size <= 1 else
170
+ 'Tiny' if size <= X else
171
+ 'Small' if size <= 40 else
172
+ 'Ideal' if 50 <= size <= 52 else
173
+ 'Normal' if size < 60 else
174
+ 'Big'
175
+ )
176
+
177
+ ZSizes.append((f"{d}°{m:02d}'{s:02d}\"", classification))
178
+
179
+ return {
180
+ 'PLadder': PLadder,
181
+ 'ZSizes': ZSizes,
182
+ 'longitudes': longitudes # Now in DMS format (e.g., "12°59'55\"")
183
+ }
184
 
185
  def plot_pladder(PLadder):
186
  fig, ax = plt.subplots()