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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
"""
Time conversion utilities for astropy.time integration.
This module provides seamless interoperability between astropy.time.Time
and hifitime Epoch objects, enabling poliastro/hapsira API compatibility
while maintaining the high-precision benefits of hifitime internally.
"""
# Try to import astropy.time - it's an optional dependency for time integration
= True
= None
= False
# Time scale mapping between astropy and hifitime
=
=
"""
Convert an astropy.time.Time object to a hifitime Epoch.
This function extracts the Julian Date and time scale from an astropy
Time object and creates the corresponding hifitime Epoch. The conversion
preserves nanosecond precision where possible.
Parameters
----------
time : astropy.time.Time
The astropy Time object to convert
Returns
-------
Epoch
The corresponding hifitime Epoch object
Raises
------
ImportError
If astropy is not installed
ValueError
If the time scale is not supported
Examples
--------
>>> from astropy.time import Time
>>> from astrora.time import astropy_time_to_epoch
>>>
>>> t = Time('2000-01-01 12:00:00', scale='tt')
>>> epoch = astropy_time_to_epoch(t)
>>> print(epoch)
Epoch('2000-01-01T12:00:00.000000000 TT')
Notes
-----
- Supported scales: UTC, TAI, TT, TDB
- TCB and TCG are mapped to TDB and TT respectively (approximation)
- Precision: Astropy uses dual-float JD representation for sub-nanosecond
precision. Hifitime uses nanoseconds internally, providing equivalent
precision for astrodynamics applications (< 65,536 years from J2000).
"""
# Get the time scale
=
# Map astropy scale to hifitime scale
=
# Get Julian Date from astropy Time
# astropy stores time as jd1 + jd2 for maximum precision
= # This gives the full JD as a float64
# Create Epoch from JD in the appropriate time scale using high-precision method
# The Epoch.from_jd_scale() method preserves nanosecond precision
return
"""
Convert a hifitime Epoch to an astropy.time.Time object.
Parameters
----------
epoch : Epoch
The hifitime Epoch to convert
scale : str, optional
The desired time scale for the output Time object.
If None, uses TT (Terrestrial Time) as the default.
Supported: 'utc', 'tai', 'tt', 'tdb'
Returns
-------
astropy.time.Time
The corresponding astropy Time object
Raises
------
ImportError
If astropy is not installed
ValueError
If the requested scale is not supported
Examples
--------
>>> from astrora._core import Epoch
>>> from astrora.time import epoch_to_astropy_time
>>>
>>> epoch = Epoch.j2000_epoch()
>>> t = epoch_to_astropy_time(epoch, scale='tt')
>>> print(t)
2000-01-01 12:00:00.000
>>> print(t.scale)
tt
Notes
-----
- Default scale is TT (Terrestrial Time) as it's the standard for J2000
- The conversion preserves precision within numerical limits
- UTC conversions account for leap seconds automatically
"""
# Default to TT if no scale specified
=
=
# Get JD from Epoch in the requested scale
=
# Use TT as proxy and convert (hifitime doesn't expose JD in TAI directly)
# Get MJD in TAI and convert to JD
=
= + 2400000.5
=
# Similar for TDB
=
= + 2400000.5
# Create astropy Time from JD
return
"""
Convert various time representations to a hifitime Epoch.
This is a convenience function that accepts multiple input types and
normalizes them to Epoch objects for internal use.
Parameters
----------
time_input : Epoch, astropy.time.Time, or None
The time to convert. If None, returns None.
Returns
-------
Epoch or None
The corresponding Epoch object, or None if input was None
Raises
------
TypeError
If the input type is not supported
ImportError
If astropy.Time is provided but astropy is not installed
Examples
--------
>>> from astrora.time import to_epoch
>>> from astrora._core import Epoch
>>> from astropy.time import Time
>>>
>>> # Already an Epoch - pass through
>>> epoch = Epoch.j2000_epoch()
>>> result = to_epoch(epoch)
>>> assert result == epoch
>>>
>>> # Convert from astropy Time
>>> t = Time('2000-01-01 12:00:00', scale='tt')
>>> epoch = to_epoch(t)
>>> print(epoch)
Epoch('2000-01-01T12:00:00 TT')
>>>
>>> # None pass-through
>>> result = to_epoch(None)
>>> assert result is None
"""
return None
return
return
"""
Convert various time representations to astropy.time.Time.
Parameters
----------
time_input : Epoch, astropy.time.Time, or None
The time to convert. If None, returns None.
scale : str, optional
The desired time scale for the output. Defaults to 'tt'.
Returns
-------
astropy.time.Time or None
The corresponding Time object, or None if input was None
Raises
------
TypeError
If the input type is not supported
ImportError
If astropy is not installed
Examples
--------
>>> from astrora.time import to_astropy_time
>>> from astrora._core import Epoch
>>>
>>> epoch = Epoch.j2000_epoch()
>>> t = to_astropy_time(epoch, scale='utc')
>>> print(t.scale)
utc
"""
return None
# Already astropy Time - optionally convert scale
# Convert to requested scale
return
return
return