Skip to content

Commit

Permalink
futurize -2 pass, plus cleanups.
Browse files Browse the repository at this point in the history
  • Loading branch information
parejkoj committed Sep 14, 2016
1 parent ca5f186 commit 9ffdf73
Show file tree
Hide file tree
Showing 31 changed files with 81 additions and 37 deletions.
2 changes: 1 addition & 1 deletion convertToFitsTable.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def main(inputName, outputName):
record.set(centroidKey.getY(), float(y))
record.set(psfFluxKey, float(cts))
flags = int(flags)
for oldName, mask in oldFlags.iteritems():
for oldName, mask in oldFlags.items():
if oldName == "BINNED1":
continue
if mask & flags:
Expand Down
5 changes: 3 additions & 2 deletions examples/getSourceSet.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import print_function
from builtins import range
#
# LSST Data Management System
# Copyright 2008, 2009, 2010 LSST Corporation.
Expand Down Expand Up @@ -354,8 +355,8 @@ def writeSourceSet(sourceSet, outfile="-"):
fd = open(outfile, "w")

for s in sourceSet:
print(s.getId(), s.getXAstrom(), s.getYAstrom(), s.getRa(
), s.getDec(), s.getPsfFlux(), s.getFlagForDetection(), file=fd)
print(s.getId(), s.getXAstrom(), s.getYAstrom(), s.getRa(), s.getDec(),
s.getPsfFlux(), s.getFlagForDetection(), file=fd)


def readSourceSet(fileName):
Expand Down
1 change: 1 addition & 0 deletions examples/lsstplots.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python

from __future__ import print_function
from builtins import range
from optparse import OptionParser
import sys
import os
Expand Down
1 change: 1 addition & 0 deletions examples/plotshift.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#! /usr/bin/env python

from __future__ import print_function
from builtins import range
import sys
from optparse import OptionParser

Expand Down
1 change: 1 addition & 0 deletions examples/queryReferenceCatalog.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import print_function
from builtins import zip
import sys

import lsst.pex.policy as policy
Expand Down
1 change: 1 addition & 0 deletions examples/ticket2710.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import print_function
from builtins import zip
import matplotlib
matplotlib.use('Agg')
import pylab as plt
Expand Down
7 changes: 5 additions & 2 deletions examples/wcsPlots.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from __future__ import print_function
from future import standard_library
standard_library.install_aliases()
from builtins import range
import matplotlib
matplotlib.use('Agg')
from matplotlib.font_manager import FontProperties
Expand All @@ -17,8 +20,8 @@


