示例#1
0
"""
Executes two cone searches to NED and 2MASS and cross matches the resultant tables
retrieving the cross match outout to local disk.
"""

import time, urllib
from astrogrid import acr
from astrogrid import Applications, ConeSearch, MySpace

# Log in (we need this to save the results in VOSpace)
acr.login()

# Perform cone searches to NED and 2MASS. We are saving the results to VOSpace and these
# will be the two tables we want to cross match.

cone1 = ConeSearch("ivo://ned.ipac/Basic_Data_Near_Position")
vot1 = cone1.execute(242.811, 54.596, 0.1, saveAs='#cones/ned.vot')

cone2 = ConeSearch('ivo://wfau.roe.ac.uk/twomass-dsa/wsa')
vot2 = cone2.execute(242.811, 54.596, 0.1, dsatab='twomass_psc', saveAs='#cones/twomass_psc.vot')

# Define the cross match application to use and fill in parameters
# See http://www.star.bris.ac.uk/~mbt/stilts/sun256/secA.14.1.html for more info
app = Applications('ivo://uk.ac.starlink/stilts', 'tmatch2')

# .. inputs
app.inputs['tmatch2_in1']['value']=vot1
app.inputs['tmatch2_in2']['value']=vot2
app.inputs['tmatch2_params']['value']="2"
app.inputs['tmatch2_values1']['value']="$3 $4"
app.inputs['tmatch2_values2']['value']="ra dec"
示例#2
0
    print "#Name \t Ra \t Dec \t S_nu_ \t e_S_nu_ \t Altnames \t Seq"
else:
    print "#Name \t Ra \t Dec \t S_nu_ \t e_S_nu_"

for name, src in catA.iteritems():
    fsrc, sep = find_src_in_cat(src, catB, opts.sep)
    if fsrc is not None: continue
    try:
        err = src.e_S_nu
    except AttributeError:
        err = 0
    #    print "%s \t %s \t"%(src.ra,src.dec),
    #perform the cone search and make a spectrum numpy array
    if opts.vo:
        log.debug("Connecting to %s" % (opts.uri))
        conesrch = ConeSearch(opts.uri)
        log.debug("Performing conesearch")
        votable = conesrch.execute(src.ra / ephem.degree,
                                   src.dec / ephem.degree, opts.sep)
        log.debug("Converting votable string to file object")
        votable_f = StringIO(votable)
        log.debug("Parsing table from votable to numpy.")
        votable_np = vot.parse_single_table(votable_f, pedantic=False)
        vodata = votable_np.array
        if len(vodata) < 2:
            print "%s \t %s \t %s \t %07.3f \t %07.3f"%\
                (name,src.ra,src.dec,src.jys,err)
            log.warning("no vo sources found within %7.3f of %s" %
                        (opts.sep, name))
            continue
        #extract a single spectrum (hope there was only one hit, throw a warning at the end if not)
示例#3
0
# Get the table from the web but this can be a file in local disk
# (in which case you can remove the next three lines)
import urllib
url = 'http://help.astrogrid.org/raw-attachment/wiki/Help/IntroScripting/AstrogridPython/sample.vot'
urllib.urlretrieve(url, 'sample.vot')

# Read input list of ra, decs from VOTable
vot=read_votable('sample.vot')
id = vot['ID_IDENTIFIER']
ra = map(float, vot['POS_EQ_RA_MAIN'])
dec = map(float, vot['POS_EQ_DEC_MAIN'])

# We are going to query 2MASS at RoE
ivorn = 'ivo://wfau.roe.ac.uk/twomass-dsa/wsa'
cone = ConeSearch(ivorn)

nsrc = len(ra) # Number of sources
radius = 0.1  # Search radius in degrees

print 'Starting Query: %d objects' % nsrc

# However this is just an example so we select a couple
nsrc = 2

# Uncomment the following line to perform the search for all objects
#nsrc = len(ra)

