def testConstructors(self): #test 2-d e1 = geom.Point2I(1, 2) e2 = geom.Point2I(e1) self.assertClose(tuple(e1), tuple(e2)) e1 = geom.Point2D(1.2, 3.4) e2 = geom.Point2D(e1) self.assertClose(tuple(e1), tuple(e2)) e1 = geom.Point2I(1, 3) e2 = geom.Point2D(e1) self.assertClose(tuple(e1), tuple(e2)) #test 3-d e1 = geom.Point3I(1, 2, 3) e2 = geom.Point3I(e1) self.assertClose(tuple(e1), tuple(e2)) e1 = geom.Point3D(1.2, 3.4, 5.6) e2 = geom.Point3D(e1) self.assertClose(tuple(e1), tuple(e2)) e1 = geom.Point3I(1, 2, 3) e2 = geom.Point3D(e1) self.assertClose(tuple(e1), tuple(e2)) #test rounding to integral coordinates e1 = geom.Point2D(1.2, 3.4) e2 = geom.Point2I(e1) self.assertClose(tuple([math.floor(v + 0.5) for v in e1]), tuple(e2)) e1 = geom.Point3D(1.2, 3.4, 5.6) e2 = geom.Point3I(e1) self.assertClose(tuple([math.floor(v + 0.5) for v in e1]), tuple(e2))
def testTicket1761(self): """Ticket 1761 found that non-normalized inputs caused failures. """ c = afwCoord.Coord(afwGeom.Point3D(0,1,0)) dfltLong = 0.0 * afwGeom.radians norm = False c1 = afwCoord.Coord(afwGeom.Point3D(0.1, 0.1, 0.1), 2000.0, norm, dfltLong) c2 = afwCoord.Coord(afwGeom.Point3D(0.6, 0.6 ,0.6), 2000.0, norm, dfltLong) sep1 = c.angularSeparation(c1).asDegrees() sep2 = c.angularSeparation(c2).asDegrees() known1 = 45.286483672428574 known2 = 55.550098012046512 print("sep: ", sep1, sep2, known1, known2) # these weren't normalized, and should get the following *incorrect* answers self.assertAlmostEqual(sep1, known1) self.assertAlmostEqual(sep2, known2) ###################### # normalize and sep1, sep2 should both equal 54.7356 norm = True c1 = afwCoord.Coord(afwGeom.Point3D(0.1, 0.1, 0.1), 2000.0, norm, dfltLong) c2 = afwCoord.Coord(afwGeom.Point3D(0.6, 0.6 ,0.6), 2000.0, norm, dfltLong) sep1 = c.angularSeparation(c1).asDegrees() sep2 = c.angularSeparation(c2).asDegrees() known = 54.735610317245339 print("sep: ", sep1, sep2, known) # these weren't normalized, and should get the following *incorrect* answers self.assertAlmostEqual(sep1, known) self.assertAlmostEqual(sep2, known)
def testInit1ArgErrors(self): """Test if 1-argument form of __init__ handles invalid input. """ # Only one singularity, at zero with self.assertRaises(pexEx.InvalidParameterError): SpherePoint(afwGeom.Point3D(0.0, 0.0, 0.0)) SpherePoint(afwGeom.Point3D(0.0, -0.2, 0.0)) SpherePoint(afwGeom.Point3D(0.0, 0.0, 1.0)) SpherePoint(afwGeom.Point3D(42.78, -46.29, 38.27))
def testTicket1761(self): """Regression test for Ticket 1761. Checks for math errors caused by unnormalized vectors. """ refPoint = SpherePoint(afwGeom.Point3D(0, 1, 0)) point1 = SpherePoint(afwGeom.Point3D(0.1, 0.1, 0.1)) point2 = SpherePoint(afwGeom.Point3D(0.6, 0.6, 0.6)) sep1 = refPoint.separation(point1) sep2 = refPoint.separation(point2) sepTrue = 54.735610317245339*degrees self.assertAnglesAlmostEqual(sepTrue, sep1) self.assertAnglesAlmostEqual(sepTrue, sep2)
def testCoordAliases(self): with self.assertWarns(FutureWarning): self.assertIsInstance(afwGeom.ExtentI(), lsst.geom.ExtentI) with self.assertWarns(FutureWarning): self.assertIsInstance(afwGeom.Extent2I(), lsst.geom.Extent2I) with self.assertWarns(FutureWarning): self.assertIsInstance(afwGeom.Extent3I(), lsst.geom.Extent3I) with self.assertWarns(FutureWarning): self.assertIsInstance(afwGeom.ExtentD(), lsst.geom.ExtentD) with self.assertWarns(FutureWarning): self.assertIsInstance(afwGeom.Extent2D(), lsst.geom.Extent2D) with self.assertWarns(FutureWarning): self.assertIsInstance(afwGeom.Extent3D(), lsst.geom.Extent3D) with self.assertWarns(FutureWarning): self.assertIsInstance(afwGeom.PointI(), lsst.geom.PointI) with self.assertWarns(FutureWarning): self.assertIsInstance(afwGeom.Point2I(), lsst.geom.Point2I) with self.assertWarns(FutureWarning): self.assertIsInstance(afwGeom.Point3I(), lsst.geom.Point3I) with self.assertWarns(FutureWarning): self.assertIsInstance(afwGeom.PointD(), lsst.geom.PointD) with self.assertWarns(FutureWarning): self.assertIsInstance(afwGeom.Point2D(), lsst.geom.Point2D) with self.assertWarns(FutureWarning): self.assertIsInstance(afwGeom.Point3D(), lsst.geom.Point3D)
def testGetItemError(self): """Test if indexing correctly handles invalid input. """ point = SpherePoint(afwGeom.Point3D(1.0, 1.0, 1.0)) with self.assertRaises(IndexError): point[2] with self.assertRaises(IndexError): point[-3]
def testTicket1394(self): """Ticket #1394 bug: coord within epsilon of RA=0 leads to negative RA and fails bounds check. """ # the problem was that the coordinate is < epsilon close to RA==0 # and bounds checking was getting a -ve RA. c = afwCoord.makeCoord(afwCoord.ICRS, afwGeom.Point3D(0.6070619982, -1.264309928e-16, 0.7946544723)) self.assertEqual(c[0], 0.0)
def testAtPoleValue(self): """Test if atPole() returns the expected value. """ poleList = [SpherePoint(42.0*degrees, lat) for lat in self._poleLatitudes] + \ [SpherePoint(42.0*degrees, 0.0*radians - lat) for lat in self._poleLatitudes] + [ SpherePoint(afwGeom.Point3D(0.0, 0.0, 1.0)), SpherePoint(afwGeom.Point3D(0.0, 0.0, -1.0)), ] nonPoleList = [SpherePoint(42.0*degrees, self.nextDown(lat)) for lat in self._poleLatitudes] + \ [SpherePoint(42.0*degrees, self.nextUp(0.0*radians - lat)) for lat in self._poleLatitudes] + [ SpherePoint(afwGeom.Point3D(9.9e-7, 0.0, 1.0)), SpherePoint(afwGeom.Point3D(9.9e-7, 0.0, -1.0)), SpherePoint(0.0*degrees, nan*degrees), ] for pole in poleList: self.assertIsInstance(pole.atPole(), bool) self.assertTrue(pole.atPole()) for nonPole in nonPoleList: self.assertIsInstance(nonPole.atPole(), bool) self.assertFalse(nonPole.atPole())
def testTicket1394(self): """Regression test for Ticket 1761. Checks that negative longitudes within epsilon of lon=0 lead are correctly bounded and rounded. """ # The problem was that the coordinate is less than epsilon # close to RA == 0 and bounds checking was getting a # negative RA. point = SpherePoint(afwGeom.Point3D( 0.6070619982, -1.264309928e-16, 0.7946544723)) self.assertEqual(point[0].asDegrees(), 0.0)
def testVector(self): """Test the getVector() method, and make sure the constructors take Point3D""" # try the axes: vernal equinox should equal 1, 0, 0; ... north pole is # 0, 0, 1; etc coordList = [] coordList.append([(0.0, 0.0), (1.0, 0.0, 0.0)]) coordList.append([(90.0, 0.0), (0.0, 1.0, 0.0)]) coordList.append([(0.0, 90.0), (0.0, 0.0, 1.0)]) for equ, p3dknown in coordList: # convert to p3d p3d = afwCoord.Fk5Coord(equ[0] * afwGeom.degrees, equ[1] * afwGeom.degrees).getVector() print("Point3d: ", p3d, p3dknown) for i in range(3): self.assertAlmostEqual(p3d[i], p3dknown[i]) # convert back equBack = afwCoord.Fk5Coord(p3d) print("Vector (back): ", equBack.getRa().asDegrees(), equ[0], equBack.getDec().asDegrees(), equ[1]) self.assertAlmostEqual(equBack.getRa().asDegrees(), equ[0]) self.assertAlmostEqual(equBack.getDec().asDegrees(), equ[1]) # and try some un-normalized ones too coordList = [] # too long coordList.append([(0.0, 0.0), (1.3, 0.0, 0.0)]) coordList.append([(90.0, 0.0), (0.0, 1.2, 0.0)]) coordList.append([(0.0, 90.0), (0.0, 0.0, 2.3)]) # too short coordList.append([(0.0, 0.0), (0.5, 0.0, 0.0)]) coordList.append([(90.0, 0.0), (0.0, 0.7, 0.0)]) coordList.append([(0.0, 90.0), (0.0, 0.0, 0.9)]) for equKnown, p3d in coordList: # convert to Coord epoch = 2000.0 norm = True c = afwCoord.Fk5Coord(afwGeom.Point3D(p3d[0], p3d[1], p3d[2]), epoch, norm) ra, dec = c.getRa().asDegrees(), c.getDec().asDegrees() print("Un-normed p3d: ", p3d, "-->", equKnown, ra, dec) self.assertAlmostEqual(equKnown[0], ra) self.assertAlmostEqual(equKnown[1], dec)
def testIsFiniteValue(self): """Test if isFinite() returns the expected value. """ finiteList = [ SpherePoint(0.0*degrees, -90.0*degrees), SpherePoint(afwGeom.Point3D(0.1, 0.2, 0.3)), ] nonFiniteList = [ SpherePoint(0.0*degrees, nan*degrees), SpherePoint(nan*degrees, 0.0*degrees), SpherePoint(inf*degrees, 0.0*degrees), SpherePoint(-inf*degrees, 0.0*degrees), SpherePoint(afwGeom.Point3D(nan, 0.2, 0.3)), SpherePoint(afwGeom.Point3D(0.1, inf, 0.3)), SpherePoint(afwGeom.Point3D(0.1, 0.2, -inf)), ] for finite in finiteList: self.assertIsInstance(finite.isFinite(), bool) self.assertTrue(finite.isFinite()) for nonFinite in nonFiniteList: self.assertIsInstance(nonFinite.isFinite(), bool) self.assertFalse(nonFinite.isFinite())
def coordFromVec(vec, defRA=None): """Convert an ICRS cartesian vector to an ICRS Coord @param[in] vec: an ICRS catesian vector as a sequence of three floats @param[in] defRA: the RA to use if the vector is too near a pole (an afwGeom Angle); ignored if not near a pole @throw RuntimeError if vec too near a pole and defRA is None """ if abs(vec[0]) < _TinyFloat and abs(vec[1]) < _TinyFloat: if defRA is None: raise RuntimeError("At pole and defRA==None") if vec[2] > 0: dec = 90.0 else: dec = -90.0 return afwCoord.makeCoord(afwCoord.ICRS, defRA, afwGeom.Angle(dec, afwGeom.degrees)) return afwCoord.makeCoord(afwCoord.ICRS, afwGeom.Point3D(*vec))
def initialWcs(self, matches, wcs): """Generate a guess Wcs from the astrometric matches We create a Wcs anchored at the center of the matches, with the scale of the input Wcs. This is necessary because matching returns only matches with no estimated Wcs, and the input Wcs is a wild guess. We're using the best of each: positions from the matches, and scale from the input Wcs. """ crpix = afwGeom.Extent2D(0, 0) crval = afwGeom.Extent3D(0, 0, 0) for mm in matches: crpix += afwGeom.Extent2D(mm.second.getCentroid()) crval += afwGeom.Extent3D(mm.first.getCoord().toIcrs().getVector()) crpix /= len(matches) crval /= len(matches) newWcs = afwImage.Wcs( afwCoord.IcrsCoord(afwGeom.Point3D(crval)).getPosition(), afwGeom.Point2D(crpix), wcs.getCDMatrix()) return newWcs
def testGetLongitudeValue(self): """Test if getLongitude() returns the expected value. """ for lon, lat in self._dataset: point = SpherePoint(lon, lat) self.assertIsInstance(point.getLongitude(), afwGeom.Angle) # Behavior for non-finite points is undefined; depends on internal # data representation if point.isFinite(): self.assertGreaterEqual(point.getLongitude().asDegrees(), 0.0) self.assertLess(point.getLongitude().asDegrees(), 360.0) # Longitude not guaranteed to match input at pole if not point.atPole(): # assertAnglesAlmostEqual handles angle wrapping internally self.assertAnglesAlmostEqual(lon, point.getLongitude()) # Vector construction should return valid longitude even in edge cases. point = SpherePoint(afwGeom.Point3D(0.0, 0.0, -1.0)) self.assertGreaterEqual(point.getLongitude().asDegrees(), 0.0) self.assertLess(point.getLongitude().asDegrees(), 360.0)
def testConstructors(self): # test extent from extent 2-d e1 = geom.Extent2I(1, 2) e2 = geom.Extent2I(e1) self.assertAlmostEqual(tuple(e1), tuple(e2)) e1 = geom.Extent2D(1.2, 3.4) e2 = geom.Extent2D(e1) self.assertAlmostEqual(tuple(e1), tuple(e2)) e1 = geom.Extent2I(1, 2) e2 = geom.Extent2D(e1) self.assertAlmostEqual(tuple(e1), tuple(e2)) # test extent from extent 3-d e1 = geom.Extent3I(1, 2, 3) e2 = geom.Extent3I(e1) self.assertAlmostEqual(tuple(e1), tuple(e2)) e1 = geom.Extent3D(1.2, 3.4, 5.6) e2 = geom.Extent3D(e1) self.assertAlmostEqual(tuple(e1), tuple(e2)) e1 = geom.Extent3I(1, 2, 3) e2 = geom.Extent3D(e1) self.assertAlmostEqual(tuple(e1), tuple(e2)) # test extent from point 2-d e1 = geom.Point2I(1, 2) e2 = geom.Extent2I(e1) self.assertAlmostEqual(tuple(e1), tuple(e2)) e1 = geom.Point2D(1.2, 3.4) e2 = geom.Extent2D(e1) self.assertAlmostEqual(tuple(e1), tuple(e2)) e1 = geom.Point2I(1, 2) e2 = geom.Extent2D(e1) self.assertAlmostEqual(tuple(e1), tuple(e2)) # test extent from point 3-d e1 = geom.Point3I(1, 2, 3) e2 = geom.Extent3I(e1) self.assertAlmostEqual(tuple(e1), tuple(e2)) e1 = geom.Point3D(1.2, 3.4, 5.6) e2 = geom.Extent3D(e1) self.assertAlmostEqual(tuple(e1), tuple(e2)) e1 = geom.Point3I(1, 2, 3) e2 = geom.Extent3D(e1) self.assertAlmostEqual(tuple(e1), tuple(e2)) # test invalid constructors e1 = geom.Extent2D(1.2, 3.4) with self.assertRaises(TypeError): e2 = geom.Extent2I(e1) e1 = geom.Extent3D(1.2, 3.4, 5.6) with self.assertRaises(TypeError): e2 = geom.Extent3I(e1) e1 = geom.Point2D(1.2, 3.4) with self.assertRaises(TypeError): e2 = geom.Extent2I(e1) e1 = geom.Point3D(1.2, 3.4, 5.6) with self.assertRaises(TypeError): e2 = geom.Extent3I(e1)
def setUp(self): x, y, z = 1.0, 1.0, 1.0 self.data = afwGeom.Point3D(x, y, z)
def testFindTract(self): """Test findTract and tractInfo.findPatch """ skyMap = DodecaSkyMap() for tractInfo0 in skyMap: tractId0 = tractInfo0.getId() ctrCoord0 = tractInfo0.getCtrCoord() vector0 = numpy.array(ctrCoord0.getVector()) # make a list of all 5 nearest neighbors nbrTractList = [] for otherTractInfo in skyMap: otherCtrCoord = otherTractInfo.getCtrCoord() dist = ctrCoord0.angularSeparation(otherCtrCoord) if abs(dist - self._NeighborAngularSeparation) < afwGeom.Angle(0.1, afwGeom.degrees): nbrTractList.append(otherTractInfo) self.assertEqual(len(nbrTractList), 5) for tractInfo1 in nbrTractList: tractId1 = tractInfo1.getId() ctrCoord1 = tractInfo1.getCtrCoord() vector1 = numpy.array(ctrCoord1.getVector()) for tractInfo2 in nbrTractList[tractInfo1.getId():]: dist = ctrCoord1.angularSeparation(tractInfo2.getCtrCoord()) if abs(dist - self._NeighborAngularSeparation) > afwGeom.Angle(0.1, afwGeom.degrees): continue tractId2 = tractInfo2.getId() ctrCoord2 = tractInfo2.getCtrCoord() vector2 = numpy.array(ctrCoord2.getVector()) # sky tracts 0, 1 and 2 form a triangle of nearest neighbors # explore the boundary between tract 0 and tract 1 # and also the boundary between tract 0 and tract 2 for deltaFrac in (-0.001, 0.001): isNearest0 = deltaFrac > 0.0 for exploreBoundary1 in (True, False): # if exploreBoundary1, explore boundary between tract 0 and tract 1, # else explore the boundary between tract 0 and tract 2 if isNearest0: expectedTractId = tractId0 elif exploreBoundary1: expectedTractId = tractId1 else: expectedTractId = tractId2 for farFrac in (0.0, 0.05, 0.3, (1.0/3.0) - 0.01): # farFrac is the fraction of the tract center vector point whose boundary # is not being explored; it must be less than 1/3; # remFrac is the remaining fraction, which is divided between tract 0 # and the tract whose boundary is being explored remFrac = 1.0 - farFrac frac0 = (remFrac / 2.0) + deltaFrac boundaryFrac = (remFrac / 2.0) - deltaFrac if exploreBoundary1: frac2 = farFrac frac1 = boundaryFrac else: frac1 = farFrac frac2 = boundaryFrac testVector = (vector0 * frac0) + (vector1 * frac1) + (vector2 * frac2) vecLen = math.sqrt(numpy.sum(testVector**2)) testVector /= vecLen lsstVec = afwGeom.Point3D(testVector) testCoord = afwCoord.IcrsCoord(lsstVec) nearestTractInfo = skyMap.findTract(testCoord) nearestTractId = nearestTractInfo.getId() if expectedTractId != nearestTractId: nearestCtrCoord = nearestTractInfo.getCtrCoord() nearestVector = nearestCtrCoord.getVector() print("tractId0=%s; tractId1=%s; tractId2=%s; nearestTractId=%s" % (tractId0, tractId1, tractId2, nearestTractId)) print("vector0=%s; vector1=%s; vector2=%s; nearestVector=%s" % (vector0, vector1, vector2, nearestVector)) print("frac0=%s; frac1=%s; frac2=%s" % (frac0, frac1, frac2)) print("testVector=", testVector) print("dist0=%s; dist1=%s; dist2=%s; nearDist=%s" % ( testCoord.angularSeparation(ctrCoord0).asDegrees(), testCoord.angularSeparation(ctrCoord1).asDegrees(), testCoord.angularSeparation(ctrCoord2).asDegrees(), testCoord.angularSeparation(nearestCtrCoord).asDegrees(), )) self.fail("Expected nearest tractId=%s; got tractId=%s" % (expectedTractId, nearestTractId)) patchInfo = nearestTractInfo.findPatch(testCoord) pixelInd = afwGeom.Point2I( nearestTractInfo.getWcs().skyToPixel(testCoord.toIcrs())) self.assertTrue(patchInfo.getInnerBBox().contains(pixelInd))
def testFindTract(self): """Test the findTract method """ for numTracts in (2, 4): config = EquatSkyMap.ConfigClass() config.numTracts = numTracts skyMap = EquatSkyMap(config) decRange = skyMap.config.decRange decList = ( (decRange[0] * 0.999) + (decRange[1] * 0.901), (decRange[0] * 0.500) + (decRange[1] * 0.500), (decRange[0] * 0.091) + (decRange[1] * 0.999), ) for tractInfo0 in skyMap: tractId0 = tractInfo0.getId() ctrCoord0 = tractInfo0.getCtrCoord() vector0 = numpy.array(ctrCoord0.getVector()) for tractInfo1 in self.getNeighborTracts(skyMap, tractId0): tractId1 = tractInfo1.getId() ctrCoord1 = tractInfo1.getCtrCoord() vector1 = numpy.array(ctrCoord1.getVector()) for deltaFrac in (-0.001, 0.001): # this fuss is because Point3D does not support * float v0 = [ v * (0.5 + deltaFrac) for v in ctrCoord0.getVector() ] v1 = [ v * (0.5 - deltaFrac) for v in ctrCoord1.getVector() ] testVec = afwGeom.Point3D(*(v0[i] + v1[i] for i in range(3))) testRa = afwCoord.IcrsCoord(testVec).getRa() if deltaFrac > 0.0: expectedTractId = tractId0 else: expectedTractId = tractId1 for testDecDeg in decList: testDec = afwGeom.Angle(testDecDeg, afwGeom.degrees) testCoord = afwCoord.IcrsCoord(testRa, testDec) nearestTractInfo = skyMap.findTract(testCoord) nearestTractId = nearestTractInfo.getId() self.assertEqual(nearestTractId, expectedTractId) patchInfo = nearestTractInfo.findPatch(testCoord) pixelInd = afwGeom.Point2I( nearestTractInfo.getWcs().skyToPixel( testCoord.toIcrs())) self.assertTrue( patchInfo.getInnerBBox().contains(pixelInd)) # find a point outside the tract and make sure it fails tractInfo = tractInfo0 wcs = tractInfo.getWcs() bbox = afwGeom.Box2D(tractInfo.getBBox()) outerPixPosList = [ bbox.getMin() - afwGeom.Extent2D(1, 1), afwGeom.Point2D(bbox.getMaxX(), bbox.getMinY()) - afwGeom.Extent2D(1, 1), bbox.getMax() + afwGeom.Extent2D(1, 1), afwGeom.Point2D(bbox.getMinX(), bbox.getMaxY()) + afwGeom.Extent2D(1, 1), ] for outerPixPos in outerPixPosList: testCoord = wcs.pixelToSky(outerPixPos) self.assertRaises(LookupError, tractInfo.findPatch, testCoord)
def testConstructors(self): #test extent from extent 2-d e1 = geom.Extent2I(1, 2) e2 = geom.Extent2I(e1) self.assertClose(tuple(e1), tuple(e2)) e1 = geom.Extent2D(1.2, 3.4) e2 = geom.Extent2D(e1) self.assertClose(tuple(e1), tuple(e2)) e1 = geom.Extent2I(1, 2) e2 = geom.Extent2D(e1) self.assertClose(tuple(e1), tuple(e2)) #test extent from extent 3-d e1 = geom.Extent3I(1, 2, 3) e2 = geom.Extent3I(e1) self.assertClose(tuple(e1), tuple(e2)) e1 = geom.Extent3D(1.2, 3.4, 5.6) e2 = geom.Extent3D(e1) self.assertClose(tuple(e1), tuple(e2)) e1 = geom.Extent3I(1, 2, 3) e2 = geom.Extent3D(e1) self.assertClose(tuple(e1), tuple(e2)) #test extent from point 2-d e1 = geom.Point2I(1, 2) e2 = geom.Extent2I(e1) self.assertClose(tuple(e1), tuple(e2)) e1 = geom.Point2D(1.2, 3.4) e2 = geom.Extent2D(e1) self.assertClose(tuple(e1), tuple(e2)) e1 = geom.Point2I(1, 2) e2 = geom.Extent2D(e1) self.assertClose(tuple(e1), tuple(e2)) #test extent from point 3-d e1 = geom.Point3I(1, 2, 3) e2 = geom.Extent3I(e1) self.assertClose(tuple(e1), tuple(e2)) e1 = geom.Point3D(1.2, 3.4, 5.6) e2 = geom.Extent3D(e1) self.assertClose(tuple(e1), tuple(e2)) e1 = geom.Point3I(1, 2, 3) e2 = geom.Extent3D(e1) self.assertClose(tuple(e1), tuple(e2)) #test invalid constructors try: e1 = geom.Extent2D(1.2, 3.4) e2 = geom.Extent2I(e1) except: pass else: self.fail("Should not allow conversion Extent2D to Extent2I") try: e1 = geom.Extent3D(1.2, 3.4, 5.6) e2 = geom.Extent3I(e1) except: pass else: self.fail("Should not allow conversion Extent3D to Extent3I") try: e1 = geom.Point2D(1.2, 3.4) e2 = geom.Extent2I(e1) except: pass else: self.fail("Should not allow conversion Point2D to Extent 2I") try: e1 = geom.Point3D(1.2, 3.4, 5.6) e2 = geom.Extent3I(e1) except: pass else: self.fail("Should not allow conversion Point3D to Extent3I")
def testGetVectorValue(self): """Test if getVector() returns the expected value. The test includes conformance to vector-angle conventions. """ pointList = [ ((0.0, 0.0), afwGeom.Point3D(1.0, 0.0, 0.0)), ((90.0, 0.0), afwGeom.Point3D(0.0, 1.0, 0.0)), ((0.0, 90.0), afwGeom.Point3D(0.0, 0.0, 1.0)), ] for lonLat, vector in pointList: # Convert to Point3D. point = SpherePoint(lonLat[0]*degrees, lonLat[1]*degrees) newVector = point.getVector() self.assertIsInstance(newVector, afwGeom.Point3D) for oldElement, newElement in zip(vector, newVector): self.assertAlmostEqual(oldElement, newElement) # Convert back to spherical. newLon, newLat = SpherePoint(newVector) self.assertAlmostEqual(newLon.asDegrees(), lonLat[0]) self.assertAlmostEqual(newLat.asDegrees(), lonLat[1]) # Try some un-normalized ones, too. pointList = [ ((0.0, 0.0), afwGeom.Point3D(1.3, 0.0, 0.0)), ((90.0, 0.0), afwGeom.Point3D(0.0, 1.2, 0.0)), ((0.0, 90.0), afwGeom.Point3D(0.0, 0.0, 2.3)), ((0.0, 0.0), afwGeom.Point3D(0.5, 0.0, 0.0)), ((90.0, 0.0), afwGeom.Point3D(0.0, 0.7, 0.0)), ((0.0, 90.0), afwGeom.Point3D(0.0, 0.0, 0.9)), ] for lonLat, vector in pointList: # Only convert from vector to spherical. point = SpherePoint(vector) newLon, newLat = point self.assertAlmostEqual(lonLat[0], newLon.asDegrees()) self.assertAlmostEqual(lonLat[1], newLat.asDegrees()) self.assertAlmostEqual(1.0, point.getVector().distanceSquared( afwGeom.Point3D(0.0, 0.0, 0.0))) # Ill-defined points should be all NaN after normalization cleanVector = afwGeom.Point3D(0.5, -0.3, 0.2) badValues = [nan, inf, -inf] for i in range(3): for badValue in badValues: # Ensure each subtest is independent dirtyVector = copy.deepcopy(cleanVector) dirtyVector[i] = badValue for element in SpherePoint(dirtyVector).getVector(): self.assertTrue(math.isnan(element))