示例#1
0
def make_summary(star, factor=2.5, clear=True):
    """
    Update the database with a summary for the given star using the given factor.
    """
    if clear:
        sql =  "DELETE FROM summaries where factor = %f and ID = %d" % (factor, star)
        run_sql(sql)

    if len(get_summary_data(star, factor)) > 0:
        print "returning??"
        return

    points = make_radial_ratio_data(star)    
    buckets = [[] for _ in range(int(360/factor))]

    for mag3, mag4, angle, radius, time in points:
        buckets[int(angle/factor)].append((mag3, mag4, radius))

    for angle, bucket in enumerate(buckets):
        if bucket:            
            bucket = recarray_wrap(bucket, names=["ratio3", "ratio4", "r"])
            mags3 = bucket["ratio3"]
            mags4 = bucket["ratio4"]
            radii = bucket["r"]
        else:
            mags3, mags4, radii = [0], [0], [0]
        sql = "INSERT INTO summaries VALUES " + \
              "(%d, %d, %f, %f, %f, %f, %f, %f, %f)" % \
              (star, angle, factor, mean(mags3), std(mags3),
               mean(mags4), std(mags4), mean(radii), std(radii))
        run_sql(sql)
示例#2
0
def make_summary(star, factor=2.5, clear=True):
    """
    Update the database with a summary for the given star using the given factor.
    """
    if clear:
        sql = "DELETE FROM summaries where factor = %f and ID = %d" % (factor,
                                                                       star)
        run_sql(sql)

    if len(get_summary_data(star, factor)) > 0:
        print "returning??"
        return

    points = make_radial_ratio_data(star)
    buckets = [[] for _ in range(int(360 / factor))]

    for mag3, mag4, angle, radius, time in points:
        buckets[int(angle / factor)].append((mag3, mag4, radius))

    for angle, bucket in enumerate(buckets):
        if bucket:
            bucket = recarray_wrap(bucket, names=["ratio3", "ratio4", "r"])
            mags3 = bucket["ratio3"]
            mags4 = bucket["ratio4"]
            radii = bucket["r"]
        else:
            mags3, mags4, radii = [0], [0], [0]
        sql = "INSERT INTO summaries VALUES " + \
              "(%d, %d, %f, %f, %f, %f, %f, %f, %f)" % \
              (star, angle, factor, mean(mags3), std(mags3),
               mean(mags4), std(mags4), mean(radii), std(radii))
        run_sql(sql)
示例#3
0
def imstat(image_id):
    filename = get_unzipped_filename(image_id)
    d = _imstat(filename)
    sql  = "INSERT IGNORE INTO imstat VALUES ("\
           "%d, %d, %d, %d, %d)" % (image_id, d["MIN"], d["MAX"],
                                    d["MEAN"], d["STDDEV"])
    run_sql(sql)
示例#4
0
def read_header(image_id):
    filename = get_unzipped_filename(image_id)
    header = getheader(filename)
    d = dict(header.items())
    sql = "INSERT IGNORE INTO header VALUES (" \
          "%d, %f, %f, '%s', %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f)" % \
          (image_id, d["TEMP"], d["EXPOSURE"], " ".join(d["DATE"].split("T")),
           d["SUNZD"], d["MOONZD"], d["MOONDIST"], d["MOONPHSE"], d["MOONMAG"],
           d["RA"], d["DEC"], d["LST"], d["JD"], d["CRVAL1"], d["CRVAL2"])
    run_sql(sql)
示例#5
0
def flat(image_id):
    filename, cam = get_cam_unzipped_filename(image_id)

    flatfile = os.path.join(FLATPATH, flat_d[cam])
    image = Image(filename)
    name, ext = os.path.splitext(filename)
    out = name + ".flat" + ext
    image.divide(flatfile, out)

    sql = "REPLACE INTO flat VALUES (%d, '%s', '%s')" % \
          (image_id, flatfile, out)
    run_sql(sql)
