def _test_outside(self, kwargs, expected): mode = kwargs.get('mode') if mode == 'sky': kwargs['wcs'] = self.testWcs with self.assertRaises(MarvinError) as cm: convertCoords(shape=self.testShape, **kwargs) self.assertIn('some indices are out of limits', str(cm.exception))
def test_coords_outside_cube(self, coords, mode, xyorig, galaxy, wcs): kwargs = {'coords': coords, 'mode': mode} if xyorig is not None: kwargs['xyorig'] = xyorig if kwargs['mode'] == 'sky': kwargs['wcs'] = wcs with pytest.raises(MarvinError) as cm: convertCoords(shape=galaxy.shape, **kwargs) assert 'some indices are out of limits' in str(cm.value)
def test_sky(self): """Tests mode='sky'.""" coords = np.array([[232.5447, 48.690201], [232.54259, 48.688948], [232.54135, 48.692415], [232.54285, 48.692372]]) expected = [[17, 17], [8, 27], [33, 33], [33, 26]] cubeCoords = convertCoords(coords, mode='sky', wcs=self.testWcs) assert_allclose(cubeCoords, np.array(expected))
def test_pix_center(self): """Tests mode='pix', xyorig='center'.""" coords = [[0, 0], [5, 3], [-5, 1], [1, -5], [10, 10], [-10, -10], [1.5, 2.5], [0.4, 0.25]] expected = [[17, 17], [20, 22], [18, 12], [12, 18], [27, 27], [7, 7], [20, 18], [17, 17]] cubeCoords = convertCoords(coords, mode='pix', shape=self.testShape) assert_allclose(cubeCoords, np.array(expected))
def test_pix_center(self, galaxy, pifu, expected): """Tests mode='pix', xyorig='center'.""" if galaxy.plateifu != pifu: pytest.skip('Skipping non-matching plateifu.') coords = [[0, 0], [5, 3], [-5, 1], [1, -5], [10, 10], [-10, -10], [1.5, 2.5], [0.4, 0.25]] cubeCoords = convertCoords(coords, mode='pix', shape=galaxy.shape) assert cubeCoords == pytest.approx(np.array(expected))
def test_sky(self, wcs): """Tests mode='sky'.""" coords = np.array([[232.5447, 48.690201], [232.54259, 48.688948], [232.54135, 48.692415], [232.54285, 48.692372]]) expected = [[17, 17], [8, 27], [33, 33], [33, 26]] cubeCoords = convertCoords(coords, mode='sky', wcs=wcs) pytest.approx(cubeCoords, np.array(expected))
def test_pix_center(self, galaxy): """Tests mode='pix', xyorig='center'.""" coords = [[0, 0], [5, 3], [-5, 1], [1, -5], [10, 10], [-10, -10], [1.5, 2.5], [0.4, 0.25]] expected = [[17, 17], [20, 22], [18, 12], [12, 18], [27, 27], [7, 7], [20, 18], [17, 17]] cubeCoords = convertCoords(coords, mode='pix', shape=galaxy.shape) pytest.approx(cubeCoords, np.array(expected))
def test_pix_lower(self): """Tests mode='pix', xyorig='lower'.""" coords = [[0, 0], [5, 3], [10, 10], [1.5, 2.5], [0.4, 0.25]] expected = [[0, 0], [3, 5], [10, 10], [2, 2], [0, 0]] cubeCoords = convertCoords(coords, mode='pix', shape=self.testShape, xyorig='lower') assert_allclose(cubeCoords, np.array(expected))
def test_sky(self, wcs, naxis0, coords): """Tests mode='sky'.""" print('wcs', wcs._naxis[0]) if wcs._naxis[0] != naxis0: pytest.skip('Skipping non-matching cube size.') expected = [[17, 17], [8, 27], [33, 33], [33, 26]] cubeCoords = convertCoords(np.array(coords), mode='sky', wcs=wcs) assert cubeCoords == pytest.approx(np.array(expected))
def test_pix_lower(self, galaxy): """Tests mode='pix', xyorig='lower'.""" coords = [[0, 0], [5, 3], [10, 10], [1.5, 2.5], [0.4, 0.25]] expected = [[0, 0], [3, 5], [10, 10], [2, 2], [0, 0]] cubeCoords = convertCoords(coords, mode='pix', shape=galaxy.shape, xyorig='lower') assert cubeCoords == pytest.approx(np.array(expected))