def __init__(self, surveyName, pattern='gaussian'): """Read in a survey file and obtain the survey parameters""" # try to open the survey file locally first if os.path.isfile(surveyName): f = open(surveyName, 'r') else: try: # try to open file in lib # get path to surveys directory __dir__ = os.path.dirname(os.path.abspath(__file__)) __libdir__ = os.path.dirname(__dir__) filepath = os.path.join(__libdir__, 'psrpoppy', 'surveys', surveyName) f = open(filepath, 'r') except IOError: # couldn't find the file s = 'File {0} does not exist!!!'.format(surveyName) raise SurveyException(s) self.surveyName = surveyName # initialise the pointings list to None # only change this is there is a list of pointings to be used self.pointingslist = None self.gainslist = None self.tobslist = None self.gainpat = pattern # adding AA parameter, so can scale s/n if the survey is # an aperture array self.AA = False # Parse the file line by line for line in f: # ignore any lines starting '#' if line.strip()[0] == '#': continue # otherwise, parse! a = line.split('!') # new feature - possible to have a list of positions in survey, # rather than a range of l,b or ra,dec if a[1].count('pointing list'): pointfname = a[0].strip() # try to open the pointing list locally if os.path.isfile(pointfname): # pointfptr = open(pointfname, 'r') filename = pointfname else: try: # try to open pointing file in the surveys dir __dir__ = os.path.dirname(os.path.abspath(__file__)) __libdir__ = os.path.dirname(__dir__) filepath = os.path.join(__libdir__, 'surveys', pointfname) # pointfptr = open(filepath, 'r') filename = filepath except: s = 'File {0} does not exist!!!'.format(pointfpath) raise CoordinateException(s) if a[1].count('galactic'): p_str = 'gal' elif a[1].count('equatorial'): p_str = 'eq' else: s = "Unknown coordinate type in survey file" raise CoordinateException(s) self.pointingslist, \ self.tobslist, \ self.gainslist = makepointinglist(filename, p_str) """ # read in the pointing list self.pointingslist = [] # set coord conversion to be done, if any for line in pointfptr: a = line.split() if len(a) != 4: s = 'File {0} should have cols: gl/gb/gain/tobs'.format( pointfpath) raise CoordinateException(s) p = Pointing(float(a[0]), float(a[1]), p_str, float(a[2]), float(a[3]) ) self.pointingslist.append(p) pointfptr.close() """ elif a[1].count('survey degradation'): # beta self.beta = float(a[0].strip()) elif a[1].count('antenna gain'): # gain self.gain = float(a[0].strip()) elif a[1].count('integration time'): # tobs self.tobs = float(a[0].strip()) elif a[1].count('sampling'): # tsamp self.tsamp = float(a[0].strip()) elif a[1].count('system temperature'): # tsys self.tsys = float(a[0].strip()) elif a[1].count('centre frequency'): # centre frequency self.freq = float(a[0].strip()) elif a[1].strip().startswith('bandwidth'): # bandwidth self.bw = float(a[0].strip()) elif a[1].count('channel bandwidth'): # bw_chan self.bw_chan = float(a[0].strip()) elif a[1].count('polarizations'): # num polns self.npol = float(a[0].strip()) elif a[1].count('half maximum'): # FWHM self.fwhm = float(a[0].strip()) elif a[1].count('minimum RA'): # min RA self.RAmin = float(a[0].strip()) elif a[1].count('maximum RA'): # max RA self.RAmax = float(a[0].strip()) elif a[1].count('minimum DEC'): # min dec self.DECmin = float(a[0].strip()) elif a[1].count('maximum DEC'): # mac dec self.DECmax = float(a[0].strip()) elif a[1].count('minimum Galactic'): # min longitude self.GLmin = float(a[0].strip()) elif a[1].count('maximum Galactic'): # max longitude self.GLmax = float(a[0].strip()) elif a[1].count('minimum abs'): # min latitude self.GBmin = float(a[0].strip()) elif a[1].count('maximum abs'): # max latitude self.GBmax = float(a[0].strip()) elif a[1].count('coverage'): # coverage fraction self.coverage = float(a[0].strip()) if self.coverage > 1.0: self.coverage = 1.0 elif a[1].count('signal-to-noise'): # SNR limit self.SNRlimit = float(a[0].strip()) elif a[1].count('gain pattern'): # Gain pattern (can specify airy, default = gaussian) self.gainpat = a[0].strip() elif a[1].count('Aperture Array'): # turn on AA self.AA = True else: print "Parameter '", a[1].strip(), "' not recognized!" f.close() # get tsky array from file self.tskylist = go.readtskyfile()
def __init__(self, surveyName, pattern='gaussian'): """Read in a survey file and obtain the survey parameters""" # try to open the survey file locally first if os.path.isfile(surveyName): f = open(surveyName, 'r') else: try: # try to open file in lib # get path to surveys directory __dir__ = os.path.dirname(os.path.abspath(__file__)) __libdir__ = os.path.dirname(__dir__) filepath = os.path.join(__libdir__, 'surveys', surveyName) f = open(filepath, 'r') except IOError: # couldn't find the file s = 'File {0} does not exist!!!'.format(surveyName) raise SurveyException(s) self.surveyName = surveyName # initialise the pointings list to None # only change this is there is a list of pointings to be used self.pointingslist = None self.gainslist = None self.tobslist = None self.gainpat = pattern # adding AA parameter, so can scale s/n if the survey is # an aperture array self.AA = False # Parse the file line by line for line in f: # ignore any lines starting '#' if line.strip()[0] == '#': continue # otherwise, parse! a = line.split('!') # new feature - possible to have a list of positions in survey, # rather than a range of l,b or ra,dec if a[1].count('pointing list'): pointfname = a[0].strip() # try to open the pointing list locally if os.path.isfile(pointfname): # pointfptr = open(pointfname, 'r') filename = pointfname else: try: # try to open pointing file in the surveys dir __dir__ = os.path.dirname(os.path.abspath(__file__)) __libdir__ = os.path.dirname(__dir__) filepath = os.path.join(__libdir__, 'surveys', pointfname) # pointfptr = open(filepath, 'r') filename = filepath except: s = 'File {0} does not exist!!!'.format(pointfpath) raise CoordinateException(s) if a[1].count('galactic'): p_str = 'gal' elif a[1].count('equatorial'): p_str = 'eq' else: s = "Unknown coordinate type in survey file" raise CoordinateException(s) self.pointingslist, \ self.tobslist, \ self.gainslist = makepointinglist(filename, p_str) """ # read in the pointing list self.pointingslist = [] # set coord conversion to be done, if any for line in pointfptr: a = line.split() if len(a) != 4: s = 'File {0} should have cols: gl/gb/gain/tobs'.format( pointfpath) raise CoordinateException(s) p = Pointing(float(a[0]), float(a[1]), p_str, float(a[2]), float(a[3]) ) self.pointingslist.append(p) pointfptr.close() """ elif a[1].count('survey degradation'): # beta self.beta = float(a[0].strip()) elif a[1].count('antenna gain'): # gain self.gain = float(a[0].strip()) elif a[1].count('integration time'): # tobs self.tobs = float(a[0].strip()) elif a[1].count('sampling'): # tsamp self.tsamp = float(a[0].strip()) elif a[1].count('system temperature'): # tsys self.tsys = float(a[0].strip()) elif a[1].count('centre frequency'): # centre frequency self.freq = float(a[0].strip()) elif a[1].strip().startswith('bandwidth'): # bandwidth self.bw = float(a[0].strip()) elif a[1].count('channel bandwidth'): # bw_chan self.bw_chan = float(a[0].strip()) elif a[1].count('polarizations'): # num polns self.npol = float(a[0].strip()) elif a[1].count('half maximum'): # FWHM self.fwhm = float(a[0].strip()) elif a[1].count('minimum RA'): # min RA self.RAmin = float(a[0].strip()) elif a[1].count('maximum RA'): # max RA self.RAmax = float(a[0].strip()) elif a[1].count('minimum DEC'): # min dec self.DECmin = float(a[0].strip()) elif a[1].count('maximum DEC'): # mac dec self.DECmax = float(a[0].strip()) elif a[1].count('minimum Galactic'): # min longitude self.GLmin = float(a[0].strip()) elif a[1].count('maximum Galactic'): # max longitude self.GLmax = float(a[0].strip()) elif a[1].count('minimum abs'): # min latitude self.GBmin = float(a[0].strip()) elif a[1].count('maximum abs'): # max latitude self.GBmax = float(a[0].strip()) elif a[1].count('coverage'): # coverage fraction self.coverage = float(a[0].strip()) if self.coverage > 1.0: self.coverage = 1.0 elif a[1].count('signal-to-noise'): # SNR limit self.SNRlimit = float(a[0].strip()) elif a[1].count('gain pattern'): # Gain pattern (can specify airy, default = gaussian) self.gainpat = a[0].strip() elif a[1].count('Aperture Array'): # turn on AA self.AA = True else: print "Parameter '", a[1].strip(), "' not recognized!" f.close() # get tsky array from file self.tskylist = go.readtskyfile()
def __init__(self, surveyName,pattern): """Read in a survey file and obtain the survey parameters""" try: # get path to surveys directory __dir__ = os.path.dirname(os.path.abspath(__file__)) __libdir__ = os.path.dirname(__dir__) filepath = os.path.join(__libdir__, 'surveys', surveyName) f = open(filepath, 'r') except IOError: print 'No such file: ',surveyName sys.exit() self.surveyName = surveyName # initialise the pointings list to None # only change this is there is a list of pointings to be used self.pointingslist = None self.gainpat = pattern # self.gainpat = 'gaussian' # Parse the file line by line for line in f: # ignore any lines starting '#' if line.strip()[0] == '#': continue # otherwise, parse! a = line.split('!') # new feature - possible to have a list of positions in survey, # rather than a range of l,b or ra,dec if a[1].count('pointing list'): pointfname = a[0].strip() pointfpath = os.path.join(__libdir__, 'surveys', pointfname) # try to open the pointing list if os.path.isfile(pointfpath): pointfptr = open(pointfpath, 'r') else: try: pointfptr = open(pointfname, 'r') except: s = 'File {0} does not exist!!!'.format(pointfpath) raise CoordinateException(s) # read in the pointing list self.pointingslist = [] if a[1].count('galactic'): # already galactic coordinates for line in pointfptr: a = line.split() # Expected form of pointing list files is hard-coded. if len(a) != 4: s = 'File {0} should have columns: gl/gb/gain/tobs!'.format(pointfpath) raise CoordinateException(s) p = Pointing(float(a[0]), float(a[1]), 'gal', float(a[2]), float(a[3])) self.pointingslist.append(p) elif a[1].count('equatorial'): # need to be converted from ra dec to gl gb for line in pointfptr: a = line.split() if len(a) != 4: s = 'File {0} should have columns: gl/gb/gain/tobs!'.format(pointfpath) raise CoordinateException(s) p = Pointing(float(a[0]), float(a[1]), 'eq', float(a[2]), float(a[3])) self.pointingslist.append(p) else: s = 'Coordinate type unspecified in {0}.'.format(surveyName) raise CoordinateException(s) pointfptr.close() elif a[1].count('survey degradation'): # beta self.beta = float(a[0].strip()) elif a[1].count('antenna gain'): # gain self.gain = float(a[0].strip()) elif a[1].count('integration time'): # tobs self.tobs = float(a[0].strip()) elif a[1].count('sampling'): # tsamp self.tsamp = float(a[0].strip()) elif a[1].count('system temperature'): # tsys self.tsys = float(a[0].strip()) elif a[1].count('centre frequency'): # centre frequency self.freq = float(a[0].strip()) elif a[1].strip().startswith('bandwidth'): # bandwidth self.bw = float(a[0].strip()) elif a[1].count('channel bandwidth'): # bw_chan self.bw_chan = float(a[0].strip()) elif a[1].count('polarizations'): # num polns self.npol = float(a[0].strip()) elif a[1].count('half maximum'): # FWHM self.fwhm = float(a[0].strip()) elif a[1].count('minimum RA'): # min RA self.RAmin = float(a[0].strip()) elif a[1].count('maximum RA'): # max RA self.RAmax = float(a[0].strip()) elif a[1].count('minimum DEC'): # min dec self.DECmin = float(a[0].strip()) elif a[1].count('maximum DEC'): # mac dec self.DECmax = float(a[0].strip()) elif a[1].count('minimum Galactic'): # min longitude self.GLmin = float(a[0].strip()) elif a[1].count('maximum Galactic'): # max longitude self.GLmax = float(a[0].strip()) elif a[1].count('minimum abs'): # min latitude self.GBmin = float(a[0].strip()) elif a[1].count('maximum abs'): # max latitude self.GBmax = float(a[0].strip()) elif a[1].count('coverage'): # coverage fraction self.coverage = float(a[0].strip()) if self.coverage > 1.0: self.coverage = 1.0 elif a[1].count('signal-to-noise'): # SNR limit self.SNRlimit = float(a[0].strip()) elif a[1].count('gain pattern'): # Gain pattern (can specify airy, default = gaussian) self.gainpat = a[0].strip() else: print "Parameter '",a[1].strip(),"' not recognized!" f.close() # get tsky array from file self.tskylist = go.readtskyfile()