Url
docarray.typing.url
AnyUrl
Bases: BaseAnyUrl
, AbstractType
Source code in docarray/typing/url/any_url.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
|
build(*, scheme, user=None, password=None, host, port=None, path=None, query=None, fragment=None, **_kwargs)
classmethod
Build a URL from its parts.
The only difference from the pydantic implementation is that we allow
missing scheme
, making it possible to pass a file path without prefix.
Source code in docarray/typing/url/any_url.py
from_protobuf(pb_msg)
classmethod
Read url from a proto msg.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pb_msg |
str
|
required |
Returns:
Type | Description |
---|---|
T
|
url |
load_bytes(timeout=None)
Convert url to bytes. This will either load or download the file and save it into a bytes object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timeout |
Optional[float]
|
timeout for urlopen. Only relevant if URI is not local |
None
|
Returns:
Type | Description |
---|---|
bytes
|
bytes. |
Source code in docarray/typing/url/any_url.py
validate_parts(parts, validate_port=True)
classmethod
A method used to validate parts of a URL.
Our URLs should be able to function both in local and remote settings.
Therefore, we allow missing scheme
, making it possible to pass a file
path without prefix.
If scheme
is missing, we assume it is a local file path.
Source code in docarray/typing/url/any_url.py
AudioUrl
Bases: AnyUrl
URL to an audio file. Can be remote (web) URL, or a local file path.
Source code in docarray/typing/url/audio_url.py
display()
Play the audio sound from url in notebook.
Source code in docarray/typing/url/audio_url.py
load()
Load the data from the url into an AudioNdArray
and the frame rate.
from typing import Optional
from docarray import BaseDoc
from docarray.typing import AudioNdArray, AudioUrl
class MyDoc(BaseDoc):
audio_url: AudioUrl
audio_tensor: Optional[AudioNdArray]
doc = MyDoc(audio_url='https://www.kozco.com/tech/piano2.wav')
doc.audio_tensor, _ = doc.audio_url.load()
assert isinstance(doc.audio_tensor, AudioNdArray)
Returns:
Type | Description |
---|---|
Tuple[AudioNdArray, int]
|
tuple of an |
Source code in docarray/typing/url/audio_url.py
load_bytes(timeout=None)
Convert url to AudioBytes
. This will either load or
download the file and save it into an AudioBytes
object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timeout |
Optional[float]
|
timeout for urlopen. Only relevant if url is not local |
None
|
Returns:
Type | Description |
---|---|
AudioBytes
|
|
Source code in docarray/typing/url/audio_url.py
ImageUrl
Bases: AnyUrl
URL to an image file. Can be remote (web) URL, or a local file path.
Source code in docarray/typing/url/image_url.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
|
display()
Display image data from url in notebook.
Source code in docarray/typing/url/image_url.py
load(width=None, height=None, axis_layout=('H', 'W', 'C'), timeout=None)
Load the data from the url into an ImageNdArray
from docarray import BaseDoc
from docarray.typing import ImageUrl, ImageNdArray
class MyDoc(BaseDoc):
img_url: ImageUrl
doc = MyDoc(
img_url="https://upload.wikimedia.org/wikipedia/commons/8/80/"
"Dag_Sebastian_Ahlander_at_G%C3%B6teborg_Book_Fair_2012b.jpg"
)
img_tensor = doc.img_url.load()
assert isinstance(img_tensor, ImageNdArray)
img_tensor = doc.img_url.load(height=224, width=224)
assert img_tensor.shape == (224, 224, 3)
layout = ('C', 'W', 'H')
img_tensor = doc.img_url.load(height=100, width=200, axis_layout=layout)
assert img_tensor.shape == (3, 200, 100)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
width |
Optional[int]
|
width of the image tensor. |
None
|
height |
Optional[int]
|
height of the image tensor. |
None
|
axis_layout |
Tuple[str, str, str]
|
ordering of the different image axes. 'H' = height, 'W' = width, 'C' = color channel |
('H', 'W', 'C')
|
timeout |
Optional[float]
|
timeout (sec) for urlopen network request. Only relevant if URL is not local |
None
|
Returns:
Type | Description |
---|---|
ImageNdArray
|
|
Source code in docarray/typing/url/image_url.py
load_bytes(timeout=None)
Convert url to ImageBytes
. This will either load or
download the file and save it into an ImageBytes
object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timeout |
Optional[float]
|
timeout for urlopen. Only relevant if url is not local |
None
|
Returns:
Type | Description |
---|---|
ImageBytes
|
|
Source code in docarray/typing/url/image_url.py
load_pil(timeout=None)
Load the image from the bytes into a PIL.Image.Image
instance
from pydantic import parse_obj_as
from docarray import BaseDoc
from docarray.typing import ImageUrl
img_url = "https://upload.wikimedia.org/wikipedia/commons/8/80/Dag_Sebastian_Ahlander_at_G%C3%B6teborg_Book_Fair_2012b.jpg"
img_url = parse_obj_as(ImageUrl, img_url)
img = img_url.load_pil()
from PIL.Image import Image
assert isinstance(img, Image)
Returns:
Type | Description |
---|---|
Image
|
a Pillow image |
Source code in docarray/typing/url/image_url.py
Mesh3DUrl
Bases: Url3D
URL to a file containing 3D mesh information. Can be remote (web) URL, or a local file path.
Source code in docarray/typing/url/url_3d/mesh_url.py
display()
Plot mesh from url. This loads the Trimesh instance of the 3D mesh, and then displays it.
Source code in docarray/typing/url/url_3d/mesh_url.py
load(skip_materials=True, trimesh_args=None)
Load the data from the url into a VerticesAndFaces
object containing vertices and faces information.
from docarray import BaseDoc
from docarray.typing import Mesh3DUrl, NdArray
class MyDoc(BaseDoc):
mesh_url: Mesh3DUrl
doc = MyDoc(mesh_url="https://people.sc.fsu.edu/~jburkardt/data/obj/al.obj")
tensors = doc.mesh_url.load()
assert isinstance(tensors.vertices, NdArray)
assert isinstance(tensors.faces, NdArray)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
skip_materials |
bool
|
Skip materials if True, else skip. |
True
|
trimesh_args |
Optional[Dict[str, Any]]
|
dictionary of additional arguments for |
None
|
Returns:
Type | Description |
---|---|
VerticesAndFaces
|
VerticesAndFaces object containing vertices and faces information. |
Source code in docarray/typing/url/url_3d/mesh_url.py
PointCloud3DUrl
Bases: Url3D
URL to a file containing point cloud information. Can be remote (web) URL, or a local file path.
Source code in docarray/typing/url/url_3d/point_cloud_url.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
|
display(samples=10000)
Plot point cloud from url.
First, it loads the point cloud into a PointsAndColors
object, and then
calls display on it. The following is therefore equivalent:
import numpy as np
from docarray import BaseDoc
from docarray.documents import PointCloud3D
pc = PointCloud3D(url="https://people.sc.fsu.edu/~jburkardt/data/obj/al.obj")
# option 1
# pc.url.display()
# option 2 (equivalent)
# pc.url.load(samples=10000).display()
Parameters:
Name | Type | Description | Default |
---|---|---|---|
samples |
int
|
number of points to sample from the mesh. |
10000
|
Source code in docarray/typing/url/url_3d/point_cloud_url.py
load(samples, multiple_geometries=False, skip_materials=True, trimesh_args=None)
Load the data from the url into an NdArray
containing point cloud information.
import numpy as np
from docarray import BaseDoc
from docarray.typing import PointCloud3DUrl
class MyDoc(BaseDoc):
point_cloud_url: PointCloud3DUrl
doc = MyDoc(point_cloud_url="thttps://people.sc.fsu.edu/~jburkardt/data/obj/al.obj")
# point_cloud = doc.point_cloud_url.load(samples=100)
# assert isinstance(point_cloud, np.ndarray)
# assert point_cloud.shape == (100, 3)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
samples |
int
|
number of points to sample from the mesh |
required |
multiple_geometries |
bool
|
if False, store point cloud in 2D np.ndarray. If True, store point clouds from multiple geometries in 3D np.ndarray. |
False
|
skip_materials |
bool
|
Skip materials if True, else load. |
True
|
trimesh_args |
Optional[Dict[str, Any]]
|
dictionary of additional arguments for |
None
|
Returns:
Type | Description |
---|---|
PointsAndColors
|
np.ndarray representing the point cloud |
Source code in docarray/typing/url/url_3d/point_cloud_url.py
TextUrl
Bases: AnyUrl
URL to a text file. Can be remote (web) URL, or a local file path.
Source code in docarray/typing/url/text_url.py
load(charset='utf-8', timeout=None)
Load the text file into a string.
from docarray import BaseDoc
from docarray.typing import TextUrl
class MyDoc(BaseDoc):
remote_url: TextUrl
doc = MyDoc(
remote_url='https://de.wikipedia.org/wiki/Brixen',
)
remote_txt = doc.remote_url.load()
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timeout |
Optional[float]
|
timeout (sec) for urlopen network request. Only relevant if URL is not local |
None
|
charset |
str
|
decoding charset; may be any character set registered with IANA |
'utf-8'
|
Returns:
Type | Description |
---|---|
str
|
the text file content |
Source code in docarray/typing/url/text_url.py
VideoUrl
Bases: AnyUrl
URL to a video file. Can be remote (web) URL, or a local file path.
Source code in docarray/typing/url/video_url.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|
display()
Play video from url in notebook.
Source code in docarray/typing/url/video_url.py
load(**kwargs)
Load the data from the url into a NamedTuple
of
VideoNdArray
,
AudioNdArray
and NdArray
.
from typing import Optional
from docarray import BaseDoc
from docarray.typing import VideoUrl, VideoNdArray, AudioNdArray, NdArray
class MyDoc(BaseDoc):
video_url: VideoUrl
video: Optional[VideoNdArray]
audio: Optional[AudioNdArray]
key_frame_indices: Optional[NdArray]
doc = MyDoc(
video_url='https://github.com/docarray/docarray/blob/main/tests/toydata/mov_bbb.mp4?raw=true'
)
doc.video, doc.audio, doc.key_frame_indices = doc.video_url.load()
assert isinstance(doc.video, VideoNdArray)
assert isinstance(doc.audio, AudioNdArray)
assert isinstance(doc.key_frame_indices, NdArray)
You can load only the key frames (or video, audio respectively):
from pydantic import parse_obj_as
from docarray.typing import NdArray, VideoUrl
url = parse_obj_as(
VideoUrl,
'https://github.com/docarray/docarray/blob/main/tests/toydata/mov_bbb.mp4?raw=true',
)
key_frame_indices = url.load().key_frame_indices
assert isinstance(key_frame_indices, NdArray)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kwargs |
supports all keyword arguments that are being supported by av.open() as described here |
{}
|
Returns:
Type | Description |
---|---|
VideoLoadResult
|
|
Source code in docarray/typing/url/video_url.py
load_bytes(timeout=None)
Convert url to VideoBytes
. This will either load or download
the file and save it into an VideoBytes
object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timeout |
Optional[float]
|
timeout for urlopen. Only relevant if url is not local |
None
|
Returns:
Type | Description |
---|---|
VideoBytes
|
|
Source code in docarray/typing/url/video_url.py
any_url
AnyUrl
Bases: BaseAnyUrl
, AbstractType
Source code in docarray/typing/url/any_url.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
|
build(*, scheme, user=None, password=None, host, port=None, path=None, query=None, fragment=None, **_kwargs)
classmethod
Build a URL from its parts.
The only difference from the pydantic implementation is that we allow
missing scheme
, making it possible to pass a file path without prefix.
Source code in docarray/typing/url/any_url.py
from_protobuf(pb_msg)
classmethod
Read url from a proto msg.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pb_msg |
str
|
required |
Returns:
Type | Description |
---|---|
T
|
url |
load_bytes(timeout=None)
Convert url to bytes. This will either load or download the file and save it into a bytes object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timeout |
Optional[float]
|
timeout for urlopen. Only relevant if URI is not local |
None
|
Returns:
Type | Description |
---|---|
bytes
|
bytes. |
Source code in docarray/typing/url/any_url.py
validate_parts(parts, validate_port=True)
classmethod
A method used to validate parts of a URL.
Our URLs should be able to function both in local and remote settings.
Therefore, we allow missing scheme
, making it possible to pass a file
path without prefix.
If scheme
is missing, we assume it is a local file path.
Source code in docarray/typing/url/any_url.py
audio_url
AudioUrl
Bases: AnyUrl
URL to an audio file. Can be remote (web) URL, or a local file path.
Source code in docarray/typing/url/audio_url.py
display()
Play the audio sound from url in notebook.
Source code in docarray/typing/url/audio_url.py
load()
Load the data from the url into an AudioNdArray
and the frame rate.
from typing import Optional
from docarray import BaseDoc
from docarray.typing import AudioNdArray, AudioUrl
class MyDoc(BaseDoc):
audio_url: AudioUrl
audio_tensor: Optional[AudioNdArray]
doc = MyDoc(audio_url='https://www.kozco.com/tech/piano2.wav')
doc.audio_tensor, _ = doc.audio_url.load()
assert isinstance(doc.audio_tensor, AudioNdArray)
Returns:
Type | Description |
---|---|
Tuple[AudioNdArray, int]
|
tuple of an |
Source code in docarray/typing/url/audio_url.py
load_bytes(timeout=None)
Convert url to AudioBytes
. This will either load or
download the file and save it into an AudioBytes
object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timeout |
Optional[float]
|
timeout for urlopen. Only relevant if url is not local |
None
|
Returns:
Type | Description |
---|---|
AudioBytes
|
|
Source code in docarray/typing/url/audio_url.py
image_url
ImageUrl
Bases: AnyUrl
URL to an image file. Can be remote (web) URL, or a local file path.
Source code in docarray/typing/url/image_url.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
|
display()
Display image data from url in notebook.
Source code in docarray/typing/url/image_url.py
load(width=None, height=None, axis_layout=('H', 'W', 'C'), timeout=None)
Load the data from the url into an ImageNdArray
from docarray import BaseDoc
from docarray.typing import ImageUrl, ImageNdArray
class MyDoc(BaseDoc):
img_url: ImageUrl
doc = MyDoc(
img_url="https://upload.wikimedia.org/wikipedia/commons/8/80/"
"Dag_Sebastian_Ahlander_at_G%C3%B6teborg_Book_Fair_2012b.jpg"
)
img_tensor = doc.img_url.load()
assert isinstance(img_tensor, ImageNdArray)
img_tensor = doc.img_url.load(height=224, width=224)
assert img_tensor.shape == (224, 224, 3)
layout = ('C', 'W', 'H')
img_tensor = doc.img_url.load(height=100, width=200, axis_layout=layout)
assert img_tensor.shape == (3, 200, 100)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
width |
Optional[int]
|
width of the image tensor. |
None
|
height |
Optional[int]
|
height of the image tensor. |
None
|
axis_layout |
Tuple[str, str, str]
|
ordering of the different image axes. 'H' = height, 'W' = width, 'C' = color channel |
('H', 'W', 'C')
|
timeout |
Optional[float]
|
timeout (sec) for urlopen network request. Only relevant if URL is not local |
None
|
Returns:
Type | Description |
---|---|
ImageNdArray
|
|
Source code in docarray/typing/url/image_url.py
load_bytes(timeout=None)
Convert url to ImageBytes
. This will either load or
download the file and save it into an ImageBytes
object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timeout |
Optional[float]
|
timeout for urlopen. Only relevant if url is not local |
None
|
Returns:
Type | Description |
---|---|
ImageBytes
|
|
Source code in docarray/typing/url/image_url.py
load_pil(timeout=None)
Load the image from the bytes into a PIL.Image.Image
instance
from pydantic import parse_obj_as
from docarray import BaseDoc
from docarray.typing import ImageUrl
img_url = "https://upload.wikimedia.org/wikipedia/commons/8/80/Dag_Sebastian_Ahlander_at_G%C3%B6teborg_Book_Fair_2012b.jpg"
img_url = parse_obj_as(ImageUrl, img_url)
img = img_url.load_pil()
from PIL.Image import Image
assert isinstance(img, Image)
Returns:
Type | Description |
---|---|
Image
|
a Pillow image |
Source code in docarray/typing/url/image_url.py
text_url
TextUrl
Bases: AnyUrl
URL to a text file. Can be remote (web) URL, or a local file path.
Source code in docarray/typing/url/text_url.py
load(charset='utf-8', timeout=None)
Load the text file into a string.
from docarray import BaseDoc
from docarray.typing import TextUrl
class MyDoc(BaseDoc):
remote_url: TextUrl
doc = MyDoc(
remote_url='https://de.wikipedia.org/wiki/Brixen',
)
remote_txt = doc.remote_url.load()
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timeout |
Optional[float]
|
timeout (sec) for urlopen network request. Only relevant if URL is not local |
None
|
charset |
str
|
decoding charset; may be any character set registered with IANA |
'utf-8'
|
Returns:
Type | Description |
---|---|
str
|
the text file content |
Source code in docarray/typing/url/text_url.py
url_3d
Mesh3DUrl
Bases: Url3D
URL to a file containing 3D mesh information. Can be remote (web) URL, or a local file path.
Source code in docarray/typing/url/url_3d/mesh_url.py
display()
Plot mesh from url. This loads the Trimesh instance of the 3D mesh, and then displays it.
Source code in docarray/typing/url/url_3d/mesh_url.py
load(skip_materials=True, trimesh_args=None)
Load the data from the url into a VerticesAndFaces
object containing vertices and faces information.
from docarray import BaseDoc
from docarray.typing import Mesh3DUrl, NdArray
class MyDoc(BaseDoc):
mesh_url: Mesh3DUrl
doc = MyDoc(mesh_url="https://people.sc.fsu.edu/~jburkardt/data/obj/al.obj")
tensors = doc.mesh_url.load()
assert isinstance(tensors.vertices, NdArray)
assert isinstance(tensors.faces, NdArray)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
skip_materials |
bool
|
Skip materials if True, else skip. |
True
|
trimesh_args |
Optional[Dict[str, Any]]
|
dictionary of additional arguments for |
None
|
Returns:
Type | Description |
---|---|
VerticesAndFaces
|
VerticesAndFaces object containing vertices and faces information. |
Source code in docarray/typing/url/url_3d/mesh_url.py
PointCloud3DUrl
Bases: Url3D
URL to a file containing point cloud information. Can be remote (web) URL, or a local file path.
Source code in docarray/typing/url/url_3d/point_cloud_url.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
|
display(samples=10000)
Plot point cloud from url.
First, it loads the point cloud into a PointsAndColors
object, and then
calls display on it. The following is therefore equivalent:
import numpy as np
from docarray import BaseDoc
from docarray.documents import PointCloud3D
pc = PointCloud3D(url="https://people.sc.fsu.edu/~jburkardt/data/obj/al.obj")
# option 1
# pc.url.display()
# option 2 (equivalent)
# pc.url.load(samples=10000).display()
Parameters:
Name | Type | Description | Default |
---|---|---|---|
samples |
int
|
number of points to sample from the mesh. |
10000
|
Source code in docarray/typing/url/url_3d/point_cloud_url.py
load(samples, multiple_geometries=False, skip_materials=True, trimesh_args=None)
Load the data from the url into an NdArray
containing point cloud information.
import numpy as np
from docarray import BaseDoc
from docarray.typing import PointCloud3DUrl
class MyDoc(BaseDoc):
point_cloud_url: PointCloud3DUrl
doc = MyDoc(point_cloud_url="thttps://people.sc.fsu.edu/~jburkardt/data/obj/al.obj")
# point_cloud = doc.point_cloud_url.load(samples=100)
# assert isinstance(point_cloud, np.ndarray)
# assert point_cloud.shape == (100, 3)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
samples |
int
|
number of points to sample from the mesh |
required |
multiple_geometries |
bool
|
if False, store point cloud in 2D np.ndarray. If True, store point clouds from multiple geometries in 3D np.ndarray. |
False
|
skip_materials |
bool
|
Skip materials if True, else load. |
True
|
trimesh_args |
Optional[Dict[str, Any]]
|
dictionary of additional arguments for |
None
|
Returns:
Type | Description |
---|---|
PointsAndColors
|
np.ndarray representing the point cloud |
Source code in docarray/typing/url/url_3d/point_cloud_url.py
mesh_url
Mesh3DUrl
Bases: Url3D
URL to a file containing 3D mesh information. Can be remote (web) URL, or a local file path.
Source code in docarray/typing/url/url_3d/mesh_url.py
display()
Plot mesh from url. This loads the Trimesh instance of the 3D mesh, and then displays it.
Source code in docarray/typing/url/url_3d/mesh_url.py
load(skip_materials=True, trimesh_args=None)
Load the data from the url into a VerticesAndFaces
object containing vertices and faces information.
from docarray import BaseDoc
from docarray.typing import Mesh3DUrl, NdArray
class MyDoc(BaseDoc):
mesh_url: Mesh3DUrl
doc = MyDoc(mesh_url="https://people.sc.fsu.edu/~jburkardt/data/obj/al.obj")
tensors = doc.mesh_url.load()
assert isinstance(tensors.vertices, NdArray)
assert isinstance(tensors.faces, NdArray)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
skip_materials |
bool
|
Skip materials if True, else skip. |
True
|
trimesh_args |
Optional[Dict[str, Any]]
|
dictionary of additional arguments for |
None
|
Returns:
Type | Description |
---|---|
VerticesAndFaces
|
VerticesAndFaces object containing vertices and faces information. |
Source code in docarray/typing/url/url_3d/mesh_url.py
point_cloud_url
PointCloud3DUrl
Bases: Url3D
URL to a file containing point cloud information. Can be remote (web) URL, or a local file path.
Source code in docarray/typing/url/url_3d/point_cloud_url.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
|
display(samples=10000)
Plot point cloud from url.
First, it loads the point cloud into a PointsAndColors
object, and then
calls display on it. The following is therefore equivalent:
import numpy as np
from docarray import BaseDoc
from docarray.documents import PointCloud3D
pc = PointCloud3D(url="https://people.sc.fsu.edu/~jburkardt/data/obj/al.obj")
# option 1
# pc.url.display()
# option 2 (equivalent)
# pc.url.load(samples=10000).display()
Parameters:
Name | Type | Description | Default |
---|---|---|---|
samples |
int
|
number of points to sample from the mesh. |
10000
|
Source code in docarray/typing/url/url_3d/point_cloud_url.py
load(samples, multiple_geometries=False, skip_materials=True, trimesh_args=None)
Load the data from the url into an NdArray
containing point cloud information.
import numpy as np
from docarray import BaseDoc
from docarray.typing import PointCloud3DUrl
class MyDoc(BaseDoc):
point_cloud_url: PointCloud3DUrl
doc = MyDoc(point_cloud_url="thttps://people.sc.fsu.edu/~jburkardt/data/obj/al.obj")
# point_cloud = doc.point_cloud_url.load(samples=100)
# assert isinstance(point_cloud, np.ndarray)
# assert point_cloud.shape == (100, 3)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
samples |
int
|
number of points to sample from the mesh |
required |
multiple_geometries |
bool
|
if False, store point cloud in 2D np.ndarray. If True, store point clouds from multiple geometries in 3D np.ndarray. |
False
|
skip_materials |
bool
|
Skip materials if True, else load. |
True
|
trimesh_args |
Optional[Dict[str, Any]]
|
dictionary of additional arguments for |
None
|
Returns:
Type | Description |
---|---|
PointsAndColors
|
np.ndarray representing the point cloud |
Source code in docarray/typing/url/url_3d/point_cloud_url.py
url_3d
Url3D
Bases: AnyUrl
, ABC
URL to a file containing 3D mesh or point cloud information. Can be remote (web) URL, or a local file path.
Source code in docarray/typing/url/url_3d/url_3d.py
video_url
VideoUrl
Bases: AnyUrl
URL to a video file. Can be remote (web) URL, or a local file path.
Source code in docarray/typing/url/video_url.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|
display()
Play video from url in notebook.
Source code in docarray/typing/url/video_url.py
load(**kwargs)
Load the data from the url into a NamedTuple
of
VideoNdArray
,
AudioNdArray
and NdArray
.
from typing import Optional
from docarray import BaseDoc
from docarray.typing import VideoUrl, VideoNdArray, AudioNdArray, NdArray
class MyDoc(BaseDoc):
video_url: VideoUrl
video: Optional[VideoNdArray]
audio: Optional[AudioNdArray]
key_frame_indices: Optional[NdArray]
doc = MyDoc(
video_url='https://github.com/docarray/docarray/blob/main/tests/toydata/mov_bbb.mp4?raw=true'
)
doc.video, doc.audio, doc.key_frame_indices = doc.video_url.load()
assert isinstance(doc.video, VideoNdArray)
assert isinstance(doc.audio, AudioNdArray)
assert isinstance(doc.key_frame_indices, NdArray)
You can load only the key frames (or video, audio respectively):
from pydantic import parse_obj_as
from docarray.typing import NdArray, VideoUrl
url = parse_obj_as(
VideoUrl,
'https://github.com/docarray/docarray/blob/main/tests/toydata/mov_bbb.mp4?raw=true',
)
key_frame_indices = url.load().key_frame_indices
assert isinstance(key_frame_indices, NdArray)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kwargs |
supports all keyword arguments that are being supported by av.open() as described here |
{}
|
Returns:
Type | Description |
---|---|
VideoLoadResult
|
|
Source code in docarray/typing/url/video_url.py
load_bytes(timeout=None)
Convert url to VideoBytes
. This will either load or download
the file and save it into an VideoBytes
object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timeout |
Optional[float]
|
timeout for urlopen. Only relevant if url is not local |
None
|
Returns:
Type | Description |
---|---|
VideoBytes
|
|