def get_grid_id(basefilename): """Return grid_id of the NRT_grid table from the position of a psrfits file """ # Get RA and DEC in degrees from psrfits file first_file = glob.glob("%s*fits"%os.path.join(LINKDISK, basefilename))[0] pfits = Psrfits(first_file) ra_deg = ra_to_rad(pfits.get_RA()) * RADTODEG dec_deg = dec_to_rad(pfits.get_DEC()) * RADTODEG pfits.close() # Connect to the DB db = Database(db=DB_NAME) DBconn = db.conn DBcursor = db.cursor QUERY = "SELECT grid_id FROM NRT_grid WHERE ABS(ra_deg-%f)<%f AND ABS(dec_deg-%f) < %f"%(ra_deg, NRT_RA_DEG/2./cos(dec_deg*DEGTORAD), dec_deg, NRT_DEC_DEG/2) if DEBUG: print QUERY DBcursor.execute(QUERY) result_query = [list(row) for row in DBcursor.fetchall()] # No observation was planned, do an INSERT #print ra_deg, dec_deg, result_query return result_query[0][0]
def get_MJD_obs(basefilename): """Return mjd from the psrfits file """ # Get RA and DEC in degrees from psrfits file first_file = glob.glob("%s*fits"%os.path.join(LINKDISK, basefilename))[0] pfits = Psrfits(first_file) mjd = pfits.get_MJD() pfits.close() return mjd