Examples
The Horizons REST API accepts specific key-words for each type of command. Some keywords are common to all commands, but most keywords are only valid for some subset of available Horizons REST API commands. Thanks to Julia's metaprogramming, and helpful community, these keyword arguments are specified precisely in the signature of each fetch_*
function. This allows users to simply press TAB
in their chosen tab-completion-supporting IDE, and view all options that are available for each individual command.
julia> fetch_vectors(399; # <TAB>
fetch_vectors(COMMAND; file, AIRMASS, ANG_FORMAT, ANG_RATE_CUTOFF, APPARENT, CAL_FORMAT, CAL_TYPE, CENTER, COORD_TYPE, CSV_FORMAT, ELEV_CUT, ELM_LABELS, EMAIL_ADDR, EXTRA_PREC, LHA_CUTOFF, OUT_UNITS, QUANTITIES, RANGE_UNITS, REF_PLANE, REF_SYSTEM, R_T_S_ONLY, SITE_COORD, SKIP_DAYLT, SOLAR_ELONG, START_TIME, STEP_SIZE, STOP_TIME, SUPPRESS_RANGE_RATE, TIME_DIGITS, TIME_ZONE, TLIST, TLIST_TYPE, TP_TYPE, VEC_CORR, VEC_DELTA_T, VEC_LABELS, VEC_TABLE, format) @ HorizonsAPI ~/Projects/Astrodynamics/HorizonsAPI.jl/src/HorizonsAPI.jl:317
Take a look at each of the following examples for ideas about how to use the Horizons REST API from within Julia.
Cartesian States
julia> using HorizonsAPI
julia> fetch_vectors( 399; # NAIF ID for Earth's center of mass START_TIME = "2024-01-01", STOP_TIME = "2025-01-01", STEP_SIZE = "1d", # one day CENTER = "@ssb", # solar system barycenter format = "text", # the "text" format is most useful; a minimal "json" format is also available file = "earth.txt", # save the HTTP response contents to a local file )
HTTP.Messages.Response: """ HTTP/1.1 200 OK Server: nginx Date: Sun, 06 Oct 2024 18:18:24 GMT Content-Type: text/plain Transfer-Encoding: chunked Connection: keep-alive """
Orbital Elements
julia> using HorizonsAPI
julia> fetch_elements( "APOPHIS"; EPOCH = "J2000", format = "text", file = "apophis.txt", # save the HTTP response contents to a local file )
HTTP.Messages.Response: """ HTTP/1.1 200 OK Server: nginx Date: Sun, 06 Oct 2024 18:18:26 GMT Content-Type: text/plain Transfer-Encoding: chunked Connection: keep-alive """
Idiomatic Julia
You'll notice that HorizonsAPI
only offers a Julia interface to the JPL Horizons REST API; without other packages, you'll need to parse the resulting ephemeris data on your own. Thankfully, HorizonsEphemeris
provides ephemeris fetching methods which are fully abstracted from the REST API. For more information, see the HorizonsEphemeris
documentation!
julia> using Dates, HorizonsEphemeris
julia> earth = let start = now() - Year(50), stop = now() + Year(50), step = Day(1) @time ephemeris("earth", start, stop, step; wrt="jupiter", units="AU-D"); end
5.080436 seconds (1.06 M allocations: 102.812 MiB, 0.44% gc time, 31.08% compilation time: 65% of which was recompilation) (t = [2.442327262841702e6, 2.442328262841702e6, 2.442329262841702e6, 2.442330262841702e6, 2.442331262841702e6, 2.442332262841702e6, 2.442333262841702e6, 2.442334262841702e6, 2.442335262841702e6, 2.442336262841702e6 … 2.478843262841702e6, 2.478844262841702e6, 2.478845262841702e6, 2.478846262841702e6, 2.478847262841702e6, 2.478848262841702e6, 2.478849262841702e6, 2.478850262841702e6, 2.478851262841702e6, 2.478852262841702e6], cal = InlineStrings.String31[" A.D. 1974-Oct-06 18:18:29.5230", " A.D. 1974-Oct-07 18:18:29.5230", " A.D. 1974-Oct-08 18:18:29.5230", " A.D. 1974-Oct-09 18:18:29.5230", " A.D. 1974-Oct-10 18:18:29.5230", " A.D. 1974-Oct-11 18:18:29.5230", " A.D. 1974-Oct-12 18:18:29.5230", " A.D. 1974-Oct-13 18:18:29.5230", " A.D. 1974-Oct-14 18:18:29.5230", " A.D. 1974-Oct-15 18:18:29.5230" … " A.D. 2074-Sep-27 18:18:29.5230", " A.D. 2074-Sep-28 18:18:29.5230", " A.D. 2074-Sep-29 18:18:29.5230", " A.D. 2074-Sep-30 18:18:29.5230", " A.D. 2074-Oct-01 18:18:29.5230", " A.D. 2074-Oct-02 18:18:29.5230", " A.D. 2074-Oct-03 18:18:29.5230", " A.D. 2074-Oct-04 18:18:29.5230", " A.D. 2074-Oct-05 18:18:29.5230", " A.D. 2074-Oct-06 18:18:29.5230"], x = [-3.859344311811599, -3.865494855863169, -3.871920483786718, -3.87862055620827, -3.885593824307402, -3.892840882228932, -3.900359501404254, -3.908148973614972, -3.916207444169237, -3.924532821731128 … 5.485909082769038, 5.488508877670793, 5.490806329092464, 5.492803510041703, 5.494500468842194, 5.495898295056369, 5.496996484677338, 5.497796433179047, 5.49829883559094, 5.498504018282451], y = [1.435032704884481, 1.443980825667133, 1.452852886226156, 1.461645194160976, 1.470352734993051, 1.478970151933583, 1.487492031845609, 1.495912494676311, 1.50422692992859, 1.512428730347267 … -2.874189825973831, -2.851143345291398, -2.828118433865653, -2.805120667344806, -2.782154069738587, -2.759222674895735, -2.736332219162358, -2.713486814956966, -2.690692048186514, -2.667951956279539], z = [0.1033037323333384, 0.1033756135683647, 0.1034471629905157, 0.1035183859420094, 0.1035892587019774, 0.1036597314908779, 0.1037297969705315, 0.103799417894893, 0.1038686327818648, 0.1039374163350188 … -0.08791017314652297, -0.08803196032024493, -0.08815354677929264, -0.08827497517320873, -0.08839626035430928, -0.08851739982382584, -0.08863847606129903, -0.08875947686869239, -0.08888044157984595, -0.08900135707483467], ẋ = [-0.006011938838531488, -0.006288803063089613, -0.006562636271117889, -0.006836851396431851, -0.007110342050481169, -0.007382861505254834, -0.007654672607371503, -0.007923743363213609, -0.008192874162062587, -0.008457677885279265 … 0.002750427664777973, 0.002448833103189693, 0.002146902187580359, 0.001846949924201616, 0.001547645751427571, 0.001247485233618715, 0.0009493985111111902, 0.00065057238978596, 0.0003540862203235626, 5.699678244801212e-5], ẏ = [0.008983956618693185, 0.008910697135017959, 0.00883326478023364, 0.008750261514743118, 0.008663978799090616, 0.008570091122466147, 0.008472364743886516, 0.008368273824254016, 0.008258924844655931, 0.008144556582064385 … 0.02305566067963085, 0.02303698137448848, 0.02301161030362528, 0.02298335611197673, 0.02294933054467441, 0.02291213865123424, 0.0228685614466823, 0.02282079397007015, 0.0227685659077584, 0.022710252414763], ż = [7.202603196223163e-5, 7.170574819138816e-5, 7.140615447336883e-5, 7.103287215094727e-5, 7.069859033573148e-5, 7.025825820642574e-5, 6.98488064871444e-5, 6.9420170222081e-5, 6.898453450968447e-5, 6.861141495684636e-5 … -0.0001219100252147345, -0.000121658840069154, -0.0001215248051590324, -0.000121338518593457, -0.0001212180165546087, -0.0001210944416464894, -0.0001210351235603303, -0.0001209920116820625, -0.000120920508641046, -0.0001209226529144365])