def __init__(self, parfilenm): self.FILE = parfilenm pf = open(parfilenm) for line in pf.readlines(): # Skip comments if line[0] == '#': continue # Convert any 'D-' or 'D+' to 'E-' or 'E+' line = line.replace("D-", "E-") line = line.replace("D+", "E+") splitline = line.split() # Skip blank lines if len(splitline) == 0: continue key = splitline[0] if key in str_keys: setattr(self, key, splitline[1]) elif key in float_keys: try: setattr(self, key, float(splitline[1])) except ValueError: pass if len( splitline ) == 3: # Some parfiles don't have flags, but do have errors if splitline[2] not in ['0', '1']: setattr(self, key + '_ERR', float(splitline[2])) if len(splitline) == 4: setattr(self, key + '_ERR', float(splitline[3])) # Deal with Ecliptic coords if (hasattr(self, 'BETA') and hasattr(self, 'LAMBDA')): setattr(self, 'ELAT', self.BETA) setattr(self, 'ELONG', self.LAMBDA) if (slalib and hasattr(self, 'ELAT') and hasattr(self, 'ELONG')): if hasattr(self, 'POSEPOCH'): epoch = self.POSEPOCH else: epoch = self.PEPOCH ra_rad, dec_rad = sla_ecleq(self.ELONG * pu.DEGTORAD, self.ELAT * pu.DEGTORAD, epoch) rstr = pu.coord_to_string(*pu.rad_to_hms(ra_rad)) dstr = pu.coord_to_string(*pu.rad_to_dms(dec_rad)) setattr(self, 'RAJ', rstr) setattr(self, 'DECJ', dstr) if hasattr(self, 'RAJ'): setattr(self, 'RA_RAD', pu.ra_to_rad(self.RAJ)) if hasattr(self, 'DECJ'): setattr(self, 'DEC_RAD', pu.dec_to_rad(self.DECJ)) # Compute the Galactic coords if (slalib and hasattr(self, 'RA_RAD') and hasattr(self, 'DEC_RAD')): l, b = sla_eqgal(self.RA_RAD, self.DEC_RAD) setattr(self, 'GLONG', l * pu.RADTODEG) setattr(self, 'GLAT', b * pu.RADTODEG) # Compute the Ecliptic coords if (slalib and hasattr(self, 'RA_RAD') and hasattr(self, 'DEC_RAD')): if hasattr(self, 'POSEPOCH'): epoch = self.POSEPOCH else: epoch = self.PEPOCH elon, elat = sla_eqecl(self.RA_RAD, self.DEC_RAD, epoch) setattr(self, 'ELONG', elon * pu.RADTODEG) setattr(self, 'ELAT', elat * pu.RADTODEG) if hasattr(self, 'P'): setattr(self, 'P0', self.P) if hasattr(self, 'P0'): setattr(self, 'F0', 1.0 / self.P0) if hasattr(self, 'F0'): setattr(self, 'P0', 1.0 / self.F0) if hasattr(self, 'FB0'): setattr(self, 'PB', (1.0 / self.FB0) / 86400.0) if hasattr(self, 'P0_ERR'): if hasattr(self, 'P1_ERR'): f, ferr, fd, fderr = pu.pferrs(self.P0, self.P0_ERR, self.P1, self.P1_ERR) setattr(self, 'F0_ERR', ferr) setattr(self, 'F1', fd) setattr(self, 'F1_ERR', fderr) else: f, fd, = pu.p_to_f(self.P0, self.P1) setattr(self, 'F0_ERR', self.P0_ERR / (self.P0 * self.P0)) setattr(self, 'F1', fd) if (hasattr(self, 'F0_ERR') and hasattr(self, 'F1_ERR')): p, perr, pd, pderr = pu.pferrs(self.F0, self.F0_ERR, self.F1, self.F1_ERR) setattr(self, 'P0_ERR', perr) setattr(self, 'P1', pd) setattr(self, 'P1_ERR', pderr) elif (hasattr(self, 'F0') and hasattr(self, 'F0_ERR')): setattr(self, 'P0_ERR', self.F0_ERR / (self.F0 * self.F0)) if hasattr(self, 'EPS1') and hasattr(self, 'EPS2'): ecc = math.sqrt(self.EPS1 * self.EPS1 + self.EPS2 * self.EPS2) omega = math.atan2(self.EPS1, self.EPS2) setattr(self, 'E', ecc) setattr(self, 'OM', omega * pu.RADTODEG) setattr(self, 'T0', self.TASC + self.PB * omega / pu.TWOPI) if hasattr(self, 'PB') and hasattr(self, 'A1') and not \ (hasattr(self, 'E') or hasattr(self, 'ECC')): setattr(self, 'E', 0.0) if hasattr(self, 'T0') and not hasattr(self, 'TASC'): setattr(self, 'TASC', self.T0 - self.PB * self.OM / 360.0) pf.close()
def __init__(self, parfilenm): self.FILE = parfilenm pf = open(parfilenm) for line in pf.readlines(): # Skip comments if line[0] == "#": continue # Convert any 'D-' or 'D+' to 'E-' or 'E+' line = line.replace("D-", "E-") line = line.replace("D+", "E+") splitline = line.split() # Skip blank lines if len(splitline) == 0: continue key = splitline[0] if key in str_keys: setattr(self, key, splitline[1]) elif key in float_keys: try: setattr(self, key, float(splitline[1])) except ValueError: pass if len(splitline) == 3: # Some parfiles don't have flags, but do have errors if splitline[2] not in ["0", "1"]: setattr(self, key + "_ERR", float(splitline[2])) if len(splitline) == 4: setattr(self, key + "_ERR", float(splitline[3])) # Deal with Ecliptic coords if hasattr(self, "BETA") and hasattr(self, "LAMBDA"): setattr(self, "ELAT", self.BETA) setattr(self, "ELONG", self.LAMBDA) if slalib and hasattr(self, "ELAT") and hasattr(self, "ELONG"): if hasattr(self, "POSEPOCH"): epoch = self.POSEPOCH else: epoch = self.PEPOCH ra_rad, dec_rad = sla_ecleq(self.ELONG * pu.DEGTORAD, self.ELAT * pu.DEGTORAD, epoch) rstr = pu.coord_to_string(*pu.rad_to_hms(ra_rad)) dstr = pu.coord_to_string(*pu.rad_to_dms(dec_rad)) setattr(self, "RAJ", rstr) setattr(self, "DECJ", dstr) if hasattr(self, "RAJ"): setattr(self, "RA_RAD", pu.ra_to_rad(self.RAJ)) if hasattr(self, "DECJ"): setattr(self, "DEC_RAD", pu.dec_to_rad(self.DECJ)) # Compute the Galactic coords if slalib and hasattr(self, "RA_RAD") and hasattr(self, "DEC_RAD"): l, b = sla_eqgal(self.RA_RAD, self.DEC_RAD) setattr(self, "GLONG", l * pu.RADTODEG) setattr(self, "GLAT", b * pu.RADTODEG) # Compute the Ecliptic coords if slalib and hasattr(self, "RA_RAD") and hasattr(self, "DEC_RAD"): if hasattr(self, "POSEPOCH"): epoch = self.POSEPOCH else: epoch = self.PEPOCH elon, elat = sla_eqecl(self.RA_RAD, self.DEC_RAD, epoch) setattr(self, "ELONG", elon * pu.RADTODEG) setattr(self, "ELAT", elat * pu.RADTODEG) if hasattr(self, "P"): setattr(self, "P0", self.P) if hasattr(self, "P0"): setattr(self, "F0", 1.0 / self.P0) if hasattr(self, "F0"): setattr(self, "P0", 1.0 / self.F0) if hasattr(self, "FB0"): setattr(self, "PB", (1.0 / self.FB0) / 86400.0) if hasattr(self, "P0_ERR"): if hasattr(self, "P1_ERR"): f, ferr, fd, fderr = pu.pferrs(self.P0, self.P0_ERR, self.P1, self.P1_ERR) setattr(self, "F0_ERR", ferr) setattr(self, "F1", fd) setattr(self, "F1_ERR", fderr) else: f, fd, = pu.p_to_f(self.P0, self.P1) setattr(self, "F0_ERR", self.P0_ERR / (self.P0 * self.P0)) setattr(self, "F1", fd) if hasattr(self, "F0_ERR"): if hasattr(self, "F1_ERR"): p, perr, pd, pderr = pu.pferrs(self.F0, self.F0_ERR, self.F1, self.F1_ERR) setattr(self, "P0_ERR", perr) setattr(self, "P1", pd) setattr(self, "P1_ERR", pderr) else: p, pd, = pu.p_to_f(self.F0, self.F1) setattr(self, "P0_ERR", self.F0_ERR / (self.F0 * self.F0)) setattr(self, "P1", pd) if hasattr(self, "EPS1") and hasattr(self, "EPS2"): ecc = math.sqrt(self.EPS1 * self.EPS1 + self.EPS2 * self.EPS2) omega = math.atan2(self.EPS1, self.EPS2) setattr(self, "E", ecc) setattr(self, "OM", omega * pu.RADTODEG) setattr(self, "T0", self.TASC + self.PB * omega / pu.TWOPI) if hasattr(self, "PB") and hasattr(self, "A1") and not (hasattr(self, "E") or hasattr(self, "ECC")): setattr(self, "E", 0.0) if hasattr(self, "T0") and not hasattr(self, "TASC"): setattr(self, "TASC", self.T0 - self.PB * self.OM / 360.0) pf.close()
def __init__(self, line): parts = line.split()[1:] part_index = 0 param_index = 0 # print parts while param_index < len(params): param = params[param_index] # print param, parts[part_index] if param=="NAME": if not parts[part_index]=='*': self.name = parts[part_index][1:] else: self.name = "" elif param=="PSRJ": if not parts[part_index]=='*': self.jname = parts[part_index][1:] if self.name == self.jname: self.name = "" elif param=="RAJ": if not parts[part_index]=='*': hms = map(float, parts[part_index].split(':')) if len(hms)==3: h, m, s = hms elif len(hms)==2: h, m = hms s = 0.0 elif len(hms)==1: h = hms m = s = 0.0 self.ra = psr_utils.hms_to_rad(h, m, s) self.raerr = float(parts[part_index+1]) * psr_utils.SECTORAD part_index += 1 elif param=="DECJ": if not parts[part_index]=='*': dms = map(float, parts[part_index].split(':')) if len(dms)==3: d, m, s = dms elif len(dms)==2: d, m = dms s = 0.0 elif len(dms)==1: d = dms m = s = 0.0 # Fixed silly dec=-0.0 bug if parts[part_index].split(":")[0]=="-00": m = -m s = -s self.dec = psr_utils.dms_to_rad(d, m, s) self.decerr = float(parts[part_index+1]) * psr_utils.ARCSECTORAD part_index += 1 elif param=="PMRA": if not parts[part_index]=='*': self.pmra, self.pmraerr = float(parts[part_index]), float(parts[part_index+1]) part_index += 1 elif param=="PMDEC": if not parts[part_index]=='*': self.pmdec, self.pmdecerr = float(parts[part_index]), float(parts[part_index+1]) part_index += 1 elif param=="PX": if not parts[part_index]=='*': self.px, self.pxerr = float(parts[part_index]), float(parts[part_index+1]) part_index += 1 elif param=="POSEPOCH": if not parts[part_index]=='*': self.posepoch = float(parts[part_index]) elif param=="Gl": if not parts[part_index]=='*': self.l = float(parts[part_index]) elif param=="Gb": if not parts[part_index]=='*': self.b = float(parts[part_index]) elif param=="P0": if not parts[part_index]=='*': self.p, self.perr = float(parts[part_index]), float(parts[part_index+1]) self.f, self.ferr = psr_utils.pferrs(self.p, self.perr) else: self.f = self.ferr = self.p = self.perr = 0.0 self.fd = self.fdd = self.fddd = 0.0 self.pd = self.pdd = self.pddd = 0.0 self.fderr = self.fdderr = self.fddderr = 0.0 self.pderr = self.pdderr = self.pddderr = 0.0 part_index += 1 elif param=="P1": if not parts[part_index]=='*': self.pd, self.pderr = float(parts[part_index]), float(parts[part_index+1]) self.f, self.ferr, self.fd, self.fderr = psr_utils.pferrs(self.p, self.perr, self.pd, self.pderr) part_index += 1 elif param=="F2": if not parts[part_index]=='*': self.fdd, self.fdderr = float(parts[part_index]), float(parts[part_index+1]) self.p, self.pd, self.pdd = presto.p_to_f(self.f, self.fd, self.fdd) part_index += 1 elif param=="F3": if not parts[part_index]=='*': self.fddd, self.fddderr = float(parts[part_index]), float(parts[part_index+1]) part_index += 1 elif param=="PEPOCH": if parts[part_index]=='*': self.pepoch = 51000.0 # Just to pick a reasonable value else: self.pepoch = float(parts[part_index]) elif param=="DM": if not parts[part_index]=='*': self.dm, self.dmerr = float(parts[part_index]), float(parts[part_index+1]) else: self.dm = self.dmerr = 0.0 part_index += 1 elif param=="DM1": if not parts[part_index]=='*': self.ddm, self.ddmerr = float(parts[part_index]), float(parts[part_index+1]) part_index += 1 elif param=="S400": if not parts[part_index]=='*': self.s400, self.s400err = float(parts[part_index]), float(parts[part_index+1]) else: self.s400 = None part_index += 1 elif param=="S1400": if not parts[part_index]=='*': self.s1400, self.s1400err = float(parts[part_index]), float(parts[part_index+1]) else: self.s1400 = None part_index += 1 elif param=="BINARY": if not parts[part_index]=='*': self.binary_model = parts[part_index] self.binary = 1 self.pb = self.x = self.w = self.To = self.e = None self.pberr = self.xerr = self.werr = self.Toerr =self.eerr = None else: self.binary = 0 elif param=="T0": if self.binary and not parts[part_index]=='*': self.To, self.Toerr = float(parts[part_index]), float(parts[part_index+1]) part_index += 1 elif param=="PB": if self.binary and not parts[part_index]=='*': self.pb, self.pberr = float(parts[part_index]), float(parts[part_index+1]) part_index += 1 elif param=="A1": if self.binary and not parts[part_index]=='*': self.x, self.xerr = float(parts[part_index]), float(parts[part_index+1]) part_index += 1 elif param=="OM": if self.binary and not parts[part_index]=='*': self.w, self.werr = float(parts[part_index]), float(parts[part_index+1]) part_index += 1 elif param=="ECC": if self.binary and not parts[part_index]=='*': self.e, self.eerr = float(parts[part_index]), float(parts[part_index+1]) part_index += 1 elif param=="TASC": if self.binary and self.binary_model=="ELL1" and not parts[part_index]=='*': self.To, self.Toerr = float(parts[part_index]), float(parts[part_index+1]) part_index += 1 elif param=="EPS1": if self.binary and self.binary_model=="ELL1" and not parts[part_index]=='*': self.eps1, self.eps1err = float(parts[part_index]), float(parts[part_index+1]) part_index += 1 elif param=="EPS2": if self.binary and self.binary_model=="ELL1" and not parts[part_index]=='*': self.eps2, self.eps2err = float(parts[part_index]), float(parts[part_index+1]) if not hasattr(self, 'eps1'): self.eps1 = 0.0 self.e = math.sqrt(self.eps1*self.eps1 + self.eps2*self.eps2) self.eerr = 0.0001 # This needs fixing... self.w = psr_utils.RADTODEG*math.atan2(self.eps1, self.eps2) if (self.w < 0.0): self.w += 360.0 self.werr = 1.0 # This needs fixing... part_index += 1 elif param=="DIST": if not parts[part_index]=='*': self.dist = float(parts[part_index]) else: self.dist = None elif param=="ASSOC": if not parts[part_index]=='*': self.assoc = parts[part_index] else: self.assoc = None elif param=="PSR": if not parts[part_index]=='*': self.type = parts[part_index] else: self.type = None part_index += 1 param_index += 1 self.alias = ""
def read(self, parfilenm): self.FILE = parfilenm #print parfilenm pf = open(parfilenm) for line in pf.readlines(): # Convert any 'D-' or 'D+' to 'E-' or 'E+' line = line.replace("D-", "E-") line = line.replace("D+", "E+") try: splitline = line.split() key = splitline[0] if key in str_keys: setattr(self, key, splitline[1]) elif key in float_keys: try: setattr(self, key, float(splitline[1])) except ValueError: pass if len( splitline ) == 3: # Some parfiles don't have flags, but do have errors if splitline[2] not in ['0', '1']: setattr(self, key + '_ERR', float(splitline[2])) if len(splitline) == 4: setattr(self, key + '_ERR', float(splitline[3])) except: if line.strip(): print ' ', line # Read PSR name if hasattr(self, 'PSR'): setattr(self, 'PSR', self.PSR) if hasattr(self, 'PSRJ'): setattr(self, 'PSRJ', self.PSRJ) # Deal with Ecliptic coords if (hasattr(self, 'BETA') and hasattr(self, 'LAMBDA')): self.use_eclip = True setattr(self, 'ELAT', self.BETA) setattr(self, 'ELONG', self.LAMBDA) if (slalib and hasattr(self, 'ELAT') and hasattr(self, 'ELONG')): self.use_eclip = True if hasattr(self, 'POSEPOCH'): epoch = self.POSEPOCH else: epoch = self.PEPOCH ra_rad, dec_rad = sla_ecleq(self.ELONG * pu.DEGTORAD, self.ELAT * pu.DEGTORAD, epoch) rstr = pu.coord_to_string(*pu.rad_to_hms(ra_rad)) dstr = pu.coord_to_string(*pu.rad_to_dms(dec_rad)) setattr(self, 'RAJ', rstr) setattr(self, 'DECJ', dstr) if (slalib and hasattr(self, 'ELAT') and hasattr(self, 'ELONG')): setattr(self, 'PMELONG', self.PMELONG) setattr(self, 'PMELAT', self.PMELAT) if hasattr(self, 'RAJ'): setattr(self, 'RA_RAD', pu.ra_to_rad(self.RAJ)) if hasattr(self, 'DECJ'): setattr(self, 'DEC_RAD', pu.dec_to_rad(self.DECJ)) # Compute the Galactic coords if (slalib and hasattr(self, 'RA_RAD') and hasattr(self, 'DEC_RAD')): l, b = sla_eqgal(self.RA_RAD, self.DEC_RAD) setattr(self, 'GLONG', l * pu.RADTODEG) setattr(self, 'GLAT', b * pu.RADTODEG) # Compute the Ecliptic coords if (slalib and hasattr(self, 'RA_RAD') and hasattr(self, 'DEC_RAD')): if hasattr(self, 'POSEPOCH'): epoch = self.POSEPOCH else: epoch = self.PEPOCH elon, elat = sla_eqecl(self.RA_RAD, self.DEC_RAD, epoch) setattr(self, 'ELONG', elon * pu.RADTODEG) setattr(self, 'ELAT', elat * pu.RADTODEG) if hasattr(self, 'P'): setattr(self, 'P0', self.P) if hasattr(self, 'P0'): setattr(self, 'F0', 1.0 / self.P0) if hasattr(self, 'F0'): setattr(self, 'P0', 1.0 / self.F0) if hasattr(self, 'F1'): setattr(self, 'P1', -self.F1 / (self.F0 * self.F0)) if hasattr(self, 'FB0'): setattr(self, 'PB', (1.0 / self.FB0) / 86400.0) if hasattr(self, 'P0_ERR'): if hasattr(self, 'P1_ERR'): f, ferr, fd, fderr = pu.pferrs(self.P0, self.P0_ERR, self.P1, self.P1_ERR) setattr(self, 'F0_ERR', ferr) setattr(self, 'F1', fd) setattr(self, 'F1_ERR', fderr) else: f, fd, = pu.p_to_f(self.P0, self.P1) setattr(self, 'F0_ERR', self.P0_ERR / (self.P0 * self.P0)) setattr(self, 'F1', fd) if hasattr(self, 'F0_ERR'): if hasattr(self, 'F1_ERR'): p, perr, pd, pderr = pu.pferrs(self.F0, self.F0_ERR, self.F1, self.F1_ERR) setattr(self, 'P0_ERR', perr) setattr(self, 'P1', pd) setattr(self, 'P1_ERR', pderr) else: p, pd, = pu.p_to_f(self.F0, self.F1) setattr(self, 'P0_ERR', self.F0_ERR / (self.F0 * self.F0)) setattr(self, 'P1', pd) if hasattr(self, 'DM'): setattr(self, 'DM', self.DM) if hasattr(self, 'DM1'): setattr(self, 'DM1', self.DM1) if hasattr(self, 'DM2'): setattr(self, 'DM2', self.DM2) if hasattr(self, 'EPS1') and hasattr(self, 'EPS2'): self.use_ell = True ecc = math.sqrt(self.EPS1 * self.EPS1 + self.EPS2 * self.EPS2) omega = math.atan2(self.EPS1, self.EPS2) if self.EPS1 == 0.0 and self.EPS2 == 0.0: ecc_err = pow( pow(self.EPS1_ERR, 2) + pow(self.EPS2_ERR, 2), .5) else: ecc_err = pow( pow(self.EPS1 * self.EPS1_ERR, 2) + pow(self.EPS2 * self.EPS2_ERR, 2), 0.5) / ecc setattr(self, 'ECC', ecc) setattr(self, 'ECC_ERR', ecc_err) setattr(self, 'OM', omega) if hasattr(self, 'PB') and hasattr(self, 'A1') and not hasattr(self, 'ECC'): setattr(self, 'ECC', 0.0) if hasattr(self, 'BINARY'): setattr(self, 'BINARY', self.BINARY) if hasattr(self, 'KIN'): setattr(self, 'SINI', math.sin(self.KIN * np.pi / 180.)) setattr( self, 'SINI_ERR', math.sin(self.KIN * np.pi / 180.) - math.sin(self.KIN * np.pi / 180. - self.KIN_ERR * np.pi / 180.)) pf.close()
def __init__(self, parfilenm): self.FILE = parfilenm pf = open(parfilenm) for line in pf.readlines(): # Convert any 'D-' or 'D+' to 'E-' or 'E+' line = line.replace("D-", "E-") line = line.replace("D+", "E+") splitline = line.split() key = splitline[0] if key in str_keys: setattr(self, key, splitline[1]) elif key in float_keys: try: setattr(self, key, float(splitline[1])) except ValueError: pass if len(splitline)==3: # Some parfiles don't have flags, but do have errors if splitline[2] not in ['0', '1']: setattr(self, key+'_ERR', float(splitline[2])) if len(splitline)==4: setattr(self, key+'_ERR', float(splitline[3])) # Deal with Ecliptic coords if (hasattr(self, 'BETA') and hasattr(self, 'LAMBDA')): setattr(self, 'ELAT', self.BETA) setattr(self, 'ELONG', self.LAMBDA) if (slalib and hasattr(self, 'ELAT') and hasattr(self, 'ELONG')): if hasattr(self, 'POSEPOCH'): epoch = self.POSEPOCH else: epoch = self.PEPOCH ra_rad, dec_rad = sla_ecleq(self.ELONG*pu.DEGTORAD, self.ELAT*pu.DEGTORAD, epoch) rstr = pu.coord_to_string(*pu.rad_to_hms(ra_rad)) dstr = pu.coord_to_string(*pu.rad_to_dms(dec_rad)) setattr(self, 'RAJ', rstr) setattr(self, 'DECJ', dstr) if hasattr(self, 'RAJ'): setattr(self, 'RA_RAD', pu.ra_to_rad(self.RAJ)) if hasattr(self, 'DECJ'): setattr(self, 'DEC_RAD', pu.dec_to_rad(self.DECJ)) # Compute the Galactic coords if (slalib and hasattr(self, 'RA_RAD') and hasattr(self, 'DEC_RAD')): l, b = sla_eqgal(self.RA_RAD, self.DEC_RAD) setattr(self, 'GLONG', l*pu.RADTODEG) setattr(self, 'GLAT', b*pu.RADTODEG) # Compute the Ecliptic coords if (slalib and hasattr(self, 'RA_RAD') and hasattr(self, 'DEC_RAD')): if hasattr(self, 'POSEPOCH'): epoch = self.POSEPOCH else: epoch = self.PEPOCH elon, elat = sla_eqecl(self.RA_RAD, self.DEC_RAD, epoch) setattr(self, 'ELONG', elon*pu.RADTODEG) setattr(self, 'ELAT', elat*pu.RADTODEG) if hasattr(self, 'P'): setattr(self, 'P0', self.P) if hasattr(self, 'P0'): setattr(self, 'F0', 1.0/self.P0) if hasattr(self, 'F0'): setattr(self, 'P0', 1.0/self.F0) if hasattr(self, 'FB0'): setattr(self, 'PB', (1.0/self.FB0)/86400.0) if hasattr(self, 'P0_ERR'): if hasattr(self, 'P1_ERR'): f, ferr, fd, fderr = pu.pferrs(self.P0, self.P0_ERR, self.P1, self.P1_ERR) setattr(self, 'F0_ERR', ferr) setattr(self, 'F1', fd) setattr(self, 'F1_ERR', fderr) else: f, fd, = pu.p_to_f(self.P0, self.P1) setattr(self, 'F0_ERR', self.P0_ERR/(self.P0*self.P0)) setattr(self, 'F1', fd) if hasattr(self, 'F0_ERR'): if hasattr(self, 'F1_ERR'): p, perr, pd, pderr = pu.pferrs(self.F0, self.F0_ERR, self.F1, self.F1_ERR) setattr(self, 'P0_ERR', perr) setattr(self, 'P1', pd) setattr(self, 'P1_ERR', pderr) else: p, pd, = pu.p_to_f(self.F0, self.F1) setattr(self, 'P0_ERR', self.F0_ERR/(self.F0*self.F0)) setattr(self, 'P1', pd) if hasattr(self, 'EPS1') and hasattr(self, 'EPS2'): ecc = math.sqrt(self.EPS1 * self.EPS1 + self.EPS2 * self.EPS2) omega = math.atan2(self.EPS1, self.EPS2) setattr(self, 'E', ecc) setattr(self, 'OM', omega * pu.RADTODEG) setattr(self, 'T0', self.TASC + self.PB * omega/pu.TWOPI) if hasattr(self, 'PB') and hasattr(self, 'A1') and not \ (hasattr(self, 'E') or hasattr(self, 'ECC')): setattr(self, 'E', 0.0) if hasattr(self, 'T0') and hasattr(self, 'PB') and hasattr(self, 'OM') and not hasattr(self, 'TASC'): setattr(self, 'TASC', self.T0 - self.PB * self.OM/360.0) pf.close()
def __init__(self, parfilenm): self.FILE = parfilenm pf = open(parfilenm) for line in pf.readlines(): # Skip comments if line[0]=='#': continue # Convert any 'D-' or 'D+' to 'E-' or 'E+' line = line.replace("D-", "E-") line = line.replace("D+", "E+") splitline = line.split() # Skip blank lines if len(splitline)==0: continue key = splitline[0] # Regex checks for non-digit chars, followed by digit chars m1 = re.search(r'(\D+)(\d+)$', key) # This one looks for the DMX[RF][12]_* params m2 = re.search(r'(\D+\d+_)(\d+)$', key) if key == "JUMP": if splitline[3] not in ['0', '1']: setattr(self, key+'_%s'%splitline[2], float(splitline[3])) if len(splitline)==5: if splitline[4] not in ['0', '1']: setattr(self, key+'_%s'%splitline[2]+'_ERR', float(splitline[4])) elif len(splitline)==6: setattr(self, key+'_%s'%splitline[2]+'_ERR', float(splitline[5])) if key in str_keys: setattr(self, key, splitline[1]) elif key in float_keys: try: setattr(self, key, float(splitline[1])) except ValueError: pass elif m1 is not None: m = m1 if m2 is not None: m = m2 if m.group(1) in floatn_keys: try: setattr(self, key, float(splitline[1])) except ValueError: pass if len(splitline)==3: # Some parfiles don't have flags, but do have errors if splitline[2] not in ['0', '1']: setattr(self, key+'_ERR', float(splitline[2])) if len(splitline)==4: setattr(self, key+'_ERR', float(splitline[3])) # Deal with Ecliptic coords if (hasattr(self, 'BETA') and hasattr(self, 'LAMBDA')): setattr(self, 'ELAT', self.BETA) setattr(self, 'ELONG', self.LAMBDA) if (slalib and hasattr(self, 'ELAT') and hasattr(self, 'ELONG')): if hasattr(self, 'POSEPOCH'): epoch = self.POSEPOCH else: epoch = self.PEPOCH ra_rad, dec_rad = sla_ecleq(self.ELONG*pu.DEGTORAD, self.ELAT*pu.DEGTORAD, epoch) rstr = pu.coord_to_string(*pu.rad_to_hms(ra_rad)) dstr = pu.coord_to_string(*pu.rad_to_dms(dec_rad)) setattr(self, 'RAJ', rstr) setattr(self, 'DECJ', dstr) if hasattr(self, 'RAJ'): setattr(self, 'RA_RAD', pu.ra_to_rad(self.RAJ)) if hasattr(self, 'DECJ'): setattr(self, 'DEC_RAD', pu.dec_to_rad(self.DECJ)) # Compute the Galactic coords if (slalib and hasattr(self, 'RA_RAD') and hasattr(self, 'DEC_RAD')): l, b = sla_eqgal(self.RA_RAD, self.DEC_RAD) setattr(self, 'GLONG', l*pu.RADTODEG) setattr(self, 'GLAT', b*pu.RADTODEG) # Compute the Ecliptic coords if (slalib and hasattr(self, 'RA_RAD') and hasattr(self, 'DEC_RAD')): if hasattr(self, 'POSEPOCH'): epoch = self.POSEPOCH else: epoch = self.PEPOCH elon, elat = sla_eqecl(self.RA_RAD, self.DEC_RAD, epoch) setattr(self, 'ELONG', elon*pu.RADTODEG) setattr(self, 'ELAT', elat*pu.RADTODEG) if hasattr(self, 'P'): setattr(self, 'P0', self.P) if hasattr(self, 'P0'): setattr(self, 'F0', 1.0/self.P0) if hasattr(self, 'F0'): setattr(self, 'P0', 1.0/self.F0) if hasattr(self, 'FB0'): setattr(self, 'PB', (1.0/self.FB0)/86400.0) if hasattr(self, 'P0_ERR'): if hasattr(self, 'P1_ERR'): f, ferr, fd, fderr = pu.pferrs(self.P0, self.P0_ERR, self.P1, self.P1_ERR) setattr(self, 'F0_ERR', ferr) setattr(self, 'F1', fd) setattr(self, 'F1_ERR', fderr) else: f, fd, = pu.p_to_f(self.P0, self.P1) setattr(self, 'F0_ERR', self.P0_ERR/(self.P0*self.P0)) setattr(self, 'F1', fd) else: if hasattr(self, 'P1'): f, fd, = pu.p_to_f(self.P0, self.P1) setattr(self, 'F1', fd) elif hasattr(self, 'F1'): p, pd, = pu.p_to_f(self.F0, self.F1) setattr(self, 'P1', pd) if (hasattr(self, 'F0_ERR') and hasattr(self, 'F1_ERR')): p, perr, pd, pderr = pu.pferrs(self.F0, self.F0_ERR, self.F1, self.F1_ERR) setattr(self, 'P0_ERR', perr) setattr(self, 'P1', pd) setattr(self, 'P1_ERR', pderr) elif (hasattr(self, 'F0') and hasattr(self, 'F0_ERR')): setattr(self, 'P0_ERR', self.F0_ERR/(self.F0*self.F0)) if hasattr(self, 'EPS1') and hasattr(self, 'EPS2'): ecc = math.sqrt(self.EPS1 * self.EPS1 + self.EPS2 * self.EPS2) omega = math.atan2(self.EPS1, self.EPS2) setattr(self, 'E', ecc) setattr(self, 'OM', omega * pu.RADTODEG) setattr(self, 'T0', self.TASC + self.PB * omega/pu.TWOPI) if hasattr(self, 'PB') and hasattr(self, 'A1') and not \ (hasattr(self, 'E') or hasattr(self, 'ECC')): setattr(self, 'E', 0.0) if hasattr(self, 'T0') and not hasattr(self, 'TASC'): setattr(self, 'TASC', self.T0 - self.PB * self.OM/360.0) pf.close()
def __init__(self, line): parts = line.split()[1:] part_index = 0 param_index = 0 # print parts while param_index < len(params): param = params[param_index] # print param, parts[part_index] if param == "NAME": if not parts[part_index] == '*': self.name = parts[part_index][1:] else: self.name = "" elif param == "PSRJ": if not parts[part_index] == '*': self.jname = parts[part_index][1:] if self.name == self.jname: self.name = "" elif param == "RAJ": if not parts[part_index] == '*': hms = map(float, parts[part_index].split(':')) if len(hms) == 3: h, m, s = hms elif len(hms) == 2: h, m = hms s = 0.0 elif len(hms) == 1: h = hms m = s = 0.0 self.ra = psr_utils.hms_to_rad(h, m, s) self.raerr = float( parts[part_index + 1]) * psr_utils.SECTORAD part_index += 1 elif param == "DECJ": if not parts[part_index] == '*': dms = map(float, parts[part_index].split(':')) if len(dms) == 3: d, m, s = dms elif len(dms) == 2: d, m = dms s = 0.0 elif len(dms) == 1: d = dms m = s = 0.0 # Fixed silly dec=-0.0 bug if parts[part_index].split(":")[0] == "-00": m = -m s = -s self.dec = psr_utils.dms_to_rad(d, m, s) self.decerr = float( parts[part_index + 1]) * psr_utils.ARCSECTORAD part_index += 1 elif param == "PMRA": if not parts[part_index] == '*': self.pmra, self.pmraerr = float(parts[part_index]), float( parts[part_index + 1]) part_index += 1 elif param == "PMDEC": if not parts[part_index] == '*': self.pmdec, self.pmdecerr = float( parts[part_index]), float(parts[part_index + 1]) part_index += 1 elif param == "PX": if not parts[part_index] == '*': self.px, self.pxerr = float(parts[part_index]), float( parts[part_index + 1]) part_index += 1 elif param == "POSEPOCH": if not parts[part_index] == '*': self.posepoch = float(parts[part_index]) elif param == "Gl": if not parts[part_index] == '*': self.l = float(parts[part_index]) elif param == "Gb": if not parts[part_index] == '*': self.b = float(parts[part_index]) elif param == "P0": if not parts[part_index] == '*': self.p, self.perr = float(parts[part_index]), float( parts[part_index + 1]) self.f, self.ferr = psr_utils.pferrs(self.p, self.perr) else: self.f = self.ferr = self.p = self.perr = 0.0 self.fd = self.fdd = self.fddd = 0.0 self.pd = self.pdd = self.pddd = 0.0 self.fderr = self.fdderr = self.fddderr = 0.0 self.pderr = self.pdderr = self.pddderr = 0.0 part_index += 1 elif param == "P1": if not parts[part_index] == '*': self.pd, self.pderr = float(parts[part_index]), float( parts[part_index + 1]) self.f, self.ferr, self.fd, self.fderr = psr_utils.pferrs( self.p, self.perr, self.pd, self.pderr) part_index += 1 elif param == "F2": if not parts[part_index] == '*': self.fdd, self.fdderr = float(parts[part_index]), float( parts[part_index + 1]) self.p, self.pd, self.pdd = presto.p_to_f( self.f, self.fd, self.fdd) part_index += 1 elif param == "F3": if not parts[part_index] == '*': self.fddd, self.fddderr = float(parts[part_index]), float( parts[part_index + 1]) part_index += 1 elif param == "PEPOCH": if parts[part_index] == '*': self.pepoch = 51000.0 # Just to pick a reasonable value else: self.pepoch = float(parts[part_index]) elif param == "DM": if not parts[part_index] == '*': self.dm, self.dmerr = float(parts[part_index]), float( parts[part_index + 1]) else: self.dm = self.dmerr = 0.0 part_index += 1 elif param == "DM1": if not parts[part_index] == '*': self.ddm, self.ddmerr = float(parts[part_index]), float( parts[part_index + 1]) part_index += 1 elif param == "S400": if not parts[part_index] == '*': self.s400, self.s400err = float(parts[part_index]), float( parts[part_index + 1]) else: self.s400 = None part_index += 1 elif param == "S1400": if not parts[part_index] == '*': self.s1400, self.s1400err = float( parts[part_index]), float(parts[part_index + 1]) else: self.s1400 = None part_index += 1 elif param == "BINARY": if not parts[part_index] == '*': self.binary_model = parts[part_index] self.binary = 1 self.pb = self.x = self.w = self.To = self.e = None self.pberr = self.xerr = self.werr = self.Toerr = self.eerr = None else: self.binary = 0 elif param == "T0": if self.binary and not parts[part_index] == '*': self.To, self.Toerr = float(parts[part_index]), float( parts[part_index + 1]) part_index += 1 elif param == "PB": if self.binary and not parts[part_index] == '*': self.pb, self.pberr = float(parts[part_index]), float( parts[part_index + 1]) part_index += 1 elif param == "A1": if self.binary and not parts[part_index] == '*': self.x, self.xerr = float(parts[part_index]), float( parts[part_index + 1]) part_index += 1 elif param == "OM": if self.binary and not parts[part_index] == '*': self.w, self.werr = float(parts[part_index]), float( parts[part_index + 1]) part_index += 1 elif param == "ECC": if self.binary and not parts[part_index] == '*': self.e, self.eerr = float(parts[part_index]), float( parts[part_index + 1]) part_index += 1 elif param == "TASC": if self.binary and self.binary_model == "ELL1" and not parts[ part_index] == '*': self.To, self.Toerr = float(parts[part_index]), float( parts[part_index + 1]) part_index += 1 elif param == "EPS1": if self.binary and self.binary_model == "ELL1" and not parts[ part_index] == '*': self.eps1, self.eps1err = float(parts[part_index]), float( parts[part_index + 1]) part_index += 1 elif param == "EPS2": if self.binary and self.binary_model == "ELL1" and not parts[ part_index] == '*': self.eps2, self.eps2err = float(parts[part_index]), float( parts[part_index + 1]) if not hasattr(self, 'eps1'): self.eps1 = 0.0 self.e = math.sqrt(self.eps1 * self.eps1 + self.eps2 * self.eps2) self.eerr = 0.0001 # This needs fixing... self.w = psr_utils.RADTODEG * math.atan2( self.eps1, self.eps2) if (self.w < 0.0): self.w += 360.0 self.werr = 1.0 # This needs fixing... part_index += 1 elif param == "DIST": if not parts[part_index] == '*': self.dist = float(parts[part_index]) else: self.dist = None elif param == "ASSOC": if not parts[part_index] == '*': self.assoc = parts[part_index] else: self.assoc = None elif param == "PSR": if not parts[part_index] == '*': self.type = parts[part_index] else: self.type = None part_index += 1 param_index += 1 self.alias = ""
def __init__(self, parfilenm): self.FILE = parfilenm pf = open(parfilenm) for line in pf.readlines(): # Skip comments if line[0] == '#': continue # Convert any 'D-' or 'D+' to 'E-' or 'E+' line = line.replace("D-", "E-") line = line.replace("D+", "E+") splitline = line.split() # Skip blank lines if len(splitline) == 0: continue key = splitline[0] # Regex checks for non-digit chars, followed by digit chars m1 = re.search(r'(\D+)(\d+)$', key) # This one looks for the DMX[RF][12]_* params m2 = re.search(r'(\D+\d+_)(\d+)$', key) if key == "JUMP": if splitline[3] not in ['0', '1']: setattr(self, key + '_%s' % splitline[2], float(splitline[3])) if len(splitline) == 5: if splitline[4] not in ['0', '1']: setattr(self, key + '_%s' % splitline[2] + '_ERR', float(splitline[4])) elif len(splitline) == 6: setattr(self, key + '_%s' % splitline[2] + '_ERR', float(splitline[5])) if key in str_keys: setattr(self, key, splitline[1]) elif key in float_keys: try: setattr(self, key, float(splitline[1])) except ValueError: pass elif m1 is not None: m = m1 if m2 is not None: m = m2 if m.group(1) in floatn_keys: try: setattr(self, key, float(splitline[1])) except ValueError: pass if len( splitline ) == 3: # Some parfiles don't have flags, but do have errors if splitline[2] not in ['0', '1']: setattr(self, key + '_ERR', float(splitline[2])) if len(splitline) == 4: setattr(self, key + '_ERR', float(splitline[3])) # Deal with Ecliptic coords if (hasattr(self, 'BETA') and hasattr(self, 'LAMBDA')): setattr(self, 'ELAT', self.BETA) setattr(self, 'ELONG', self.LAMBDA) if (slalib and hasattr(self, 'ELAT') and hasattr(self, 'ELONG')): # TEMPO's ecliptic coords are always based on J2000 epoch ra_rad, dec_rad = sla_ecleq(self.ELONG * pu.DEGTORAD, self.ELAT * pu.DEGTORAD, J2000) rstr = pu.coord_to_string(*pu.rad_to_hms(ra_rad)) dstr = pu.coord_to_string(*pu.rad_to_dms(dec_rad)) setattr(self, 'RAJ', rstr) setattr(self, 'DECJ', dstr) if hasattr(self, 'RAJ'): setattr(self, 'RA_RAD', pu.ra_to_rad(self.RAJ)) if hasattr(self, 'DECJ'): setattr(self, 'DEC_RAD', pu.dec_to_rad(self.DECJ)) # Compute the Galactic coords if (slalib and hasattr(self, 'RA_RAD') and hasattr(self, 'DEC_RAD')): l, b = sla_eqgal(self.RA_RAD, self.DEC_RAD) setattr(self, 'GLONG', l * pu.RADTODEG) setattr(self, 'GLAT', b * pu.RADTODEG) # Compute the Ecliptic coords if (slalib and hasattr(self, 'RA_RAD') and hasattr(self, 'DEC_RAD')): # TEMPO's ecliptic coords are always based on J2000 epoch elon, elat = sla_eqecl(self.RA_RAD, self.DEC_RAD, J2000) setattr(self, 'ELONG', elon * pu.RADTODEG) setattr(self, 'ELAT', elat * pu.RADTODEG) if hasattr(self, 'P'): setattr(self, 'P0', self.P) if hasattr(self, 'P0'): setattr(self, 'F0', 1.0 / self.P0) if hasattr(self, 'F0'): setattr(self, 'P0', 1.0 / self.F0) if hasattr(self, 'FB0'): setattr(self, 'PB', (1.0 / self.FB0) / 86400.0) if hasattr(self, 'P0_ERR'): if hasattr(self, 'P1_ERR'): f, ferr, fd, fderr = pu.pferrs(self.P0, self.P0_ERR, self.P1, self.P1_ERR) setattr(self, 'F0_ERR', ferr) setattr(self, 'F1', fd) setattr(self, 'F1_ERR', fderr) else: f, fd, = pu.p_to_f(self.P0, self.P1) setattr(self, 'F0_ERR', self.P0_ERR / (self.P0 * self.P0)) setattr(self, 'F1', fd) else: if hasattr(self, 'P1'): f, fd, = pu.p_to_f(self.P0, self.P1) setattr(self, 'F1', fd) elif hasattr(self, 'F1'): p, pd, = pu.p_to_f(self.F0, self.F1) setattr(self, 'P1', pd) if (hasattr(self, 'F0_ERR') and hasattr(self, 'F1_ERR')): p, perr, pd, pderr = pu.pferrs(self.F0, self.F0_ERR, self.F1, self.F1_ERR) setattr(self, 'P0_ERR', perr) setattr(self, 'P1', pd) setattr(self, 'P1_ERR', pderr) elif (hasattr(self, 'F0') and hasattr(self, 'F0_ERR')): setattr(self, 'P0_ERR', self.F0_ERR / (self.F0 * self.F0)) if hasattr(self, 'EPS1') and hasattr(self, 'EPS2'): ecc = math.sqrt(self.EPS1 * self.EPS1 + self.EPS2 * self.EPS2) omega = math.atan2(self.EPS1, self.EPS2) setattr(self, 'E', ecc) setattr(self, 'OM', omega * pu.RADTODEG) setattr(self, 'T0', self.TASC + self.PB * omega / pu.TWOPI) if hasattr(self, 'PB') and hasattr(self, 'A1') and not \ (hasattr(self, 'E') or hasattr(self, 'ECC')): setattr(self, 'E', 0.0) if hasattr(self, 'T0') and not hasattr(self, 'TASC'): setattr(self, 'TASC', self.T0 - self.PB * self.OM / 360.0) if hasattr(self, 'E') and not hasattr(self, 'ECC'): setattr(self, 'ECC', self.E) if not hasattr(self, 'EPS1'): setattr(self, 'ECC_ERR', self.E_ERR) if hasattr(self, 'ECC') and not hasattr(self, 'E'): setattr(self, 'E', self.ECC) setattr(self, 'E_ERR', self.ECC_ERR) pf.close()