Example #1
0
def decstr_to_rad(decstr):
    """
    decstr_to_rad(decstr)

    Convert declination string of the form DDMMSS.SSSS to
    declination in radians
    """
    decstr = str(decstr) # Ensure decstr is string, not int or float    
    sign, d, m, s = parse_decstr(decstr)

    return sign_to_int(sign)*psr_utils.dms_to_rad(float(d), float(m), float(s))
Example #2
0
    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 = ""
Example #3
0
    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 = ""