def _getplotdata(format='png'):
import cStringIO
io = cStringIO.StringIO()
import io
io = io.StringIO()
plt.savefig(io, format=format)
val = io.getvalue()
io.close()
Expand Down
5 changes: 4 additions & 1 deletion python/lsst/meas/astrom/anetAstrometry.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from __future__ import print_function
from builtins import input
from builtins import zip
from builtins import range
#
# LSST Data Management System
# Copyright 2008-2016 AURA/LSST.
Expand Down Expand Up @@ -531,7 +534,7 @@ def showAstrometry(exposure, wcs, allMatches, useMatches, frame=0, title=None, p
import sys
while True:
try:
reply = raw_input("Debugging? [p]db [q]uit; any other key to continue... ").strip()
reply = input("Debugging? [p]db [q]uit; any other key to continue... ").strip()
except EOFError:
reply = ""

Expand Down
7 changes: 6 additions & 1 deletion python/lsst/meas/astrom/anetBasicAstrometry.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
from __future__ import absolute_import, division
from __future__ import print_function
from builtins import zip
from builtins import next
from builtins import input
from builtins import range
from builtins import object
#
# LSST Data Management System
#
Expand Down Expand Up @@ -765,7 +770,7 @@ def plotNext(x, y, xLabel, yLabel, xMax):

while True:
try:
reply = raw_input("Pausing for inspection, enter to continue... [hpQ] ").strip()
reply = input("Pausing for inspection, enter to continue... [hpQ] ").strip()
except EOFError:
reply = "n"

Expand Down
2 changes: 2 additions & 0 deletions python/lsst/meas/astrom/approximateWcs.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from builtins import range
from builtins import object
#
# LSST Data Management System
# Copyright 2008, 2009, 2010 LSST Corporation.
Expand Down
1 change: 1 addition & 0 deletions python/lsst/meas/astrom/astrometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# see <https://www.lsstcorp.org/LegalNotices/>.
#
from __future__ import absolute_import, division, print_function
from builtins import range

from lsst.afw.image.utils import getDistortedWcs
import lsst.afw.geom as afwGeom
Expand Down
2 changes: 2 additions & 0 deletions python/lsst/meas/astrom/astrometryNetDataConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
mechanism, but we need nested lists, so we do this home-brew version
instead.
'''
from past.builtins import execfile
from builtins import object


def _checkMagMap(magmap):
Expand Down
4 changes: 3 additions & 1 deletion python/lsst/meas/astrom/catalogStarSelector.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from builtins import input
from builtins import object
#
# LSST Data Management System
# Copyright 2008, 2009, 2010 LSST Corporation.
Expand Down Expand Up @@ -181,7 +183,7 @@ def selectStars(self, exposure, sourceCat, matches=None):
size=4, frame=frame, ctype=ctype)

if display and pauseAtEnd:
raw_input("Continue? y[es] p[db] ")
input("Continue? y[es] p[db] ")

return Struct(
starCat=starCat,
Expand Down
17 changes: 9 additions & 8 deletions python/lsst/meas/astrom/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# see <http://www.lsstcorp.org/LegalNotices/>.
#
from __future__ import absolute_import, division, print_function
from builtins import zip
import math

import numpy as np
Expand Down Expand Up @@ -134,11 +135,11 @@ def plotAstrometry(
srcCentroidKey = Point2DKey(srcSchema["slot_Centroid"])

if refCat is not None:
refXArr, refYArr = zip(*[ref.get(refCentroidKey) for ref in refCat])
refXArr, refYArr = list(zip(*[ref.get(refCentroidKey) for ref in refCat]))
plt.plot(refXArr, refYArr, marker=refMarker, color=refColor, linestyle="")

if sourceCat is not None:
srcXArr, srcYArr = zip(*[src.get(srcCentroidKey) for src in sourceCat])
srcXArr, srcYArr = list(zip(*[src.get(srcCentroidKey) for src in sourceCat]))
plt.plot(srcXArr, srcYArr, marker=sourceMarker, color=sourceColor, linestyle="")

def makeLineSegmentData(refXYArr, srcXYArr, colorArr):
Expand All @@ -156,22 +157,22 @@ def makeLineSegmentData(refXYArr, srcXYArr, colorArr):
raise RuntimeError("len(refXYArr) = %d != %d = len(colorArr)" %
(len(refXYArr), len(colorArr)))

refXArr, refYArr = zip(*refXYArr)
srcXArr, srcYArr = zip(*srcXYArr)
refSrcXArr = zip(refXArr, srcXArr)
refSrcYArr = zip(refYArr, srcYArr)
refXArr, refYArr = list(zip(*refXYArr))
srcXArr, srcYArr = list(zip(*srcXYArr))
refSrcXArr = list(zip(refXArr, srcXArr))
refSrcYArr = list(zip(refYArr, srcYArr))
dataList = []
for xycolor in zip(refSrcXArr, refSrcYArr, colorArr):
for val in xycolor:
dataList.append(val)
return dataList

refXYArr, srcXYArr = \
zip(*[(match[0].get(refCentroidKey), match[1].get(srcCentroidKey)) for match in matches])
list(zip(*[(match[0].get(refCentroidKey), match[1].get(srcCentroidKey)) for match in matches]))

def plotSourceCircles(matches, color):
srcXYArr = [match[1].get(srcCentroidKey) for match in matches]
srcXArr, srcYArr = zip(*srcXYArr)
srcXArr, srcYArr = list(zip(*srcXYArr))
plt.plot(srcXArr, srcYArr, "o", mec=color, mfc="none", ms=10,)

if callable(matchColor):
Expand Down
2 changes: 2 additions & 0 deletions python/lsst/meas/astrom/fitTanSipWcs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from __future__ import absolute_import, division, print_function
from builtins import zip
from builtins import range

import numpy as np

Expand Down
1 change: 1 addition & 0 deletions python/lsst/meas/astrom/loadAstrometryNetObjects.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import absolute_import, division, print_function
from builtins import object

import lsst.pipe.base as pipeBase
from lsst.meas.algorithms import LoadReferenceObjectsTask, getRefFluxField
Expand Down
2 changes: 2 additions & 0 deletions python/lsst/meas/astrom/matchOptimisticB.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from __future__ import absolute_import, division, print_function
from builtins import range
from builtins import object
import math

import numpy as np
Expand Down
5 changes: 4 additions & 1 deletion python/lsst/meas/astrom/multiindex.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from builtins import zip
from builtins import range
from builtins import object
import os

import numpy
Expand Down Expand Up @@ -186,7 +189,7 @@ def __init__(self, andConfig):

def _initFromIndexFiles(self, andConfig):
"""Initialise from the index files in an AstrometryNetDataConfig"""
indexFiles = zip(andConfig.indexFiles, andConfig.indexFiles) + andConfig.multiIndexFiles
indexFiles = list(zip(andConfig.indexFiles, andConfig.indexFiles)) + andConfig.multiIndexFiles
self._multiInds = [MultiIndexCache.fromFilenameList(fnList) for fnList in indexFiles]

def writeCache(self):
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/meas/astrom/sip/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
in an astronomical image"""
from __future__ import absolute_import

from sipLib import *
from .sipLib import *

from . import genDistortedImage
from . import cleanBadPoints
Expand Down
14 changes: 8 additions & 6 deletions python/lsst/meas/astrom/sip/cleanBadPoints.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import absolute_import
from builtins import range
#
# LSST Data Management System
# Copyright 2008, 2009, 2010 LSST Corporation.
Expand Down Expand Up @@ -26,7 +28,7 @@

import lsst.afw.detection as det

import sipLib as sip
from . import sipLib as sip


def clean(srcMatch, wcs, order=3, nsigma=3):
Expand Down Expand Up @@ -73,14 +75,14 @@ def indicesOfGoodPoints(x, y, s, order=1, nsigma=3, maxiter=100):
# Indices of elements of x sorted in order of increasing value
idx = x.argsort()
newidx = []
for niter in xrange(maxiter):
for niter in range(maxiter):
rx = chooseRx(x, idx, order)
ry = chooseRy(y, idx, order)
rs = np.ones((len(rx)))

lsf = sip.LeastSqFitter1dPoly(list(rx), list(ry), list(rs), order)
fit = map(lambda x: lsf.valueAt(x), rx)
f = map(lambda x: lsf.valueAt(x), x)
fit = [lsf.valueAt(value) for value in rx]
f = [lsf.valueAt(value) for value in x]

sigma = (y-f).std()
deviance = np.fabs((y - f) / sigma)
Expand Down Expand Up @@ -112,7 +114,7 @@ def chooseRx(x, idx, order):
rx = np.zeros((order+1))

for i in range(order+1):
rng = range(int(rSize*i), int(rSize*(i+1)))
rng = list(range(int(rSize*i), int(rSize*(i+1))))
rx[i] = np.mean(x[idx[rng]])
return rx

Expand All @@ -123,6 +125,6 @@ def chooseRy(y, idx, order):
ry = np.zeros((order+1))

for i in range(order+1):
rng = range(int(rSize*i), int(rSize*(i+1)))
rng = list(range(int(rSize*i), int(rSize*(i+1))))
ry[i] = np.median(y[idx[rng]])
return ry
1 change: 1 addition & 0 deletions python/lsst/meas/astrom/sip/genDistortedImage.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import print_function
from builtins import range
#
# LSST Data Management System
# Copyright 2008, 2009, 2010 LSST Corporation.
Expand Down
1 change: 1 addition & 0 deletions python/lsst/meas/astrom/verifyWcs.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from builtins import range
#
# LSST Data Management System
# Copyright 2008, 2009, 2010 LSST Corporation.
Expand Down
4 changes: 3 additions & 1 deletion tests/testFitTanSipWcsTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
# discovery to only run tests found in the subclasses.

from __future__ import print_function
from builtins import range
from builtins import object
import math
import unittest

Expand Down Expand Up @@ -301,7 +303,7 @@ def plotWcs(self, tanSipWcs, name=""):
pnum += 1


class SideLoadTestCases():
class SideLoadTestCases(object):

"""Base class implementations of testing methods.
Expand Down
3 changes: 2 additions & 1 deletion tests/testJoinMatchListWithCatalog.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from builtins import range
#!/usr/bin/env python
#
# LSST Data Management System
Expand Down Expand Up @@ -83,7 +84,7 @@ def testJoin(self):
matches2 = self.astrom.refObjLoader.joinMatchListWithCatalog(normalized, self.srcSet)

self.assertEqual(len(matches2), len(matches))
for i in xrange(len(matches)):
for i in range(len(matches)):
self.assertEqual(matches2[i].second.table, matches[i].second.table)
self.assertEqual(matches2[i].second.getId(), matches[i].second.getId())
self.assertEqual(matches2[i].second, matches[i].second) # no deep copying, so we can compare ptrs
Expand Down
5 changes: 3 additions & 2 deletions tests/testLoadAstrometryNetObjects.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
from __future__ import absolute_import, division, print_function
from builtins import zip

#
# LSST Data Management System
Expand Down Expand Up @@ -192,12 +193,12 @@ def plotStars(self, refCat, bbox=None):
if bbox is not None:
cornerList = list(afwGeom.Box2D(bbox).getCorners())
cornerList.append(cornerList[0]) # show 4 sides of the box by going back to the beginning
xc, yc = zip(*cornerList)
xc, yc = list(zip(*cornerList))
pyplot.plot(xc, yc, '-')

centroidKey = refCat.schema["centroid"].asKey()
centroidList = [rec.get(centroidKey) for rec in refCat]
xp, yp = zip(*centroidList)
xp, yp = list(zip(*centroidList))
pyplot.plot(xp, yp, '.')
pyplot.show()

Expand Down
1 change: 1 addition & 0 deletions tests/testLsf1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#

from __future__ import print_function
from builtins import range
import unittest

import lsst.utils.tests
Expand Down
1 change: 1 addition & 0 deletions tests/testLsf2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#

from __future__ import print_function
from builtins import range
import unittest

import lsst.utils.tests
Expand Down

0 comments on commit 9ffdf73

Please sign in to comment.