From d8c4a28ca279609163f64fb3492c05da19e85e62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Defferrard?= Date: Mon, 23 Nov 2020 23:01:36 +0100 Subject: [PATCH] Sphere -> SphereRandom, Cube -> CubeRandom, SphereIcosahedron -> SphereIcosahedral --- pygsp/graphs/__init__.py | 12 +++++------ .../nngraphs/{cube.py => cuberandom.py} | 11 +++++----- pygsp/graphs/nngraphs/spheregausslegendre.py | 2 +- pygsp/graphs/nngraphs/spherehealpix.py | 2 +- ...ereicosahedron.py => sphereicosahedral.py} | 12 +++++------ .../nngraphs/{sphere.py => sphererandom.py} | 10 +++++----- pygsp/graphs/sphereequiangular.py | 2 +- pygsp/tests/test_graphs.py | 20 +++++++++---------- 8 files changed, 36 insertions(+), 35 deletions(-) rename pygsp/graphs/nngraphs/{cube.py => cuberandom.py} (82%) rename pygsp/graphs/nngraphs/{sphereicosahedron.py => sphereicosahedral.py} (93%) rename pygsp/graphs/nngraphs/{sphere.py => sphererandom.py} (88%) diff --git a/pygsp/graphs/__init__.py b/pygsp/graphs/__init__.py index 6805a6d1..1697595e 100644 --- a/pygsp/graphs/__init__.py +++ b/pygsp/graphs/__init__.py @@ -165,7 +165,7 @@ NNGraph Bunny - Cube + CubeRandom ImgPatches Grid2dImgPatches Sensor @@ -178,9 +178,9 @@ SphereEquiangular SphereGaussLegendre - SphereIcosahedron + SphereIcosahedral SphereHealpix - Sphere + SphereRandom """ @@ -211,14 +211,14 @@ _NNGRAPHS = [ 'NNGraph', 'Bunny', - 'Cube', + 'CubeRandom', 'ImgPatches', 'Grid2dImgPatches', 'Sensor', - 'Sphere', + 'SphereRandom', 'SphereGaussLegendre', 'SphereHealpix', - 'SphereIcosahedron', + 'SphereIcosahedral', 'TwoMoons' ] diff --git a/pygsp/graphs/nngraphs/cube.py b/pygsp/graphs/nngraphs/cuberandom.py similarity index 82% rename from pygsp/graphs/nngraphs/cube.py rename to pygsp/graphs/nngraphs/cuberandom.py index 180d2210..c6d839d2 100644 --- a/pygsp/graphs/nngraphs/cube.py +++ b/pygsp/graphs/nngraphs/cuberandom.py @@ -5,8 +5,8 @@ from pygsp.graphs import NNGraph # prevent circular import in Python < 3.5 -class Cube(NNGraph): - r"""Randomly sampled cube. +class CubeRandom(NNGraph): + r"""Random uniform sampling of a cube. Parameters ---------- @@ -19,11 +19,12 @@ class Cube(NNGraph): See Also -------- Sensor : randomly sampled square + SphereRandom : randomly sampled hypersphere Examples -------- >>> import matplotlib.pyplot as plt - >>> G = graphs.Cube(seed=42) + >>> G = graphs.CubeRandom(seed=42) >>> fig = plt.figure() >>> ax1 = fig.add_subplot(121) >>> ax2 = fig.add_subplot(122, projection='3d') @@ -54,9 +55,9 @@ def __init__(self, N=300, seed=None, **kwargs): 'distance': 9, } - super(Cube, self).__init__(coords, plotting=plotting, **kwargs) + super(CubeRandom, self).__init__(coords, plotting=plotting, **kwargs) def _get_extra_repr(self): attrs = {'seed': self.seed} - attrs.update(super(Cube, self)._get_extra_repr()) + attrs.update(super(CubeRandom, self)._get_extra_repr()) return attrs diff --git a/pygsp/graphs/nngraphs/spheregausslegendre.py b/pygsp/graphs/nngraphs/spheregausslegendre.py index 9f699297..53db425c 100644 --- a/pygsp/graphs/nngraphs/spheregausslegendre.py +++ b/pygsp/graphs/nngraphs/spheregausslegendre.py @@ -32,7 +32,7 @@ class SphereGaussLegendre(NNGraph): See Also -------- SphereEquiangular : based on quadrature theorems - SphereIcosahedron, SphereHealpix : based on subdivided polyhedra + SphereIcosahedral, SphereHealpix : based on subdivided polyhedra SphereRandom : random uniform sampling Notes diff --git a/pygsp/graphs/nngraphs/spherehealpix.py b/pygsp/graphs/nngraphs/spherehealpix.py index 803afb0c..1ae727f0 100644 --- a/pygsp/graphs/nngraphs/spherehealpix.py +++ b/pygsp/graphs/nngraphs/spherehealpix.py @@ -43,7 +43,7 @@ class SphereHealpix(NNGraph): See Also -------- SphereEquiangular, SphereGaussLegendre : based on quadrature theorems - SphereIcosahedron : based on subdivided polyhedra + SphereIcosahedral : based on subdivided polyhedra SphereRandom : random uniform sampling Notes diff --git a/pygsp/graphs/nngraphs/sphereicosahedron.py b/pygsp/graphs/nngraphs/sphereicosahedral.py similarity index 93% rename from pygsp/graphs/nngraphs/sphereicosahedron.py rename to pygsp/graphs/nngraphs/sphereicosahedral.py index 6aff6465..f16303b0 100644 --- a/pygsp/graphs/nngraphs/sphereicosahedron.py +++ b/pygsp/graphs/nngraphs/sphereicosahedral.py @@ -18,7 +18,7 @@ def _import_trimesh(): return trimesh -class SphereIcosahedron(NNGraph): +class SphereIcosahedral(NNGraph): r"""Sphere sampled as a subdivided icosahedron. Background information is found at :doc:`/background/spherical_samplings`. @@ -61,7 +61,7 @@ class SphereIcosahedron(NNGraph): Examples -------- >>> import matplotlib.pyplot as plt - >>> G = graphs.SphereIcosahedron() + >>> G = graphs.SphereIcosahedral() >>> fig = plt.figure() >>> ax1 = fig.add_subplot(131) >>> ax2 = fig.add_subplot(132, projection='3d') @@ -75,10 +75,10 @@ class SphereIcosahedron(NNGraph): >>> import matplotlib.pyplot as plt >>> fig, axes = plt.subplots(1, 2) - >>> graph = graphs.SphereIcosahedron(0, dual=False, k=5) + >>> graph = graphs.SphereIcosahedral(0, dual=False, k=5) >>> graph.set_coordinates('sphere', dim=2) >>> _ = graph.plot(indices=True, ax=axes[0], title='Icosahedron') - >>> graph = graphs.SphereIcosahedron(0, dual=True, k=3) + >>> graph = graphs.SphereIcosahedral(0, dual=True, k=3) >>> graph.set_coordinates('sphere', dim=2) >>> _ = graph.plot(indices=True, ax=axes[1], title='Dodecahedron') @@ -127,7 +127,7 @@ def normalize(vertices): vertices = mesh.vertices[mesh.faces].mean(axis=1) normalize(vertices) - super(SphereIcosahedron, self).__init__(vertices, **kwargs) + super(SphereIcosahedral, self).__init__(vertices, **kwargs) lat, lon = utils.xyz2latlon(*vertices.T) self.signals['lat'] = lat @@ -138,5 +138,5 @@ def _get_extra_repr(self): 'subdivisions': self.subdivisions, 'dual': self.dual, } - attrs.update(super(SphereIcosahedron, self)._get_extra_repr()) + attrs.update(super(SphereIcosahedral, self)._get_extra_repr()) return attrs diff --git a/pygsp/graphs/nngraphs/sphere.py b/pygsp/graphs/nngraphs/sphererandom.py similarity index 88% rename from pygsp/graphs/nngraphs/sphere.py rename to pygsp/graphs/nngraphs/sphererandom.py index d472d536..731cb311 100644 --- a/pygsp/graphs/nngraphs/sphere.py +++ b/pygsp/graphs/nngraphs/sphererandom.py @@ -6,7 +6,7 @@ from pygsp import utils -class Sphere(NNGraph): +class SphereRandom(NNGraph): r"""Random uniform sampling of an hypersphere. Parameters @@ -29,7 +29,7 @@ class Sphere(NNGraph): See Also -------- SphereEquiangular, SphereGaussLegendre : based on quadrature theorems - SphereIcosahedron, SphereHealpix : based on subdivided polyhedra + SphereIcosahedral, SphereHealpix : based on subdivided polyhedra CubeRandom : randomly sampled cube References @@ -42,7 +42,7 @@ class Sphere(NNGraph): Examples -------- >>> import matplotlib.pyplot as plt - >>> G = graphs.Sphere(100, seed=42) + >>> G = graphs.SphereRandom(100, seed=42) >>> fig = plt.figure() >>> ax1 = fig.add_subplot(131) >>> ax2 = fig.add_subplot(132, projection='3d') @@ -67,7 +67,7 @@ def __init__(self, N=300, dim=3, seed=None, **kwargs): 'vertex_size': 80, } - super(Sphere, self).__init__(coords, plotting=plotting, **kwargs) + super(SphereRandom, self).__init__(coords, plotting=plotting, **kwargs) if dim == 3: lat, lon = utils.xyz2latlon(*coords.T) @@ -79,5 +79,5 @@ def _get_extra_repr(self): 'dim': self.dim, 'seed': self.seed, } - attrs.update(super(Sphere, self)._get_extra_repr()) + attrs.update(super(SphereRandom, self)._get_extra_repr()) return attrs diff --git a/pygsp/graphs/sphereequiangular.py b/pygsp/graphs/sphereequiangular.py index 46dbbb2e..0ae067b4 100644 --- a/pygsp/graphs/sphereequiangular.py +++ b/pygsp/graphs/sphereequiangular.py @@ -35,7 +35,7 @@ class SphereEquiangular(Graph): See Also -------- SphereGaussLegendre : based on quadrature theorems - SphereIcosahedron, SphereHealpix : based on subdivided polyhedra + SphereIcosahedral, SphereHealpix : based on subdivided polyhedra SphereRandom : random uniform sampling Notes diff --git a/pygsp/tests/test_graphs.py b/pygsp/tests/test_graphs.py index 80c9e37a..619800f1 100644 --- a/pygsp/tests/test_graphs.py +++ b/pygsp/tests/test_graphs.py @@ -481,10 +481,10 @@ def test_nngraph(self, n_vertices=30): def test_bunny(self): graphs.Bunny() - def test_cube(self): - self.assertEqual(graphs.Cube(60).n_vertices, 60) - self.assertEqual(graphs.Cube(65).n_vertices, 60) - graph = graphs.Cube(30) + def test_cube_random(self): + self.assertEqual(graphs.CubeRandom(60).n_vertices, 60) + self.assertEqual(graphs.CubeRandom(65).n_vertices, 60) + graph = graphs.CubeRandom(30) self.assertTrue(np.all(graph.coords >= 0)) self.assertTrue(np.all(graph.coords <= 1)) @@ -503,11 +503,11 @@ def _test_sphere(self, graph): graph.set_coordinates('sphere', dim=3) np.testing.assert_allclose(graph.coords, coords, atol=1e-7) - def test_sphere(self): - graph = graphs.Sphere(20, dim=4) + def test_sphere_random(self): + graph = graphs.SphereRandom(20, dim=4) self.assertTupleEqual(graph.coords.shape, (20, 4)) np.testing.assert_allclose(np.linalg.norm(graph.coords, axis=1), 1) - self._test_sphere(graphs.Sphere()) + self._test_sphere(graphs.SphereRandom()) def test_sphere_equiangular(self, size=7): for poles in [0, 1, 2]: @@ -555,17 +555,17 @@ def test_sphere_gausslegendre(self, nrings=11): self.assertRaises(NotImplementedError, graphs.SphereGaussLegendre, reduced='glesp-equal-area') - def test_sphere_icosahedron(self, subdivisions=3): + def test_sphere_icosahedral(self, subdivisions=3): n_faces = 20 * 4**subdivisions n_edges = 30 * 4**subdivisions n_vertices = n_edges - n_faces + 2 - graph = graphs.SphereIcosahedron(subdivisions, kind='radius', + graph = graphs.SphereIcosahedral(subdivisions, kind='radius', radius=1.6/2**subdivisions) self.assertEqual(graph.n_vertices, n_vertices) self.assertEqual(graph.n_edges, n_edges) self._test_sphere(graph) self.assertEqual(np.sum(graph.signals['lat'] == 0), 4*2**subdivisions) - graph = graphs.SphereIcosahedron(subdivisions, dual=True, k=3) + graph = graphs.SphereIcosahedral(subdivisions, dual=True, k=3) self.assertEqual(graph.n_vertices, n_faces) self.assertEqual(graph.n_edges, n_edges) self._test_sphere(graph)