# Create out/ directory in local disk if it does not exist
if not os.access('out', os.R_OK): os.makedirs('out')
示例#4
0
Example:

   conesearch_iphas.py -o iphas.vot 15.45 60.0 0.1
"""
__id__='$Id: conesearch_iphas.py 62 2007-05-10 13:04:34Z eddie $'

import os
from astrogrid import ConeSearch
from astrogrid.plastic import broadcast
from optparse import OptionParser

parser=OptionParser()
parser.add_option("-o", "--out", default='iphas.vot',
                  help="Output file.")
(options, args) = parser.parse_args()

ra, dec, radius = args

# We add here the IVORN of the IPHAS service
ivorn = 'ivo://uk.ac.cam.ast/iphas-dsa-catalog/IDR'
cone = ConeSearch(ivorn)

print 'Querying %s %s %s' % (ra, dec, radius)
res = cone.execute(ra, dec, radius, dsatab='PhotoObjBest')
# Uncomment the following line if you want to send the output to TOPCAT
# broadcast(res)
print 'Writting %s' % options.out
open(options.out, 'w').write(res)


示例#5
0
if opts.vo:
    print "#Name \t Ra \t Dec \t S_nu_ \t e_S_nu_ \t Altnames \t Seq"
else:
     print "#Name \t Ra \t Dec \t S_nu_ \t e_S_nu_"
    

for name,src in catA.iteritems():
    fsrc,sep = find_src_in_cat(src,catB,opts.sep)
    if fsrc is not None: continue
    try: err=src.e_S_nu
    except AttributeError: err = 0
#    print "%s \t %s \t"%(src.ra,src.dec),
    #perform the cone search and make a spectrum numpy array
    if opts.vo:
        log.debug("Connecting to %s"%(opts.uri))
        conesrch = ConeSearch(opts.uri)
        log.debug("Performing conesearch")
        votable = conesrch.execute(src.ra/ephem.degree,src.dec/ephem.degree,opts.sep)
        log.debug("Converting votable string to file object")
        votable_f = StringIO(votable)
        log.debug("Parsing table from votable to numpy.")
        votable_np = vot.parse_single_table(votable_f,pedantic=False)
        vodata = votable_np.array
        if len(vodata)<2: 
            print "%s \t %s \t %s \t %07.3f \t %07.3f"%\
                (name,src.ra,src.dec,src.jys,err)
            log.warning("no vo sources found within %7.3f of %s"%(opts.sep,name))
            continue
        #extract a single spectrum (hope there was only one hit, throw a warning at the end if not)
        seqs = list(set(vodata['Seq']))
        if len(seqs)>1: log.warning("%d vo sources found within %7.3f of %s"%(len(seqs),opts.sep,name))
示例#6
0
#!/usr/bin/python
"""
Convert a file from one format to another using STILTS.
"""

import time, urllib
from astrogrid import acr
from astrogrid import Applications, MySpace, ConeSearch

acr.login()

# Perform a cone search to NED to obtain a VOTable
cone = ConeSearch("ivo://ned.ipac/Basic_Data_Near_Position")
vot = cone.execute(242.811, 54.596, 0.1, saveAs='#cones/ned.vot')

# Use tcopy (STILTS) to do the conversion
app = Applications('ivo://uk.ac.starlink/stilts','tcopy')

app.inputs['tcopy_in']['value']='#cones/ned.vot'
app.inputs['tcopy_ifmt']['value']='VOTABLE'
app.inputs['tcopy_ofmt']['value']="FITS"

app.outputs['tcopy_out']['value']='#cones/ned.fits'

res=app.submit()
示例#7
0
#!/usr/bin/python
"""This example shows how to submit a list of ra,dec positions to SDSS DR5.
"""

import sys, time
import random
import math

from astrogrid import ConeSearch
from astrogrid.threadpool import easy_pool

# Define the service endpoint IVORN
cone=ConeSearch('ivo://wfau.roe.ac.uk/sdssdr5-dsa/dsa', dsatab='PhotoObjAll')

# Generate 20 random positions.
# In real astronomy these would be read from a file
nsrc=20
ra=[random.random()*math.pi*2*math.degrees(1) for i in range(nsrc)]
dec=[(random.random()*math.pi-math.pi/2.)*math.degrees(1) for i in range(nsrc)]
radius=[0.001]*nsrc

for i in range(nsrc):
	res = cone.execute(ra[i], dec[i], radius[i])
	open('sdss%02d.vot' % (i+1), 'w').write(res)
	print i+1, 'sdss%02d.vot' % (i+1)
示例#8
0
a.scripting.add_standard_options(o, cal=True)
o.add_option(
    "--uri",
    default="ivo://CDS.VizieR/VIII/85",
    help="URI for vo data source that supports cone search. default=ivo://CDS.VizieR/VIII/85 [specfindv2]",
)
o.add_option(
    "--max_degen",
    help="If there are M frequencies available, limit the covariance matrix to a size of Mx<max_degen>*M ",
)
opts, args = o.parse_args(sys.argv[1:])


src = a.phs.RadioFixedBody("4:13:49.93", "11:11:06.1")
ep.FixedBody.compute(src, ep.J2000)
conesrch = ConeSearch(opts.uri)
votable = conesrch.execute(src.ra / ep.degree, src.dec / ep.degree, 5)
votable_f = StringIO(votable)
votable_np = vot.parse_single_table(votable_f, pedantic=False)
vodata = votable_np.array

all_freqs = n.sort(n.array(list(set(vodata["nu"]))))
seqs = list(set(vodata["Seq"]))
print seqs
X = n.matrix(n.zeros([len(seqs), len(all_freqs)]))
for i, seq in enumerate(seqs):
    spec = n.sort(vodata[n.where(vodata["Seq"] == seq)[0]], order="nu")
    flux_sc = n.log10(spec["S_nu_"]) - n.average(n.log10(spec["S_nu_"]))
    P = n.poly1d(n.polyfit(n.log10(spec["nu"]), n.log10(spec["S_nu_"]), 2))
    chi_sq = n.sum(n.log10(spec["S_nu_"]) - n.log10(P(n.log10(spec["nu"]))) / (2 * n.log10(spec["e_S_nu_"]))) / (
        len(spec) - 1
示例#9
0
import time, urllib
from astrogrid import acr
from astrogrid import Applications, ConeSearch, MySpace

# Log in (we need this to save the results in VOSpace)
acr.login()

# Perform cone searches to UKIDSS and SDSS. We are saving the results to VOSpace and these
# will be the two tables we want to cross match.

ra = 152.8
dec = 8.5
radius = 0.1

cone1 = ConeSearch("ivo://wfau.roe.ac.uk/ukidssDR1-dsa/wsa")
vot1 = cone1.execute(ra, dec, radius, saveAs='#cones/ukidsslas.vot', dsatab='lasSource', clobber=True)

cone2=ConeSearch('ivo://wfau.roe.ac.uk/sdssdr5-dsa/dsa')
vot2 = cone2.execute(ra, dec, radius, dsatab='PhotoObjAll', saveAs='#cones/sdsslas.vot', clobber=True)

# Define the cross match application to use and fill in parameters
# See http://www.star.bris.ac.uk/~mbt/stilts/sun256/secA.14.1.html for more info
app = Applications('ivo://uk.ac.starlink/stilts', 'tmatch2')

# .. inputs
app.inputs['tmatch2_in1']['value']=vot1
app.inputs['tmatch2_in2']['value']=vot2
app.inputs['tmatch2_params']['value']="1.0"
app.inputs['tmatch2_values1']['value']="ra dec"
app.inputs['tmatch2_values2']['value']="ra dec"