Last active
June 9, 2022 19:20
-
-
Save daleghent/2d80fffbaef2f1614962f0ddc04bee92 to your computer and use it in GitHub Desktop.
Scripts for querying the SIMBAD TAP interface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
OBJECT=$1 | |
query_tap() { | |
curl -sL -X POST 'https://simbad.u-strasbg.fr/simbad/sim-tap/sync' \ | |
--form "query=\"${1}\"" \ | |
--form 'format="json"' \ | |
--form 'lang="ADQL"' \ | |
--form 'request="doQuery"' | |
} | |
## | |
## Get basic object info | |
## | |
QUERY="SELECT basic.OID,main_id,RA,DEC | |
FROM basic | |
JOIN ident ON oidref = oid | |
WHERE id = '${OBJECT}'" | |
OUT=$(query_tap "$QUERY") | |
OID=$(jq -r '.data[0][0]' <<<"$OUT") | |
MAIN_ID=$(jq -r '.data[0][1]' <<<"$OUT") | |
RA=$(jq -r '.data[0][2]' <<<"$OUT") | |
DEC=$(jq -r '.data[0][3]' <<<"$OUT") | |
## | |
## Get list of all the object's names | |
## | |
QUERY="SELECT id | |
FROM ident | |
WHERE oidref = ${OID}" | |
OUT=$(query_tap "$QUERY") | |
NAMES=$(jq -r '.data | flatten' <<<"$OUT") | |
## | |
## Assemble the condensed JSON output | |
## | |
jq --null-input \ | |
--argjson simbad_oid "${OID}" \ | |
--arg main_id "${MAIN_ID}" \ | |
--argjson ra "${RA}" \ | |
--argjson dec "${DEC}" \ | |
--argjson names "${NAMES}" \ | |
'{"simbad_oid": $simbad_oid, "main_id": $main_id, "ra": $ra, "dec": $dec, "names": $names}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment