Calculate the altitude, rise, and set times of celestial objects (Sun, Moon, planets, stars, and deep-space objects) for any location on Earth.
Calculate the altitude, rise, and set times of celestial objects (Sun, Moon, planets, stars, and deep-space objects) for any location on Earth, with optional light pollution analysis.
pip install astropy pytz numpy astroquery rasterio geopy
from src.celestial import celestial_pos from astropy.coordinates import EarthLocation import pytz from datetime import datetime # Observer location (New York) location = EarthLocation(lat=40.7128, lon=-74.0060) # Time (local timezone-aware) local_time = pytz.timezone("America/New_York").localize(datetime(2023, 10, 1, 12, 0)) altitude, azimuth = celestial_pos("sun", location, local_time) print(f"Sun Position: Altitude={altitude:.1f}°, Azimuth={azimuth:.1f}°")
from src.celestial import celestial_rise_set rise, set_ = celestial_rise_set("andromeda", location, local_time.date()) print(f"Andromeda: Rise={rise.iso}, Set={set_.iso}")
from src.light_pollution import load_map # Load a GeoTIFF light pollution map vriis_data, bounds, crs, transform = load_map("path/to/map.tif") print(f"Map Bounds: {bounds}")
celestial_pos(celestial_object, observer_location, time)
(src/celestial.py
)celestial_object
: Name (e.g., "sun"
, "andromeda"
).observer_location
: EarthLocation
object.time
: datetime
(timezone-aware) or Astropy Time
.(altitude_degrees, azimuth_degrees)
.celestial_rise_set(celestial_object, observer_location, date, horizon=0.0)
(src/celestial.py
)date
: Timezone-aware datetime
.horizon
: Horizon elevation (default: 0°).(rise_time, set_time)
as UTC Time
objects.load_map(map_path)
(src/light_pollution.py
)map_path
: Path to GeoTIFF file.(vriis_data, bounds, crs, transform)
for light pollution analysis.Run tests with:
pytest tests/
tests/test_celestial.py
)def test_calculate_altitude_deepspace(): """Test deep-space object resolution.""" altitude, _ = celestial_pos("andromeda", NYC, Time.now()) assert -90 <= altitude <= 90 def test_calculate_rise_set_sun(): """Validate Sun rise/set times.""" rise, set_ = celestial_rise_set("sun", NYC, datetime(2023, 10, 1)) assert rise < set_
.
├── src/
│ ├── celestial.py # Core celestial calculations
│ ├── light_pollution.py # Light pollution map utilities
│ ├── utils.py # Time/location helpers
│ └── main.py # CLI entry point
├── tests/
│ ├── test_celestial.py
│ └── test_utils.py
└── README.md
light_pollution.py
to features and API reference.rasterio
and geopy
to installation instructions.
Discover shared experiences
Shared threads will appear here, showcasing real-world applications and insights from the community. Check back soon for updates!