Skip to content

Commit

Permalink
Sphere -> SphereRandom, Cube -> CubeRandom, SphereIcosahedron -> Sphe…
Browse files Browse the repository at this point in the history
…reIcosahedral
  • Loading branch information
mdeff committed Nov 30, 2020
1 parent 2ba2372 commit d8c4a28
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 35 deletions.
12 changes: 6 additions & 6 deletions pygsp/graphs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
NNGraph
Bunny
Cube
CubeRandom
ImgPatches
Grid2dImgPatches
Sensor
Expand All @@ -178,9 +178,9 @@
SphereEquiangular
SphereGaussLegendre
SphereIcosahedron
SphereIcosahedral
SphereHealpix
Sphere
SphereRandom
"""

Expand Down Expand Up @@ -211,14 +211,14 @@
_NNGRAPHS = [
'NNGraph',
'Bunny',
'Cube',
'CubeRandom',
'ImgPatches',
'Grid2dImgPatches',
'Sensor',
'Sphere',
'SphereRandom',
'SphereGaussLegendre',
'SphereHealpix',
'SphereIcosahedron',
'SphereIcosahedral',
'TwoMoons'
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------
Expand All @@ -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')
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion pygsp/graphs/nngraphs/spheregausslegendre.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pygsp/graphs/nngraphs/spherehealpix.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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')
Expand All @@ -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')
Expand Down Expand Up @@ -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
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pygsp import utils


class Sphere(NNGraph):
class SphereRandom(NNGraph):
r"""Random uniform sampling of an hypersphere.
Parameters
Expand All @@ -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
Expand All @@ -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')
Expand All @@ -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)
Expand All @@ -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
2 changes: 1 addition & 1 deletion pygsp/graphs/sphereequiangular.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions pygsp/tests/test_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -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]:
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit d8c4a28

Please sign in to comment.