Пример #1
0
    def test_equality(self):
        """Test __eq__ and __ne__
        """
        frame = ast.Frame(2)
        zoomMap = ast.ZoomMap(2, 1.5)
        frameSet1 = ast.FrameSet(frame, zoomMap, frame)
        frameSet2 = ast.FrameSet(frame, zoomMap, frame)
        self.assertTrue(frameSet1 == frameSet2)
        self.assertFalse(frameSet1 != frameSet2)
        self.assertEqual(frameSet1, frameSet2)

        # the base attribute of frameSet1 is not set; set the base attribute
        # of framesSet2 and make sure the frame sets are now not equal
        self.assertFalse(frameSet1.test("Base"))
        frameSet2.base = 1
        self.assertTrue(frameSet2.test("Base"))
        self.assertFalse(frameSet1 == frameSet2)
        self.assertTrue(frameSet1 != frameSet2)
        self.assertNotEqual(frameSet1, frameSet2)

        # make sure base is unset in the inverse of the inverse of frameSet1,
        # else the equality test will fail for hard-to-understand reasons
        self.assertFalse(frameSet1.inverted().inverted().test("Base"))
        self.assertNotEqual(frameSet1, frameSet1.inverted())
        self.assertEqual(frameSet1, frameSet1.inverted().inverted())
        self.assertFalse(frameSet1.inverted().inverted().test("Base"))

        frame3 = ast.Frame(2)
        frame3.title = "Frame 3"
        frameSet3 = ast.FrameSet(frame3)
        self.assertNotEqual(frameSet1, frameSet3)
Пример #2
0
    def test_FrameSetRemapFrame(self):
        frame = ast.Frame(2, "Ident=base")
        initialNumFrames = frame.getNObject()  # may be >1 when run using pytest
        frameSet = ast.FrameSet(frame)
        self.assertIsInstance(frameSet, ast.FrameSet)
        self.assertEqual(frameSet.nFrame, 1)
        self.assertEqual(frame.getNObject(), initialNumFrames + 1)

        newFrame = ast.Frame(2, "Ident=current")
        self.assertEqual(frame.getNObject(), initialNumFrames + 2)
        zoom = 0.5
        zoomMap = ast.ZoomMap(2, zoom, "Ident=zoom")
        initialNumZoomMap = zoomMap.getNObject()
        frameSet.addFrame(1, zoomMap, newFrame)
        self.assertEqual(frameSet.nFrame, 2)
        self.assertEqual(frame.getNObject(), initialNumFrames + 3)
        self.assertEqual(zoomMap.getNObject(), initialNumZoomMap + 1)

        input_data = np.array([
            [0.0, 0.1, -1.5],
            [5.1, 0.0, 3.1],
        ])
        predicted_output1 = input_data * zoom
        assert_allclose(frameSet.applyForward(input_data), predicted_output1)
        self.checkMappingPersistence(frameSet, input_data)

        shift = (0.5, -1.5)
        shiftMap = ast.ShiftMap(shift, "Ident=shift")
        initialNumShiftMap = shiftMap.getNObject()
        self.assertEqual(zoomMap.getNObject(), initialNumZoomMap + 1)
        frameSet.remapFrame(1, shiftMap)
        self.assertEqual(zoomMap.getNObject(), initialNumZoomMap + 1)
        self.assertEqual(shiftMap.getNObject(), initialNumShiftMap + 1)
        predicted_output2 = (input_data.T - shift).T * zoom
        assert_allclose(frameSet.applyForward(input_data), predicted_output2)
Пример #3
0
 def test_FrameMatchAxes(self):
     frame = ast.Frame(2)
     frame2 = ast.Frame(3)
     axes = frame.matchAxes(frame2)
     self.assertEqual(axes[0], 1)
     self.assertEqual(axes[1], 2)
     self.assertEqual(axes[2], 0)
