def xyz2sphericalR(xyz, offset, R):
            """ Calculate the spherical coordinates from indices """
            rx = xyz[:, 0] - offset[0]
            idx = indices_fabs_le(rx, R)
            ry = xyz[idx, 1] - offset[1]
            ix = indices_fabs_le(ry, R)
            ry = ry[ix]
            idx = idx[ix]
            rz = xyz[idx, 2] - offset[2]
            ix = indices_fabs_le(rz, R)
            ry = ry[ix]
            rz = rz[ix]
            idx = idx[ix]
            if len(idx) == 0:
                return [], [], [], []
            rx = rx[idx]

            # Calculate radius ** 2
            ix = indices_le(rx**2 + ry**2 + rz**2, R**2)
            idx = idx[ix]
            if len(idx) == 0:
                return [], [], [], []
            rx = rx[ix]
            ry = ry[ix]
            rz = rz[ix]
            xyz_to_spherical_cos_phi(rx, ry, rz)
            return idx, rx, ry, rz
        def xyz2spherical(xyz, offset):
            """ Calculate the spherical coordinates from indices """
            rx = xyz[:, 0] - offset[0]
            ry = xyz[:, 1] - offset[1]
            rz = xyz[:, 2] - offset[2]

            # Calculate radius ** 2
            xyz_to_spherical_cos_phi(rx, ry, rz)
            return rx, ry, rz
 def idx2spherical(ix, iy, iz, offset, dc, R):
     """ Calculate the spherical coordinates from indices """
     rx = addouter(addouter(ix * dc[0, 0], iy * dc[1, 0]),
                   iz * dc[2, 0] - offset[0]).ravel()
     ry = addouter(addouter(ix * dc[0, 1], iy * dc[1, 1]),
                   iz * dc[2, 1] - offset[1]).ravel()
     rz = addouter(addouter(ix * dc[0, 2], iy * dc[1, 2]),
                   iz * dc[2, 2] - offset[2]).ravel()
     # Total size of the indices
     n = rx.shape[0]
     # Reduce our arrays to where the radius is "fine"
     idx = indices_le(rx**2 + ry**2 + rz**2, R**2)
     rx = rx[idx]
     ry = ry[idx]
     rz = rz[idx]
     xyz_to_spherical_cos_phi(rx, ry, rz)
     return n, idx, rx, ry, rz