示例#1
0
def objid2dr7id(objID):
    """
    This function takes a SDSS DR13 objID and returns a DR7 objID based on
    RA/DEC
    """
    
    sql = """
SELECT
 p.ra,p.dec
FROM PhotoObj AS p
WHERE p.objid = {objID}
    """.format(**vars())
    result = SDSS.query_sql_async(sql)
    radecstring = result.content.split('\n')
    try:    
        ra,dec = radecstring[2].split(',')
    except:
        return False, 'empty'
    ra,dec = float(ra),float(dec)
    print( ra,dec)
    sql2 = """
SELECT
 p.objid,p.ra,p.dec
FROM PhotoObj AS p
JOIN dbo.fGetNearestObjEq({ra},{dec}, 1) AS pN
ON p.objID = pN.objID
    """.format(**vars())
    result2 = SDSS.query_sql_async(sql2, data_release=7)
    datastring = result2.content
    try:    
        data = datastring.split('\n')[1]
        dr7objid,ra2,dec2 = data.split(',')
        ra2,dec2 = float(ra2),float(dec2)
        print(dr7objid,ra2,dec2 )
    except:
        print('No neighbour found for ',objID)
        dr7objid = 'empty'
        

    try:
        assert abs(ra - ra2) < 0.0003 #1 arcsec = 0.000277 deg
        assert abs(dec - dec2) < 0.0003
        matchfound = True
    except:
        print('No match found for ',objID)
        matchfound = False
    return matchfound,dr7objid
示例#2
0
    PhotoObj AS p
    JOIN SpecObj AS s ON s.bestobjid = p.objid
WHERE
    p.objID > {}
    AND s.mjd < 52365
    AND (s.primTarget & 0x00000040)+(s.primTarget & 0x00000080) > 0
    AND s.zWarning = 0
    AND (p.flags_r & 0x0000000000000100) = 0
ORDER BY
    p.objID ASC
'''

last_id = -1
result = None
while True:
    response = SDSS.query_sql_async(query.format(last_id), data_release=2,
                                    timeout=300, cache=True)
    batch = np.genfromtxt(io.StringIO(response.text), delimiter=',', names=True)
    if batch.size == 0:
        break
    if result is None:
        result = batch
    else:
        result = np.concatenate([result, batch])
    last_id = batch['id'][-1]

Ngal = len(result)

print('selected %d galaxies' % Ngal)

R50_r, r, z = result['R50_r'], result['r'], result['z']
mu50_r = r + 2.5*np.log10(2*np.pi*R50_r**2)