summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormdroe <mdroe@stsci.edu>2012-06-04 17:02:28 -0400
committermdroe <mdroe@stsci.edu>2012-06-04 17:02:28 -0400
commitf502335a1a9121eeaa8bd2e06adae49c5408830a (patch)
treed442735fd8b7de3a298a60d93352fe3f200d87d8
parentb6749b81e09abad7944a4af21417e23cd8ad3460 (diff)
downloadstsci.sphere-f502335a1a9121eeaa8bd2e06adae49c5408830a.tar.gz
Python 3.x fixes
git-svn-id: http://svn.stsci.edu/svn/ssb/stsci_python/stsci_python/branches/sphere@17201 fe389314-cf27-0410-b35b-8c050e845b92 Former-commit-id: 645db247912b7d5985ab878bd3c7fb5e9574f05d
-rw-r--r--lib/__init__.py5
-rw-r--r--lib/graph.py5
-rw-r--r--lib/great_circle_arc.py10
-rw-r--r--lib/polygon.py32
-rw-r--r--lib/skyline.py18
-rw-r--r--lib/test/test.py12
-rw-r--r--lib/test/test_intersection.py6
-rw-r--r--lib/test/test_union.py6
-rw-r--r--lib/test/test_util.py2
-rw-r--r--lib/vector.py8
10 files changed, 57 insertions, 47 deletions
diff --git a/lib/__init__.py b/lib/__init__.py
index e69de29..6a03273 100644
--- a/lib/__init__.py
+++ b/lib/__init__.py
@@ -0,0 +1,5 @@
+import sys
+
+if sys.version_info[0] >= 3:
+ # Python 3 compatibility
+ __builtins__['xrange'] = range
diff --git a/lib/graph.py b/lib/graph.py
index 97c12b4..58b918d 100644
--- a/lib/graph.py
+++ b/lib/graph.py
@@ -36,6 +36,7 @@
This contains the code that does the actual unioning of regions.
"""
# TODO: Weak references for memory management problems?
+from __future__ import absolute_import, division, unicode_literals, print_function
# STDLIB
import itertools
@@ -45,8 +46,8 @@ import weakref
import numpy as np
# LOCAL
-from sphere import great_circle_arc
-from sphere import vector
+from . import great_circle_arc
+from . import vector
# Set to True to enable some sanity checks
DEBUG = False
diff --git a/lib/great_circle_arc.py b/lib/great_circle_arc.py
index f70d16e..399cb3d 100644
--- a/lib/great_circle_arc.py
+++ b/lib/great_circle_arc.py
@@ -41,14 +41,14 @@ coincident with the center of the sphere. Great circle arcs are the
section of those circles between two points on the unit sphere.
"""
-from __future__ import with_statement, division, absolute_import
+from __future__ import with_statement, division, absolute_import, unicode_literals
# THIRD-PARTY
import numpy as np
try:
- from sphere import math_util
+ from . import math_util
HAS_C_UFUNCS = True
except ImportError:
HAS_C_UFUNCS = False
@@ -89,7 +89,7 @@ if not HAS_C_UFUNCS:
return TN
def intersection(A, B, C, D):
- ur"""
+ r"""
Returns the point of intersection between two great circle arcs.
The arcs are defined between the points *AB* and *CD*. Either *A*
and *B* or *C* and *D* may be arrays of points, but not both.
@@ -188,7 +188,7 @@ else:
def length(A, B, degrees=True):
- ur"""
+ r"""
Returns the angular distance between two points (in vector space)
on the unit sphere.
@@ -320,7 +320,7 @@ def midpoint(A, B):
def interpolate(A, B, steps=50):
- ur"""
+ r"""
Interpolate along the great circle arc.
Parameters
diff --git a/lib/polygon.py b/lib/polygon.py
index b7ea5d1..80ef131 100644
--- a/lib/polygon.py
+++ b/lib/polygon.py
@@ -36,7 +36,7 @@
The `polygon` module defines the `SphericalPolygon` class for managing
polygons on the unit sphere.
"""
-from __future__ import division, print_function
+from __future__ import division, print_function, unicode_literals, absolute_import
# STDLIB
from copy import copy, deepcopy
@@ -45,14 +45,14 @@ from copy import copy, deepcopy
import numpy as np
# LOCAL
-from sphere import great_circle_arc
-from sphere import vector
+from . import great_circle_arc
+from . import vector
__all__ = ['SphericalPolygon']
class SphericalPolygon(object):
- ur"""
+ r"""
Polygons are represented by both a set of points (in Cartesian
(*x*, *y*, *z*) normalized on the unit sphere), and an inside
point. The inside point is necessary, because both the inside and
@@ -61,7 +61,7 @@ class SphericalPolygon(object):
"""
def __init__(self, points, inside):
- ur"""
+ r"""
Parameters
----------
points : An Nx3 array of (*x*, *y*, *z*) triples in vector space
@@ -111,7 +111,7 @@ class SphericalPolygon(object):
@classmethod
def from_radec(cls, ra, dec, center=None, degrees=True):
- ur"""
+ r"""
Create a new `SphericalPolygon` from a list of (*ra*, *dec*)
points.
@@ -151,7 +151,7 @@ class SphericalPolygon(object):
@classmethod
def from_cone(cls, ra, dec, radius, degrees=True, steps=16.0):
- ur"""
+ r"""
Create a new `SphericalPolygon` from a cone (otherwise known
as a "small circle") defined using (*ra*, *dec*, *radius*).
@@ -211,7 +211,7 @@ class SphericalPolygon(object):
@classmethod
def from_wcs(cls, fitspath, steps=1, crval=None):
- ur"""
+ r"""
Create a new `SphericalPolygon` from the footprint of a FITS
WCS specification.
@@ -273,7 +273,7 @@ class SphericalPolygon(object):
return cls(np.dstack((x, y, z))[0], (xc[0], yc[0], zc[0]))
def contains_point(self, point):
- ur"""
+ r"""
Determines if this `SphericalPolygon` contains a given point.
Parameters
@@ -296,7 +296,7 @@ class SphericalPolygon(object):
return (crossings % 2) == 0
def intersects_poly(self, other):
- ur"""
+ r"""
Determines if this `SphericalPolygon` intersects another
`SphericalPolygon`.
@@ -376,7 +376,7 @@ class SphericalPolygon(object):
return False
def area(self):
- ur"""
+ r"""
Returns the area of the polygon on the unit sphere.
The algorithm is not able to compute the area of polygons
@@ -459,7 +459,7 @@ class SphericalPolygon(object):
For implementation details, see the :mod:`~sphere.graph`
module.
"""
- import graph
+ from . import graph
g = graph.Graph([self, other])
polygon = g.union()
@@ -488,7 +488,7 @@ class SphericalPolygon(object):
for polygon in polygons:
assert isinstance(polygon, SphericalPolygon)
- import graph
+ from . import graph
g = graph.Graph(polygons)
polygon = g.union()
@@ -560,7 +560,7 @@ class SphericalPolygon(object):
# if not self.intersects_poly(other):
# return self.__class__([], [0, 0, 0])
- import graph
+ from . import graph
g = graph.Graph([self, other])
polygon = g.intersection()
@@ -611,7 +611,7 @@ class SphericalPolygon(object):
# if not polyA.intersects_poly(polyB):
# return cls([], [0, 0, 0])
- import graph
+ from . import graph
if method.lower() == 'parallel':
g = graph.Graph(polygons)
@@ -627,7 +627,7 @@ class SphericalPolygon(object):
raise ValueError("method must be 'parallel' or 'serial'")
def overlap(self, other):
- ur"""
+ r"""
Returns the fraction of *self* that is overlapped by *other*.
Let *self* be *a* and *other* be *b*, then the overlap is
diff --git a/lib/skyline.py b/lib/skyline.py
index b77fe49..b6cc73c 100644
--- a/lib/skyline.py
+++ b/lib/skyline.py
@@ -51,7 +51,7 @@ Examples
>>> from sphere import SkyLine
"""
-from __future__ import division, print_function
+from __future__ import division, print_function, absolute_import
# STDLIB
from copy import copy, deepcopy
@@ -61,14 +61,14 @@ import pyfits
from stwcs import wcsutil
# LOCAL
-from sphere.polygon import SphericalPolygon
+from .polygon import SphericalPolygon
__all__ = ['SkyLine']
__version__ = '0.1a'
__vdate__ = '31-May-2012'
class SkyLineMember(object):
-
+
def __init__(self, fname, ext):
"""Container for SkyLine members.
@@ -83,7 +83,7 @@ class SkyLineMember(object):
ext: int
Image extension.
-
+
"""
self._fname = fname
self._ext = ext
@@ -126,7 +126,7 @@ class SkyLine(SphericalPolygon):
"""
# Inherit from SphericalPolygon
SphericalPolygon.__init__(self, [], None)
-
+
# Convert SCI data to SkyLineMember
poly_list = []
with pyfits.open(fname) as pf:
@@ -159,7 +159,7 @@ class SkyLine(SphericalPolygon):
new_members: list
List of SkyLineMember associated with `new_polygon`.
-
+
"""
self._points = new_polygon.points
self._inside = new_polygon.inside
@@ -226,13 +226,13 @@ class SkyLine(SphericalPolygon):
See also
--------
sphere.polygon.SphericalPolygon.union
-
+
"""
out_skyline = copy(self)
# Not using set -- need to keep order
new_members = [m for m in other.members if m not in self.members]
-
+
if len(new_members) > 0:
all_poly = self.multi_union(self.polygons +
[m.polygon for m in new_members])
@@ -264,7 +264,7 @@ class SkyLine(SphericalPolygon):
See also
--------
sphere.polygon.SphericalPolygon.intersection
-
+
"""
pass
diff --git a/lib/test/test.py b/lib/test/test.py
index bceac50..34b5afa 100644
--- a/lib/test/test.py
+++ b/lib/test/test.py
@@ -1,16 +1,18 @@
+from __future__ import absolute_import
+
import os
import random
import numpy as np
from numpy.testing import assert_almost_equal, assert_array_less
-from sphere import graph
-from sphere import great_circle_arc
-from sphere import polygon
-from sphere import vector
+from .. import graph
+from .. import great_circle_arc
+from .. import polygon
+from .. import vector
from .test_util import *
-from test_shared import resolve_imagename
+from .test_shared import resolve_imagename
graph.DEBUG = True
diff --git a/lib/test/test_intersection.py b/lib/test/test_intersection.py
index 12b3ce7..d25ce2e 100644
--- a/lib/test/test_intersection.py
+++ b/lib/test/test_intersection.py
@@ -1,4 +1,4 @@
-from __future__ import print_function
+from __future__ import print_function, absolute_import
# STDLIB
import functools
@@ -13,8 +13,8 @@ import numpy as np
from numpy.testing import assert_array_almost_equal
# LOCAL
-from sphere import polygon
-from test_shared import resolve_imagename
+from .. import polygon
+from .test_shared import resolve_imagename
GRAPH_MODE = False
ROOT_DIR = os.path.join(os.path.dirname(__file__), 'data')
diff --git a/lib/test/test_union.py b/lib/test/test_union.py
index d29eb25..fda91cb 100644
--- a/lib/test/test_union.py
+++ b/lib/test/test_union.py
@@ -1,4 +1,4 @@
-from __future__ import print_function
+from __future__ import print_function, absolute_import
# STDLIB
import functools
@@ -13,8 +13,8 @@ import numpy as np
from numpy.testing import assert_array_almost_equal
# LOCAL
-from sphere import polygon
-from test_shared import resolve_imagename
+from .. import polygon
+from .test_shared import resolve_imagename
GRAPH_MODE = False
ROOT_DIR = os.path.join(os.path.dirname(__file__), 'data')
diff --git a/lib/test/test_util.py b/lib/test/test_util.py
index 47a3444..6dc0393 100644
--- a/lib/test/test_util.py
+++ b/lib/test/test_util.py
@@ -1,7 +1,7 @@
import os
import numpy as np
-from sphere import vector
+from .. import vector
ROOT_DIR = os.path.join(os.path.dirname(__file__), 'data')
diff --git a/lib/vector.py b/lib/vector.py
index 5d26161..c6887c4 100644
--- a/lib/vector.py
+++ b/lib/vector.py
@@ -37,6 +37,8 @@ The `sphere.vector` module contains the basic operations for handling
vectors and converting them to and from other representations.
"""
+from __future__ import unicode_literals
+
# THIRD-PARTY
import numpy as np
@@ -46,7 +48,7 @@ __all__ = ['radec_to_vector', 'vector_to_radec', 'normalize_vector',
def radec_to_vector(ra, dec, degrees=True):
- ur"""
+ r"""
Converts a location on the unit sphere from right-ascension and
declination to an *x*, *y*, *z* vector.
@@ -93,7 +95,7 @@ def radec_to_vector(ra, dec, degrees=True):
def vector_to_radec(x, y, z, degrees=True):
- ur"""
+ r"""
Converts a vector to right-ascension and declination.
Parameters
@@ -134,7 +136,7 @@ def vector_to_radec(x, y, z, degrees=True):
def normalize_vector(x, y, z, inplace=False):
- ur"""
+ r"""
Normalizes a vector so it falls on the unit sphere.
*x*, *y*, *z* may be scalars or 1-D arrays