Skip to content

Commit

Permalink
Many py2/py3 compatability fixes found running full search script
Browse files Browse the repository at this point in the history
  • Loading branch information
scottransom committed Nov 17, 2019
1 parent 8b9b8a8 commit 4ec8edf
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 28 deletions.
1 change: 1 addition & 0 deletions bin/DDplan.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
from __future__ import print_function
from __future__ import absolute_import
from builtins import zip
from numpy import *
from presto.Pgplot import *
Expand Down
2 changes: 1 addition & 1 deletion bin/gotocand.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def get_datfile_len(nodename, datfile):
sys.argv.pop(1)
outdir = os.getcwd()
if (len(sys.argv) > 2):
extraargs = string.join(sys.argv[2:])
extraargs = "".join(sys.argv[2:])
else:
extraargs = ""
candfile, candnum = sys.argv[1].split(':')
Expand Down
10 changes: 6 additions & 4 deletions bin/pyplotres.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
# A simple command line version of plotres written in python
# using matplotlib and numpy
#
# Patrick Lazarus, Feb 26th, 2009

# Patrick Lazarus, Feb 26th, 2009
# Many other tweaks by S. Ransom, T. Pennucci et al over years
#
from __future__ import print_function
from __future__ import absolute_import
from builtins import input
from builtins import str
from builtins import range
Expand Down Expand Up @@ -308,8 +310,8 @@ def plot_data(tempo_results, xkey, ykey, postfit=True, prefit=False, \
for ii,(lo,hi) in enumerate(tempo_results.freqbands):
freq_label = get_freq_label(lo, hi)
resids = tempo_results.residuals[freq_label]
xlabel, xdata = resids.get_xdata(xkey)
ylabel, ydata, yerr = resids.get_ydata(ykey, usepostfit)
xlabel, xdata = resids.get_xdata(str(xkey))
ylabel, ydata, yerr = resids.get_ydata(str(ykey), usepostfit)
if len(xdata):
# Plot the residuals
handle = plt.errorbar(xdata, ydata, yerr=yerr, fmt='.', \
Expand Down
1 change: 1 addition & 0 deletions python/ACCEL_sift.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
from builtins import map
import re
import glob
Expand Down
9 changes: 5 additions & 4 deletions python/presto/binary_psr.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import print_function
from __future__ import absolute_import
from builtins import object
import numpy as Num
from presto import parfile, psr_utils
Expand Down Expand Up @@ -244,14 +245,14 @@ def shapiro_measurable(self, R, S, MJD):


if __name__=='__main__':
from Pgplot import *
import presto.Pgplot as pg

# The following reproduces the RV plot in Hulse & Taylor, 1975
psrA = binary_psr("B1913+16.par")
T0 = 42320.933 # From Hulse & Taylor, 1975
times = psr_utils.span(0.0, psrA.par.PB, 1000) + T0
rv = psrA.radial_velocity(times)
plotxy(rv, (times-T0)*24,
labx="Hours since Periastron", laby="Radial Velocity (km.s)")
closeplot()
pg.plotxy(rv, (times-T0)*24, \
labx="Hours since Periastron", laby="Radial Velocity (km.s)")
pg.closeplot()

1 change: 1 addition & 0 deletions python/presto/cosine_rand.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import print_function
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
import numpy as Num
Expand Down
10 changes: 5 additions & 5 deletions python/presto/kuiper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import print_function
from __future__ import absolute_import
from builtins import range
import numpy as num
from presto import Pgplot
Expand Down Expand Up @@ -114,7 +115,6 @@ def kuiper_uniform_test(data, output=0):
print("Kuiper:")
(D, P) = kuiper_uniform_test(data, output=1)
if (1):
from Pgplot import *
p1s = []
p2s = []
p3s = []
Expand All @@ -124,7 +124,7 @@ def kuiper_uniform_test(data, output=0):
p1s.append(kuiper_prob(D, N))
p2s.append(kuiper_prob2(D, N))
p3s.append(kuiper_prob3(D, N))
plotxy(num.log10(num.asarray(p1s)), Ds, color='red')
plotxy(num.log10(num.asarray(p2s)), Ds, color='blue')
plotxy(num.log10(num.asarray(p3s)), Ds, color='green')
closeplot()
Pgplot.plotxy(num.log10(num.asarray(p1s)), Ds, color='red')
Pgplot.plotxy(num.log10(num.asarray(p2s)), Ds, color='blue')
Pgplot.plotxy(num.log10(num.asarray(p3s)), Ds, color='green')
Pgplot.closeplot()
20 changes: 11 additions & 9 deletions python/presto/parfile.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from __future__ import print_function
from __future__ import absolute_import
from builtins import object
import six
import math, re
from presto import psr_utils as pu
from presto import psr_constants as pc
try:
from slalib import sla_ecleq, sla_eqecl, sla_eqgal
slalib = True
Expand Down Expand Up @@ -114,8 +116,8 @@ def __init__(self, parfilenm):
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)
ra_rad, dec_rad = sla_ecleq(self.ELONG*pc.DEGTORAD,
self.ELAT*pc.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)
Expand All @@ -127,22 +129,22 @@ def __init__(self, parfilenm):
# 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)
setattr(self, 'GLONG', l*pc.RADTODEG)
setattr(self, 'GLAT', b*pc.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)
setattr(self, 'ELONG', elon*pc.RADTODEG)
setattr(self, 'ELAT', elat*pc.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)
setattr(self, 'PB', (1.0/self.FB0)/pc.SECPERDAY)
if hasattr(self, 'P0_ERR'):
if hasattr(self, 'P1_ERR'):
f, ferr, fd, fderr = pu.pferrs(self.P0, self.P0_ERR,
Expand Down Expand Up @@ -173,8 +175,8 @@ def __init__(self, parfilenm):
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)
setattr(self, 'OM', omega * pc.RADTODEG)
setattr(self, 'T0', self.TASC + self.PB * omega/pc.TWOPI)
if hasattr(self, 'PB') and hasattr(self, 'A1') and not \
(hasattr(self, 'E') or hasattr(self, 'ECC')):
setattr(self, 'E', 0.0)
Expand Down
1 change: 1 addition & 0 deletions python/presto/polycos.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
from builtins import range
from builtins import object
import os
Expand Down
1 change: 1 addition & 0 deletions python/presto/prepfold.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import print_function
from __future__ import absolute_import
from builtins import range
from builtins import object
import numpy as Num
Expand Down
10 changes: 5 additions & 5 deletions python/presto/psr_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@ def calc_phs(MJD, refMJD, *args):
optional freq derivs (f1...) as ordered in the *args
list (e.g. [f0, f1, f2, ...]).
"""
t = (MJD - refMJD) * SECPERDAY
t = (MJD - refMJD) * pc.SECPERDAY
n = len(args) # polynomial order
nargs = Num.concatenate(([0.0], args))
taylor_coeffs = Num.concatenate(([0.0],
Expand All @@ -1042,7 +1042,7 @@ def calc_freq(MJD, refMJD, *args):
optional freq derivs (f1...) as ordered in the *args
list (e.g. [f0, f1, f2, ...]).
"""
t = (MJD - refMJD) * SECPERDAY
t = (MJD - refMJD) * pc.SECPERDAY
n = len(args) # polynomial order
taylor_coeffs = Num.concatenate(([1.0],
Num.cumprod(1.0 / (Num.arange(float(n - 1)) + 1.0))))
Expand All @@ -1058,7 +1058,7 @@ def calc_t0(MJD, refMJD, *args):
"""
phs = calc_phs(MJD, refMJD, *args)
p = 1.0 / calc_freq(MJD, refMJD, *args)
return MJD - phs * p / SECPERDAY
return MJD - phs * p / pc.SECPERDAY


def write_princeton_toa(toa_MJDi, toa_MJDf, toaerr, freq, dm, obs='@', name=' ' * 13):
Expand Down Expand Up @@ -1877,7 +1877,7 @@ def pdot_from_age(p, age):
Return the pdot that a pulsar with spin period 'p' (in sec)
would experience given a characteristic age 'age' (in yrs).
"""
return p / (2.0 * age * SECPERJULYR)
return p / (2.0 * age * pc.SECPERJULYR)


def pdot_from_edot(p, edot, I=1.0e45):
Expand All @@ -1898,7 +1898,7 @@ def pulsar_age(f, fdot, n=3, fo=1e99):
is returned (assuming a braking index 'n'=3 and an initial
spin freqquency fo >> f). But 'n' and 'fo' can be set.
"""
return -f / ((n - 1.0) * fdot) * (1.0 - (f / fo) ** (n - 1.0)) / SECPERJULYR
return -f / ((n - 1.0) * fdot) * (1.0 - (f / fo) ** (n - 1.0)) / pc.SECPERJULYR


def pulsar_edot(f, fdot, I=1.0e45):
Expand Down
1 change: 1 addition & 0 deletions python/presto/rfifind.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import print_function
from __future__ import absolute_import
from builtins import zip
from builtins import range
from builtins import object
Expand Down
1 change: 1 addition & 0 deletions python/presto/sifting.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
from __future__ import print_function
from __future__ import absolute_import
from builtins import zip, str, range, object
from operator import attrgetter
import sys, re, os, copy
Expand Down
1 change: 1 addition & 0 deletions python/presto/sinc_interp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import print_function
from __future__ import absolute_import
import numpy as Num
import numpy.fft as FFT

Expand Down

0 comments on commit 4ec8edf

Please sign in to comment.