示例#1
0
文件: search2.py 项目: OSSOS/MOP
def get_nailing(expnum,ccd):
    """Get the 'nailing' images associated with expnum"""
    sql="""
    SELECT e.expnum, (e.mjdate - f.mjdate) dt
    FROM bucket.exposure e
    JOIN bucket.exposure f
    JOIN bucket.association b ON b.expnum=f.expnum
    JOIN bucket.association a ON a.pointing=b.pointing AND a.expnum=e.expnum
    WHERE f.expnum=%d
    AND abs(e.mjdate - f.mjdate) > 0.5
    AND abs(e.mjdate - f.mjdate) < 15.0
    ORDER BY abs(e.mjdate-f.mjdate)
    """ % ( expnum )
    try:
        import MOPdbaccess
        mysql=MOPdbaccess.connect('bucket','cfhls',dbSystem='MYSQL')
        bucket=mysql.cursor()
        bucket.execute(sql)
        nailings = bucket.fetchall()
        mysql.close()
        if int(ccd) < 18:
            cutout="[-*,-*]"
        else:
            cutout=None
        import MOPfits
        for nailing in nailings:
            filename=MOPfits.adGet(str(nailing[0])+opt.raw,extno=int(ccd),cutout=cutout)
    except:
        raise TaskError, "get nailing failed"
示例#2
0
文件: search.py 项目: stephengwyn/MOP
def get_nailing(expnum,ccd):
    """Get the 'nailing' images associated with expnum"""
    sql="""
    SELECT e.expnum, (e.mjdate - f.mjdate) dt
    FROM bucket.exposure e
    JOIN bucket.exposure f
    JOIN bucket.association b ON b.expnum=f.expnum
    JOIN bucket.association a ON a.pointing=b.pointing AND a.expnum=e.expnum
    WHERE f.expnum=%d
    AND abs(e.mjdate - f.mjdate) > 0.5
    AND abs(e.mjdate - f.mjdate) < 15.0
    ORDER BY abs(e.mjdate-f.mjdate)
    """ % ( expnum )
    try:
        import MOPdbaccess
        mysql=MOPdbaccess.connect('bucket','cfhls',dbSystem='MYSQL')
        bucket=mysql.cursor()
        bucket.execute(sql)
        nailings = bucket.fetchall()
        mysql.close()
	if not os.access("nailing",os.F_OK):
	   os.mkdir("nailing")
	os.chdir("nailing")
        if int(ccd) < 18:
            cutout="[-*,-*]"
        else:
            cutout=None
        import MOPfits
        for nailing in nailings:
            filename=MOPfits.adGet(str(nailing[0])+opt.raw,extno=int(ccd),cutout=cutout)
    except:
        raise TaskError, "get nailing failed"
示例#3
0
def find_images(file_id,ra,dec):
    import os
    import MOPdbaccess
    intersect_info = {}

    #################################################
    # get datasets that contain cutout circle center
    #################################################
    db = MOPdbaccess.connect('cfeps','cfhls',dbSystem='MYSQL')

    dbcmd = "SELECT * FROM wcs w WHERE file_id='%s'" % ( file_id)
    c = db.cursor()
    c.execute(dbcmd)
    wcsInfo = c.fetchall()
    db.close()
    import wcsutil,string

    for dataset in wcsInfo:
        ### build a WCSObject
        wcsDict={}
        for i,elt in enumerate(dataset):
            wcsDict[string.upper(c.description[i][0])]=elt
        wcs=wcsutil.WCSObject(wcsDict)
        print wcs
        (x1,y1)=wcs.rd2xy((ra,dec))

    return (x1,y1)
示例#4
0
def get_file_ids(object):
    """Get the exposure for a particular line in the meausre table"""
    import MOPdbaccess
    mysql = MOPdbaccess.connect('cfeps','cfhls',dbSystem='MYSQL')
    cfeps=mysql.cursor()
    sql="SELECT file_id FROM measure WHERE provisional LIKE %s"
    cfeps.execute(sql,(object, ))
    file_ids=cfeps.fetchall()

    return (file_ids)
示例#5
0
def get_file_ids(object):
    """Get the exposure for a particular line in the meausre table"""
    import MOPdbaccess
    mysql = MOPdbaccess.connect('cfeps', 'cfhls', dbSystem='MYSQL')
    cfeps = mysql.cursor()
    sql = "SELECT file_id FROM measure WHERE provisional LIKE %s"
    cfeps.execute(sql, (object, ))
    file_ids = cfeps.fetchall()

    return (file_ids)
示例#6
0
def store(hdu, dbase='cfeps', duser='******', dtype='MYSQL', table='source'):
    """Write the contents of a MOP data structure to a SQL table"""

    import MOPdbaccess
    db = MOPdbaccess.connect(dbase, duser, dbSystem=dtype)
    dbc = db.cursor()

    ### INSERT THE 'HEADER' in the meta-data table
    file_id = hdu['header']['image']
    for key in hdu['header'].keys():
        if key == 'image':
            continue
        value = hdu['header'][key]
        ### require that the file_id+keyword is unique
        sql = "DELETE FROM metadata WHERE file_id='%s' and keyword='%s' " % (
            file_id, key)
        dbc.execute(sql)
        sql = "INSERT INTO metadata (file_id, keyword, value) values ('%s','%s','%s' ) " % (
            file_id, key, value)
        dbc.execute(sql)
    db.commit()

    sql = "DELETE FROM source WHERE file_id LIKE '%s'  " % (file_id)
    dbc.execute(sql)

    sql = "INSERT INTO %s ( " % (table)
    sep = " "
    values = "("
    cols = hdu['hdu2sql'].keys()
    for col in cols:
        sql += sep + hdu['hdu2sql'][col]
        values += sep + " %s "
        sep = ', '
    values += ", '%s', %d, %d )" % (file_id, int(
        hdu['header']['EXPNUM']), int(hdu['header']['CHIP']) - 1)
    sql += ", file_id, expnum, ccd ) VALUES " + values
    #print sql
    #sys.exit()
    #values=[]
    for row in range(len(hdu['data'][cols[0]])):
        value = []
        for col in cols:
            value.append(hdu['data'][col][row])
        dbc.execute(sql, value)

    sql = """insert into source_idx ( sourceID, x, y, z ) SELECT sourceID, 
           (360.0*COS(RADIANS(raDeg))*COS(RADIANS(decDeg))),
           (360.0*SIN(RADIANS(raDeg))*COS(RADIANS(decDeg))),
           (360.0*SIN(RADIANS(decDeg))) FROM source  WHERE file_id='%s'""" % (
        file_id)

    dbc.execute(sql)
    db.commit()

    return