Пример #4
0
    def test_FrameDictPermutationUnequal(self):
        """Test permuting FrameDict axes with nIn != nOut

        Permuting the axes of the current frame of a frame set
        *in situ* (by calling `permAxes` on the frame set itself)
        should update the connected mappings.

        Make nIn != nOut in order to test DM-9899
        FrameDict.permAxes would fail if nIn != nOut
        """
        # Initial mapping: 3 inputs, 2 outputs: 1-1, 2-2, 3=z
        # Test using arbitrary values for x,y,z
        x = 75.1
        y = -53.2
        z = 0.123
        frame1 = ast.Frame(3)
        permMap = ast.PermMap([1, 2, -1], [1, 2], [z])
        frame2 = ast.Frame(2)
        frameDict = ast.FrameDict(frame1, permMap, frame2)
        self.assertAlmostEqual(frameDict.applyForward([x, y, z]), [x, y])
        self.assertAlmostEqual(frameDict.applyInverse([x, y]), [x, y, z])

        # permuting the axes of the current frame also permutes the mapping
        frameDict.permAxes([2, 1])
        self.assertAlmostEqual(frameDict.applyForward([x, y, z]), [y, x])
        self.assertAlmostEqual(frameDict.applyInverse([x, y]), [y, x, z])

        # permuting again puts things back
        frameDict.permAxes([2, 1])
        self.assertAlmostEqual(frameDict.applyForward([x, y, z]), [x, y])
        self.assertAlmostEqual(frameDict.applyInverse([x, y]), [x, y, z])
Пример #5
0
 def setUp(self):
     self.frame1 = ast.Frame(2, "Domain=frame1, Ident=f1")
     self.frame2 = ast.Frame(2, "Domain=frame2, Ident=f2")
     self.zoom = 1.5
     self.zoomMap = ast.ZoomMap(2, self.zoom, "Ident=zoomMap")
     self.initialNumFrames = self.frame1.getNObject()  # may be >2 when run using pytest
     self.initialNumZoomMap = self.zoomMap.getNObject()  # may be > 1 when run using pytest
Пример #6
0
    def makeBadFrames(name):
        """Return a list of 0 or more frames that are not a valid match for the
        named endpoint

        Parameters
        ----------
        name : `str`
            Endpoint class name prefix; the full class name is name + "Endpoint"

        Returns
        -------
        Collection of `ast.Frame`
            A collection of 0 or more frames
        """
        return {
            "Generic": [],
            "Point2": [
                ast.SkyFrame(),
                ast.Frame(1),
                ast.Frame(3),
            ],
            "SpherePoint": [
                ast.Frame(1),
                ast.Frame(2),
                ast.Frame(3),
            ],
        }[name]
Пример #7
0
    def test_FrameSetRemoveFrame(self):
        frame = ast.Frame(2, "Ident=base")
        initialNumFrames = frame.getNObject(
        )  # may be >1 when run using pytest
        frameSet = ast.FrameSet(frame)
        self.assertIsInstance(frameSet, ast.FrameSet)
        self.assertEqual(frameSet.nFrame, 1)
        self.assertEqual(frame.getNObject(), initialNumFrames + 1)

        newFrame = ast.Frame(2, "Ident=current")
        self.assertEqual(frame.getNObject(), initialNumFrames + 2)
        zoomMap = ast.ZoomMap(2, 0.5, "Ident=zoom")
        initialNumZoomMap = zoomMap.getNObject()
        frameSet.addFrame(1, zoomMap, newFrame)
        self.assertEqual(frameSet.nFrame, 2)
        self.assertEqual(frame.getNObject(), initialNumFrames + 3)
        self.assertEqual(zoomMap.getNObject(), initialNumZoomMap + 1)

        # remove the frame named "base", leaving the frame named "current"
        frameSet.removeFrame(1)
        self.assertEqual(frameSet.nFrame, 1)
        # removing one frame leaves frame, newFrame and a copy of newFrame in FrameSet
        self.assertEqual(frame.getNObject(), initialNumFrames + 2)
        self.assertEqual(zoomMap.getNObject(), initialNumZoomMap)
        frameDeep = frameSet.getFrame(1)
        self.assertEqual(frameDeep.ident, "current")

        # it is not allowed to remove the last frame
        with self.assertRaises(RuntimeError):
            frameSet.removeFrame(1)
