def get_most_recent_dataset(conn):
    dsid_dicts = dbutils.columns_from_table(conn,
                               table='dataset',
                               keywords=['id'],
                               alias={'id':'datasetid'},
                               where=None)
    return dsid_dicts[-1]['datasetid']
def gather_source_info(runcatid, conn):
    """
    Pulls information from extracted sources which have 
    been marked as associated together, and tagged with this 
    running catalog id.
    
    Returns: A tuple,
        ( ra_std_dev, dec_std_dev)
    
    Logic:
    -Grab all the xtrsrc ids associated with this runcatid
    -Get the corresponding entries from extractedsource
    -Calculate std. deviation etc.
    """    
    
    assocxtrsrc_entries = dbutils.columns_from_table(conn,
                         table='assocxtrsource',
                         keywords = ['xtrsrc'],
                         where = {'runcat': runcatid}
                         )
    xtrsrc_ids = [entry['xtrsrc'] for entry in assocxtrsrc_entries]
    extractedsources=[]
    
    #This bit in particular is horribly horribly inefficient,
    # as it stands. Oh well.
    for id in xtrsrc_ids:
        extractedsources.extend(
            dbutils.columns_from_table(conn,
                   table='extractedsource',
                   where={'id':id}
                   )
                                )
    
#    print "Extracted sources:"
#    for src in extractedsources:
#        print src
    
    ra_list = [src['ra'] for src in extractedsources]
    dec_list = [src['decl'] for src in extractedsources]
    
    src_info = {'runcat':runcatid,
                'ra': numpy.mean(ra_list),
                'dec': numpy.mean(dec_list),
                'ra_sd':numpy.std(ra_list), 
                'dec_sd':numpy.std(dec_list)
                }
    return  src_info