示例#7
0
文件: MOPfiles.py 项目: OSSOS/MOP
def store(hdu,dbase='cfeps',duser='******',dtype='MYSQL',table='source'):
    """Write the contents of a MOP data structure to a SQL table"""

    import MOPdbaccess
    db=MOPdbaccess.connect(dbase,duser,dbSystem=dtype)
    dbc=db.cursor()

    ### INSERT THE 'HEADER' in the meta-data table
    file_id=hdu['header']['image']
    for key in hdu['header'].keys():
        if key == 'image':
            continue
        value=hdu['header'][key]
        ### require that the file_id+keyword is unique
        sql="DELETE FROM metadata WHERE file_id='%s' and keyword='%s' " % ( file_id, key)
        dbc.execute(sql)
        sql="INSERT INTO metadata (file_id, keyword, value) values ('%s','%s','%s' ) "% ( file_id, key, value)
        dbc.execute(sql)
    db.commit()

    sql="DELETE FROM source WHERE file_id LIKE '%s'  " % ( file_id )
    dbc.execute(sql)

    sql="INSERT INTO %s ( " % ( table)
    sep=" "
    values="("
    cols=hdu['hdu2sql'].keys()
    for col in cols:
        sql+=sep+hdu['hdu2sql'][col]
        values+=sep+" %s " 
        sep=', '
    values+=", '%s', %d, %d )" % ( file_id, int(hdu['header']['EXPNUM']), int(hdu['header']['CHIP'] )-1 )
    sql+=", file_id, expnum, ccd ) VALUES "+values
    #print sql
    #sys.exit()
    #values=[]
    for row in range(len(hdu['data'][cols[0]])):
        value=[]
        for col in cols:
            value.append(hdu['data'][col][row])
        dbc.execute(sql,value)
        
    sql="""insert into source_idx ( sourceID, x, y, z ) SELECT sourceID, 
           (360.0*COS(RADIANS(raDeg))*COS(RADIANS(decDeg))),
           (360.0*SIN(RADIANS(raDeg))*COS(RADIANS(decDeg))),
           (360.0*SIN(RADIANS(decDeg))) FROM source  WHERE file_id='%s'""" % (file_id)

    dbc.execute(sql)
    db.commit()

    return 
示例#8
0
文件: MOPplot.py 项目: OSSOS/MOP
    def get_pointings(self):
        """Query for some pointings, given a block name"""
	import MOPdbaccess,ephem,math
        import tkSimpleDialog
        result = tkSimpleDialog.askstring("Block Load", "Which Block do you want to plot?")
        db = MOPdbaccess.connect('bucket','cfhls',dbSystem='MYSQL')
        SQL = """SELECT object,ra,`dec`,status,ccd FROM blocks b 
			JOIN cfeps.triple_members m ON m.expnum=b.expnum
			JOIN cfeps.discovery d ON d.triple=m.triple
			JOIN exposure e ON e.expnum=b.expnum
                        LEFT JOIN cfeps.processing p ON p.triple=m.triple
		WHERE p.process='plant' and b.block RLIKE '%s' GROUP BY m.triple,p.ccd """ % (result)
	points=[]
	c = db.cursor()
	r = c.execute(SQL)
	rows=c.fetchall()

        print len(rows)
        geo = camera.geometry['MEGACAM_36']
        main_pointing=''
	for row in rows:
            if main_pointing != row[0]:
                # put down the 'full MP FOV' here
                c=camera(camera='MEGACAM_1')
                if row[4]!= "NULL":
                    color='pale green'
                else:
                    color='gray'
                label={'text': row[0]}
                c.ra=ephem.hours(math.radians(float(row[1])))
                c.dec=ephem.degrees(math.radians(float(row[2])))
                self.pointings.append({"label": label,
                                       "camera": c,
                                       "color": color})
                main_pointing=row[0]
            if int(row[3]) < 0:
                # Create a 'red' box for this CCD
                c=camera(camera='MP_CCD')
                c.ra = ephem.hours(math.radians(float(row[1])-geo[int(row[4])]["ra"]/math.cos(math.radians(float(row[2])))))
                c.dec =ephem.degrees(math.radians(float(row[2])-geo[int(row[4])]["dec"]))
                color='red'
                label={'text': str(row[4])}
                self.pointings.append({"label": label, "camera": c,"color":color})
                                       
        self.plot_pointings()

        return
示例#9
0
#!/usr/cadc/misc/bin/python

import MOPdbaccess,sys

cadc = MOPdbaccess.connect('cfht','kavelaar')
cfhlsvw = MOPdbaccess.connect('bucket','lsadmin','MYSQL')

bucket=cfhlsvw.cursor()
cfht=cadc.cursor()

sql="SELECT expnum FROM exposure " 
bucket.execute(sql)
rows=bucket.fetchall()
sql_insert="UPDATE exposure SET qso_status=%s, obs_iq_refccd=%s WHERE expnum=%s"
sql_select="SELECT qso_status,obs_iq_refccd FROM detrended WHERE expnum=@expnum"
for row in rows:
	expnum = int(row[0])
	cfht.execute(sql_select,{'@expnum': expnum} )
	exposures=cfht.fetchone()
	if not exposures:
		sys.stdout.write( "No IQ for "+str(expnum)+"     \r")
		continue

	sys.stdout.write(sql_insert % (exposures[0],exposures[1], str(expnum) ) )
	sys.stdout.write('\r')
	bucket.execute(sql_insert ,(exposures[0],exposures[1], expnum ) )
	if bucket.rowcount>0:
		sys.stdout.write("inserted qso_status and obs_iq_refccd for "+str(expnum)+" \r")
	else:
		sys.stdout.write("Nothing happend? \r")
	
示例#10
0
文件: s1.py 项目: OSSOS/MOP
    parser.add_option("--verbose", "-v", action="store_true", dest="verbose", help="Provide feedback on what I'm doing")
    parser.add_option("--triple", "-t", action="store", type="int", dest="triple", help="Triple to search")
    parser.add_option("--block", "-b", action="store", dest="block", help="CFEPS block to search")
    parser.add_option(
        "--ccd", "-c", action="store", default=-1, type="int", dest="ccd", help="Provide feedback on what I'm doing"
    )
    (opt, file_ids) = parser.parse_args()

    import os, shutil

    if os.getenv("_CONDOR_SCRATCH_DIR") != None:
        os.chdir(os.getenv("_CONDOR_SCRATCH_DIR"))

    import MOPdbaccess

    mysql = MOPdbaccess.connect("cfeps", "cfhls", dbSystem="MYSQL")
    cfeps = mysql.cursor()

    if not opt.triple:
        sql = """SELECT DISTINCT(t.id) 
            FROM triples t JOIN recovery d ON t.id=d.triple 
            JOIN bucket.association a ON t.pointing=a.pointing
            JOIN bucket.blocks b ON a.expnum=b.expnum
            WHERE b.qname LIKE '%s'""" % (
            opt.block,
        )
        print sql
        cfeps.execute(sql)
        rows = cfeps.fetchall()
    else:
        rows = [opt.triple]
示例#11
0
文件: nailing.py 项目: OSSOS/MOP
                          dest="ccd")
        parser.add_option("--raw",
                          action="store_true",
                          default=False,
                          help="Use the raw exposures?")

        (opt, file_ids)=parser.parse_args()
	if opt.raw:
	    opt.raw="o"
	else:
	    opt.raw="p"
	fext = opt.raw

        import os, shutil, sys
        import MOPdbaccess
        mysql=MOPdbaccess.connect('bucket','cfhls',dbSystem='MYSQL')
        bucket=mysql.cursor()
        if opt.verbose:
            print "Starting to gather info about chips to search\n"

        field=None
	if opt.field:
	  field=" e.object like '%s' " % ( opt.field)
        qname=None
	if opt.block:
	  qname=" b.block LIKE '%s' " % ( opt.block ) 

        sql="""SELECT e.expnum,e.object FROM exposure e JOIN blocks b ON
               e.expnum = b.expnum """
        sep=" WHERE "
        if field :
