# Examples from pyvista.StructuredSphere
# ======================================

# Create a sphere as a structured surface using default parameters.
import numpy as np
import pyvista as pv
sphere = pv.StructuredSphere()
sphere.plot(show_edges=True)

# The dimensions follow the `i-j-k` ordering: one entry per radius, then
# `phi_resolution`, then `theta_resolution` plus one.
pv.StructuredSphere(theta_resolution=20, phi_resolution=10).dimensions

# Swapping the two resolutions swaps the last two dimensions, and the extra
# point stays with theta.
pv.StructuredSphere(theta_resolution=10, phi_resolution=20).dimensions

# Use a sequence of radii to set the first dimension and generate a 3D grid
# with concentric layers of cells. This is useful for modeling volumetric data
# such as an atmosphere.
pv.StructuredSphere(
    radius=[1.0, 1.5, 2.0], theta_resolution=20, phi_resolution=10
).dimensions

# Show the layers by clipping the grid in half.
sphere = pv.StructuredSphere(radius=np.linspace(1, 2, 5))
sphere.clip(normal='x').plot(show_edges=True)

# Create a partial sphere by restricting the angular ranges.
sphere = pv.StructuredSphere(
    start_theta=90, end_theta=270, start_phi=30, end_phi=150
)
sphere.plot(show_edges=True)

# Use the `i-j-k` ordering to work with the grid by index. Since `i` is the
# radial axis, an array shaped like
# `dimensions` assigns a value per layer.
sphere = pv.StructuredSphere(radius=np.linspace(1, 2, 5))
layer = np.zeros(sphere.dimensions)
layer[:] = np.arange(5).reshape(5, 1, 1)
sphere['layer'] = layer.ravel(order='F')
sphere.clip(normal='y').plot(scalars='layer', show_edges=True)

# The same indexing selects part of the grid, here the outermost layer of
# points.
outer = sphere.extract_subset([4, 4, 0, 29, 0, 30])
outer.dimensions

# ----------------------------------------------------------------------
# Generated by sphinx-examples-as-code https://github.com/pyvista/sphinx-examples-as-code