Пример #8
0
 def test_FrameOver(self):
     frame1 = astshim.Frame(2, "label(1)=a, label(2)=b")
     frame2 = astshim.Frame(1, "label(1)=c")
     cf = frame1.under(frame2)
     self.assertEqual(cf.nAxes, 3)
     self.assertEqual(cf.getLabel(1), "a")
     self.assertEqual(cf.getLabel(2), "b")
     self.assertEqual(cf.getLabel(3), "c")
Пример #9
0
    def makeFrameSet(self, baseFrame, currFrame):
        """Make a FrameSet

        The FrameSet will contain 4 frames and three transforms connecting them.
        The idenity of each frame is provided by self.frameIdentDict

        Frame       Index   Mapping from this frame to the next
        `baseFrame`   1     `ast.UnitMap(nIn)`
        Frame(nIn)    2     `polyMap`
        Frame(nOut)   3     `ast.UnitMap(nOut)`
        `currFrame`   4

        where:
        - `nIn` = `baseFrame.nAxes`
        - `nOut` = `currFrame.nAxes`
        - `polyMap` = `makeTwoWayPolyMap(nIn, nOut)`

        Returns
        ------
        `ast.FrameSet`
            The FrameSet as described above

        Parameters
        ----------
        baseFrame : `ast.Frame`
            base frame
        currFrame : `ast.Frame`
            current frame
        """
        nIn = baseFrame.nAxes
        nOut = currFrame.nAxes
        polyMap = makeTwoWayPolyMap(nIn, nOut)

        # The only way to set the Ident of a frame in a FrameSet is to set it in advance,
        # and I don't want to modify the inputs, so replace the input frames with copies
        baseFrame = baseFrame.copy()
        baseFrame.ident = self.frameIdentDict[1]
        currFrame = currFrame.copy()
        currFrame.ident = self.frameIdentDict[4]

        frameSet = ast.FrameSet(baseFrame)
        frame2 = ast.Frame(nIn)
        frame2.ident = self.frameIdentDict[2]
        frameSet.addFrame(ast.FrameSet.CURRENT, ast.UnitMap(nIn), frame2)
        frame3 = ast.Frame(nOut)
        frame3.ident = self.frameIdentDict[3]
        frameSet.addFrame(ast.FrameSet.CURRENT, polyMap, frame3)
        frameSet.addFrame(ast.FrameSet.CURRENT, ast.UnitMap(nOut), currFrame)
        return frameSet
Пример #10
0
    def test_FrameSetBasics(self):
        frame = ast.Frame(2, "Ident=base")
        initialNumFrames = frame.getNObject(
        )  # may be >1 when run using pytest
        frameSet = ast.FrameSet(frame)
        self.assertIsInstance(frameSet, ast.FrameSet)
        self.assertEqual(frameSet.nFrame, 1)

        # Make sure the frame is deep copied
        frame.ident = "newIdent"
        self.assertEqual(frameSet.getFrame(frameSet.BASE).ident, "base")
        self.assertEqual(frame.getRefCount(), 1)
        self.assertEqual(frame.getNObject(), initialNumFrames + 1)

        # add a new frame and mapping; make sure they are deep copied
        newFrame = ast.Frame(2, "Ident=current")
        mapping = ast.UnitMap(2, "Ident=mapping")
        initialNumUnitMap = mapping.getNObject()
        self.assertEqual(frame.getNObject(), initialNumFrames + 2)
        frameSet.addFrame(1, mapping, newFrame)
        self.assertEqual(frameSet.nFrame, 2)
        newFrame.ident = "newFrameIdent"
        mapping.ident = "newMappingIdent"
        self.assertEqual(frameSet.getFrame(frameSet.CURRENT).ident, "current")
        self.assertEqual(frameSet.getMapping().ident, "mapping")
        self.assertEqual(newFrame.getRefCount(), 1)
        self.assertEqual(frame.getNObject(), initialNumFrames + 3)
        self.assertEqual(mapping.getRefCount(), 1)
        self.assertEqual(mapping.getNObject(), initialNumUnitMap + 1)

        # make sure BASE is available on the class and instance
        self.assertEqual(ast.FrameSet.BASE, frameSet.BASE)

        baseframe = frameSet.getFrame(frameSet.BASE)
        self.assertEqual(frame.getNObject(), initialNumFrames + 4)
        self.assertEqual(baseframe.ident, "base")
        self.assertEqual(frameSet.base, 1)
        currframe = frameSet.getFrame(frameSet.CURRENT)
        self.assertEqual(frame.getNObject(), initialNumFrames + 5)
        self.assertEqual(currframe.ident, "current")
        self.assertEqual(frameSet.current, 2)

        self.checkCopy(frameSet)

        input_data = np.array([
            [0.0, 0.1, -1.5],
            [5.1, 0.0, 3.1],
        ])
        self.checkMappingPersistence(frameSet, input_data)