示例#12
0
文件: TapQuery.py 项目: OSSOS/MOP
              sys.stderr.write("# TAP Query got Code: %s Attempt: %d (exiting)\n" % (str(e.code),cnt))
              sys.exit(-1)
          sys.stderr.write("# TAP Query got Code: %s Attempt: %d (sleeping for 10)\n" % (str(e.code),cnt))
          time.sleep(10)


queryResult=TAPQuery(inputListQuery)
tf = open('obs.vot','w')
for line in queryResult:
    tf.write(line)
tf.flush()
tf.close()
print "opening local votable"
t=atpy.Table('obs.vot',type='vo')
print t.columns
mysql=MOPdbaccess.connect('bucket','lsadmin','MYSQL')
bucket=mysql.cursor()
cols=("expnum","object","ra","dec","exptime","mjdate","filter","runid")
print cols
print t
#,"qrunid","date","uttime")

for irow in range(len(t)):
    
    sql="SELECT count(*) from bucket.exposure where expnum=%s" 
    bucket.execute(sql,(t[irow]['expnum']))
    count=bucket.fetchall()
    if count[0][0] > 0:
        continue
    
    ### now add to the exposure table too.
示例#13
0
def searchTriples(expnums,ccd):
    """Given a list of exposure numbers, find all the KBOs in that set of exposures"""
    import MOPfits,os 
    import MOPdbaccess
    
    if len(expnums)!=3:
        return(-1)


    


    mysql=MOPdbaccess.connect('bucket','cfhls','MYSQL')
    bucket=mysql.cursor()
    ### Some program Constants

    proc_file = open("proc-these-files","w")
    proc_file.write("# Files to be planted and searched\n")
    proc_file.write("#            image fwhm plant\n")
    
    import string
    import os.path
    filenames=[]
    import pyfits
    for expnum in expnums:
        bucket.execute("SELECT obs_iq_refccd FROM exposure WHERE expnum=%s" , (expnum, ) )
        row=bucket.fetchone()
        fwhm=row[0]
        if not fwhm > 0:
            fwhm=1.0

        if int(ccd)<18:
            cutout="\[-*,-*\]"
        else:
            cutout=None
        filename=MOPfits.adGet(str(expnum)+"p",extno=int(ccd),cutout=cutout)
        print filename
        if not os.access(filename,os.R_OK):
            return(-3)
        filename=os.path.splitext(filename)
        filenames.append(filename[0])
        proc_file.write("%s %f %s \n" % ( filename[0], fwhm/0.183, "no"))

    proc_file.flush()
    proc_file.close()
    
    command="find.pl -p '' -d ./ "
    sys.stderr.write(command)
    try:
        os.system(command)
    except:
        sys.stderr.write("Failed while running find")
    

    file_extens=[
        "cands.comb",
        "measure3.cands.astrom",
        "measure3.WARNING",
        "measure3.astrom.scatter"]
    
    if os.access("find.OK",os.R_OK):
        os.system("touch /home/cadc/kavelaar/results/05AQ06B/"+filenames[0]+".OK")
    else:
        os.system("touch /home/cadc/kavelaar/results/05AQ06B/"+filenames[0]+".FAILED")
        
        ### look for the cand.comb file and store in the DB
    import shutil
    for ext in file_extens:
        if os.access(filenames[0]+"."+ext,os.R_OK):
            shutil.copy(filenames[0]+"."+ext,"/home/cadc/kavelaar/results/05AQ06B")
    astrom=filenames[0]+".measure3.cands.astrom"
    print astrom
    cmd = "mpc_gen.pl -c "+astrom
    print os.access(astrom,os.R_OK)
    if os.access(astrom,os.R_OK):
        print cmd
        os.system(cmd)
        os.system("mpcIngest.pl *.MPC")
	os.system("cp *.MPC /home/cadc/kavelaar/results/05AQ06B")
    return(0)
示例#14
0
#!/usr/bin/env python

import MOPdbaccess,sys

sybase=MOPdbaccess.connect('cfht','kavelaar')
cfht=sybase.cursor()


sql="SELECT ra_rad,dec_rad, mjdate, measure,file_id  FROM measure m join object o ON m.provisional=o.provisional where official LIKE 'l%' ORDER BY mjdate";
bucket.execute(sql)
measures =bucket.fetchall()


import string
for measure in measures:
    #sql="SELECT w.dataset_name,w.ext_no FROM wcsInfo w JOIN cfht_files c ON w.dataset_name=c.dataset_name JOIN exposure e on e.expnum=c.expnum where ra_1 < %s and ra_4 > %s and dec_1 > %s and dec_2 < %s and ABS(mjdate - %s)*24*3600<90.0 "
    sql="SELECT w.dataset_name,w.ext_no FROM wcsInfo w WHERE ra_1 < %s and ra_4 > %s and dec_1 > %s and dec_2 < %s AND dataset_name='%s' "
    thisRA=measure[0]*57.3
    thisDEC=measure[1]*57.3
    thisMJDATE=measure[2]
    thisMEASURE=measure[3]
    thisDATASET=measure[4]
    print measure[4]
    SQL= sql % (thisRA,thisRA, thisDEC, thisDEC, thisDATASET)
    print SQL 
    cfht.execute(SQL)
    wcsInfo = cfht.fetchone()
    print wcsInfo 
    thisFILE_ID="%6sp%2s" % ( str(wcsInfo[0]) ,string.zfill(str(wcsInfo[1]),2))
    sql="UPDATE  measure SET file_id=%s WHERE measure=%s"
    #bucket.execute( sql % ( thisFILE_ID,thisMJDATE))
示例#15
0
#!/usr/bin/env python

import MOPdbaccess, sys

cfhlsvw = MOPdbaccess.connect('bucket', 'lsadmin', 'MYSQL')
bucket = cfhlsvw.cursor()

#sql="SELECT ra_rad,dec_rad, mjdate, official,measure  FROM cfeps.measure c join cfeps.object o on c.provisional like o.official where official like 'l%' ORDER BY official,mjdate ";
sql = "SELECT ra_rad,dec_rad, mjdate, measure  FROM cfeps.measure WHERE file_id LIKE 'unknown' and observatory=568 and mjdate >  52722.44745  "
bucket.execute(sql)
measures = bucket.fetchall()

for measure in measures:
    sql = "SELECT expnum FROM exposure where ABS(ra - %s)<1.0*cos(`dec`/57.3) and ABS(`dec` - %s)<1.0 and ABS(mjdate - %s)*24*3600<90 "
    bucket.execute(sql, (measure[0] * 57.3, measure[1] * 57.2, measure[2]))
    exps = bucket.fetchall()
    for exp in exps:
        sql = "UPDATE cfeps.measure SET file_id=%s WHERE measure=%s"
        #print sql % ( exp[0], measure[3])
        bucket.execute(sql, (exp[0], measure[3]))
        #print ("http://services.cadc-ccha.hia-iha.nrc-cnrc.gc.ca/cfhtProxies/getData?dataset_name%s&cutout=(%08.3f,%08.3f,%5.3f)" % (exp[0],measure[0]*57.3,measure[1]*57.3,1.0/60.0) )
示例#16
0
            sys.stderr.write(
                "# TAP Query got Code: %s Attempt: %d (sleeping for 10)\n" %
                (str(e.code), cnt))
            time.sleep(10)


