def search(waveband, keyword='', ucds={}, units=[], service='conesearch', registry='US'): ''' Search and filter services to be used for SED analysis ''' from pyvo import regsearch if not _validRegistry(registry): _regsOK = [k for k, v in _registries.items() if v] logcrt("Registry not supported. Choices are: %s" % (_regsOK)) return False loginf( "Querying registry '%s' for services '%s' providing '%s' data matching '%s' keyword" % (registry, service, waveband, keyword)) # We use PyVO for querying the registry records = regsearch(waveband=waveband, keywords=keyword, servicetype=service) loginf("Number of services found: %d" % (records.nrecs)) # Let's get --first-- empty tables from the retrieved records/services catalogues = selectCatalogs(records, ucds, units) loginf("%d tables were retrieved." % len(catalogues)) return catalogues
def getUltravioletUrl(self): uv_services = vo.regsearch(servicetype=self.serviceType, waveband=self.waveBand) uvot_services = vo.regsearch(servicetype=self.serviceType, waveband=self.waveBand, keywords=[self.keyword]) coords = coord.SkyCoord.from_name(self.coord) im_table = uvot_services[0].search(pos=coords, size=self.size, format='image/jpeg') im_table.to_table() url = im_table[0].getdataurl() return (url)
def search(waveband, keyword='', ucds=[], units=[], service='conesearch', registry='US', sample=0, filter_columns=False, nprocs=1): ''' Search and filter services to be used for SED analysis ''' from pyvo import regsearch if not _validRegistry(registry): _regsOK = [k for k, v in _registries.items() if v] logcrt("Registry not supported. Choices are: %s" % (_regsOK)) return False loginf( "Querying registry '%s' for services '%s' providing '%s' data matching '%s' keyword" % (registry, service, waveband, keyword)) # We use PyVO for querying the registry records = regsearch(waveband=waveband, keywords=keyword, servicetype=service) num_records = len(records) loginf("Number of services found: %d" % (num_records)) if not num_records: print("No catalogues found.") return None if sample is True: sample = int(num_records / 10) if sample: assert sample > 0, "Sample should be a positive number" sample = int(sample) if sample >= 1 else int(num_records * sample) from random import shuffle irec = list(range(num_records)) shuffle(irec) records = [records[i] for i in irec[:sample]] catalogues = _selectCatalogs(records, ucds, units, filter_columns=filter_columns, nprocs=max(1, nprocs)) loginf("%d tables were retrieved." % len(catalogues)) return catalogues
def getUltravioletFits(self): uv_services = vo.regsearch(servicetype=self.serviceType, waveband=self.waveBand) uvot_services = vo.regsearch(servicetype=self.serviceType, waveband=self.waveBand, keywords=[self.keyword]) coords = coord.SkyCoord.from_name(self.coord) im_table = uvot_services[0].search(pos=coords, size=self.size, format='image/fits') fitUrl = im_table[0].getdataurl() #print(fitUrl) return (fitUrl) #test = Images("image", "uv", "swift", "m51", 0.2) #x = test.getUltravioletUrl() #print(x) #test.getUltravioletFits()
def getSpectral(self): services = vo.regsearch(servicetype=self.serviceType, waveband=self.waveBand) chandra_service = [s for s in services if 'Chandra' in s.short_name][0] Pos = SkyCoord.from_name(self.name) spec_tables = chandra_service.search(pos=Pos, diameter=0.1) spec_tables.to_table().show_in_notebook() Url = spec_tables[0].getdataurl() return(Url) #test = Spectral("ssa", "x-ray", "Delta Ori", "m51", 0.2) #test.getSpectral()
#! /usr/bin/env python import pyvo as vo # find archives with x-ray images archives = vo.regsearch(servicetype='image', waveband='xray') # position of my favorite source pos = vo.object2pos('Cas A') # find images and list in a file with open('cas-a.csv', 'w') as csv: print >> csv, "Archive short name,Archive title,Image", \ "title,RA,Dec,format,URL" for arch in archives: print "searching %s..." % arch.shortname try: matches = arch.search(pos=pos, size=0.25) except vo.DALAccessError, ex: print "Trouble accessing %s archive (%s)"\ % (arch.shortname, str(ex)) continue print "...found %d images" % matches.nrecs for image in matches: print >> csv, ','.join( (arch.shortname, arch.title, image.title, str(image.ra), str(image.dec), image.format, image.getdataurl()) )
if "outfilename" in locals(): HARDCOPY = True outfile = open(outfilename, "w") else: HARDCOPY = False coords = SkyCoord.from_name(targetname) print "Target: ", targetname print "Coordinates: ", coords.to_string('hmsdms') print "Search radius: ", r * 60, " arcmin" print "" print 20 * "-", " Available services ", 20 * "-" #Querying all Simple Spectrum Access services in all bands #see http://www.ivoa.net/documents/SSA/20120210/REC-SSA-1.1-20120210.htm for protocol details services = vo.regsearch(servicetype="ssa") i = 0 for service in services: print i, service.short_name, " " * ( 20 - len(service.short_name)), service.res_title i += 1 print "-" * 60 i = 0 for service in services: #Following 3 lines for testing purposes only: #if i in [32,48,71,76,80,81]: #if i in [62]: if True:
import numpy as np # Astropy imports import astropy.units as u import astropy.constants as const from astropy.coordinates import SkyCoord from astropy.cosmology import Planck15 from astropy.io import votable as apvot ## Generic VO access routines import pyvo as vo coord = SkyCoord.from_name("m51") print(coord) services = vo.regsearch(servicetype='scs', keywords=['zcat']) services.to_table()['ivoid', 'short_name', 'res_title'] ## Use the one that's CFAZ. ## Use list comprehension to check each service's short_name attribute and use the first. cfaz_cone_service = [s for s in services if 'CFAZ' in s.short_name][0] ## We are searching for sources within 10 arcminutes of M51. results = cfaz_cone_service.search(pos=coord, radius=10*u.arcmin) results.to_table() heasarc_tap_services = vo.regsearch(servicetype='tap', keywords=['heasarc']) heasarc_tap_services.to_table()['ivoid', 'short_name', 'res_title'] heasarc_tables = heasarc_tap_services[0].service.tables for tablename in heasarc_tables.keys():
#! /usr/bin/env python import pyvo as vo # find archives with x-ray images archives = vo.regsearch(servicetype='image', waveband='xray') # position of my favorite source pos = vo.object2pos('Cas A') # find images and list in a file with open('cas-a.csv', 'w') as csv: print("Archive short name,Archive title,Image" "title,RA,Dec,format,URL", file=csv) for arch in archives: print("searching %s..." % arch.shortname) try: matches = arch.search(pos=pos, size=0.25) except vo.DALAccessError as ex: print("Trouble accessing %s archive (%s)" % (arch.shortname, str(ex))) continue print("...found %d images" % matches.nrecs) for image in matches: print(','.join( (arch.shortname, arch.title, image.title, str(image.ra), str(image.dec), image.format, image.getdataurl())), file=csv)
import pyvo as vo from astropy.io import fits import astropy.coordinates as coord # For downloading files from astropy.utils.data import download_file import aplpy from IPython.display import Image as ipImage, display # There are a number of relatively unimportant warnings that show up, so for now, suppress them: import warnings warnings.filterwarnings("ignore", module="astropy.io.votable.*") warnings.filterwarnings("ignore", module="pyvo.utils.xml.*") uv_services = vo.regsearch(servicetype='image', waveband='uv') uv_services.to_table()['ivoid', 'short_name', 'res_title'] uvot_services = vo.regsearch(servicetype='image', waveband='uv', keywords=['swift']) uvot_services.to_table()['ivoid', 'short_name', 'res_title'] coords = coord.SkyCoord.from_name("m51") im_table = uvot_services[0].search(pos=coords, size=0.2, format='image/jpeg') im_table.to_table() url = im_table[0].getdataurl() print(url)
def get_spectral_access_services(servicetype, waveband): services = vo.regsearch(servicetype=servicetype, waveband=waveband) return services