Example #1
0
def dump_trans(dbname, dataset_id):
    db = DataBase(name=dbname, user=dbname, password=dbname)

    #Note it is possible to query the database using the python routines 
    #in tkp.database.utils.generic, without any knowledge of SQL.
    #But for the data requested here it's much easier to use proper queries.
    transients_query = """\
    SELECT  tr.*
           ,rc.dataset
           ,rc.wm_ra
           ,rc.wm_decl
    FROM transient tr
         ,runningcatalog rc
         ,runningcatalog_flux rf
    WHERE tr.runcat = rc.id
      AND rf.runcat = rc.id
      AND tr.band = rf.band
      AND rc.dataset = %s
    """
    db.execute(transients_query, dataset_id)
    raw_transient_results = db.fetchall()
    transients = convert_results_to_list_of_dicts(raw_transient_results,
                                                  db.cursor.description)
    print "Found", len(transients), "transient datapoints"
    outfile_prefix = './ds_' + str(dataset_id) + '_'
    dump_list_of_dicts_to_csv(transients, outfile_prefix + 'transients.csv')

    return 0
Example #2
0
def dump_images(dbname, dataset_id):
    db = DataBase(name=dbname, user=dbname, password=dbname)
    
    sources_query = """\
    SELECT  im.id
            ,im.freq_eff
            ,im.url
            ,im.taustart_ts
            ,im.rb_smaj
            ,im.rb_smin
            ,sr.centre_ra
            ,sr.centre_decl
            ,r.comment
    FROM image im
         ,rejectreason rr
         ,rejection r
         ,skyregion sr
    WHERE im.dataset = %s
      AND im.id=r.image
      AND r.rejectreason=rr.id
      AND im.skyrgn=sr.id
      ORDER BY im.id
    """
    db.execute(sources_query, dataset_id)
    raw_sources_results = db.fetchall()
    sources = convert_results_to_list_of_dicts(raw_sources_results,
                                               db.cursor.description)

    print "Found", len(sources), "images"

    outfile_prefix = './ds_' + str(dataset_id) + '_'
    dump_list_of_dicts_to_csv(sources, outfile_prefix + 'images.csv')

    return 0
def main(dbname, dataset_id):
    db = DataBase(name=dbname, user=dbname, password=dbname)

    #Note it is possible to query the database using the python routines 
    #in tkp.database.utils.generic, without any knowledge of SQL.
    #But for the data requested here it's much easier to use proper queries.
    transients_query = """\
    SELECT  tr.*
           ,rc.dataset
           ,rc.wm_ra
           ,rc.wm_decl
    FROM transient tr
         ,runningcatalog rc
         ,runningcatalog_flux rf
    WHERE tr.runcat = rc.id
      AND rf.runcat = rc.id
      AND rc.dataset = %s
    """
    db.execute(transients_query, dataset_id)
    raw_transient_results = db.fetchall()
    #print db.cursor.description
    #print raw_transient_results[0]
    transients = convert_results_to_list_of_dicts(raw_transient_results,
                                                  db.cursor.description)
    print "Found", len(transients), "transients"

    sources_query = """\
    SELECT  im.taustart_ts
            ,im.tau_time
            ,ex.f_int
            ,ex.f_int_err
            ,ax.xtrsrc
            ,rc.id as runcatid
            ,rc.dataset
            ,rc.wm_ra
            ,rc.wm_decl
            ,rf.avg_f_int
            ,rf.avg_f_int_sq
            ,im.freq_eff
    FROM extractedsource ex
         ,assocxtrsource ax
         ,image im
         ,runningcatalog rc
         ,runningcatalog_flux rf
    WHERE rf.runcat = rc.id
      and ax.runcat = rc.id
      AND ax.xtrsrc = ex.id
      and ex.image = im.id
      AND rc.dataset = %s
      ORDER BY rc.id
    """
    db.execute(sources_query, dataset_id)
    raw_sources_results = db.fetchall()
    sources = convert_results_to_list_of_dicts(raw_sources_results,
                                               db.cursor.description)

    print "Found", len(sources), "source datapoints"

    outfile_prefix = './ds_' + str(ds_id) + '_'
    dump_list_of_dicts_to_csv(transients, outfile_prefix + 'transients.csv')
    dump_list_of_dicts_to_csv(sources, outfile_prefix + 'sources.csv')

    return 0
Example #4
0
    def get_file_by_url(url):
        image = None
        try:
            if os.path.isdir(url):
                # Likely a CASA image
                image = CasaImage(url)
            elif os.path.exists(url):
                image = FitsImage(url)
            elif MONGODB["enabled"]:
                hdu = fetch_hdu_from_mongo(url)
                image = FitsImage(hdu)
            else:
                raise Exception("FITS file not available")
        except Exception, e:
            # Unable to access file
            print e
        return image

    image = None
    if isinstance(url, DataAccessor):
        image = url
    elif isinstance(url, basestring):
        image = get_file_by_url(url)
    elif isinstance(url, (int, long)):
        db = database if database else DataBase()
        url = Image(id=url, database=database).url
        image = get_file_by_url(url)
    else:
        raise ValueError("unable to fetch url")
    return image