queryResult = TAPQuery(inputListQuery)
tf = open('obs.vot', 'w')
for line in queryResult:
    tf.write(line)
tf.flush()
tf.close()
print "opening local votable"
t = atpy.Table('obs.vot', type='vo')
print t.columns
mysql = MOPdbaccess.connect('bucket', 'lsadmin', 'MYSQL')
bucket = mysql.cursor()
cols = ("expnum", "object", "ra", "dec", "exptime", "mjdate", "filter",
        "runid")
print cols
print t
#,"qrunid","date","uttime")

for irow in range(len(t)):

    sql = "SELECT count(*) from bucket.exposure where expnum=%s"
    bucket.execute(sql, (t[irow]['expnum']))
    count = bucket.fetchall()
    if count[0][0] > 0:
        continue
示例#17
0
文件: scrample.py 项目: OSSOS/MOP
def searchTriples(filenames, plant=False):
    """Given a list of exposure numbers, find all the KBOs in that set of exposures"""

    print filenames
    if opt.none:
        return

    import MOPfits, os
    import MOPdbaccess
    import string
    import os.path
    import pyfits

    if len(filenames) != 3:
        raise TaskError, "got %d exposures" % (len(expnums))

    ### Some program Constants
    proc_these_files = []
    if not plant:
        proc_these_files.append("# Files to be planted and searched\n")
        proc_these_files.append("#            image fwhm plant\n")

    for filename in filenames:
        try:
            mysql = MOPdbaccess.connect("bucket", "cfhls", "MYSQL")
            bucket = mysql.cursor()
        except:
            raise TaskError, "mysql failed"
        # bucket.execute("SELECT obs_iq_refccd FROM exposure WHERE expnum=%s" , (expnum, ) )
        # row=bucket.fetchone()
        # mysql.close()
        # fwhm=row[0]
        # if not fwhm > 0:
        fwhm = 1.0

        if not plant:
            # proc_these_files.append("%s %f %s \n" % ( filename[0], fwhm/0.183, 'no'))
            pstr = "NO"
        else:
            pstr = "YES"
            ### since we're planting we need a psf.  JMPMAKEPSF will
            ### update the proc-these-files listing

            ### run the make psf script .. always.  This creates proc-these-files
            ### which is needed by the find.pl script.
        command = "jmpmakepsf.csh ./ %s %s" % (filename, pstr)
        if opt.verbose:
            sys.stderr.write(command)
        try:
            os.system(command)
        except:
            raise TaskError, "jmpmakepsf noexec"
        if os.access(filename + ".jmpmakepsf.FAILED", os.R_OK) or not os.access(filename + ".psf.fits", os.R_OK):
            if plant:
                raise TaskError, "jmpmakepsf failed"
            # 	do without plant
            else:
                plant = False
                pstr = "NO"
                ### we're not planting so, lets keep going
                ### but check that there is a line in proc_these_files
                add_line = True
                if not os.access("proc-these-files", os.R_OK):
                    f = open("proc-these-files", "w")
                    for l in proc_these_files:
                        f.write(l)
                    f.close()
                f = open("proc-these-files", "r")
                ptf_lines = f.readlines()
                f.close()
                for ptf_line in ptf_lines:
                    if ptf_line[0] == "#":
                        continue
                    ptf_a = ptf_line.split()
                    import re

                    if re.search("%s" % (filename), ptf_a[0]):
                        ### there's already a line for this one
                        add_line = False
                        break
                if add_line:
                    f = open("proc-these-files", "a")
                    f.write("%s %f %s \n" % (filename, fwhm / 0.183, "no"))
                    f.close()

    if opt.none:
        return -1
    prefix = ""
    if plant:
        command = "plant.csh ./ "
        # command="plant.csh ./ -rmin %s -rmax %s -ang %s -width %s " % ( opt.rmin, opt.rmax, opt.angle, opt.width)
        try:
            os.system(command)
        except:
            raise TaskError, "plant exec. failed"
        if not os.access("plant.OK", os.R_OK):
            raise TaskError, "plant failed"
        prefix = "fk"
    # else:
    #    f=open('proc-these-files','w')
    #    for line in proc_these_files:
    #        f.write(line)
    #    f.flush()
    #    f.close()

    if opt.rerun and os.access("find.OK", os.R_OK):
        os.unlink("find.OK")

    # command="find.pl -p "+prefix+" -rn %s -rx %s -a %s -aw %s -d ./ " % ( opt.rmin, opt.rmax, opt.angle, opt.width)
    command = "find.pl -p " + prefix + " -d ./ "
    if opt.union:
        command += " -u"

    if opt.verbose:
        sys.stderr.write(command)

    try:
        os.system(command)
    except:
        raise TaskErorr, "execute find"

    if not os.access("find.OK", os.R_OK):
        raise TaskError, "find failed"

    ### check the transformation file
    command = "checktrans -p " + prefix

    try:
        os.system(command)
    except:
        raise TaskError, "execute checktrans"

    if not os.access("checktrans.OK", os.R_OK):
        raise TaskError, "checktrans failed"
    elif os.access("checktrans.FAILED", os.R_OK):
        os.unlink("checktrans.FAILED")

    if os.access("BAD_TRANS" + prefix, os.R_OK):
        raise TaskError, "BAD TRANS"

    ## check that the transformation in .trans.jmp files look reasonable
    import math

    for filename in filenames:
        try:
            for line in open(filename + ".trans.jmp"):
                for v in line.split():
                    if math.fabs(float(v)) > 200:
                        raise TaskError, "BAD TRANS"
        except:
            raise TaskError, "TRAN_CHECK FAILED"

    astrom = prefix + filenames[0] + ".cands.comb"
    if opt.plant:
        for filename in filenames:
            try:
                ushort(prefix + filename + ".fits")
            except:
                raise TaskError("ushort failed %s" % (prefix + filename + ".fits"))

    if opt.plant:
        astrom = prefix + filenames[0] + ".comb.found"
        try:
            # make sure we have +5 lines in this file
            lines = file(astrom).readlines()
            if len(lines) < 5:
                raise TaskError, "Too few Found"
        except:
            raise TaskError, "Error reading %s" % (astrom)

    if os.access(astrom, os.R_OK):
        return 1
    else:
        return 0
示例#18
0
#!/usr/cadc/misc/bin/python

import MOPdbaccess, sys

cadc = MOPdbaccess.connect('cfht', 'kavelaar')
cfhlsvw = MOPdbaccess.connect('bucket', 'lsadmin', 'MYSQL')

bucket = cfhlsvw.cursor()
cfht = cadc.cursor()

sql = "SELECT expnum FROM exposure "
bucket.execute(sql)
rows = bucket.fetchall()
sql_insert = "UPDATE exposure SET qso_status=%s, obs_iq_refccd=%s WHERE expnum=%s"
sql_select = "SELECT qso_status,obs_iq_refccd FROM detrended WHERE expnum=@expnum"
for row in rows:
    expnum = int(row[0])
    cfht.execute(sql_select, {'@expnum': expnum})
    exposures = cfht.fetchone()
    if not exposures:
        sys.stdout.write("No IQ for " + str(expnum) + "     \r")
        continue

    sys.stdout.write(sql_insert % (exposures[0], exposures[1], str(expnum)))
    sys.stdout.write('\r')
    bucket.execute(sql_insert, (exposures[0], exposures[1], expnum))
    if bucket.rowcount > 0:
        sys.stdout.write("inserted qso_status and obs_iq_refccd for " +
                         str(expnum) + " \r")
    else:
        sys.stdout.write("Nothing happend? \r")
