Skip to content

Commit

Permalink
Update to Python3
Browse files Browse the repository at this point in the history
  • Loading branch information
obscode committed Jan 13, 2019
1 parent fc37057 commit 32cca35
Show file tree
Hide file tree
Showing 68 changed files with 1,015 additions and 1,051 deletions.
2 changes: 1 addition & 1 deletion depricated/lib/Eric/dat2fits.py
Expand Up @@ -35,7 +35,7 @@
of = FITS.FITS(outfile, create=1)
of.newhead("T", -32, 2, [nx,ny])
of.putdata(flux)
print 1, x0, dx, 1, y0, dy
print(1, x0, dx, 1, y0, dy)
of.inskey("NAXIS2","CRPIX1",1)
of.inskey("CRPIX1","CRVAL1",x0)
of.inskey("CRVAL1","CDELT1",dx)
Expand Down
26 changes: 13 additions & 13 deletions depricated/plot_sne_pg.py
Expand Up @@ -48,8 +48,8 @@ def plot_filters(self, bands=None, day=0):
p.z = self.z

# Next, for each filter, plot the response and rest band closest to it:
if bands is None: bands = self.data.keys()
if type(bands) is types.StringType:
if bands is None: bands = list(self.data.keys())
if type(bands) is bytes:
bands = [bands]