Пример #11
0
    def test_CmpFrame(self):
        frame1 = astshim.Frame(2, "label(1)=a, label(2)=b")
        frame2 = astshim.Frame(1, "label(1)=c")
        cmpframe = astshim.CmpFrame(frame1, frame2)
        # adding to a CmpFrame increases by 1
        self.assertEqual(frame1.getRefCount(), 2)
        # adding to a CmpFrame increases by 1
        self.assertEqual(frame2.getRefCount(), 2)

        self.assertEqual(cmpframe.nAxes, 3)
        self.assertEqual(cmpframe.getLabel(1), "a")
        self.assertEqual(cmpframe.getLabel(2), "b")
        self.assertEqual(cmpframe.getLabel(3), "c")

        self.checkPersistence(cmpframe)
Пример #12
0
    def test_FrameOver(self):
        frame1 = ast.Frame(2, "label(1)=a, label(2)=b")
        initialNumFrames = frame1.getNObject(
        )  # may be >1 when run using pytest
        frame2 = ast.Frame(1, "label(1)=c")
        self.assertEqual(frame1.getNObject(), initialNumFrames + 1)
        cf = frame1.under(frame2)
        self.assertEqual(cf.nAxes, 3)
        self.assertEqual(cf.getLabel(1), "a")
        self.assertEqual(cf.getLabel(2), "b")
        self.assertEqual(cf.getLabel(3), "c")

        # check that the contained frames are shallow copies
        self.assertEqual(frame1.getNObject(), initialNumFrames + 1)
        self.assertEqual(frame1.getRefCount(), 2)
        self.assertEqual(frame2.getRefCount(), 2)
Пример #13
0
    def test_FrameBasics(self):
        frame = ast.Frame(2)
        self.assertEqual(frame.className, "Frame")
        self.assertEqual(frame.nIn, 2)
        self.assertEqual(frame.nAxes, 2)
        self.assertEqual(frame.maxAxes, 2)
        self.assertEqual(frame.minAxes, 2)
        self.assertEqual(frame.alignSystem, "Cartesian")
        self.assertEqual(frame.dut1, 0.0)
        self.assertEqual(frame.epoch, 2000.0)
        self.assertEqual(frame.obsAlt, 0.0)
        self.assertEqual(frame.obsLat, "N0:00:00.00")
        self.assertEqual(frame.obsLon, "E0:00:00.00")
        self.assertTrue(frame.permute)
        self.assertFalse(frame.preserveAxes)
        self.assertEqual(frame.system, "Cartesian")
        self.assertEqual(frame.title, "2-d coordinate system")
        self.assertEqual(frame.getDigits(), 7)

        for axis in (1, 2):
            self.assertGreater(abs(frame.getBottom(axis)), 1e99)
            self.assertGreater(abs(frame.getTop(axis)), 1e99)
            self.assertGreater(frame.getTop(axis), frame.getBottom(axis))
            self.assertTrue(frame.getDirection(axis))
            self.assertEqual(frame.getDigits(axis), 7)
            self.assertEqual(frame.getInternalUnit(axis), "")
            self.assertEqual(frame.getNormUnit(axis), "")
            self.assertEqual(frame.getSymbol(axis), "x{}".format(axis))
            self.assertEqual(frame.getUnit(axis), "")

        self.checkCopy(frame)
        self.checkPersistence(frame)
