Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python: Named component accessors for S2Point #268

Merged
merged 2 commits into from
Aug 24, 2022

Conversation

podsvirov
Copy link
Contributor

With this small change we can code something like this:

import numpy as np
from pywraps2 import S2Cell, S2CellId
from matplotlib import pyplot as plt

def surf4face(f, l):
    m = 2**l; m1 = m + 1; m2 = m - 1
    k = range(0, 2**S2CellId.kMaxLevel, 2**(S2CellId.kMaxLevel - l))
    x = np.empty((m1,m1)); y = np.empty((m1,m1)); z = np.empty((m1,m1));
    for i in range(m):
        for j in range(m):
            c = S2Cell(S2CellId.FromFaceIJ(f, k[i], k[j]).parent(l))
            v = c.GetVertex(0)
            x[i][j] = v.x(); y[i][j] = v.y(); z[i][j] = v.z();
            if i == m2:
                v = c.GetVertex(1)
                x[m][j] = v.x(); y[m][j] = v.y(); z[m][j] = v.z();
            if j == m2:
                v = c.GetVertex(3)
                x[i][m] = v.x(); y[i][m] = v.y(); z[i][m] = v.z();
            if i == m2 and j == m2:
                v = c.GetVertex(2)
                x[m][m] = v.x(); y[m][m] = v.y(); z[m][m] = v.z();
    return (x, y, z)

fig = plt.figure()
ax = fig.add_subplot(projection='3d')

for f in range(6):
    s = surf4face(f, 2)
    ax.plot_surface(*s, color='blue')
    ax.plot_wireframe(*s, color='green')

fig.savefig('s2sphere.svg')

to render this:

s2sphere

and not only...

@MikePlayle
Copy link
Contributor

This overlaps with a change that I proposed: e8f4ae4

I don't know which way is better. I'd be happy with either.

@podsvirov
Copy link
Contributor Author

The changes do not conflict, but complement each other. I hope that one small change will be quickly reviewed and accepted.

@jmr
Copy link
Member

jmr commented Aug 24, 2022

Please add a test to pywraps2_test.py so these new functions don't get broken in the future.

@podsvirov
Copy link
Contributor Author

Please add a test to pywraps2_test.py so these new functions don't get broken in the future.

Done. Please review again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants