Data Central uses cookies to make your browsing experience better. By using Data Central you agree to its use of cookies. Learn more I agree


Find information, examples, FAQs and extensive descriptions of the data, curated by the survey teams.

Docs hc

Help Center

Browse FAQs, guides and tutorials on common use cases.
Feb. 10, 2021 by B. Miszalski
Feb. 17, 2021, 12:40 a.m. B. Miszalski

SSA: Retrieving and Parsing a VOTable

If you want to quickly generate some download links from the SSA service, the following may be suitable:

  1. Create a string containing your query request.
  2. Send the request and download the VOTABLE results.
  3. Parse the VOTABLE file and extract the download links to each spectrum.
  4. Download the spectra internally or by printing out wget commands.

An example Python script is provided below. It requires the astropy module to be installed.

from import parse_single_table
import requests
from io import BytesIO
from astropy.time import Time

#SSA query URL
#query 6dF final data release only around RA=55 deg, DEC=-29.1 deg in a circle of 0.4 deg diameter 
url = ",-29.1&SIZE=0.4&REQUEST=queryData&COLLECTION=6dfgs_fdr"

#perform the query via the above url and store contents in vot 
vot = requests.get(url).content
#optionally write table to file
#fptr = open("ssa_table.xml","wb")

#open the table with astropy's votable package
table = parse_single_table(BytesIO(vot))
data = table.array

#Go through each row in the table
for i in range (0,len(data)):
    #For 6dF spectra the band_name is either V, R or VR (the combined V+R spectrum)
    band_name = data['band_name'][i]
    #Since multiple observations may be available, use the midpoint of the observation
    #in the filename to ensure all unique spectra are retrieved
    midpoint = data['t_midpoint'][i]
    #optionally, convert midpoint (MJD) to date string using astropy
    #trimming off any fractional seconds at the end with '[:-4]'
    t = Time(midpoint,format='mjd')
    midpoint = t.value[:-4]
    target_name = data['target_name'][i]
    #URL of the spectrum; N.B. We add RESPONSEFORMAT=fits to get fits format
    #otherwise the VO table is returned by default which would then have to be parsed 
    #to get the full link to the fits file
    access_url = data['access_url'][i] + "&RESPONSEFORMAT=fits"
    #filename to save spectrum to
    ofname = "%s-%s-%s.fits" % (target_name,band_name,midpoint)

    #Print out a wget command to download the data
    #download_cmd = "wget -O %s \"%s\"" % (ofname,access_url)
    #print (download_cmd)

    #alternatively, download directly...
    print ("Downloading ",ofname)
    spec = requests.get(access_url).content
    fptr = open(ofname,"wb")
Feb. 10, 2021 by B. Miszalski
Feb. 17, 2021, 12:40 a.m. B. Miszalski