for band in bands:
Expand Down Expand Up @@ -126,7 +126,7 @@ def plot_sn(self, xrange=None, yrange=None, device=None,
if self.filter_order is not None:
bands = self.filter_order
else:
bands = self.data.keys()
bands = list(self.data.keys())
if not single:
eff_wavs = []
for filter in bands:
Expand Down Expand Up @@ -405,17 +405,17 @@ def add_knot(x, y, key, inst):
'''Add a knot point to the spline. This is called through the interactive interface).'''
self = inst.lc_inst
if self.model_type is None or self.model_type != 'spline':
print "Adding knots not supported for this model"
print("Adding knots not supported for this model")
return
x,y = lc_data_conv(inst, x, y)
if x <= self.tck[0][0] or x >= self.tck[0][-1]:
print "Error, can't add knots outside the current range."
print("Error, can't add knots outside the current range.")
old_knots = self.tck[0]
print old_knots
print(old_knots)
knots = concatenate([[x],self.tck[0]])
knots = sort(knots)
self.tck = (knots, self.tck[1], self.tck[2])
print knots
print(knots)
try:
update_plot(self, task=-1)
except:
Expand All @@ -426,7 +426,7 @@ def move_knot(x, y, key, inst):
'''Move the point closest to x to a new location.'''
self = inst.lc_inst
if self.model_type is None or self.model_type != 'spline':
print "Moving knots not supported for this model"
print("Moving knots not supported for this model")
return
x,y = lc_data_conv(inst, x, y)
old_knots = self.tck[0]
Expand All @@ -443,7 +443,7 @@ def move_knot(x, y, key, inst):
def delete_knot(x, y, key, inst):
self = inst.lc_inst
if self.model_type is None or self.model_type != 'spline':
print "Deleting knots not supported for this model"
print("Deleting knots not supported for this model")
return
x,y = lc_data_conv(inst, x, y)
old_knots = self.tck[0]
Expand All @@ -461,7 +461,7 @@ def delete_knot(x, y, key, inst):
def change_s(x, y, key, inst):
self = inst.lc_inst
if self.model_type is None or self.model_type != 'spline':
print "Changing s not supported for this model"
print("Changing s not supported for this model")
return
if self.tck is not None:
if key == 's':
Expand Down Expand Up @@ -678,7 +678,7 @@ def plot_lc(self, device='/XSERVE', interactive=0, epoch=1, flux=0, gloes=0,
def plot_kcorrs(self, device='13/XW', colors=None, symbols=None):
'''Plot the k-corrections, both mangled and un-mangled.'''
# See what filters we're going to use:
bands = self.ks.keys()
bands = list(self.ks.keys())
if len(bands) == 0:
return

Expand Down Expand Up @@ -708,8 +708,8 @@ def plot_kcorrs(self, device='13/XW', colors=None, symbols=None):
x = self.data[b].MJD - self.Tmax
days = arange(int(x[0]), int(x[-1]), 1)
rest_days = days/(1+self.z)/self.ks_s
k,k_m = map(array, kcorr.kcorr(rest_days.tolist(), self.restbands[b], b,
self.z, self.EBVgal, 0.0, version=self.k_version))
k,k_m = list(map(array, kcorr.kcorr(rest_days.tolist(), self.restbands[b], b,
self.z, self.EBVgal, 0.0, version=self.k_version)))
k_m = equal(k_m, 1)
pp = pygplot.Plot(fsize=1, font=2, xlabel='Epoch (days)',
leftpad=0.1, rotylab=1, xrange=[minx,maxx])
Expand Down
8 changes: 4 additions & 4 deletions depricated/snMCMC.py
Expand Up @@ -15,15 +15,15 @@ def __init__(self, snobj, filters=None, inc_var=False, **args):

self.sn = snobj
if filters is None:
filters = self.sn.data.keys()
filters = list(self.sn.data.keys())


self.model = snobj.model
self.model.args = {}
self.model._fbands = filters
self.model.setup()
params = []
paramnames = self.model.parameters.keys()
paramnames = list(self.model.parameters.keys())
# First, setup stochastics for our parameters
for param in paramnames:
if param in args:
Expand All @@ -45,7 +45,7 @@ def __init__(self, snobj, filters=None, inc_var=False, **args):
elif param.find('max') > 0:
params.append(pymc.Uniform(str(param), 10., 30.))
else:
raise AttributeError, "Error, parameter %s not recognized. Update MCMC package" % (param)
raise AttributeError("Error, parameter %s not recognized. Update MCMC package" % (param))
if self.model.parameters[param] is None:
params[-1].value = self.model.guess(param)
else:
Expand All @@ -67,7 +67,7 @@ def model(params=params, vars=vars, paramnames=paramnames, filters=filters,
# Set the parameters in the model
for i,param in enumerate(paramnames):
if debug:
print "setting ",param, " to ",params[i]
print("setting ",param, " to ",params[i])
self.model.parameters[param] = params[i]

logp = 0
Expand Down
16 changes: 8 additions & 8 deletions docs/conf.py
Expand Up @@ -47,8 +47,8 @@
master_doc = 'index'

# General information about the project.
project = u'SNooPy'
copyright = u'2015, Chris Burns'
project = 'SNooPy'
copyright = '2015, Chris Burns'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -200,8 +200,8 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
('index', 'SNooPy.tex', u'SNooPy Documentation',
u'Chris Burns', 'manual'),
('index', 'SNooPy.tex', 'SNooPy Documentation',
'Chris Burns', 'manual'),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -230,8 +230,8 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'snoopy', u'SNooPy Documentation',
[u'Chris Burns'], 1)
('index', 'snoopy', 'SNooPy Documentation',
['Chris Burns'], 1)
]

# If true, show URL addresses after external links.
Expand All @@ -244,8 +244,8 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'SNooPy', u'SNooPy Documentation',
u'Chris Burns', 'SNooPy', 'One line description of project.',
('index', 'SNooPy', 'SNooPy Documentation',
'Chris Burns', 'SNooPy', 'One line description of project.',
'Miscellaneous'),
]

Expand Down
6 changes: 3 additions & 3 deletions get_swift.py
@@ -1,7 +1,7 @@
'''
Module for SNooPy to download/parse data from the Open Supernova Catalog.
'''
import urllib
import urllib.request, urllib.parse, urllib.error
from snpy import lc
from numpy import array

Expand All @@ -10,9 +10,9 @@
def load_lcs(obj):

try:
u = urllib.urlopen(SWIFT_URL.format(obj.name))
u = urllib.request.urlopen(SWIFT_URL.format(obj.name))
except:
raise ValueError, "Object not found in SWIFT database"
raise ValueError("Object not found in SWIFT database")