示例#6
0
def get_images_by_date_and_cam(cam, frm, to):

    sql = "select image.id from " \
          "image inner join cam on image.cam_id=cam.id " \
          "where time > '%s' and time < '%s' and cam.name='%s'" % \
          (frm, to, cam)
    return run_sql(sql)['id']
示例#7
0
 def find_closest_star(self, x, y, image_id):
     sql = "select star_id, X, Y from phot where image_id=%d" % image_id
     data = run_sql(sql)
     if len(data):
         i = N.argmin((data['X'] - x)**2 + (data['Y'] - y)**2)
         star_id = data[i][0]
         self.set_busy_message("Processing star %d..." % star_id)
         self.parent.star_spin.set_value(star_id)
         self.unset_busy_message()
     else:
         print "no stars"
示例#8
0
def apt_phot(image_id):
    print "apt_phot"
    sql = "SELECT * from phot where image_id=%d" % image_id
    if len(run_sql(sql)) > 0:
        return

    sql = "SELECT success FROM astrom where image_id=%d" % image_id
    if run_sql_single(sql) == 0:
        sql = "INSERT IGNORE INTO starcount values (%d, 0)" % image_id
        run_sql(sql)
        print "taking the easy way out"
        return 

    filename, cam = get_cam_flat_filename(image_id)
    outfile = get_outfile(filename)
    cat, maxmag = apt_phot_d[cam]
    iraf.AptPhot(filename, outfile, cat, maxmag=maxmag)

    f = open(outfile)
    n = 0
    for line in f:
        vals = line.split()
        for i in range(len(vals)):
            if vals[i] == 'INDEF':
                vals[i] = '1e-40' #HACK. how to get an Nan in mysql?
        d = dict(zip(apt_phot_keys, vals))

        sql = "INSERT IGNORE INTO star (cat_id, ra, decl) VALUES( %(ID)s, %(RA)s, %(Dec)s)" % d
        run_sql(sql)
        
        sql = "INSERT INTO phot SELECT " + str(image_id)
        sql += (", star_id, %(Vmag)s, %(smag)s, %(mag3)s, %(mag4)s, '%(err3)s', '%(err4)s', %(X)s, %(Y)s from star where cat_id = %(ID)s" % d)
        run_sql(sql)
        n += 1
    sql = "INSERT IGNORE INTO starcount values (%d, %d)" % (image_id, n)
    run_sql(sql)
示例#9
0
def apt_astrom(image_id):
    print "apt_astrom"
    sql = "SELECT * FROM astrom where image_id=%d" % image_id
    if len(run_sql(sql)) > 0:
        print "bailing"
        #return


    filename, cam = get_cam_flat_filename(image_id)
    rot, refine, cat, range, maxmag= apt_astrom_d[cam]
    
    try:
        print "running aptastrom", filename, range, rot, refine, cam, cat, maxmag
        iraf.AptAstrom(filename, range=range, rotate=rot,
                       display=False, refine=refine, Stdout=1,
                       box=300, telescope=cam, cat=cat, maxmag=maxmag)
    except SubprocessError, e:
        print "failing on subprocess error"
        success = False
示例#10
0
def unzip_pass(image_id, outfile):
    sql = "REPLACE INTO unzip values (%d, 1, '%s')" % (image_id, outfile)
    print "I put it in", outfile
    run_sql(sql)
示例#11
0
def unzip_fail(image_id):
    sql = "REPLACE INTO unzip values(%d, 0, NULL)" % image_id
    print "UNZIP FAIL!"
    run_sql(sql)
示例#12
0
def get_cam_flat_filename(image_id):
    sql = "SELECT flat.outputfile, cam.name FROM image " \
          "INNER JOIN cam ON image.cam_id = cam.id "\
          "INNER JOIN flat ON image.id = flat.image_id "\
          "WHERE image.id = %d" % image_id
    return run_sql(sql)[0]