Пример #14
0
    def testSpherePointEndpoint(self):
        self.assertEqual("SpherePoint", afwGeom.SpherePointEndpoint.getClassPrefix())
        endpoint = afwGeom.SpherePointEndpoint()
        self.checkEndpointBasics(
            endpoint=endpoint, pointType=lsst.geom.SpherePoint, nAxes=2)
        self.assertEqual(repr(endpoint), "lsst.afw.geom.SpherePointEndpoint()")
        self.assertEqual("{}".format(endpoint), "SpherePointEndpoint()")

        for doPermute in (False, True):
            frame = astshim.SkyFrame()
            if doPermute:
                frame.permAxes([2, 1])
                self.assertEqual(frame.lonAxis, 2)
                self.assertEqual(frame.latAxis, 1)
            else:
                self.assertEqual(frame.lonAxis, 1)
                self.assertEqual(frame.latAxis, 2)
            endpoint.normalizeFrame(frame)
            # the normalized frame always has axis in order Lon, Lat
            self.assertEqual(frame.lonAxis, 1)
            self.assertEqual(frame.latAxis, 2)

        badFrame = astshim.Frame(2)
        with self.assertRaises(InvalidParameterError):
            endpoint.normalizeFrame(badFrame)

        newFrame = endpoint.makeFrame()
        self.assertEqual(type(newFrame), astshim.SkyFrame)
        self.assertEqual(newFrame.lonAxis, 1)
        self.assertEqual(newFrame.latAxis, 2)
Пример #15
0
    def test_FrameDictAddFrame(self):
        frameDict = ast.FrameDict(self.frame1)
        self.assertEqual(self.frame1.getNObject(), self.initialNumFrames + 1)
        frameDict.addFrame(1, self.zoomMap, self.frame2)
        self.assertEqual(frameDict.nFrame, 2)
        self.assertEqual(frameDict.getFrame("FRAME2").domain, "FRAME2")
        self.assertEqual(
            frameDict.getFrame(frameDict.CURRENT).domain, "FRAME2")
        self.assertEqual(frameDict.getAllDomains(), {"FRAME1", "FRAME2"})
        self.assertEqual(self.frame2.getRefCount(), 1)
        self.assertEqual(self.frame1.getNObject(), self.initialNumFrames + 2)

        # make sure all objects were deep copied
        self.frame1.domain = "newBase"
        self.zoomMap.ident = "newMapping"
        self.frame2.domain = "newCurrent"
        self.assertEqual(frameDict.getFrame(frameDict.BASE).domain, "FRAME1")
        self.assertEqual(
            frameDict.getFrame(frameDict.CURRENT).domain, "FRAME2")
        self.assertEqual(frameDict.getMapping().ident, "zoomMap")
        self.checkPersistence(frameDict, typeFromChannel=ast.FrameSet)
        self.checkDict(frameDict)

        # make sure we can't add a frame with a duplicate domain name
        # and that attempting to do so leave the FrameDict unchanged
        duplicateFrame = ast.Frame(2, "Domain=FRAME1, Ident=duplicate")
        with self.assertRaises(ValueError):
            frameDict.addFrame(1, self.zoomMap, duplicateFrame)
        self.assertEqual(frameDict.getAllDomains(), {"FRAME1", "FRAME2"})
        self.assertEqual(frameDict.getFrame("FRAME1").ident, "f1")
        self.checkDict(frameDict)
Пример #16
0
    def test_FrameDictPermutationSkyFrame(self):
        """Test permuting FrameDict axes using a SkyFrame

        Permuting the axes of the current frame of a frame set
        *in situ* (by calling `permAxes` on the frame set itself)
        should update the connected mappings.
        """
        # test with arbitrary values that will not be wrapped by SkyFrame
        x = 0.257
        y = 0.832
        frame1 = ast.Frame(2)
        unitMap = ast.UnitMap(2)
        frame2 = ast.SkyFrame()
        frameDict = ast.FrameDict(frame1, unitMap, frame2)
        self.assertAlmostEqual(frameDict.applyForward([x, y]), [x, y])
        self.assertAlmostEqual(frameDict.applyInverse([x, y]), [x, y])

        # permuting the axes of the current frame also permutes the mapping
        frameDict.permAxes([2, 1])
        self.assertAlmostEqual(frameDict.applyForward([x, y]), [y, x])
        self.assertAlmostEqual(frameDict.applyInverse([x, y]), [y, x])

        # permuting again puts things back
        frameDict.permAxes([2, 1])
        self.assertAlmostEqual(frameDict.applyForward([x, y]), [x, y])
        self.assertAlmostEqual(frameDict.applyInverse([x, y]), [x, y])
