Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def parse_eph(filenm):
global period, time
suffix = filenm.split(".")[-1]
if suffix=="bestprof":
x = bestprof.bestprof(filenm)
fs = pu.p_to_f(x.p0_bary, x.p1_bary, x.p2_bary)
epoch = x.epochi_bary + x.epochf_bary
T = x.T
elif suffix=="par":
x = parfile.psr_par(filenm)
# Try to see how many freq derivs we have
fs = [x.F0]
for ii in range(1, 20): # hopefully 20 is an upper limit!
attrib = "F%d"%ii
if hasattr(x, attrib):
fs.append(getattr(x, attrib))
else:
break
epoch = x.PEPOCH
T = (x.FINISH - x.START) * 86400.0
else:
print("I don't recognize the file type for", filenm)
bestpd = self.fold_p2
bestpdd = self.fold_p3
else:
bestp = self.topo_p1
bestpd = self.topo_p2
bestpdd = self.topo_p3
if p is not None:
bestp = p
if pd is not None:
bestpd = pd
if pdd is not None:
bestpdd = pdd
# self.fold_p[123] are actually frequencies, convert to periods
foldf, foldfd, foldfdd = self.fold_p1, self.fold_p2, self.fold_p3
foldp, foldpd, foldpdd = psr_utils.p_to_f(self.fold_p1, \
self.fold_p2, self.fold_p3)
# Get best f, fd, fdd
# Use folding values to be consistent with prepfold_plot.c
bestfdd = psr_utils.p_to_f(foldp, foldpd, bestpdd)[2]
bestfd = psr_utils.p_to_f(foldp, bestpd)[1]
bestf = 1.0/bestp
# Get frequency and frequency derivative offsets
f_diff = bestf - foldf
fd_diff = bestfd - foldfd
# bestpdd=0.0 only if there was no searching over pdd
if bestpdd != 0.0:
fdd_diff = bestfdd - foldfdd
else:
if p is not None:
bestp = p
if pd is not None:
bestpd = pd
if pdd is not None:
bestpdd = pdd
# self.fold_p[123] are actually frequencies, convert to periods
foldf, foldfd, foldfdd = self.fold_p1, self.fold_p2, self.fold_p3
foldp, foldpd, foldpdd = psr_utils.p_to_f(self.fold_p1, \
self.fold_p2, self.fold_p3)
# Get best f, fd, fdd
# Use folding values to be consistent with prepfold_plot.c
bestfdd = psr_utils.p_to_f(foldp, foldpd, bestpdd)[2]
bestfd = psr_utils.p_to_f(foldp, bestpd)[1]
bestf = 1.0/bestp
# Get frequency and frequency derivative offsets
f_diff = bestf - foldf
fd_diff = bestfd - foldfd
# bestpdd=0.0 only if there was no searching over pdd
if bestpdd != 0.0:
fdd_diff = bestfdd - foldfdd
else:
fdd_diff = 0.0
return (f_diff, fd_diff, fdd_diff)
bestpdd = self.topo_p3
if p is not None:
bestp = p
if pd is not None:
bestpd = pd
if pdd is not None:
bestpdd = pdd
# self.fold_p[123] are actually frequencies, convert to periods
foldf, foldfd, foldfdd = self.fold_p1, self.fold_p2, self.fold_p3
foldp, foldpd, foldpdd = psr_utils.p_to_f(self.fold_p1, \
self.fold_p2, self.fold_p3)
# Get best f, fd, fdd
# Use folding values to be consistent with prepfold_plot.c
bestfdd = psr_utils.p_to_f(foldp, foldpd, bestpdd)[2]
bestfd = psr_utils.p_to_f(foldp, bestpd)[1]
bestf = 1.0/bestp
# Get frequency and frequency derivative offsets
f_diff = bestf - foldf
fd_diff = bestfd - foldfd
# bestpdd=0.0 only if there was no searching over pdd
if bestpdd != 0.0:
fdd_diff = bestfdd - foldfdd
else:
fdd_diff = 0.0
return (f_diff, fd_diff, fdd_diff)