Examples

HorizonsEphemeris.jl provides an idiomatic Julia interface to the JPL Horizons REST API. Rather than recall specific queries REST API queries, or describe your desired ephemeris data in the verbose REST interface through HorizonsAPI.jl, you can use the ephemeris method to fetch send the correct REST query (using HorizonsAPI.jl under the hood), and return the data parsed into a NamedTuple for convenient data processing.

Take a look at each of the following examples for ideas about how to use the Horizons platform idiomatically from within Julia.

Warning

At this time, only Cartesian state vectors are supported in HorizonsEphemeris.jl. If you want to fetch more complicated ephemeris data, use HorizonsAPI.jl.

Object Identification

The SPICE Toolkit (with SPICE.jl) is used under the hood to identify celestial bodies by their name, or by their NAIF ID code. You can use the NAIF method to query an object's code, or the code's corresponding object name.

julia> using HorizonsEphemeris
julia> using DataFrames
julia> names = ["solar system barycenter", "sun", "mercury", "venus", "earth", "mars", "jupiter", "saturn", "uranus", "neptune", "pluto"];
julia> codes = NAIF.(names);
julia> DataFrame(Name = names, Code = codes)11×2 DataFrame Row │ Name Code │ String Int64 ─────┼──────────────────────────────── 1 │ solar system barycenter 0 2 │ sun 10 3 │ mercury 199 4 │ venus 299 5 │ earth 399 6 │ mars 499 7 │ jupiter 599 8 │ saturn 699 9 │ uranus 799 10 │ neptune 899 11 │ pluto 999

Cartesian States

You can specify a single time point, e.g. now(), or a list of time points, or the combination of a start time, end time, and step duration. Each time point can be a string, a Julia day or Modified Julian day (AbstractFloat), or an AbstractDateTime. For more information, see the ephemeris reference.

julia> using HorizonsEphemeris
julia> ephemeris("earth", "1999-12-31T11:59:59")(t = [2.451543999988426e6], cal = InlineStrings.String31[" A.D. 1999-Dec-31 11:59:59.0000"], x = [-0.1670437396074802], y = [0.8875474384517587], z = [0.3850193725088548], ẋ = [-0.01725350249359643], ẏ = [-0.002627413685548899], ż = [-0.001139263696835267])

DataFrame Support

If you include DataFrames.jl, you can use the DataFrame constructor with the NamedTuple output of the ephemeris method.

