diff --git a/docs/conf.py b/docs/conf.py index 52353df..1909b56 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -40,8 +40,8 @@ master_doc = 'index' # General information about the project. -project = u'PsrPopPy' -copyright = u'2012, S Bates' +project = 'PsrPopPy' +copyright = '2012, S Bates' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the @@ -183,8 +183,8 @@ # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, documentclass [howto/manual]). latex_documents = [ - ('index', 'PsrPopPy.tex', u'PsrPopPy Documentation', - u'S Bates', 'manual'), + ('index', 'PsrPopPy.tex', 'PsrPopPy Documentation', + 'S Bates', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of @@ -213,8 +213,8 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - ('index', 'psrpoppy', u'PsrPopPy Documentation', - [u'S Bates'], 1) + ('index', 'psrpoppy', 'PsrPopPy Documentation', + ['S Bates'], 1) ] # If true, show URL addresses after external links. @@ -227,8 +227,8 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - ('index', 'PsrPopPy', u'PsrPopPy Documentation', - u'S Bates', 'PsrPopPy', 'One line description of project.', + ('index', 'PsrPopPy', 'PsrPopPy Documentation', + 'S Bates', 'PsrPopPy', 'One line description of project.', 'Miscellaneous'), ] diff --git a/examples/ppdot.py b/examples/ppdot.py index 8f48e7a..bf78d95 100755 --- a/examples/ppdot.py +++ b/examples/ppdot.py @@ -1,14 +1,14 @@ #!/usr/bin/python import sys -import cPickle +import pickle import matplotlib.pyplot as plt # open file, read in model filename = sys.argv[1] f = open(filename, 'rb') -pop = cPickle.load(f) +pop = pickle.load(f) f.close() # lists to store p/pdot diff --git a/psrpoppy/dataobj.py b/psrpoppy/dataobj.py index 1ba8d70..8606c50 100644 --- a/psrpoppy/dataobj.py +++ b/psrpoppy/dataobj.py @@ -2,7 +2,7 @@ import os -import cPickle +import pickle class DataObj: @@ -46,13 +46,13 @@ def readfile_return_dataobj(filename): try: f = open(filename, 'rb') except IOError: - print "Could not open file {0}.".format(filename) + print(("Could not open file {0}.".format(filename))) return try: - pop = cPickle.load(f) - except cPickle.UnpicklingError: - print "File {0} could not be unpickled!".format(filename) + pop = pickle.load(f) + except pickle.UnpicklingError: + print(("File {0} could not be unpickled!".format(filename))) return f.close() diff --git a/psrpoppy/dosurvey.py b/psrpoppy/dosurvey.py index 86ca0bb..2f5591b 100755 --- a/psrpoppy/dosurvey.py +++ b/psrpoppy/dosurvey.py @@ -5,13 +5,13 @@ import math import random -import cPickle +import pickle try: # try and import from the current path (for package usage or use as an uninstalled executable) - from population import Population - from pulsar import Pulsar - from survey import Survey + from .population import Population + from .pulsar import Pulsar + from .survey import Survey except: try: # import from the installed package @@ -42,7 +42,7 @@ def loadModel(popfile='populate.model', popmodel=None): or pass in a model from memory (popmodel)""" if popmodel is None: with open(popfile, 'rb') as f: - pop = cPickle.load(f) + pop = pickle.load(f) else: pop = popmodel @@ -97,8 +97,8 @@ def run(pop, # print the population if not nostdout: - print "Running doSurvey on population..." - print pop + print("Running doSurvey on population...") + print(pop) # loop over the surveys we want to run on the pop file surveyPops = [] @@ -106,7 +106,7 @@ def run(pop, s = Survey(surv) s.discoveries = 0 if not nostdout: - print "\nRunning survey {0}".format(surv) + print("\nRunning survey {0}".format(surv)) # create a new population object to store discovered pulsars in survpop = Population() @@ -154,13 +154,13 @@ def run(pop, # report the results if not nostdout: - print "Total pulsars in model = {0}".format(len(pop.population)) - print "Number detected by survey {0} = {1}".format(surv, ndet) - print "Of which are discoveries = {0}".format(s.discoveries) - print "Number too faint = {0}".format(ntf) - print "Number smeared = {0}".format(nsmear) - print "Number out = {0}".format(nout) - print "\n" + print("Total pulsars in model = {0}".format(len(pop.population))) + print("Number detected by survey {0} = {1}".format(surv, ndet)) + print("Of which are discoveries = {0}".format(s.discoveries)) + print("Number too faint = {0}".format(ntf)) + print("Number smeared = {0}".format(nsmear)) + print("Number out = {0}".format(nout)) + print("\n") d = Detections(ndet=ndet, ntf=ntf, diff --git a/psrpoppy/evolve.py b/psrpoppy/evolve.py index 8963747..0efa44a 100755 --- a/psrpoppy/evolve.py +++ b/psrpoppy/evolve.py @@ -6,22 +6,22 @@ import random import inspect -import cPickle +import pickle import scipy.integrate import numpy as np try: # try and import from the current path (for package usage or use as an uninstalled executable) - import distributions as dists - import galacticops as go - import beaming as beammodels - import populate + from . import distributions as dists + from . import galacticops as go + from . import beaming as beammodels + from . import populate - from population import Population - from pulsar import Pulsar - from survey import Survey + from .population import Population + from .pulsar import Pulsar + from .survey import Survey - from progressbar import ProgressBar + from .progressbar import ProgressBar except: try: # import from the installed package @@ -109,30 +109,30 @@ def generate(ngen, pop.zscale = zscale if widthModel == 'kj07': - print "\tLoading KJ07 models...." + print("\tLoading KJ07 models....") kj_p_vals, kj_pdot_vals, kj_dists = beammodels.load_kj2007_models() - print "\tDone\n" + print("\tDone\n") if not nostdout: - print "\tGenerating evolved pulsars with parameters:" - print "\t\tngen = {0}".format(ngen) - print "\t\tUsing electron distn model {0}".format( - pop.electronModel) - print "\n\t\tPeriod mean, sigma = {0}, {1}".format( + print("\tGenerating evolved pulsars with parameters:") + print("\t\tngen = {0}".format(ngen)) + print("\t\tUsing electron distn model {0}".format( + pop.electronModel)) + print("\n\t\tPeriod mean, sigma = {0}, {1}".format( pop.pmean, - pop.psigma) - print "\t\tLuminosity mean, sigma = {0}, {1}".format( + pop.psigma)) + print("\t\tLuminosity mean, sigma = {0}, {1}".format( pop.lummean, - pop.lumsigma) - print "\t\tSpectral index mean, sigma = {0}, {1}".format( + pop.lumsigma)) + print("\t\tSpectral index mean, sigma = {0}, {1}".format( pop.simean, - pop.sisigma) - print "\t\tGalactic z scale height = {0} kpc".format( - pop.zscale) + pop.sisigma)) + print("\t\tGalactic z scale height = {0} kpc".format( + pop.zscale)) if widthModel is None: - print "\t\tWidth {0}% ".format(duty) + print("\t\tWidth {0}% ".format(duty)) else: - print "\t\tUsing Karastergiou & Johnston beam width model" + print("\t\tUsing Karastergiou & Johnston beam width model") # set up progress bar for fun :) prog = ProgressBar(min_value=0, @@ -233,7 +233,7 @@ def generate(ngen, """ else: - print "Undefined width model!" + print("Undefined width model!") sys.exit() # print width # print pulsar.period, width, pulsar.pdot @@ -343,7 +343,7 @@ def generate(ngen, # update the counter if not nostdout: prog.increment_amount() - print prog, '\r', + print(prog, '\r', end=' ') sys.stdout.flush() else: @@ -353,7 +353,7 @@ def generate(ngen, # update the counter if not nostdout: prog.increment_amount() - print prog, '\r', + print(prog, '\r', end=' ') sys.stdout.flush() # pulsar isn't dead, add to population! @@ -367,20 +367,20 @@ def generate(ngen, # update the counter if not nostdout: prog.increment_amount() - print prog, '\r', + print(prog, '\r', end=' ') sys.stdout.flush() if not nostdout: - print "\n\n" - print " Total pulsars = {0}".format(len(pop.population)) - print " Total detected = {0}".format(pop.ndet) + print("\n\n") + print(" Total pulsars = {0}".format(len(pop.population))) + print(" Total detected = {0}".format(pop.ndet)) for surv in surveys: - print "\n Results for survey '{0}'".format(surv.surveyName) - print " Number detected = {0}".format(surv.ndet) - print " Number too faint = {0}".format(surv.ntf) - print " Number smeared = {0}".format(surv.nsmear) - print " Number outside survey area = {0}".format(surv.nout) + print("\n Results for survey '{0}'".format(surv.surveyName)) + print(" Number detected = {0}".format(surv.ndet)) + print(" Number too faint = {0}".format(surv.ntf)) + print(" Number smeared = {0}".format(surv.nsmear)) + print(" Number outside survey area = {0}".format(surv.nout)) # save list of arguments into the pop try: diff --git a/psrpoppy/galacticops.py b/psrpoppy/galacticops.py index b5d775f..cb16f36 100755 --- a/psrpoppy/galacticops.py +++ b/psrpoppy/galacticops.py @@ -62,8 +62,9 @@ def vxyz(pulsar): pulsar.vz = vz.value -def calc_dtrue((x, y, z)): +def calc_dtrue(xxx_todo_changeme): """Calculate true distance to pulsar from the sun.""" + (x, y, z) = xxx_todo_changeme rsun = 8.5 # kpc return math.sqrt(x*x + (y-rsun)*(y-rsun) + z*z) @@ -198,8 +199,9 @@ def radec_to_lb(ra, dec): return l.value, b.value -def xyz_to_lb((x, y, z)): +def xyz_to_lb(xxx_todo_changeme1): """ Convert galactic xyz in kpc to l and b in degrees.""" + (x, y, z) = xxx_todo_changeme1 rsun = 8.5 # kpc # distance to pulsar diff --git a/psrpoppy/orbitalparams.py b/psrpoppy/orbitalparams.py index 70210b1..9780cbf 100644 --- a/psrpoppy/orbitalparams.py +++ b/psrpoppy/orbitalparams.py @@ -17,10 +17,10 @@ def test_1802_2124(pulsar): pulsar.inclination_degrees = 78.52 pulsar.pulsar_mass_msolar = 1.24 - print pulsar.gb, pulsar.gl + print((pulsar.gb, pulsar.gl)) pulsar.gb = 0.61 pulsar.gl = 4.38 - print pulsar.gb, pulsar.gl + print((pulsar.gb, pulsar.gl)) pulsar.galcoords = (0.49, 5.2, 0.04) pulsar.lum_1400 = 8.54 pulsar.t_scatter = 0.0 diff --git a/psrpoppy/populate.py b/psrpoppy/populate.py index 8f4285d..a0c98db 100755 --- a/psrpoppy/populate.py +++ b/psrpoppy/populate.py @@ -6,19 +6,19 @@ import random import inspect -import cPickle +import pickle try: # try and import from the current path (for package usage or use as an uninstalled executable) - import distributions as dists - import galacticops as go - import orbitalparams + from . import distributions as dists + from . import galacticops as go + from . import orbitalparams - from population import Population - from pulsar import Pulsar - from survey import Survey + from .population import Population + from .pulsar import Pulsar + from .survey import Survey - from progressbar import ProgressBar + from .progressbar import ProgressBar except: try: # import from the installed package @@ -84,23 +84,23 @@ def generate(ngen, # check that the distribution types are supported.... if lumDistType not in ['lnorm', 'pow']: - print "Unsupported luminosity distribution: {0}".format(lumDistType) + print("Unsupported luminosity distribution: {0}".format(lumDistType)) if pDistType not in ['lnorm', 'norm', 'cc97', 'lorimer12']: - print "Unsupported period distribution: {0}".format(pDistType) + print("Unsupported period distribution: {0}".format(pDistType)) if radialDistType not in ['lfl06', 'yk04', 'isotropic', 'slab', 'disk', 'gauss']: - print "Unsupported radial distribution: {0}".format(radialDistType) + print("Unsupported radial distribution: {0}".format(radialDistType)) if electronModel not in ['ne2001', 'lmt85']: - print "Unsupported electron model: {0}".format(electronModel) + print("Unsupported electron model: {0}".format(electronModel)) if pattern not in ['gaussian', 'airy']: - print "Unsupported gain pattern: {0}".format(pattern) + print("Unsupported gain pattern: {0}".format(pattern)) if duty_percent < 0.: - print "Unsupported value of duty cycle: {0}".format(duty_percent) + print("Unsupported value of duty cycle: {0}".format(duty_percent)) # need to use properties in this class so they're get/set-type props pop.pDistType = pDistType @@ -137,7 +137,7 @@ def generate(ngen, pass if not nostdout: - print "\tGenerating pulsars with parameters:" + print("\tGenerating pulsars with parameters:") param_string_list = [] for key, value in key_values: s = ": ".join([key, str(value)]) @@ -145,7 +145,7 @@ def generate(ngen, # join this list of strings, and print it s = "\n\t\t".join(param_string_list) - print "\t\t{0}".format(s) + print("\t\t{0}".format(s)) # set up progress bar for fun :) prog = ProgressBar(min_value=0, @@ -182,7 +182,7 @@ def generate(ngen, elif pop.pDistType == 'cc97': p.period = _cc97() elif pop.pDistType == 'gamma': - print "Gamma function not yet supported" + print("Gamma function not yet supported") sys.exit() elif pop.pDistType == 'lorimer12': p.period = _lorimer2012_msp_periods() @@ -293,7 +293,7 @@ def generate(ngen, # add in orbital parameters if orbits: orbitalparams.test_1802_2124(p) - print p.gb, p.gl + print(p.gb, p.gl) # if no surveys, just generate ngen pulsars if surveyList is None: @@ -301,7 +301,7 @@ def generate(ngen, pop.ndet += 1 if not nostdout: prog.increment_amount() - print prog, '\r', + print(prog, '\r', end=' ') sys.stdout.flush() # if surveys are given, check if pulsar detected or not # in ANY of the surveys @@ -345,22 +345,22 @@ def generate(ngen, pop.ndet += 1 if not nostdout: prog.increment_amount() - print prog, '\r', + print(prog, '\r', end=' ') sys.stdout.flush() # print info to stdout if not nostdout: - print "\n" - print " Total pulsars = {0}".format(len(pop.population)) - print " Total detected = {0}".format(pop.ndet) + print("\n") + print(" Total pulsars = {0}".format(len(pop.population))) + print(" Total detected = {0}".format(pop.ndet)) # print " Number not beaming = {0}".format(surv.nnb) for surv in surveys: - print "\n Results for survey '{0}'".format(surv.surveyName) - print " Number detected = {0}".format(surv.ndet) - print " Number too faint = {0}".format(surv.ntf) - print " Number smeared = {0}".format(surv.nsmear) - print " Number outside survey area = {0}".format(surv.nout) + print("\n Results for survey '{0}'".format(surv.surveyName)) + print(" Number detected = {0}".format(surv.ndet)) + print(" Number too faint = {0}".format(surv.ntf)) + print(" Number smeared = {0}".format(surv.nsmear)) + print(" Number outside survey area = {0}".format(surv.nout)) return pop diff --git a/psrpoppy/population.py b/psrpoppy/population.py index ef28306..56d7b5c 100755 --- a/psrpoppy/population.py +++ b/psrpoppy/population.py @@ -1,7 +1,7 @@ #!/usr/bin/python import copy -import cPickle +import pickle import numpy as np @@ -68,7 +68,7 @@ def __str__(self): s = "Population model:" try: - for key, value in self.arguments.iteritems(): + for key, value in self.arguments.items(): s = '\n\t'.join([s, "{0} = {1}".format(key, value)]) except AttributeError: # handle old-fashioned models without self.arguments @@ -102,7 +102,7 @@ def write(self, outf): """Write the population object to a file""" output = open(outf, 'wb') - cPickle.dump(self, output, 2) + pickle.dump(self, output, 2) output.close() def write_asc(self, outf): diff --git a/psrpoppy/progressbar.py b/psrpoppy/progressbar.py index c5dc54c..7869b4a 100644 --- a/psrpoppy/progressbar.py +++ b/psrpoppy/progressbar.py @@ -95,29 +95,29 @@ def __str__(self): def main(): - print + print() limit = 1000000 - print 'Example 1: Fixed Bar' + print('Example 1: Fixed Bar') prog = ProgressBar(0, limit, 77, mode='fixed') oldprog = str(prog) - for i in xrange(limit+1): + for i in range(limit+1): prog.update_amount(i) if oldprog != str(prog): - print prog, "\r", + print(prog, "\r", end=' ') sys.stdout.flush() oldprog = str(prog) - print '\n\n' + print('\n\n') - print 'Example 2: Dynamic Bar' + print('Example 2: Dynamic Bar') prog = ProgressBar(0, limit, 77, mode='dynamic', char='-') oldprog = str(prog) - for i in xrange(limit+1): + for i in range(limit+1): prog.increment_amount() if oldprog != str(prog): - print prog, "\r", + print(prog, "\r", end=' ') sys.stdout.flush() oldprog = str(prog) - print '\n\n' + print('\n\n') diff --git a/psrpoppy/pulsar.py b/psrpoppy/pulsar.py index f40cd48..af646af 100644 --- a/psrpoppy/pulsar.py +++ b/psrpoppy/pulsar.py @@ -3,8 +3,8 @@ import math import random -from orbit import Orbit -import galacticops as go +from .orbit import Orbit +from . import galacticops as go class PulsarException(Exception): diff --git a/psrpoppy/survey.py b/psrpoppy/survey.py index ab09d73..94fd7d2 100755 --- a/psrpoppy/survey.py +++ b/psrpoppy/survey.py @@ -8,10 +8,10 @@ import random from scipy.special import j1 -import galacticops as go -from population import Population -import radiometer as rad -import degradation +from . import galacticops as go +from .population import Population +from . import radiometer as rad +from . import degradation class SurveyException(Exception): @@ -274,7 +274,7 @@ def __init__(self, surveyName, pattern='gaussian'): # turn on AA self.AA = True else: - print "Parameter '", a[1].strip(), "' not recognized!" + print("Parameter '", a[1].strip(), "' not recognized!") f.close() @@ -455,37 +455,37 @@ def SNRcalc(self, if pulsar.is_binary: # print "the pulsar is a binary!" if jerksearch: - print "jerk" + print("jerk") gamma = degradation.gamma3(pulsar, self.tobs, 1) elif accelsearch: - print "accel" + print("accel") gamma = degradation.gamma2(pulsar, self.tobs, 1) else: - print "norm" + print("norm") gamma = degradation.gamma1(pulsar, self.tobs, 1) - print "gamma harm1 = ", gamma + print("gamma harm1 = ", gamma) gamma = degradation.gamma1(pulsar, self.tobs, 2) - print "gamma harm2 = ", gamma + print("gamma harm2 = ", gamma) gamma = degradation.gamma1(pulsar, self.tobs, 3) - print "gamma harm3 = ", gamma + print("gamma harm3 = ", gamma) gamma = degradation.gamma1(pulsar, self.tobs, 4) - print "gamma harm4 = ", gamma + print("gamma harm4 = ", gamma) # return the S/N accounting for beam offset return sig_to_noise * degfac