示例#19
0
文件: ph2.py 项目: stephengwyn/MOP
#!/usr/bin/env python

import RO.StringUtil

deg_2_dms = RO.StringUtil.dmsStrFromDeg

sql = "select p.* from opposition o join pointings p on o.pointing=p.id join association a on a.pointing=p.id JOIN blocks b on b.expnum=a.expnum where runid LIKE '06AQ02' and qname LIKE '03BQ06A' group by p.id"

import MOPdbaccess

mysql = MOPdbaccess.connect('bucket', 'cfhtlsvw', 'MYSQL')
bucket = mysql.cursor()
bucket.execute(sql)
rows = bucket.fetchall()
print """
<?xml version = "1.0"?>
<!DOCTYPE ASTRO SYSTEM "http://vizier.u-strasbg.fr/xml/astrores.dtd">
<ASTRO ID="v0.8" xmlns:ASTRO="http://vizier.u-strasbg.fr/doc/astrores.htx">
<TABLE ID="Table">
   <NAME>Fixed Targets</NAME>
   <TITLE>Fixed Targets for CFHT QSO</TITLE>
   <!-- Definition of each field -->
   <FIELD name="NAME" datatype="A" width="20">
       <DESCRIPTION>Name of target</DESCRIPTION>
   </FIELD>
   <FIELD name="RA" datatype="A" width="11" unit="h" format="RAh:RAm:RAs">
       <DESCRIPTION>Right ascension of target</DESCRIPTION>
   </FIELD>
   <FIELD name="DEC" datatype="A" width="11" unit="deg" format="DEd:DEm:DEs">
       <DESCRIPTION>Declination of target</DESCRIPTION>
   </FIELD>
示例#20
0
文件: search.py 项目: stephengwyn/MOP
def searchTriples(expnums,ccd,plant=False):
    """Given a list of exposure numbers, find all the KBOs in that set of exposures"""
    import MOPfits,os 
    import MOPdbaccess
    
    if len(expnums)!=3:
        raise TaskError, "got %d exposures"%(len(expnums))


    ### Some program Constants
    proc_these_files=[]
    if not plant:
        proc_these_files.append("# Files to be planted and searched\n")
        proc_these_files.append("#            image fwhm plant\n")
        
    import string
    import os.path
    filenames=[]
    import pyfits
    for expnum in expnums:
        ### Get the processed images from AD
        if int(ccd)<18:
            cutout="[-*,-*]"
        else:
            cutout="[*,*]"
        filename=MOPfits.adGet(str(expnum)+opt.raw,extno=int(ccd),cutout=cutout)

        if not os.access(filename,os.R_OK):
            sys.stderr.write("Ad Get Failed\n")
            raise TaskError, 'adGet Failed'
	    
	if opt.none:
	    continue
        filename=os.path.splitext(filename)
        filenames.append(filename[0])

    	try: 
            mysql=MOPdbaccess.connect('bucket','cfhls','MYSQL')
            bucket=mysql.cursor()
	except:
            raise TaskError, "mysql failed"
        bucket.execute("SELECT obs_iq_refccd FROM exposure WHERE expnum=%s" , (expnum, ) )
        row=bucket.fetchone()
	mysql.close()
        fwhm=row[0]
        if not fwhm > 0:
            fwhm=1.0

        if not plant:
            #proc_these_files.append("%s %f %s \n" % ( filename[0], fwhm/0.183, 'no'))
	    pstr='NO'
        else:
	    pstr='YES'
            ### since we're planting we need a psf.  JMPMAKEPSF will
            ### update the proc-these-files listing

        ### run the make psf script .. always.  This creates proc-these-files
        ### which is needed by the find.pl script.
        command='jmpmakepsf.csh ./ %s %s' % ( filename[0]+".fits", pstr )

        if opt.verbose:
            sys.stderr.write( command )
        try:
            os.system(command)
        except:
            raise TaskError, "jmpmakepsf noexec"
        if os.access(filename[0]+'.jmpmakepsf.FAILED',os.R_OK) or not os.access(filename[0]+".psf.fits", os.R_OK) :
#	    if plant:
#                raise TaskError, "jmpmakepsf failed"
#	do without plant
            if 1==1 :
	        plant=False
		pstr='NO'
	        ### we're not planting so, lets keep going
		### but check that there is a line in proc_these_files
	        add_line=True
		if not os.access('proc-these-files',os.R_OK):
		    f=open('proc-these-files','w')
		    for l in proc_these_files:
		        f.write(l)
		    f.close()
	    	f=open('proc-these-files','r')
		ptf_lines=f.readlines()
		f.close()
		for ptf_line in ptf_lines:
		    if ptf_line[0]=='#':
		        continue
	            ptf_a=ptf_line.split()
		    import re
		    if re.search('%s' % (filename[0]),ptf_a[0]):
		        ### there's already a line for this one
			add_line=False
		        break
                if add_line:
		    f=open('proc-these-files','a')
		    f.write("%s %f %s \n" % ( filename[0], fwhm/0.183, 'no'))
		    f.close()

    if opt.none:
        return(-1)
    prefix=''
    if plant:
        command="plant.csh ./ -rmin %s -rmax %s -ang %s -width %s " % ( opt.rmin, opt.rmax, opt.angle, opt.width)
        try: 
            os.system(command)
        except:
            raise TaskError, 'plant exec. failed'
        if not os.access('plant.OK',os.R_OK):
            raise TaskError, 'plant failed'
        prefix='fk'
    #else:
    #    f=open('proc-these-files','w')
    #    for line in proc_these_files:
    #        f.write(line)
    #    f.flush()
    #    f.close()
    	
    if opt.rerun and os.access('find.OK',os.R_OK):
        os.unlink("find.OK")

    command="find.pl -p "+prefix+" -rn %s -rx %s -a %s -aw %s -d ./ " % ( opt.rmin, opt.rmax, opt.angle, opt.width) 
    #command="find.pl -p "+prefix+" -d ./ " 
    if opt.verbose:
        sys.stderr.write( command )

    try:
        os.system(command)
    except:
        raise TaskErorr, "execute find"
    

    if not os.access("find.OK",os.R_OK):
        raise TaskError, "find failed"

    ### check the transformation file
    command = "checktrans -p "+prefix
    
    try:
        os.system(command)
    except:
        raise TaskError, "execute checktrans"
    
    if not os.access("checktrans.OK",os.R_OK):
        raise TaskError, "checktrans failed"

    if os.access("BAD_TRANS"+prefix,os.R_OK):
        raise TaskError,"BAD TRANS"
        
    astrom=prefix+filenames[0]+".cands.comb"
    if opt.plant:
        astrom=prefix+filenames[0]+".comb.found"
        try:
            #make sure we have +10 lines in this file
	    lines=file(astrom).readlines()
	    if len(lines)<10:
	       raise TaskError,"Too few Found"
	except:
	    raise TaskError, "Error reading %s" %(astrom)
	    
    
    if os.access(astrom,os.R_OK):
        return(1)
    else:
        return(0)
示例#21
0
文件: objects.py 项目: OSSOS/MOP
#!/usr/bin/env python

import MOPdbaccess


db = MOPdbaccess.connect("cfeps", "cfhls", dbSystem="MYSQL", password="******")

cfhls = db.cursor()

cfhls.execute("SELECT official, a, e, i  FROM orbits WHERE official LIKE 'L3%'")
rows = cfhls.fetchall()


print "<TABLE>"
print "<TR><TH>OBJECT</TH><TH>a</TH><TH>e</TH><TH>i</TH></TR>"
for row in rows:
    print "<TR>"
    for col in row:
        print "<TD>%s</TD>" % (col)
    print "</TR>"
print "</table>"
示例#22
0
def searchTriples(expnums, ccd):
    """Given a list of exposure numbers, find all the KBOs in that set of exposures"""
    import MOPfits, os
    import MOPdbaccess

    if len(expnums) != 3:
        return (-1)

    ### Some program Constants

    proc_file = open("proc-these-files", "w")
    proc_file.write("# Files to be planted and searched\n")
    proc_file.write("#            image fwhm plant\n")

    import string
    import os.path
    filenames = []
    import pyfits
    for expnum in expnums:
        try:
            mysql = MOPdbaccess.connect('bucket', 'cfhls', 'MYSQL')
            bucket = mysql.cursor()
        except:
            raise TaskError, "mysql failed"
        bucket.execute("SELECT obs_iq_refccd FROM exposure WHERE expnum=%s",
                       (expnum, ))
        row = bucket.fetchone()
        mysql.close()
        fwhm = row[0]
        if not fwhm > 0:
            fwhm = 1.0

        if int(ccd) < 18:
            cutout = "[-*,-*]"
        else:
            cutout = None
        filename = MOPfits.adGet(str(expnum) + "p",
                                 extno=int(ccd),
                                 cutout=cutout)

        if not os.access(filename, os.R_OK):
            raise TaskError, 'adGet Failed'

        filename = os.path.splitext(filename)
        filenames.append(filename[0])
        proc_file.write("%s %f %s \n" % (filename[0], fwhm / 0.183, "no"))

    proc_file.flush()
    proc_file.close()

    command = "find.pl -p '' -d ./ "

    try:
        os.system(command)
    except:
        raise TaskErorr, "execute find"

    file_extens = [
        "cands.comb", "measure3.cands.astrom", "measure3.WARNING",
        "measure3.astrom.scatter"
    ]

    if not os.access("find.OK", os.R_OK):
        raise TaskError, "find failed"

    astrom = filenames[0] + ".measure3.cands.astrom"

    if os.access(astrom, os.R_OK):
        return (1)
    else:
        return (0)
示例#23
0
文件: ph2.py 项目: OSSOS/MOP
#!/usr/bin/env python


import RO.StringUtil

deg_2_dms=RO.StringUtil.dmsStrFromDeg


sql="select p.* from opposition o join pointings p on o.pointing=p.id join association a on a.pointing=p.id JOIN blocks b on b.expnum=a.expnum where runid LIKE '06AQ02' and qname LIKE '03BQ06A' group by p.id"

import MOPdbaccess

mysql=MOPdbaccess.connect('bucket','cfhtlsvw','MYSQL')
bucket=mysql.cursor()
bucket.execute(sql)
rows=bucket.fetchall()
print """
<?xml version = "1.0"?>
<!DOCTYPE ASTRO SYSTEM "http://vizier.u-strasbg.fr/xml/astrores.dtd">
<ASTRO ID="v0.8" xmlns:ASTRO="http://vizier.u-strasbg.fr/doc/astrores.htx">
<TABLE ID="Table">
   <NAME>Fixed Targets</NAME>
   <TITLE>Fixed Targets for CFHT QSO</TITLE>
   <!-- Definition of each field -->
   <FIELD name="NAME" datatype="A" width="20">
       <DESCRIPTION>Name of target</DESCRIPTION>
   </FIELD>
   <FIELD name="RA" datatype="A" width="11" unit="h" format="RAh:RAm:RAs">
       <DESCRIPTION>Right ascension of target</DESCRIPTION>
   </FIELD>
   <FIELD name="DEC" datatype="A" width="11" unit="deg" format="DEd:DEm:DEs">