lines = u.readlines()
lines = [line.strip().split() for line in lines if line[0] != '#']
Expand Down
54 changes: 27 additions & 27 deletions setup_CSP.py
Expand Up @@ -28,20 +28,20 @@
def get_package(package, url, setup=1, test=1, verbose=1, options=''):
'''Retrieve a python package from the source url, unpack it,
and install it'''
from urllib import urlopen
from urllib.request import urlopen
import tarfile
from StringIO import StringIO
from io import StringIO
import tempfile

if verbose: print "Downloading %s..." % (package)
if verbose: print("Downloading %s..." % (package))
u = urlopen(url)
t = StringIO(u.read())
if not setup:
f = open(os.path.basename(url),'w')
f.write(u.read())
return 1,"Package saved as %s" % (os.path.basename(url))

if verbose: print "Extracting..."
if verbose: print("Extracting...")
# extract the package and run the old python setup install
try:
tar = tarfile.open('blah',fileobj=t)
Expand All @@ -59,15 +59,15 @@ def get_package(package, url, setup=1, test=1, verbose=1, options=''):
os.chdir(os.path.join(tmp,files[0]))

if verbose:
print "Running python setup.py install %s (this may take a while)..." %\
(options)
print("Running python setup.py install %s (this may take a while)..." %\
(options))
logfile = os.path.join(cwd, package+".log")
res = os.system('%s setup.py install %s > %s 2> %s' % \
(sys.executable, options, logfile, logfile))
if res != 0:
return 0,"Sorry, package %s failed to install, see %s.log" % (package,package)
os.chdir(cwd)
if verbose: print "Cleaning up..."
if verbose: print("Cleaning up...")
os.system('rm -rf %s' % tmp)

if not test:
Expand Down Expand Up @@ -103,21 +103,21 @@ def configuration(parent_package='', top_path=None):
try:
from numpy.distutils.core import setup
except ImportError:
print "You don't have numpy installed. Would you like me to try to"
print "install it? (y/n)"
print("You don't have numpy installed. Would you like me to try to")
print("install it? (y/n)")
answer = ""
while answer != 'n' and answer != 'y':
answer = raw_input()
answer = input()
if answer == 'n':
print "Okay, but you'll need to install Numpy before installing SNPY"
print("Okay, but you'll need to install Numpy before installing SNPY")
sys.exit(1)

# So, at this point, we're going to try to install numpy:
flag,mesg = get_package('numpy',
'http://sourceforge.net/projects/numpy/files/NumPy/1.2.1/numpy-1.2.1.tar.gz/download',
options=extra_options)
if flag != 1:
print mesg
print(mesg)
sys.exit(1)
from numpy.distutils.core import setup
from numpy.distutils.misc_util import Configuration
Expand All @@ -137,40 +137,40 @@ def configuration(parent_package='', top_path=None):
pass


print "Package %s does not appear to be installed. Would you" % \
(package)
print "like me to install it now? (y/n)"
print("Package %s does not appear to be installed. Would you" % \
(package))
print("like me to install it now? (y/n)")
answer = ""
while answer != 'y' and answer != 'n':
answer = raw_input()
answer = input()
if answer == 'n':
print "Okay, but you'll need to install %s before installing SNPY"\
% (package)
print "You can find it here:"
print url
print("Okay, but you'll need to install %s before installing SNPY"\
% (package))
print("You can find it here:")
print(url)
sys.exit(1)

flag,mesg = get_package(package, url, options=extra_options)
if flag != 1:
print mesg
print(mesg)
sys.exit(1)
print mesg
print(mesg)

# Now, see if optional packages are there
for package,url in optional_packages:
try:
res = __import__(package)
except ImportError:
print "Package %s is does not appear to be installed. It is optional" %\
(package)
print "Would you like me to try installing it now? (y/n)"
print("Package %s is does not appear to be installed. It is optional" %\
(package))
print("Would you like me to try installing it now? (y/n)")
answer = ""
while answer != 'y' and answer != 'n':
answer = raw_input()
answer = input()
if answer == 'n':
continue
flag,mesg = get_package(package, url, options=extra_options)
print mesg
print(mesg)
setup(version='0.5.0',
author='Chris Burns (Carnegie Observatories)',
author_email='cburns@ociw.edu',
Expand Down

0 comments on commit 32cca35

Please sign in to comment.