julia> using Dates, HorizonsEphemeris
julia> using DataFrames
julia> data = ephemeris("earth", now() - Year(1), now() + Year(1), Day(3); wrt="sun")(t = [2.460224264082801e6, 2.460227264082801e6, 2.460230264082801e6, 2.460233264082801e6, 2.460236264082801e6, 2.460239264082801e6, 2.460242264082801e6, 2.460245264082801e6, 2.460248264082801e6, 2.460251264082801e6 … 2.460926264082801e6, 2.460929264082801e6, 2.460932264082801e6, 2.460935264082801e6, 2.460938264082801e6, 2.460941264082801e6, 2.460944264082801e6, 2.460947264082801e6, 2.460950264082801e6, 2.460953264082801e6], cal = InlineStrings.String31[" A.D. 2023-Oct-06 18:20:16.7540", " A.D. 2023-Oct-09 18:20:16.7540", " A.D. 2023-Oct-12 18:20:16.7540", " A.D. 2023-Oct-15 18:20:16.7540", " A.D. 2023-Oct-18 18:20:16.7540", " A.D. 2023-Oct-21 18:20:16.7540", " A.D. 2023-Oct-24 18:20:16.7540", " A.D. 2023-Oct-27 18:20:16.7540", " A.D. 2023-Oct-30 18:20:16.7540", " A.D. 2023-Nov-02 18:20:16.7540" … " A.D. 2025-Sep-07 18:20:16.7540", " A.D. 2025-Sep-10 18:20:16.7540", " A.D. 2025-Sep-13 18:20:16.7540", " A.D. 2025-Sep-16 18:20:16.7540", " A.D. 2025-Sep-19 18:20:16.7540", " A.D. 2025-Sep-22 18:20:16.7540", " A.D. 2025-Sep-25 18:20:16.7540", " A.D. 2025-Sep-28 18:20:16.7540", " A.D. 2025-Oct-01 18:20:16.7540", " A.D. 2025-Oct-04 18:20:16.7540"], x = [1.457818889169263e8, 1.437396585691643e8, 1.413119592240041e8, 1.38503851670213e8, 1.353221699068757e8, 1.317755758621546e8, 1.278742313754301e8, 1.236290210161014e8, 1.190506715347898e8, 1.141497022032029e8 … 1.456137202626073e8, 1.47293235463935e8, 1.485905231219728e8, 1.494999754797533e8, 1.500167229359614e8, 1.50137473341063e8, 1.498608135032405e8, 1.491870864735949e8, 1.481181299976379e8, 1.466570525338291e8], y = [3.341729643689223e7, 4.086787970758444e7, 4.821051670506962e7, 5.54241448784349e7, 6.248781521657216e7, 6.938122446895353e7, 7.608531588620296e7, 8.258257994128528e7, 8.88565853880083e7, 9.489090019657461e7 … -3.894119741187922e7, -3.146686964431045e7, -2.39093391863732e7, -1.628713372345669e7, -8.620240469954543e6, -929743.2848408417, 6.76285123190305e6, 1.443617781951359e7, 2.206932395815349e7, 2.964205839195576e7], z = [-3256.559642571956, -3619.975804101676, -3813.369584597647, -3912.441489759833, -4032.065607257187, -4288.528705511242, -4741.411184702069, -5343.744503423572, -5953.319964777678, -6427.413868404925 … 1554.377061739564, 813.9998517986387, 212.1295997928828, -180.7656611185521, -408.0381416562013, -582.3571874213521, -823.450513495598, -1214.127814607695, -1782.095574801788, -2488.902571059763], ẋ = [-7.130460564868522, -8.62526999172876, -10.10373711242518, -11.55937174598695, -12.98505158115688, -14.37405736825913, -15.72184219292886, -17.02750706167506, -18.29257221119005, -19.51640625219382 … 7.209830330909087, 5.745917670263545, 4.260337152060866, 2.753854659726312, 1.231259232611796, -0.3004408681040988, -1.834040405894106, -3.363276994749017, -4.882823405896616, -6.388311350669863], ẏ = [28.92583718498496, 28.5498111257051, 28.09277622299238, 27.55442887484602, 26.93610315529325, 26.24150509560207, 25.47636528138663, 24.64636658787566, 23.75363542812584, 22.79652738337833 … 28.65294892400701, 29.00811410030682, 29.29428486892958, 29.50614660175373, 29.63837648698152, 29.6880127671345, 29.65467059671654, 29.53963727105208, 29.34506362597574, 29.07414065069081], ż = [-0.001776198706384235, -0.001041826487361064, -0.0004998629201367066, -0.0003408903949857489, -0.0006609169096165601, -0.001359974190025426, -0.002104136941632362, -0.002444600288969312, -0.002161292985682906, -0.001456516263827368 … -0.002935676001049714, -0.002671676861181638, -0.001925135086569441, -0.001137889492104804, -0.0006925028968360891, -0.0007324597813003209, -0.001182005128788077, -0.001850827686245893, -0.002508191086793232, -0.002869087632371148])
julia> DataFrame(data)244×8 DataFrame Row │ t cal x y z ⋯ │ Float64 String31 Float64 Float64 Floa ⋯ ─────┼────────────────────────────────────────────────────────────────────────── 1 │ 2.46022e6 A.D. 2023-Oct-06 18:20:16.7540 1.45782e8 3.34173e7 -325 ⋯ 2 │ 2.46023e6 A.D. 2023-Oct-09 18:20:16.7540 1.4374e8 4.08679e7 -361 3 │ 2.46023e6 A.D. 2023-Oct-12 18:20:16.7540 1.41312e8 4.82105e7 -381 4 │ 2.46023e6 A.D. 2023-Oct-15 18:20:16.7540 1.38504e8 5.54241e7 -391 5 │ 2.46024e6 A.D. 2023-Oct-18 18:20:16.7540 1.35322e8 6.24878e7 -403 ⋯ 6 │ 2.46024e6 A.D. 2023-Oct-21 18:20:16.7540 1.31776e8 6.93812e7 -428 7 │ 2.46024e6 A.D. 2023-Oct-24 18:20:16.7540 1.27874e8 7.60853e7 -474 8 │ 2.46025e6 A.D. 2023-Oct-27 18:20:16.7540 1.23629e8 8.25826e7 -534 ⋮ │ ⋮ ⋮ ⋮ ⋮ ⋱ 238 │ 2.46094e6 A.D. 2025-Sep-16 18:20:16.7540 1.495e8 -1.62871e7 -18 ⋯ 239 │ 2.46094e6 A.D. 2025-Sep-19 18:20:16.7540 1.50017e8 -8.62024e6 -40 240 │ 2.46094e6 A.D. 2025-Sep-22 18:20:16.7540 1.50137e8 -9.29743e5 -58 241 │ 2.46094e6 A.D. 2025-Sep-25 18:20:16.7540 1.49861e8 6.76285e6 -82 242 │ 2.46095e6 A.D. 2025-Sep-28 18:20:16.7540 1.49187e8 1.44362e7 -121 ⋯ 243 │ 2.46095e6 A.D. 2025-Oct-01 18:20:16.7540 1.48118e8 2.20693e7 -178 244 │ 2.46095e6 A.D. 2025-Oct-04 18:20:16.7540 1.46657e8 2.96421e7 -248 4 columns and 229 rows omitted

CSV Support

You can save the ephemeris content to a CSV file using the file keyword argument.

julia> using HorizonsEphemeris
julia> ephemeris("moon", 0.0; wrt="earth", mjd=true, file="moon.csv")[ Info: Ephemeris data for object with NAIF ID 301 has been written to moon.csv. (t = [2.4000005e6], cal = InlineStrings.String31[" A.D. 1858-Nov-17 00:00:00.0000"], x = [0.002556334699436511], y = [6.867284869775472e-5], z = [0.0001352955722818409], ẋ = [-6.905182516461547e-5], ẏ = [0.0005198755620635187], ż = [0.0002749449851752871])