示例#24
0
                      dest="ccd")
    parser.add_option("--raw",
                      action="store_true",
                      default=False,
                      help="Use the raw exposures?")

    (opt, file_ids) = parser.parse_args()
    if opt.raw:
        opt.raw = "o"
    else:
        opt.raw = "p"
    fext = opt.raw

    import os, shutil, sys
    import MOPdbaccess
    mysql = MOPdbaccess.connect('bucket', 'cfhls', dbSystem='MYSQL')
    bucket = mysql.cursor()
    if opt.verbose:
        print "Starting to gather info about chips to search\n"

    field = None
    if opt.field:
        field = " e.object like '%s' " % (opt.field)
    qname = None
    if opt.block:
        qname = " b.block LIKE '%s' " % (opt.block)

    sql = """SELECT e.expnum,e.object FROM exposure e JOIN blocks b ON
               e.expnum = b.expnum """
    sep = " WHERE "
    if field:
示例#25
0
    "object": "object",
    "ra_deg": "ra_deg",
    "dec_deg": "dec_deg",
    "exptime": "exptime",
    "mjdate": "mjdate",
    "date_obs": "date-obs",
    "utc_obs": "utc-obs",
    "filter": "filter" }

import sys
import os
import wcsutil

basename = os.path.basename

db=MOPdbaccess.connect('cfeps','cfhls','MYSQL')
cfeps=db.cursor()

for file in sys.argv[1:] :
    file = file.strip()
    try:
        fits = pyfits.open(file)
    except:
        sys.stderr.write("\nERROR: failed to open %s\n" % ( file))
        continue
    values={}
    values['file_id']=basename(file).split('.')[0]
    values['active']=file
    values['archive']='not available'
    sys.stdout.write("Ingesting %30s \r" % (file))
示例#26
0
                          dest="block",
                          help="CFEPS block to search")
        parser.add_option("--ccd","-c",
                          action="store",
                          default=-1,
                          type="int",
                          dest="ccd",
                          help="Provide feedback on what I'm doing")
        (opt, file_ids)=parser.parse_args()


        import os, shutil
        if os.getenv('_CONDOR_SCRATCH_DIR') != None: os.chdir(os.getenv('_CONDOR_SCRATCH_DIR'))

        import MOPdbaccess
        mysql=MOPdbaccess.connect('cfeps','cfhls',dbSystem='MYSQL')
        cfeps=mysql.cursor()

        if not opt.triple:
            sql="""SELECT DISTINCT(t.id)
            FROM triples t JOIN discovery d ON t.id=d.triple
            JOIN bucket.association a ON t.pointing=a.pointing
            JOIN bucket.blocks b ON a.expnum=b.expnum
            WHERE b.qname LIKE '%s'""" % ( opt.block, )

            cfeps.execute(sql)
            results=cfeps.fetchall()
            rows=[]
            for result in results:
                for ccd in range(36):
                    rows.append([result[0],ccd])
