def parse_file(self): """ Read a source catalog data file. """ # open data file fileName = os.path.join(self.get_directory(), '4c.dat') with open(fileName, 'r') as catFile: # read source info lineNum = 1 line = catFile.readline() while line: try: name = line[0:8] raHours = int(line[10:12]) raMinutes = int(line[13:15]) raSeconds = float(line[16:20]) decSign = line[22] decDegrees = int(line[23:25]) decMinutes = float(line[26:30]) alias = line[64:-1] except ValueError: raise RuntimeError( "file %s, line %d incorectly formated [%s]" % (fileName, lineNum, line)) name = name.strip() name = ('4C' + name) alias = alias.strip() alias = alias.rstrip('*') ra = astro.hms(raHours, raMinutes, raSeconds) (decSeconds, decMinutes) = math.modf(decMinutes) if decSign == '-': sign = True else: sign = False dec = astro.dms(sign, decDegrees, int(decMinutes), (60 * decSeconds)) sourcePos = astro.equ_posn(ra, dec) # precess coordinates from B1950 entry = CatalogEntry( name, transform.CelestialPosition(sourcePos, epoch='B1950', name=name)) self.source_map[name] = entry if len(alias.strip()): alias = alias.rstrip() entry.alias_list.append(alias) self.alias_map[alias] = entry line = catFile.readline() lineNum += 1
def parse_file(self): """ Read a source catalog data file. """ # open data file fileName = os.path.join(self.get_directory(), 'PKS90.txt') with open(fileName, 'r') as catFile: # read source info lineNum = 1 line = catFile.readline() while line: if line == '\n': line = catFile.readline() lineNum += 1 continue try: name = line[0:10] alias0 = line[139:148] alias1 = line[168:175] raHours = int(line[10:12]) raMinutes = int(line[13:15]) raSeconds = float(line[16:20]) decSign = line[23] decDegrees = int(line[24:26]) decMinutes = int(line[27:29]) decSeconds = float(line[30:34]) except ValueError: raise RuntimeError( "file %s, line %d incorectly formated [%s]" % (fileName, lineNum, line)) ra = astro.hms(raHours, raMinutes, raSeconds) if decSign == '-': sign = True else: sign = False dec = astro.dms(sign, decDegrees, decMinutes, decSeconds) sourcePos = astro.equ_posn(ra, dec) entry = CatalogEntry( name, transform.CelestialPosition(sourcePos, name=name)) self.source_map[name] = entry if len(alias0.strip()): alias = alias0.rstrip() entry.alias_list.append(alias) self.alias_map[alias] = entry if len(alias1.strip()): alias = alias1.rstrip() entry.alias_list.append(alias) self.alias_map[alias] = entry line = catFile.readline() lineNum += 1
def j2000_equ(self, value): if not isinstance(value, (astro.equ_posn, SequenceABC)): raise TypeError( "value must be type astro.equ_posn or sequence of length 2") if isinstance(value, SequenceABC): if len(value) != 2: raise TypeError("value sequence must be length 2") value = astro.equ_posn(*value) self._posn = copy.copy(value)
def parse_file(self): """ Read a source catalog data file. """ # open data file fileName = os.path.join(self.get_directory(), 'pkscat.txt') with open(fileName, 'r') as catFile: # read source info lineNum = 1 line = catFile.readline() while line: if line == '\n': line = catFile.readline() lineNum += 1 continue try: name = line[0:8] alias = line[12:19] raHours = int(line[22:24]) raMinutes = int(line[25:27]) raSeconds = float(line[28:32]) decSign = line[33] decDegrees = int(line[34:36]) decMinutes = int(line[37:39]) decSeconds = int(line[40:42]) except ValueError: raise RuntimeError( "file %s, line %d incorectly formated [%s]" % (fileName, lineNum, line)) ra = astro.hms(raHours, raMinutes, raSeconds) if decSign == '-': sign = True else: sign = False dec = astro.dms(sign, decDegrees, decMinutes, decSeconds) sourcePos = astro.equ_posn(ra, dec) # precess coordinates from B1950 entry = CatalogEntry( name, transform.CelestialPosition(sourcePos, epoch='B1950', name=name)) self.source_map[name] = entry if len(alias.strip()): alias = alias.rstrip() self.alias_map[alias] = entry entry.alias_list.append(alias) line = catFile.readline() lineNum += 1
def b1950_equ(self, value): if not isinstance(value, (astro.equ_posn, SequenceABC)): raise TypeError( "value must be type astro.equ_posn or sequence of length 2") if isinstance(value, SequenceABC): if len(value) != 2: raise TypeError("value sequence must be length 2") value = astro.equ_posn(*value) self._posn = astro.get_equ_prec2(value, astro.B1950_UTC_JD, astro.J2000_UTC_JD)
def parse_file(self): """ Read a source catalog data file. """ # open data file fileName = os.path.join(self.get_directory(), '3c.dat') with open(fileName, 'r') as catFile: # read source info lineNum = 1 line = catFile.readline() while line: try: name = line[0:3] raHours = int(line[12:14]) raMinutes = int(line[15:17]) raSeconds = float(line[18:22]) decSign = line[27] decDegrees = int(line[28:30]) decMinutes = float(line[31:35]) except ValueError: raise RuntimeError( "file %s, line %d incorectly formated [%s]" % (fileName, lineNum, line)) name = ('3C' + name.strip()) ra = astro.hms(raHours, raMinutes, raSeconds) (decSeconds, decMinutes) = math.modf(decMinutes) if decSign == '-': sign = True else: sign = False dec = astro.dms(sign, decDegrees, int(decMinutes), (60 * decSeconds)) sourcePos = astro.equ_posn(ra, dec) # precess coordinates from B1950 entry = CatalogEntry( name, transform.CelestialPosition(sourcePos, epoch='B1950', name=name)) self.source_map[name] = entry line = catFile.readline() lineNum += 1
def _radec_of(antennaarray, az, alt): # az/el -> HA/dec HA = numpy.arctan2( numpy.sin(az - numpy.pi), (numpy.cos(az - numpy.pi) * numpy.sin(antennaarray.lat) + numpy.tan(alt) * numpy.cos(antennaarray.lat))) dec = numpy.arcsin( numpy.sin(antennaarray.lat) * numpy.sin(alt) - numpy.cos(antennaarray.lat) * numpy.cos(alt) * numpy.cos(az - numpy.pi)) # HA -> RA RA = antennaarray.sidereal_time() - HA # radians -> degrees RA = RA * 180.0 / numpy.pi RA %= 360.0 dec = dec * 180.0 / numpy.pi # RA/dec -> astro.eqn_posn() pos = astro.equ_posn(RA, dec) # Correct for aberration pos2 = astro.get_equ_aber(pos, antennaarray.date + astro.DJD_OFFSET) dRA, dDec = pos2.ra - pos.ra, pos2.dec - pos.dec pos.ra = (pos.ra - dRA) % 360.0 pos.ra %= 360.0 pos.dec = pos.dec - dDec # Correct for nutation pos2 = astro.get_equ_nut(pos, antennaarray.date + astro.DJD_OFFSET) dRA, dDec = pos2.ra - pos.ra, pos2.dec - pos.dec pos.ra = (pos.ra - dRA) % 360.0 pos.ra %= 360.0 pos.dec = pos.dec - dDec # Precess back to J2000 pos = astro.get_precession(antennaarray.date + astro.DJD_OFFSET, pos, ephem.J2000 + astro.DJD_OFFSET) RA, dec = pos.ra, pos.dec # degrees -> radians RA = RA * numpy.pi / 180.0 dec = dec * numpy.pi / 180.0 return RA, dec
def parse_file(self): """ Read a source catalog data file. """ debug = False # open data file fileName = os.path.join(self.get_directory(), 'psrcat.db') with open(fileName, 'r') as catFile: # read source info psrb = None psrj = None ra = None dec = None bad = False for line in catFile: if line.startswith('PSRB'): psrb = line.split()[1] if line.startswith('PSRJ'): psrj = line.split()[1] if line.startswith('RAJ'): rastr = line.split()[1] sp = rastr.split(':') if len(sp) == 3: (raHours, raMinutes, raSeconds) = sp elif len(sp) == 2: (raHours, raMinutes) = sp raSeconds = 0.0 else: if debug: print('Bad format for RAJ line : ' + line) bad = True raHours = int(raHours) raMinutes = int(raMinutes) raSeconds = float(raSeconds) try: ra = astro.hms(raHours, raMinutes, raSeconds) except: if debug: print('PSRCAT: Bad RA for ', psrj, " : ", rastr) bad = True if line.startswith('DECJ'): decstr = line.split()[1] sp = decstr.split(':') if len(sp) == 3: (decDegrees, decMinutes, decSeconds) = sp elif len(sp) == 2: (decDegrees, decMinutes) = sp decSeconds = 0.0 else: if debug: print('PSRCAT: Bad format for DECJ line : ' + line) bad = True continue if decDegrees.startswith('-'): decDegrees = decDegrees[1:] sign = True else: sign = False decDegrees = int(decDegrees) decMinutes = int(decMinutes) decSeconds = float(decSeconds) try: dec = astro.dms(sign, decDegrees, decMinutes, decSeconds) except: if debug: print('PSRCAT: Bad DEC for ', psrj, " : ", decstr) bad = True if line.startswith('@-'): # New source, save current source info if psrb is not None: name = psrb alias = psrj else: name = psrj alias = None if ra is None or dec is None: # These pulsars don't have RAJ, DECJ # I think they may all have ecliptic positions # which should be converted to ra,dec but I'm # going to ignore them for now. -- paulr #print "PSRCAT: No position for pulsar ",name bad = True # Add source to list if good. if not bad: sourcePos = astro.equ_posn(ra, dec) entry = CatalogEntry( name, transform.CelestialPosition(sourcePos, name=name)) self.source_map[name] = entry if debug: print('Added ', name) if alias is not None: alias = alias.rstrip() self.alias_map[alias] = entry entry.alias_list.append(alias) if debug: print('Alias : ', alias.rstrip()) # Clear out vars for next source psrb = None psrj = None ra = None dec = None bad = False
print('---------------------------------------------------------------') print('RA: %s (%0.3f)' % (saturn_ra, saturn_equ.ra)) print('DEC: %s (%0.3f)' % (saturn_dec, saturn_equ.dec)) print('Ecl longitude: %s (%0.3f)' % (saturn_lng, saturn_ecl.lng)) print('Ecl latitude: %s (%0.3f)' % (saturn_lat, saturn_ecl.lat)) print('Rise: %s (%0.3f) [%s]' % (saturn_utc_rise, saturn_rst.rise, saturn_lcl_rise)) print('Transit: %s (%0.3f) [%s]' % (saturn_utc_trans, saturn_rst.transit, saturn_lcl_trans)) print('Set: %s (%0.3f) [%s]' % (saturn_utc_set, saturn_rst.set, saturn_lcl_set)) print('Azimuth: %0.3f %s' % (saturn_hrz.az, astro.hrz_to_nswe(saturn_hrz))) print('Altitude: %0.3f' % saturn_hrz.alt) print('Zenith: %0.3f' % saturn_hrz.zen()) print('Sun angle: %0.3f' % saturn_sun_ang) # calculate SgrA phenomena sgra_j2000_equ = astro.equ_posn(astro.hms(17, 42, 48.1), astro.dms(True, 28, 55, 8)) sgra_equ = astro.get_apparent_posn(sgra_j2000_equ, utc) sgra_rst = astro.get_object_rst(utc, lwa_lnlat, sgra_equ) (sgra_utc_rise, sgra_utc_set, sgra_utc_trans) = sgra_rst.format() sgra_lcl_rise = sgra_utc_rise.to_zone() sgra_lcl_trans = sgra_utc_trans.to_zone() sgra_lcl_set = sgra_utc_set.to_zone() (sgra_ra, sgra_dec) = sgra_equ.format() sgra_hrz = sgra_equ.to_hrz(lwa_lnlat, utc) sgra_gal = sgra_equ.to_gal(utc) (sgra_l, sgra_b) = sgra_gal.format() sgra_sun_ang = sun_equ.angular_separation(sgra_equ) print('---------------------------------------------------------------')