示例#13
0
def get_cam_unzipped_filename(image_id):
    sql = "SELECT unzip.outputfile, cam.name FROM image " \
          "INNER JOIN cam ON image.cam_id = cam.id "\
          "INNER JOIN unzip ON image.id = unzip.image_id "\
          "WHERE image.id = %d" % image_id
    return run_sql(sql)[0]
示例#14
0
        print "failing on subprocess error"
        success = False
    except irafglobals.IrafError:
        print "failing on iraf error"
        success = False

    d2 = dict(getheader(filename).items())
    print "d2 =", d2
    try:
        sql = "REPLACE INTO astrom VALUES (" \
              "%d, %d, %f, %f, %f)" % \
              (image_id, d2["ASTROMOK"], d2["SMAG"], d2["ZMAG"], d2["SKY"])
    except KeyError:
        sql = "REPLACE INTO astrom VALUES (%d, 0, 0, 0, 0)" % image_id
    print "SQL:", sql
    run_sql(sql)

##################    


def imstat(image_id):
    filename = get_unzipped_filename(image_id)
    d = _imstat(filename)
    sql  = "INSERT IGNORE INTO imstat VALUES ("\
           "%d, %d, %d, %d, %d)" % (image_id, d["MIN"], d["MAX"],
                                    d["MEAN"], d["STDDEV"])
    run_sql(sql)

#########

示例#15
0
"""
Quick and dirty script to provide some number of interest to Michael.
"""

from db.db import run_sql
import numpy as N

if __name__ == '__main__':

    sql = "select header.sunzd, header.moonzd, astrom.sky from header inner join astrom on header.image_id = astrom.image_id inner join image on image.id = header.image_id where header.exposure=40 and image.time > 060401 and image.cam_id = 2"
    run_sql(sql).tofile("sky-40.txt", sep="\n")

    sql = "select header.sunzd, header.moonzd, astrom.sky from header inner join astrom on header.image_id = astrom.image_id inner join image on image.id = header.image_id where header.exposure=8 and image.time > 060401 and image.cam_id = 2"
    run_sql(sql).tofile("sky-8.txt", sep="\n")

    sql = "select header.sunzd, header.moonzd, astrom.smag from header inner join astrom on header.image_id = astrom.image_id inner join image on image.id = header.image_id where header.exposure=40 and image.time > 060401 and image.cam_id = 2"
    run_sql(sql).tofile("smag-40.txt", sep="\n")

    sql = "select header.sunzd, header.moonzd, astrom.smag from header inner join astrom on header.image_id = astrom.image_id inner join image on image.id = header.image_id where header.exposure=8 and image.time > 060401 and image.cam_id = 2"
    run_sql(sql).tofile("smag-8.txt", sep="\n")
示例#16
0
"""
Quick and dirty script to provide some number of interest to Michael.
"""

from db.db import run_sql
import numpy as N

if __name__ == '__main__':

    sql = "select header.sunzd, header.moonzd, astrom.sky from header inner join astrom on header.image_id = astrom.image_id inner join image on image.id = header.image_id where header.exposure=40 and image.time > 060401 and image.cam_id = 2"
    run_sql(sql).tofile("sky-40.txt", sep="\n")
    
    sql = "select header.sunzd, header.moonzd, astrom.sky from header inner join astrom on header.image_id = astrom.image_id inner join image on image.id = header.image_id where header.exposure=8 and image.time > 060401 and image.cam_id = 2"
    run_sql(sql).tofile("sky-8.txt", sep="\n")
    
    sql = "select header.sunzd, header.moonzd, astrom.smag from header inner join astrom on header.image_id = astrom.image_id inner join image on image.id = header.image_id where header.exposure=40 and image.time > 060401 and image.cam_id = 2"
    run_sql(sql).tofile("smag-40.txt", sep="\n")
    
    sql = "select header.sunzd, header.moonzd, astrom.smag from header inner join astrom on header.image_id = astrom.image_id inner join image on image.id = header.image_id where header.exposure=8 and image.time > 060401 and image.cam_id = 2"
    run_sql(sql).tofile("smag-8.txt", sep="\n")