Expand description
§Astronomical Calculator
A high-precision library for calculating solar position, sunrise/sunset times, and related astronomical phenomena.
This library provides accurate calculations of the Sun’s position and timing of solar events for any location on Earth. It accounts for atmospheric refraction, parallax, nutation, aberration, and other astronomical phenomena that affect solar position calculations.
This is a Rust port of the freespa library, based on VSOP87 theory.
The library is no_std compatible, making it suitable for embedded systems and constrained environments.
§Key Types
AstronomicalCalculator- Main calculator struct for solar position and event calculationsSolarPosition- Represents the Sun’s position with zenith and azimuth anglesSolarEventResult- Result type for sunrise/sunset and twilight calculationsRefraction- Atmospheric refraction model selectionget_delta_t- Function to calculate ΔT (Terrestrial Time - Universal Time)
§Basic Usage
use astronomical_calculator::{AstronomicalCalculator, Refraction};
use chrono::NaiveDateTime;
// Create a datetime (UTC)
let dt = NaiveDateTime::parse_from_str("2024-01-15 12:00:00", "%Y-%m-%d %H:%M:%S").unwrap().and_utc();
// Create calculator for New York City
// Note: longitude and latitude are in degrees
let mut calc = AstronomicalCalculator::new(
dt,
Some(69.0), // delta_t: TT-UT in seconds (≈69s for 2024)
0.0, // delta_ut1: UT1-UTC in seconds
-74.0, // longitude in degrees (negative = West)
40.7, // latitude in degrees (positive = North)
0.0, // elevation in meters
15.0, // temperature in Celsius
1013.0, // pressure in millibars
None, // optional geometric dip angle
Refraction::ApSolposBennetNA, // refraction model (recommended for precision)
).unwrap();
// Get current solar position
let position = calc.get_solar_position();
println!("Zenith: {:.2}°", position.zenith.to_degrees());
println!("Azimuth: {:.2}°", position.azimuth.to_degrees());
// Get sunrise and sunset times (as Unix timestamps)
use astronomical_calculator::SolarEventResult;
match calc.get_sunrise().unwrap() {
SolarEventResult::Occurs(timestamp) => {
println!("Sunrise at Unix timestamp: {}", timestamp);
}
SolarEventResult::AllDay => println!("Sun never sets (midnight sun)"),
SolarEventResult::AllNight => println!("Sun never rises (polar night)"),
}Structs§
- Astronomical
Calculator - Main calculator for solar position and astronomical events.
- Julian
Date - Julian date and related time values for astronomical calculations.
- Solar
Position - Solar position in local horizontal coordinates.
Enums§
- Calculation
Error - Errors that can occur during solar position calculations.
- Refraction
- Atmospheric refraction model selection.
- Solar
Event Result - Result of a solar event calculation (sunrise, sunset, twilight, etc.)
Functions§
- get_
delta_ t - Calculate ΔT (Terrestrial Time minus Universal Time) for a given date.