示例#27
0
文件: search2.py 项目: OSSOS/MOP
def searchTriples(expnums,ccd,plant=False):
    """Given a list of exposure numbers, find all the KBOs in that set of exposures"""
    import MOPfits,os 
    import MOPdbaccess
    
    if len(expnums)!=3:
        raise TaskError, "got %d exposures"%(len(expnums))


    ### Some program Constants
    proc_these_files=[]
    if not plant:
        proc_these_files.append("# Files to be planted and searched\n")
        proc_these_files.append("#            image fwhm plant\n")
        
    import string
    import os.path
    filenames=[]
    import pyfits
    for expnum in expnums:
        ### Get the processed images from AD
        if int(ccd)<18:
            cutout="[-*,-*]"
        else:
            cutout="[*,*]"
        filename=MOPfits.adGet(str(expnum)+opt.raw,extno=int(ccd),cutout=cutout)

        if not os.access(filename,os.R_OK):
            sys.stderr.write("Ad Get Failed\n")
            raise TaskError, 'adGet Failed'
	    
	if opt.none:
	    continue

        filename=os.path.splitext(filename)
        filenames.append(filename[0])

    	try: 
            mysql=MOPdbaccess.connect('bucket','cfhls','MYSQL')
            bucket=mysql.cursor()
	except:
            raise TaskError, "mysql failed"
        bucket.execute("SELECT obs_iq_refccd FROM exposure WHERE expnum=%s" , (expnum, ) )
        row=bucket.fetchone()
	mysql.close()
        fwhm=row[0]
        if not fwhm > 0:
            fwhm=1.0

        if not plant:
            #proc_these_files.append("%s %f %s \n" % ( filename[0], fwhm/0.183, 'no'))
	    pstr='NO'
        else:
	    pstr='YES'
            ### since we're planting we need a psf.  JMPMAKEPSF will
            ### update the proc-these-files listing

        ### run the make psf script .. always.  This creates proc-these-files
        ### which is needed by the find.pl script.
        command='jmpmakepsf.csh ./ %s %s' % ( filename[0], pstr )
        if opt.verbose:
            sys.stderr.write( command )
        try:
            os.system(command)
        except:
            raise TaskError, "jmpmakepsf noexec"
        if os.access(filename[0]+'.jmpmakepsf.FAILED',os.R_OK) or not os.access(filename[0]+".psf.fits", os.R_OK) :
#	    if plant:
#                raise TaskError, "jmpmakepsf failed"
#	do without plant
            if 1==1 :
	        plant=False
		pstr='NO'
	        ### we're not planting so, lets keep going
		### but check that there is a line in proc_these_files
	        add_line=True
		if not os.access('proc-these-files',os.R_OK):
		    f=open('proc-these-files','w')
		    for l in proc_these_files:
		        f.write(l)
		    f.close()
	    	f=open('proc-these-files','r')
		ptf_lines=f.readlines()
		f.close()
		for ptf_line in ptf_lines:
		    if ptf_line[0]=='#':
		        continue
	            ptf_a=ptf_line.split()
		    import re
		    if re.search('%s' % (filename[0]),ptf_a[0]):
		        ### there's already a line for this one
			add_line=False
		        break
                if add_line:
		    f=open('proc-these-files','a')
		    f.write("%s %f %s \n" % ( filename[0], fwhm/0.183, 'no'))
		    f.close()

    if opt.none:
        return(-1)
    prefix=''
    if plant:
        command="plant.csh ./ -rmin %s -rmax %s -ang %s -width %s " % ( opt.rmin, opt.rmax, opt.angle, opt.width)
        try: 
            os.system(command)
        except:
            raise TaskError, 'plant exec. failed'
        if not os.access('plant.OK',os.R_OK):
            raise TaskError, 'plant failed'
        prefix='fk'
    #else:
    #    f=open('proc-these-files','w')
    #    for line in proc_these_files:
    #        f.write(line)
    #    f.flush()
    #    f.close()
    	
    if opt.rerun and os.access('find.OK',os.R_OK):
        os.unlink("find.OK")

    command="find.pl -p "+prefix+" -rn %s -rx %s -a %s -aw %s -d ./ " % ( opt.rmin, opt.rmax, opt.angle, opt.width) 
    #command="find.pl -p "+prefix+" -d ./ " 
    if opt.verbose:
        sys.stderr.write( command )

    try:
        os.system(command)
    except:
        raise TaskErorr, "execute find"
    

    if not os.access("find.OK",os.R_OK):
        raise TaskError, "find failed"

    ### check the transformation file
    command = "checktrans -p "+prefix
    
    try:
        os.system(command)
    except:
        raise TaskError, "execute checktrans"
    
    if not os.access("checktrans.OK",os.R_OK):
        raise TaskError, "checktrans failed"

    if os.access("BAD_TRANS"+prefix,os.R_OK):
        raise TaskError,"BAD TRANS"
        
    astrom=prefix+filenames[0]+".cands.comb"
    if opt.plant:
        astrom=prefix+filenames[0]+".comb.found"
        try:
            #make sure we have +10 lines in this file
	    lines=file(astrom).readlines()
	    if len(lines)<10:
	       raise TaskError,"Too few Found"
	except:
	    raise TaskError, "Error reading %s" %(astrom)
	    
    
    if os.access(astrom,os.R_OK):
        return(1)
    else:
        return(0)
示例#28
0
文件: s2.py 项目: OSSOS/MOP
def searchTriples(expnums,ccd):
    """Given a list of exposure numbers, find all the KBOs in that set of exposures"""
    import MOPfits,os 
    import MOPdbaccess
    
    if len(expnums)!=3:
        return(-1)


    ### Some program Constants

    proc_file = open("proc-these-files","w")
    proc_file.write("# Files to be planted and searched\n")
    proc_file.write("#            image fwhm plant\n")
    
    import string
    import os.path
    filenames=[]
    import pyfits
    for expnum in expnums:
    	try: 
            mysql=MOPdbaccess.connect('bucket','cfhls','MYSQL')
            bucket=mysql.cursor()
	except:
            raise TaskError, "mysql failed"
        bucket.execute("SELECT obs_iq_refccd FROM exposure WHERE expnum=%s" , (expnum, ) )
        row=bucket.fetchone()
	mysql.close()
        fwhm=row[0]
        if not fwhm > 0:
            fwhm=1.0

        if int(ccd)<18:
            cutout="[-*,-*]"
        else:
            cutout=None
        filename=MOPfits.adGet(str(expnum)+"p",extno=int(ccd),cutout=cutout)

        if not os.access(filename,os.R_OK):
            raise TaskError, 'adGet Failed'
	    
        filename=os.path.splitext(filename)
        filenames.append(filename[0])
        proc_file.write("%s %f %s \n" % ( filename[0], fwhm/0.183, "no"))

    proc_file.flush()
    proc_file.close()
    
    command="find.pl -p '' -d ./ "

    try:
        os.system(command)
    except:
        raise TaskErorr, "execute find"
    

    file_extens=[
        "cands.comb",
        "measure3.cands.astrom",
        "measure3.WARNING",
        "measure3.astrom.scatter"]
    
    if not os.access("find.OK",os.R_OK):
        raise TaskError, "find failed"
    
        
    astrom=filenames[0]+".measure3.cands.astrom"
    
    if os.access(astrom,os.R_OK):
        return(1)
    else:
        return(0)