Пример #17
0
    def testFrameSetFrameMappingFrameConstructor(self):
        baseFrame = ast.Frame(2, "Ident=base")
        mapping = ast.UnitMap(2, "Ident=mapping")
        currFrame = ast.Frame(2, "Ident=current")
        frameSet = ast.FrameSet(baseFrame, mapping, currFrame)
        self.assertEqual(frameSet.nFrame, 2)
        self.assertEqual(frameSet.base, 1)
        self.assertEqual(frameSet.current, 2)

        # make sure all objects were deep copied
        baseFrame.ident = "newBase"
        mapping.ident = "newMapping"
        currFrame.ident = "newCurrent"
        self.assertEqual(frameSet.getFrame(frameSet.BASE).ident, "base")
        self.assertEqual(frameSet.getFrame(frameSet.CURRENT).ident, "current")
        self.assertEqual(frameSet.getMapping().ident, "mapping")
Пример #18
0
    def test_FrameTitle(self):
        frame = ast.Frame(3, "Title=A Title")

        self.assertEqual(frame.title, "A Title")
        testtitle = "Test Frame"
        frame.title = testtitle
        frame.clear("Title")
        self.assertEqual(frame.title, "3-d coordinate system")
Пример #19
0
    def test_FrameSetGetFrame(self):
        frame = ast.Frame(2, "Ident=base")
        frameSet = ast.FrameSet(frame)
        self.assertIsInstance(frameSet, ast.FrameSet)
        self.assertEqual(frameSet.nFrame, 1)

        newFrame = ast.Frame(2, "Ident=current")
        frameSet.addFrame(1, ast.UnitMap(2), newFrame)
        self.assertEqual(frameSet.nFrame, 2)

        # check that getFrame returns a deep copy
        baseFrameDeep = frameSet.getFrame(ast.FrameSet.BASE)
        self.assertEqual(baseFrameDeep.ident, "base")
        self.assertEqual(baseFrameDeep.getRefCount(), 1)
        baseFrameDeep.ident = "modifiedBase"
        self.assertEqual(frameSet.getFrame(ast.FrameSet.BASE).ident, "base")
        self.assertEqual(frame.ident, "base")
Пример #20
0
 def test_FrameAxis(self):
     """Test Frame.axAngle, axDistance and axOffset"""
     frame = ast.Frame(2)
     angle = frame.axAngle([0, 0], [4, 3], 1)
     self.assertEqual(angle, -math.atan2(3, 4))
     distance = frame.axDistance(1, 0, 4)
     self.assertEqual(distance, 4)
     axoffset = frame.axOffset(1, 1, 4)
     self.assertEqual(axoffset, 5)
Пример #21
0
    def test_FrameLabels(self):
        frame = ast.Frame(2, "label(1)=a b,label(2)=c d")

        self.assertEqual(frame.getLabel(1), "a b")
        self.assertEqual(frame.getLabel(2), "c d")
        frame.setLabel(2, "A new label")
        self.assertEqual(frame.getLabel(2), "A new label")
        frame.clear("Label(2)")
        self.assertEqual(frame.getLabel(2), "Axis 2")
