1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
//! Sidereal time calculations for astronomical observations.
//!
//! This module provides functions to calculate sidereal time - the time system based on
//! Earth's rotation relative to the stars rather than the Sun. Sidereal time is essential
//! for telescope pointing and celestial coordinate conversions.
//!
//! # Overview
//!
//! While solar time (UTC) is based on the Sun's position, sidereal time tracks Earth's
//! rotation relative to distant stars. A sidereal day is about 23h 56m 4s, roughly 4
//! minutes shorter than a solar day.
//!
//! # Types of Sidereal Time
//!
//! - **Greenwich Mean Sidereal Time (GMST)**: Sidereal time at Greenwich meridian,
//! based on Earth's uniform rotation
//! - **Local Mean Sidereal Time (LMST)**: GMST adjusted for observer's longitude
//! - **Apparent Sidereal Time**: True sidereal time including nutation effects
//!
//! # Applications
//!
//! - **Telescope Pointing**: Converting RA/Dec to Alt/Az requires local sidereal time
//! - **Meridian Transit**: Objects transit when their RA equals the LST
//! - **Hour Angle**: HA = LST - RA tells you where an object is relative to meridian
//!
//! # Example
//!
//! ```
//! use chrono::{Utc, TimeZone};
//! use astro_math::{julian_date, Location};
//!
//! let location = Location {
//! latitude_deg: 40.0,
//! longitude_deg: -74.0,
//! altitude_m: 0.0
//! };
//! let dt = Utc::now();
//! let lst = location.local_sidereal_time(dt);
//!
//! // Object at RA = LST is on the meridian (highest point)
//! println!("Current LST: {:.2} hours", lst);
//! ```
use crateerfa;
/// Computes the Greenwich Mean Sidereal Time (GMST) in fractional hours (0.0–24.0)
/// from a Julian Date (JD).
///
/// This function uses ERFA's IAU 2006 model for maximum accuracy and compatibility
/// with professional astronomy software like astropy.
///
/// ### Accuracy:
/// This provides milliarcsecond-level accuracy, suitable for professional
/// astronomical observations and precise telescope pointing.
///
/// # Arguments
/// * `jd` - Julian Date, typically computed using [`julian_date`](crate::time::julian_date)
///
/// # Returns
/// GMST in fractional hours (e.g. `13.781` = 13h 46m 51s)
///
/// # Example
/// ```
/// use chrono::{Utc, TimeZone};
/// use astro_math::time::julian_date;
/// use astro_math::sidereal::gmst;
///
/// let dt = Utc.with_ymd_and_hms(1987, 4, 10, 19, 21, 0).unwrap();
/// let jd = julian_date(dt);
/// let gmst = gmst(jd);
/// assert!((gmst - 8.5825).abs() < 1e-4); // matches Meeus Example 11.a
/// ```
/// Computes **Local Mean Sidereal Time** (LMST) in fractional hours (0.0–24.0)
/// from a Julian Date and a geographic longitude.
///
/// This function adds the observer’s longitude to the **Greenwich Mean Sidereal Time (GMST)**
/// to calculate the **Local Mean Sidereal Time** (LMST) — a standard value used in
/// telescope pointing models and mount alignment logic.
///
/// This does **not** include nutation or the equation of the equinoxes.
/// For that, see Apparent Sidereal Time.
///
/// # Arguments
///
/// - `jd` — Julian Date (e.g. from [`julian_date`](crate::time::julian_date))
/// - `longitude_deg` — Observer’s longitude in **degrees**, positive east of Greenwich, negative west
///
/// # Returns
///
/// Local **Mean** Sidereal Time in fractional hours, normalized to the range `[0.0, 24.0)`
///
/// # Notes
///
/// The formula used is:
///
/// ```text
/// LMST = GMST + (longitude in hours)
/// ```
///
/// Since Earth rotates 15° per hour, the longitude is divided by 15
/// to convert to sidereal time. This formulation is based on Meeus’
/// *Astronomical Algorithms* (2nd ed., Chapter 12).
///
/// # Example
///
/// ```
/// use chrono::{Utc, TimeZone};
/// use astro_math::time::julian_date;
/// use astro_math::sidereal::local_mean_sidereal_time;
///
/// let dt = Utc.with_ymd_and_hms(1987, 4, 10, 19, 21, 0).unwrap();
/// let jd = julian_date(dt);
/// let local_sidereal = local_mean_sidereal_time(jd, -64.0);
/// assert!((local_sidereal - 4.317).abs() < 1e-2);
/// ```
/// Computes **Local Apparent Sidereal Time (LAST)** in fractional hours (0.0–24.0)
/// from a Julian Date and geographic longitude.
///
/// This uses ERFA's Greenwich Apparent Sidereal Time function which includes
/// the effect of nutation and equation of the equinoxes for maximum accuracy.
///
/// # Arguments
///
/// - `jd`: Julian Date (e.g. from [`julian_date`](crate::time::julian_date))
/// - `longitude_deg`: Observer's longitude (degrees, east positive)
///
/// # Returns
///
/// Local **apparent** sidereal time in fractional hours, normalized to `[0.0, 24.0)`
///
/// # Notes
///
/// ```text
/// LAST = GMST + Equation of the Equinoxes + longitude / 15
///
/// Equation of Equinoxes = Δψ × cos(ε)
/// where:
/// Δψ = nutation in longitude (arcseconds)
/// ε = mean obliquity of the ecliptic (arcseconds)
/// ```
///
/// # Example
///
/// ```
/// use chrono::{Utc, TimeZone};
/// use astro_math::time::julian_date;
/// use astro_math::sidereal::apparent_sidereal_time;
///
/// let dt = Utc.with_ymd_and_hms(2024, 8, 4, 6, 0, 0).unwrap();
/// let jd = julian_date(dt);
/// let last = apparent_sidereal_time(jd, -111.6);
/// assert!(last >= 0.0 && last < 24.0);
/// ```