You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Adding indices at coords to other structured mesh types #3867
I've gone through PR #3824 discussion and the current state of the code. It looks like RectilinearMesh.get_indices_at_coords was already added (using np.searchsorted per axis with boundary clamping), so the only remaining piece is SphericalMesh.
My approach for SphericalMesh.get_indices_at_coords:
Accept Cartesian (x, y, z) coordinates (consistent with CylindricalMesh)
Convert to spherical (r, theta, phi) relative to self.origin:
r = sqrt(dx**2 + dy**2 + dz**2)
theta = arccos(dz / r) (polar angle from z-axis)
phi = atan2(dy, dx), normalized to [0, 2*pi]
Validate each value against its grid bounds, raising ValueError if outside (following CylindricalMesh precedent)
Find bin indices with np.searchsorted(..., side='right') - 1
Handle the degenerate case r = 0 where theta and phi are undefined: default to theta = 0, phi = 0
Return (r_index, theta_index, phi_index)
I'll also add tests following the existing pattern in test_mesh.py.
Activity
EdenRochmanSharabi commentedon Apr 5, 2026
Hi, I'd like to take this on.
I've gone through PR #3824 discussion and the current state of the code. It looks like
RectilinearMesh.get_indices_at_coordswas already added (usingnp.searchsortedper axis with boundary clamping), so the only remaining piece isSphericalMesh.My approach for
SphericalMesh.get_indices_at_coords:(x, y, z)coordinates (consistent withCylindricalMesh)(r, theta, phi)relative toself.origin:r = sqrt(dx**2 + dy**2 + dz**2)theta = arccos(dz / r)(polar angle from z-axis)phi = atan2(dy, dx), normalized to[0, 2*pi]ValueErrorif outside (followingCylindricalMeshprecedent)np.searchsorted(..., side='right') - 1r = 0wherethetaandphiare undefined: default totheta = 0, phi = 0(r_index, theta_index, phi_index)I'll also add tests following the existing pattern in
test_mesh.py.Does this approach sound right?
Implement SphericalMesh.get_indices_at_coords