Пример #22
0
    def test_FitsChanTAB(self):
        """Test that FITS -TAB WCS can be created.
        """

        wavelength = np.array([0., 0.5, 1.5, 3., 5.])

        # Create a FrameSet using a LutMap with non-linear coordinates
        pixelFrame = ast.Frame(1, "Domain=PIXELS")
        wavelengthFrame = ast.SpecFrame("System=wave, unit=nm")
        lutMap = ast.LutMap(wavelength, 1, 1)
        frameSet = ast.FrameDict(pixelFrame)
        frameSet.addFrame("PIXELS", lutMap, wavelengthFrame)

        # Now serialize it using -TAB WCS
        fc = writeFitsWcs(frameSet, "TabOk=1")

        fv = fc.getFitsS("CTYPE1")
        self.assertEqual(fv.value, "WAVE-TAB")

        # PS1_0 is the table extension name
        fv = fc.getFitsS("PS1_0")
        waveext = fv.value
        self.assertEqual(waveext, "WCS-TAB")

        # PS1_1 is the column name for the wavelength
        fv = fc.getFitsS("PS1_1")
        wavecol = fv.value
        self.assertEqual(wavecol, "COORDS1")

        # Get the WCS table from the FitsChan
        km = fc.getTables()
        table = km.getA(waveext, 0)
        fc_bintab = table.getTableHeader()

        fv = fc_bintab.getFitsS("TDIM1")
        self.assertEqual(fv.value, "(1,5)")

        self.assertEqual(table.nRow, 1)
        self.assertEqual(table.nColumn, 1)

        # 1-based column numbering to match FITS
        cname = table.columnName(1)
        self.assertEqual(cname, "COORDS1")
        self.assertEqual(table.columnType(cname), ast.DataType.DoubleType)
        self.assertEqual(table.columnSize(cname), 40)
        self.assertEqual(table.columnNdim(cname), 2)
        self.assertEqual(table.columnUnit(cname), "nm")
        self.assertEqual(table.columnLength(cname), 5)
        self.assertEqual(table.columnShape(cname), [1, 5])
        coldata = table.getColumnData1D(cname)
        self.assertEqual(list(coldata), list(wavelength))

        # This will be shaped correctly as a numpy array with third dimension
        # the row count.
        coldata = table.getColumnData(cname)
        self.assertEqual(coldata.ndim, 3)
        self.assertEqual(coldata.shape, (1, 5, 1))
Пример #23
0
 def test_FrameOffset(self):
     """Test Frame.offset and Frame.offset2"""
     frame = ast.Frame(2)
     point = frame.offset([0, 0], [4, 3], 10)
     self.assertEqual(point[0], 8)
     self.assertEqual(point[1], 6)
     dp = frame.offset2([0, 0], math.atan2(4, 3), 10)
     self.assertAlmostEqual(dp.point[0], 8)
     self.assertAlmostEqual(dp.point[1], 6)
Пример #24
0
 def test_FramePerm(self):
     frame = ast.Frame(2)
     frame.permAxes([2, 1])
     fm = frame.pickAxes([2])
     self.assertEqual(fm.frame.className, "Frame")
     self.assertEqual(fm.frame.nIn, 1)
     self.assertEqual(fm.mapping.className, "PermMap")
     self.assertEqual(fm.mapping.nIn, 2)
     self.assertEqual(fm.mapping.nOut, 1)
Пример #25
0
    def test_CmpFrame(self):
        frame1 = ast.Frame(2, "label(1)=a, label(2)=b")
        frame2 = ast.Frame(1, "label(1)=c")
        cmpframe = ast.CmpFrame(frame1, frame2)
        # adding to a CmpFrame increases by 1
        self.assertEqual(frame1.getRefCount(), 2)
        # adding to a CmpFrame increases by 1
        self.assertEqual(frame2.getRefCount(), 2)

        self.assertEqual(cmpframe.nAxes, 3)
        self.assertEqual(cmpframe.getLabel(1), "a")
        self.assertEqual(cmpframe.getLabel(2), "b")
        self.assertEqual(cmpframe.getLabel(3), "c")

        self.checkPersistence(cmpframe)
        self.checkMemoryForCompoundObject(frame1,
                                          frame2,
                                          cmpframe,
                                          isSeries=None)
Пример #26
0
    def test_FrameSetGetMapping(self):
        frame = ast.Frame(2, "Ident=base")
        frameSet = ast.FrameSet(frame)
        self.assertIsInstance(frameSet, ast.FrameSet)
        self.assertEqual(frameSet.nFrame, 1)

        newFrame = ast.Frame(2)
        mapping = ast.UnitMap(2, "Ident=mapping")
        initialNumUnitMap = mapping.getNObject()  # may be >1 when run using pytest
        frameSet.addFrame(1, mapping, newFrame)
        self.assertEqual(frameSet.nFrame, 2)
        self.assertEqual(mapping.getNObject(), initialNumUnitMap + 1)

        # check that getMapping returns a deep copy
        mappingDeep = frameSet.getMapping(1, 2)
        self.assertEqual(mappingDeep.ident, "mapping")
        mappingDeep.ident = "modifiedMapping"
        self.assertEqual(mapping.ident, "mapping")
        self.assertEqual(mappingDeep.getRefCount(), 1)
        self.assertEqual(mapping.getNObject(), initialNumUnitMap + 2)
