diff options
author | mdroe <mdroe@stsci.edu> | 2014-06-13 18:04:04 -0400 |
---|---|---|
committer | mdroe <mdroe@stsci.edu> | 2014-06-13 18:04:04 -0400 |
commit | e0211e21f3db0bb27a04490d712dabe04c0fed26 (patch) | |
tree | c48efb390b1baabb99ee349b2980d38b3e7f5bb6 /stsci/sphere/polygon.py | |
parent | 99b3bdc918d81c78ed1583804bcfa0d42f123667 (diff) | |
download | stsci.sphere-e0211e21f3db0bb27a04490d712dabe04c0fed26.tar.gz |
More speedups.
git-svn-id: http://svn.stsci.edu/svn/ssb/stsci_python/stsci.sphere/trunk@32541 fe389314-cf27-0410-b35b-8c050e845b92
Former-commit-id: 36e70c1cac043d59089f386a6b6d730c4887fa84
Diffstat (limited to 'stsci/sphere/polygon.py')
-rw-r--r-- | stsci/sphere/polygon.py | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/stsci/sphere/polygon.py b/stsci/sphere/polygon.py index f7c44be..5167171 100644 --- a/stsci/sphere/polygon.py +++ b/stsci/sphere/polygon.py @@ -168,11 +168,11 @@ class SphericalPolygon(object): # Convert to Cartesian x, y, z = vector.radec_to_vector(ra, dec, degrees=degrees) + points = np.dstack((x, y, z))[0] + if center is None: - xc = x.mean() - yc = y.mean() - zc = z.mean() - center = vector.normalize_vector(xc, yc, zc) + center = points.mean(axis=0) + vector.normalize_vector(center, output=center) else: center = vector.radec_to_vector(*center, degrees=degrees) @@ -556,24 +556,21 @@ class SphericalPolygon(object): # Rotate polygon so that center of polygon is at north pole centroid = np.mean(points[:-1], axis=0) - centroid = vector.normalize_vector(*centroid) + centroid = vector.normalize_vector(centroid) points = self._points - (centroid + np.array([0, 0, 1])) - vector.normalize_vector( - points[:, 0], points[:, 1], points[:, 2], inplace=True) + vector.normalize_vector(points, output=points) - X = [] - Y = [] + XYs = [] for A, B in zip(points[:-1], points[1:]): length = great_circle_arc.length(A, B, degrees=True) interp = great_circle_arc.interpolate(A, B, length * 4) - x, y, z = vector.normalize_vector( - interp[:, 0], interp[:, 1], interp[:, 2], inplace=True) - x, y = vector.equal_area_proj(x, y, z) - X.extend(x) - Y.extend(y) - - X = np.array(X) - Y = np.array(Y) + vector.normalize_vector(interp, output=interp) + XY = vector.equal_area_proj(interp) + XYs.append(XY) + + XY = np.vstack(XYs) + X = XY[..., 0] + Y = XY[..., 1] return np.abs(np.sum(X[:-1] * Y[1:] - X[1:] * Y[:-1]) * 0.5 * np.pi) |