import os, string rootdir = '' experiment = '' ################################################################################ # Set the globals def setexperiment(root, exp): global rootdir, experiment rootdir = root experiment = exp ################################################################################ # Find the antenna number def get_antenna_number(ant_name, uvdata): ant = 0 for antenna in uvdata.antennas: ant = ant + 1 if antenna == ant_name: return ant raise RuntimeError, "antenna not found!" return None ################################################################################ # Create handle for a given file def check_data_file(prefix, telescope, extension): if telescope == '': fullpath = rootdir + '/' + prefix + '/' + experiment + extension else: fullpath = rootdir + '/' + prefix + '/' + experiment + '.' + telescope + extension if not os.path.isfile(fullpath): print 'Ooops - cant find file ' + fullpath if telescope == '': fullpath = rootdir + '/' + prefix + '/' + experiment + extension else: fullpath = rootdir + '/' + prefix + '/' + experiment + '.' + telescope + extension assert(os.path.isfile(fullpath)) return fullpath ################################################################################ # Create handle for a given file def check_root_file(filename): fullpath = rootdir + '/' + filename if not os.path.isfile(fullpath): fullpath = rootdir + '/' + filename print 'Checking file ' + fullpath assert(os.path.isfile(fullpath)) return fullpath ################################################################################ # Checks if a given source is a primary phase reference def isphaseref(source, primary_phaserefs): for phaseref in primary_phaserefs: if source == phaseref: return 1 return 0 ################################################################################ # Checks if a given source is present in the source table def wasobserved(uvdata, source): for s in uvdata.sources: if source == s: return 1 return 0 ################################################################################ # Checks if user wants to do something or not def yesno(autoyes, prompt): if autoyes: return True ans = raw_input(prompt) return (ans[0]=='y' or ans[0]=='Y') ################################################################################ # Returns an MJD from a date string from a header def header_mjd(headerstring): year = string.atoi(headerstring[0:4]) month = string.atoi(headerstring[5:7]) day = string.atoi(headerstring[8:10]) return year*367 - int(7*(year + int((month + 9)/12))/4) + int(275*month/9) + day - 678987 ################################################################################ # Returns an MJD from a date string from a header def getdoy(headerstring): year = string.atoi(headerstring[0:4]) month = string.atoi(headerstring[5:7]) day = string.atoi(headerstring[8:10]) mjd1 = year*367 - int(7*(year + int((month + 9)/12))/4) + int(275*month/9) + day - 678987 month = 1 day = 1 mjd0 = year*367 - int(7*(year + int((month + 9)/12))/4) + int(275*month/9) + day - 678987 return mjd1 - mjd0 + 1