Skip to content

Instantly share code, notes, and snippets.

@daleghent
Last active June 9, 2022 19:20
Show Gist options
  • Save daleghent/2d80fffbaef2f1614962f0ddc04bee92 to your computer and use it in GitHub Desktop.
Save daleghent/2d80fffbaef2f1614962f0ddc04bee92 to your computer and use it in GitHub Desktop.
Scripts for querying the SIMBAD TAP interface
#!/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