#!/usr/bin/env python # Version: 2019-02-13 import sys import math from pyvo.dal import tap from astropy.coordinates import SkyCoord from astropy.units import Quantity ESO_TAP_OBS = "http://archive.eso.org/tap_obs" tapobs = tap.TAPService(ESO_TAP_OBS) target = "eta car" radius = 0.5 # degrees print() print("Looking for public SCIENCE FORS2 frames around target %s in a cone of radius %f deg." %(target, radius)) print("Querying the ESO TAP service at %s" %(ESO_TAP_OBS)) # -------------------------------------------------- # The actual position of the selected target # is queried by the from_name() function, # which queries the CDS SESAME service # (http://cdsweb.u-strasbg.fr/cgi-bin/Sesame). # -------------------------------------------------- print("The provided target is being resolved by SESAME...") pos = SkyCoord.from_name(target) print("SESAME coordinates for %s: %s" % (target, pos.to_string())) cosd = math.cos( pos.dec.to_value() * math.pi/180. ) if ( math.fabs( pos.dec.to_value() - 90 ) < radius ): cosd = 1; ra_min = pos.ra.to_value() - radius * cosd ra_max = pos.ra.to_value() + radius * cosd dec_min = pos.dec.to_value() - radius dec_max = pos.dec.to_value() + radius top = "TOP %d" % (3) query="""SELECT %s object, ra, dec, tpl_start, prog_id, filter_path, dp_id from dbo.raw where ra between %f and %f and dec between %f and %f and instrument='FORS2' and release_date < getdate() and dp_cat='SCIENCE' """ % ( top, ra_min, ra_max, dec_min, dec_max ); print(query) res = tapobs.search(query=query) print(res.to_table()) # -------------------------------------------------- import urllib prompt = "Shall I download those %d files, [y|n]:" % (len(res.to_table())) shall_I = input(prompt) # Python 3 if shall_I != "y": print("Stopping here, without downloading any file") sys.exit(0) print("Downloading the non-proprietary files (%d files)" % (len(res.to_table()))) nfiles = 0 for row in res: nfiles += 1 # Change from previous version: the access_url points to the datalink and not directly to the file download. # Given a dp_id of a public file, the link to download it is constructed as follows: download_url = "http://archive.eso.org/datalink/links?ID=ivo://eso.org/ID?%s&eso_download=file" % row["dp_id"].decode() urllib.request.urlretrieve(download_url, row["dp_id"].decode()) # informing user: print("%4d/%d dp_id: %s downloaded" % (nfiles, len(res.to_table()), row["dp_id"].decode()))