Пример #27
0
    def test_FrameConvert(self):
        frame = ast.Frame(2)
        nframe = ast.Frame(2)
        fset = frame.convert(nframe)
        self.assertEqual(fset.className, "FrameSet")

        # the conversion FrameSet should contain two frames
        # connected by a unit mapping with 2 axes
        self.assertEqual(fset.nFrame, 2)
        self.assertEqual(fset.nIn, 2)
        self.assertEqual(fset.nOut, 2)
        indata = np.array([
            [1.1, 2.2],
            [-43.5, 1309.31],
        ])
        outdata = fset.applyForward(indata)
        assert_allclose(outdata, indata)
        self.checkRoundTrip(fset, indata)

        self.assertIsNone(frame.convert(ast.Frame(3)))
Пример #28
0
 def test_FrameResolve(self):
     frame = ast.Frame(2)
     res = frame.resolve([0, 0], [2, 1], [0, 4])
     theta = math.atan2(1, 2)
     d1pred = 4 * math.sin(theta)
     d2pred = 4 * math.cos(theta)
     predpoint = [
         d1pred * math.cos(theta),
         d1pred * math.sin(theta),
     ]
     self.assertAlmostEqual(res.d1, d1pred)
     self.assertAlmostEqual(res.d2, d2pred)
     assert_allclose(res.point, predpoint)
Пример #29
0
    def insertPixelMapping(self, mapping, frameSet):
        """Make a new WCS by inserting a new mapping at the beginnning of the
        GRID-IWC mapping

        Return the new FrameSet (the original is not altered).
        """
        frameSet = frameSet.copy()

        skyFrame = frameSet.getFrame(ast.FrameSet.CURRENT)  # use this copy for the new sky frame
        self.assertIsInstance(skyFrame, ast.SkyFrame)
        oldSkyIndex = frameSet.current

        if not frameSet.findFrame(ast.Frame(2, "Domain=GRID")):
            raise KeyError("No GRID frame")
        gridIndex = frameSet.current

        if not frameSet.findFrame(ast.Frame(2, "Domain=IWC")):
            raise KeyError("No IWC frame")
        oldIwcIndex = frameSet.current
        iwcFrame = frameSet.getFrame(oldIwcIndex)  # use this copy for the new IWC frame

        oldGridToIwc = frameSet.getMapping(gridIndex, oldIwcIndex)
        iwcToSky = frameSet.getMapping(oldIwcIndex, oldSkyIndex)

        # Remove frames in order high to low, so removal doesn't alter the
        # indices remaining to be removed;
        # update gridIndex during removal so it still points to the GRID frame
        framesToRemove = reversed(sorted([oldIwcIndex, oldSkyIndex]))
        for index in framesToRemove:
            if (index < gridIndex):
                gridIndex -= 1
            frameSet.removeFrame(index)

        newGridToIwc = mapping.then(oldGridToIwc).simplified()
        frameSet.addFrame(gridIndex, newGridToIwc, iwcFrame)
        frameSet.addFrame(ast.FrameSet.CURRENT, iwcToSky, skyFrame)
        return frameSet
Пример #30
0
    def test_FrameSetDigits(self):
        frame = ast.Frame(2)
        self.assertEqual(frame.getDigits(), 7)
        for axis in (1, 2):
            self.assertEqual(frame.getDigits(axis), 7)

        frame.setDigits(1, 9)
        self.assertEqual(frame.getDigits(), 7)
        self.assertEqual(frame.getDigits(1), 9)
        self.assertEqual(frame.getDigits(2), 7)

        frame.setDigits(2, 4)
        self.assertEqual(frame.getDigits(), 7)
        self.assertEqual(frame.getDigits(1), 9)
        self.assertEqual(frame.getDigits(2), 4)