示例#29
0
def searchTriples(expnums, ccd):
    """Given a list of exposure numbers, find all the KBOs in that set of exposures"""
    import MOPfits, os
    import MOPdbaccess

    if len(expnums) != 3:
        return (-1)

    mysql = MOPdbaccess.connect('bucket', 'cfhls', 'MYSQL')
    bucket = mysql.cursor()
    ### Some program Constants

    proc_file = open("proc-these-files", "w")
    proc_file.write("# Files to be planted and searched\n")
    proc_file.write("#            image fwhm plant\n")

    import string
    import os.path
    filenames = []
    import pyfits
    for expnum in expnums:
        bucket.execute("SELECT obs_iq_refccd FROM exposure WHERE expnum=%s",
                       (expnum, ))
        row = bucket.fetchone()
        fwhm = row[0]
        if not fwhm > 0:
            fwhm = 1.0

        if int(ccd) < 18:
            cutout = "\[-*,-*\]"
        else:
            cutout = None
        filename = MOPfits.adGet(str(expnum) + "p",
                                 extno=int(ccd),
                                 cutout=cutout)
        print filename
        if not os.access(filename, os.R_OK):
            return (-3)
        filename = os.path.splitext(filename)
        filenames.append(filename[0])
        proc_file.write("%s %f %s \n" % (filename[0], fwhm / 0.183, "no"))

    proc_file.flush()
    proc_file.close()

    command = "find.pl -p '' -d ./ "
    sys.stderr.write(command)
    try:
        os.system(command)
    except:
        sys.stderr.write("Failed while running find")

    file_extens = [
        "cands.comb", "measure3.cands.astrom", "measure3.WARNING",
        "measure3.astrom.scatter"
    ]

    if os.access("find.OK", os.R_OK):
        os.system("touch /home/cadc/kavelaar/results/05AQ06B/" + filenames[0] +
                  ".OK")
    else:
        os.system("touch /home/cadc/kavelaar/results/05AQ06B/" + filenames[0] +
                  ".FAILED")

        ### look for the cand.comb file and store in the DB
    import shutil
    for ext in file_extens:
        if os.access(filenames[0] + "." + ext, os.R_OK):
            shutil.copy(filenames[0] + "." + ext,
                        "/home/cadc/kavelaar/results/05AQ06B")
    astrom = filenames[0] + ".measure3.cands.astrom"
    print astrom
    cmd = "mpc_gen.pl -c " + astrom
    print os.access(astrom, os.R_OK)
    if os.access(astrom, os.R_OK):
        print cmd
        os.system(cmd)
        os.system("mpcIngest.pl *.MPC")
        os.system("cp *.MPC /home/cadc/kavelaar/results/05AQ06B")
    return (0)
示例#30
0
#!/usr/bin/env python

import MOPdbaccess,sys

mysql = MOPdbaccess.connect('cfeps','lsadmin','MYSQL')
sybase=MOPdbaccess.connect('cfht','kavelaar')
bucket=mysql.cursor()
cfht=sybase.cursor()


sql="SELECT ra_rad,dec_rad, mjdate, measure,file_id  FROM measure m join object o ON m.provisional=o.provisional where official LIKE 'l%' ORDER BY mjdate";
bucket.execute(sql)
measures =bucket.fetchall()


import string
for measure in measures:
    #sql="SELECT w.dataset_name,w.ext_no FROM wcsInfo w JOIN cfht_files c ON w.dataset_name=c.dataset_name JOIN exposure e on e.expnum=c.expnum where ra_1 < %s and ra_4 > %s and dec_1 > %s and dec_2 < %s and ABS(mjdate - %s)*24*3600<90.0 "
    sql="SELECT w.dataset_name,w.ext_no FROM wcsInfo w WHERE ra_1 < %s and ra_4 > %s and dec_1 > %s and dec_2 < %s AND dataset_name='%s' "
    thisRA=measure[0]*57.3
    thisDEC=measure[1]*57.3
    thisMJDATE=measure[2]
    thisMEASURE=measure[3]
    thisDATASET=measure[4]
    print measure[4]
    SQL= sql % (thisRA,thisRA, thisDEC, thisDEC, thisDATASET)
    print SQL 
    cfht.execute(SQL)
    wcsInfo = cfht.fetchone()
    print wcsInfo 
    thisFILE_ID="%6sp%2s" % ( str(wcsInfo[0]) ,string.zfill(str(wcsInfo[1]),2))
示例#31
0
#!/usr/bin/env python

import MOPdbaccess


db = MOPdbaccess.connect('cfeps','cfhls',dbSystem='MYSQL',password='******')

cfhls=db.cursor()

cfhls.execute("SELECT official, a, e, i  FROM orbits WHERE official LIKE 'L3%'")
rows = cfhls.fetchall()


print "<TABLE>"
print "<TR><TH>OBJECT</TH><TH>a</TH><TH>e</TH><TH>i</TH></TR>"
for row in rows:
   print "<TR>"
   for col in row:
      print "<TD>%s</TD>" %(col)
   print "</TR>"
print "</table>"
示例#32
0
                      default=False,
                      help="run a scrambled version as eff check")
    file_ids = []
    (opt, file_ids) = parser.parse_args()
    if opt.raw:
        opt.raw = "o"
    else:
        opt.raw = "p"
    fext = opt.raw

    import os, shutil, sys
    if os.getenv('_CONDOR_SCRATCH_DIR') != None:
        os.chdir(os.getenv('_CONDOR_SCRATCH_DIR'))

    import MOPdbaccess
    mysql = MOPdbaccess.connect('cfeps', 'cfhls', dbSystem='MYSQL')
    cfeps = mysql.cursor()
    if opt.verbose:
        print "Starting to gather info about chips to search\n"

    process = 'search'
    if opt.plant:
        process = 'plant'

    rerun = ""
    if not opt.rerun:
        rerun = " (p.comment IS NULL OR p.status=-2 ) AND "
    field = ''
    if opt.field:
        field = " pointings.name LIKE '%s' AND " % (opt.field)
    qname = ''
示例#33
0
文件: get_file_ids.py 项目: OSSOS/MOP
#!/usr/bin/env python

import MOPdbaccess,sys

cfhlsvw = MOPdbaccess.connect('bucket','lsadmin','MYSQL')
bucket=cfhlsvw.cursor()


#sql="SELECT ra_rad,dec_rad, mjdate, official,measure  FROM cfeps.measure c join cfeps.object o on c.provisional like o.official where official like 'l%' ORDER BY official,mjdate ";
sql="SELECT ra_rad,dec_rad, mjdate, measure  FROM cfeps.measure WHERE file_id LIKE 'unknown' and observatory=568 and mjdate >  52722.44745  "
bucket.execute(sql)
measures =bucket.fetchall()


for measure in measures:
    sql="SELECT expnum FROM exposure where ABS(ra - %s)<1.0*cos(`dec`/57.3) and ABS(`dec` - %s)<1.0 and ABS(mjdate - %s)*24*3600<90 "
    bucket.execute(sql,(measure[0]*57.3,measure[1]*57.2,measure[2]))
    exps = bucket.fetchall()
    for exp in exps:
        sql="UPDATE cfeps.measure SET file_id=%s WHERE measure=%s"
        #print sql % ( exp[0], measure[3])
        bucket.execute(sql,(exp[0],measure[3]) )
        #print ("http://services.cadc-ccha.hia-iha.nrc-cnrc.gc.ca/cfhtProxies/getData?dataset_name%s&cutout=(%08.3f,%08.3f,%5.3f)" % (exp[0],measure[0]*57.3,measure[1]*57.3,1.0/60.0) )