Skip to content

Commit

Permalink
HTTP/JSON for get_radec_mpc
Browse files Browse the repository at this point in the history
  • Loading branch information
LuEdRaMo committed Aug 22, 2023
1 parent e73bf72 commit f50772e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
IntervalArithmetic = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253"
IntervalRootFinding = "d2bf35a9-74e0-55ec-b149-d360ff49b807"
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
LazyArtifacts = "4af54fe1-eca0-43a8-85a7-787d91b784e3"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
PlanetaryEphemeris = "d83715d0-7e5f-11e9-1a59-4137b20d8363"
Expand All @@ -44,6 +45,7 @@ Interpolations = "0.14"
IntervalArithmetic = "0.20"
IntervalRootFinding = "0.5.11"
JLD2 = "0.4"
JSON = "0.21"
PlanetaryEphemeris = "0.7"
Quadmath = "0.5"
SPICE = "0.2"
Expand Down
2 changes: 1 addition & 1 deletion src/NEOs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import SatelliteToolboxTransformations.sv_ecef_to_ecef
import Downloads

using Distributed, JLD2, TaylorIntegration, Printf, DelimitedFiles, Test, LinearAlgebra,
Dates, SPICE, Quadmath, LazyArtifacts, TaylorSeries,
Dates, SPICE, Quadmath, LazyArtifacts, TaylorSeries, JSON,
InteractiveUtils, AutoHashEquals, Scratch
using PlanetaryEphemeris: daysec, su, ea, α_p_sun, δ_p_sun, t2c_jpl_de430, pole_rotation,
au, c_au_per_day, R_sun, c_cm_per_sec, c_au_per_sec, yr, RE, TaylorInterpolant, Rx,
Expand Down
31 changes: 22 additions & 9 deletions src/observations/radec_mpc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -502,15 +502,28 @@ end
Download MPC optical astrometry of NEO `id` and save the output to `filename`.
"""
function get_radec_mpc(id::AbstractString, filename::AbstractString = replace(id, " " => "_") * ".txt")
# MPC search url
search_url = search_mpc_url * replace(id, " " => "+")
# MPC observations file url
obs_url = obs_mpc_url * replace(id, " " => "_") * ".txt"
# Download database search
download(search_url, filename)
# Download observations file
download(obs_url, filename)
return nothing
# HTTP query
resp = get(
"http://minorplanetcenter.net/search_db";
query = ["table" => "observations", "designation" => id]
)
# Converty to String
text = String(resp.body)
# Parse JSON
obs = JSON.parse(text)
# Find matches
matches = Vector{RegexMatch}(undef, length(obs))
for i in eachindex(obs)
s = obs[i]["original_record"]
matches[i] = match(mpc_radec_regex, s)
end
filter!(!isnothing, matches)
# Parse RadecMPC
radec = RadecMPC.(matches)
# Write observations to file
write_radec_mpc(radec, filename)

return radec
end

# Methods to convert a Vector{<:AbstractAstrometry} to a DataFrame
Expand Down

0 comments on commit f50772e

Please sign in to comment.