Skip to content

Commit

Permalink
[#133] Created plot_sphere_surface() (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
dignojrteogalbo authored Mar 12, 2024
1 parent 7972a8c commit b076b36
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 8 deletions.
28 changes: 20 additions & 8 deletions GoVizzy/GoVizzy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,18 @@
"id": "09026008-ce47-49d7-9fca-4b7c123022d1",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/mnt/d/Documents/GoVizzy/s24-slice-n-dice/.venv/lib/python3.11/site-packages/pandas/core/arrays/masked.py:60: UserWarning: Pandas requires version '1.3.6' or newer of 'bottleneck' (version '1.3.5' currently installed).\n",
" from pandas.core import (\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "fe1d0a81c0c74a07be2994082d69065b",
"model_id": "9c1c4da74c5e45ebbd1e0cf73c8c6f87",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -45,12 +53,13 @@
],
"source": [
"from widgets import form, test_slider\n",
"from GoVizzy import plotting\n",
"from GoVizzy import plotting, meshes\n",
"from UI import DisplayUI\n",
"import fileInput\n",
"import ipyvolume as ipv\n",
"import numpy as np\n",
"from cube_viskit import Cube"
"from cube_viskit import Cube\n",
"import itertools"
]
},
{
Expand Down Expand Up @@ -81,7 +90,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 18,
"id": "ef52d91c-9d81-41db-953b-78f7ef718f24",
"metadata": {},
"outputs": [
Expand All @@ -96,7 +105,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "db7b576af62c48a294254ecdc19f7c3b",
"model_id": "d55b62f3bc1246d59178a47ba3fe83d0",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -114,7 +123,10 @@
"cube.load_cube(\"data/rhopol.cube\")\n",
"visualizer = plotting.Visualizer(cube)\n",
"# Display Cube File\n",
"visualizer.display_cell()"
"visualizer.display_cell()\n",
"origin = (50, 50, 50)\n",
"radius = 10\n",
"meshes.plot_sphere_surface(origin, radius)"
]
},
{
Expand Down Expand Up @@ -146,7 +158,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "2cc4ec86-2666-442f-a30b-7727d2a2ad9a",
"id": "9c03262a-288d-45e2-b5df-96a191097c9e",
"metadata": {},
"outputs": [],
"source": []
Expand All @@ -168,7 +180,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.7"
"version": "3.11.5"
}
},
"nbformat": 4,
Expand Down
26 changes: 26 additions & 0 deletions GoVizzy/GoVizzy/meshes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from widgets import color
from cube_viskit import Cube
import ipywidgets as widgets
import ipyvolume as ipv
import numpy as np
from IPython.display import display

def plot_sphere_surface(origin: tuple[int, int, int]=(0, 0, 0), radius: int=1, color: str="red"):
'''
Plots on an existing ipyvolume figure the surface of a sphere. By default
the sphere is located at the origin (0, 0, 0) with a radius of 1 and color
"red".
'''
x_origin, y_origin, z_origin = origin
step = 0.1
gridx, gridy = np.ix_(np.arange(0, np.pi + step, step), np.arange(0, 2 * np.pi + step, step))

@np.vectorize
def sphere_surface(phi: float, theta: float):
x = x_origin + radius * np.sin(phi) * np.cos(theta)
y = y_origin + radius * np.sin(phi) * np.sin(theta)
z = z_origin + radius * np.cos(phi)
return (x, y, z)

x, y, z = np.array(list(sphere_surface(gridx, gridy)))
ipv.plot_surface(x, z, y, color=color)

0 comments on commit b076b36

Please sign in to comment.