Exemplo n.º 1
0
def add_obs2DB(pointing_name, basefilename, numfiles, disk):

    grid_id = get_grid_id(basefilename)

    # Connect to the DB
    db = Database(db=DB_NAME)
    DBconn = db.conn
    DBcursor = db.cursor

    QUERY = "SELECT * FROM processing WHERE pointing_name = '%s'"%(pointing_name)
    DBcursor.execute(QUERY)
    result_query = [list(row) for row in DBcursor.fetchall()]

    # Get Date
    mjd = get_MJD_obs(basefilename)
    gregdate = slalib.sla_djcl(mjd)
    yr, month, day, fracday = gregdate[:4]
    h, m, s = MJDfrac_to_hms(fracday)

    # No observation was planned, do an INSERT
    if not result_query:
	QUERY = "INSERT IGNORE INTO processing (basefilename, numfiles, institution, diskname, obs_date, add_date, grid_id, proc_stat) VALUES ('%s', %d, '%s', '%s', '%d-%d-%d %d:%d:%d', NOW(), %d, 'o');" % (basefilename, numfiles, INSTITUTION, get_disk_label_nfs(disk), yr, month, day,h, m, s, grid_id)
    # Found that the observation was planned, do an UPDATE
    else:	    
	QUERY = "UPDATE processing SET basefilename='%s', numfiles=%d, institution='%s', diskname='%s', obs_date='%d-%d-%d %d:%d:%d', add_date=NOW(), proc_stat='o' WHERE pointing_name='%s' ;" % (basefilename, numfiles, INSTITUTION, get_disk_label_nfs(disk), yr, month, day,h, m, s, pointing_name)

    if DEBUG: print QUERY
    DBcursor.execute(QUERY)

    # Get the obs_id number
    QUERY = "SELECT obs_id FROM processing WHERE basefilename='%s'"%(basefilename)
    DBcursor.execute(QUERY)
    obs_id = DBcursor.fetchone()[0]

    # Update the full search table
    QUERY = "INSERT IGNORE INTO full_processing (obs_id, proc_stat) VALUES (%d, 'o');" % (obs_id)
    DBcursor.execute(QUERY)


    # Now update the rawdata table
    files = glob.glob("/survey_data/survey?/%s*.fits"%basefilename)
    files.sort()
    for fullfilename in files:
        path, filename = os.path.split(fullfilename)

	datasize = os.path.getsize(fullfilename)
	QUERY = "INSERT INTO raw_files (obs_id, path, filename, datasize) VALUES (%d, '%s', '%s', %ld);"%(obs_id, path, filename, datasize)
	DBcursor.execute(QUERY)



    DBconn.close()	
Exemplo n.º 2
0
def jd_utc2datetime(jd):
    """Converts a passed Julian date to a Python datetime object. 'None' is
    returned if the conversion was not possible."""

    try:
        mjd_utc = jd - 2400000.5
    except TypeError:
        try:
            mjd_utc = float(jd) - 2400000.5
        except:
            return None
    year, month, day, frac, status = S.sla_djcl(mjd_utc)
    if status != 0:
        return None
    sign, hms = S.sla_dd2tf(0, frac)
    dt = datetime(year, month, day, hms[0], hms[1], hms[2])
    return dt
Exemplo n.º 3
0
def main():
  parser = OptionParser(usage)

  (opts, args) = parser.parse_args()			
	
  # Scan files
  db = Database(db="local-SBON512")
  DBconn = db.conn
  DBcursor = db.cursor

  files = glob.glob("/survey_data/survey?/*1261_0001.fits")
  files.sort()

  files_list = []
  
  #print files

  for fullfilename in files:
      path, filename = os.path.split(fullfilename)
      pointing_name = filename.split("_")[2]

      print filename

      try:
          pfits = Psrfits(fullfilename)
      except:
          continue
      mjd = pfits.get_MJD()

      gregdate = slalib.sla_djcl(mjd)
      yr, month, day, fracday = gregdate[:4]
      h, m, s = MJDfrac_to_hms(fracday)

      QUERY = "UPDATE processing SET obs_date=\"%d-%d-%d %d:%d:%d\" where pointing_name='%s';"%(yr, month, day,h, m, s, pointing_name)
      print QUERY
      DBcursor.execute(QUERY)
  #result_query = [list(row) for row in DBcursor.fetchall()]
  #print result_query
  
  DBconn.close()