Skip to content

Commit 38f771d

Browse files
author
anna-charlotte
committed
fix: only display in notebook
Signed-off-by: anna-charlotte <[email protected]>
1 parent 3a8dc5e commit 38f771d

File tree

5 files changed

+11
-37
lines changed

5 files changed

+11
-37
lines changed

docarray/documents/mesh/mesh_3d.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class Mesh3D(BaseDocument):
4646
from docarray.typing import AnyEmbedding
4747
from typing import Optional
4848
49+
4950
# extend it
5051
class MyMesh3D(Mesh3D):
5152
name: Optional[Text]
@@ -65,6 +66,7 @@ class MyMesh3D(Mesh3D):
6566
from docarray import BaseDocument
6667
from docarray.documents import Mesh3D, Text
6768
69+
6870
# compose it
6971
class MultiModalDoc(BaseDocument):
7072
mesh: Mesh3D
@@ -81,7 +83,7 @@ class MultiModalDoc(BaseDocument):
8183
mmdoc.mesh.bytes = mmdoc.mesh.url.load_bytes()
8284
8385
84-
You can display your 3D mesh from either its url, or its tensors:
86+
You can display your 3D mesh in a notebook from either its url, or its tensors:
8587
8688
.. code-block:: python
8789

docarray/documents/point_cloud/points_and_colors.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from docarray.base_document import BaseDocument
66
from docarray.typing import AnyTensor
77
from docarray.typing.tensor.abstract_tensor import AbstractTensor
8-
from docarray.utils.misc import is_notebook, is_tf_available, is_torch_available
8+
from docarray.utils.misc import is_tf_available, is_torch_available
99

1010
torch_available = is_torch_available()
1111
if torch_available:
@@ -46,7 +46,8 @@ def validate(
4646

4747
def display(self) -> None:
4848
"""
49-
Plot point cloud consisting of points in 3D space and optionally colors.
49+
Plot point cloud consisting of points in 3D space and optionally colors in
50+
notebook.
5051
"""
5152
import trimesh
5253
from IPython.display import display
@@ -61,8 +62,5 @@ def display(self) -> None:
6162
)
6263
pc = trimesh.points.PointCloud(vertices=self.points, colors=colors)
6364

64-
if is_notebook():
65-
s = trimesh.Scene(geometry=pc)
66-
display(s.show())
67-
else:
68-
display(pc.show())
65+
s = trimesh.Scene(geometry=pc)
66+
display(s.show())

docarray/typing/url/url_3d/mesh_url.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class MyDoc(BaseDocument):
5959

6060
def display(self) -> None:
6161
"""
62-
Plot mesh from url.
62+
Plot mesh in notebook from url.
6363
This loads the Trimesh instance of the 3D mesh, and then displays it.
6464
"""
6565
from IPython.display import display

docarray/typing/url/url_3d/point_cloud_url.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class MyDoc(BaseDocument):
7373

7474
def display(self, samples: int = 10000) -> None:
7575
"""
76-
Plot point cloud from url.
76+
Plot point cloud in notebook from url.
7777
First, it loads the point cloud into a :class:`PointsAndColors` object, and then
7878
calls display on it. The following is therefore equivalent:
7979
@@ -90,7 +90,7 @@ def display(self, samples: int = 10000) -> None:
9090
pc.url.display()
9191
9292
# option 2 (equivalent)
93-
pc.url.load().display()
93+
pc.url.load(samples=10000).display()
9494
9595
:param samples: number of points to sample from the mesh.
9696
"""

docarray/utils/misc.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,3 @@ def is_torch_available():
2020

2121
def is_tf_available():
2222
return tf_imported
23-
24-
25-
def is_notebook() -> bool:
26-
"""
27-
Check if we're running in a Jupyter notebook, using magic command
28-
`get_ipython` that only available in Jupyter.
29-
30-
:return: True if run in a Jupyter notebook else False.
31-
"""
32-
33-
try:
34-
shell = get_ipython().__class__.__name__ # type: ignore
35-
except NameError:
36-
return False
37-
38-
if shell == 'ZMQInteractiveShell':
39-
return True
40-
41-
elif shell == 'Shell':
42-
return True
43-
44-
elif shell == 'TerminalInteractiveShell':
45-
return False
46-
47-
else:
48-
return False

0 commit comments

Comments
 (0)