Skip to content

Commit a7cefcf

Browse files
Merge pull request #47 from TileDB-Inc/mg/examples-readme
Mg/examples readme
2 parents 2ec9c76 + 6dd93f3 commit a7cefcf

File tree

8 files changed

+947
-134
lines changed

8 files changed

+947
-134
lines changed

README.md

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -65,34 +65,36 @@ of those flags here.
6565

6666
#### TypeScript
6767

68-
If you use JupyterLab to develop then you can watch the source directory and run JupyterLab at the same time in different
69-
terminals to watch for changes in the extension's source and automatically rebuild the widget.
68+
The TypeScript code for the visualizations can be found in the [TileDB-Viz](https://github.com/TileDB-Inc/TileDB-Viz) package. After making changes in TileDB-Viz build the package with:
7069

71-
```bash
72-
# Watch the source directory in one terminal, automatically rebuilding when needed
73-
yarn run watch
74-
# Run JupyterLab in another terminal
75-
jupyter lab
76-
```
70+
`yarn build`
7771

78-
After a change wait for the build to finish and then refresh your browser and the changes should take effect.
72+
To then see these changes in TileDB-PyBabylonJS run:
7973

80-
To add a TypeScript package use [yarn](https://classic.yarnpkg.com/lang/en/docs/cli/add/):
74+
`yarn add file:/path/to/TileDB-Viz/packages/core`
8175

82-
```bash
83-
yarn add <package-name>
84-
yarn add --dev <dev-package-name>
85-
```
76+
`yarn build`
77+
78+
And restart the notebook kernel.
8679

8780
#### Python
8881

89-
If you make a change to the python code then you will need to restart the notebook kernel to have it take effect.
82+
When you make a change to the Python code rebuild the package and restart the notebook kernel to see your changes.
9083

9184
## Usage
9285

93-
Jupyter notebooks are provided in the [Examples](https://github.com/TileDB-Inc/TileDB-PyBabylonJS/tree/main/examples).
86+
### Point clouds
87+
88+
Jupyter notebooks are provided in the [Examples folder](https://github.com/TileDB-Inc/TileDB-PyBabylonJS/tree/main/examples) for the following visualizations:
9489

95-
Create a default visualization from a local sparse array containing LiDAR data by specifying the bounding box (`bbox`) of the slice of the data in the array uri:
90+
* [Point cloud](/examples/point_cloud.ipynb)
91+
* [Point cloud with a time slider](/examples/point-cloud-time.ipynb)
92+
* [Point cloud with a classes slider](/examples/point-cloud-classes.ipynb)
93+
* [Point cloud with a Mapbox base map](/examples/point-cloud-topo.ipynb)
94+
* [Point cloud with gltf models](/examples/point-cloud-gltf.ipynb)
95+
* [MBRS of a point cloud](/examples/mbrs.ipynb)
96+
97+
Display a point cloud visualization from a local sparse array by specifying the bounding box of a slice of the data:
9698

9799
```python
98100
from pybabylonjs import Show as show
@@ -103,14 +105,13 @@ bbox = {
103105
'Z': [406.14, 615.26]
104106
}
105107

108+
lidar_array = "autzen-classified"
109+
106110
show.point_cloud(source="local",
107-
mode="default",
108-
uri="./data/autzen",
109-
bbox=bbox)
111+
uri=lidar_array,
112+
bbox = bbox)
110113
```
111114

112-
This creates an interactive visualization in a notebook widget of which the below is a screenshot:
113-
114115
<img src="examples/pointcloud.png" width="400" height="300" />
115116

116117
To add a slider over `GpsTime` change the `mode` to `time`:

examples/mbrs.ipynb

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,10 @@
99
"source": [
1010
"import os\n",
1111
"import pdal\n",
12-
"import pybabylonjs\n",
1312
"from pybabylonjs import Show as show\n",
1413
"import tiledb"
1514
]
1615
},
17-
{
18-
"cell_type": "code",
19-
"execution_count": null,
20-
"id": "ee8f4ea7-1b51-43d9-ab4d-189149f40831",
21-
"metadata": {},
22-
"outputs": [],
23-
"source": [
24-
"pybabylonjs.__version__"
25-
]
26-
},
2716
{
2817
"cell_type": "markdown",
2918
"id": "376c7606-efde-45b5-b512-39b6987fbbf2",
@@ -73,7 +62,7 @@
7362
"id": "8fce1435-d6b6-4a9d-b961-c36416375a0e",
7463
"metadata": {},
7564
"source": [
76-
"### MBRS\n",
65+
"### MBRS visualization\n",
7766
"\n",
7867
"Detailed information about the fragments in the array is read with:"
7968
]

examples/point-cloud-classes.ipynb

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "d4f53ca1-2726-4c0c-af0b-d39831237087",
6+
"metadata": {},
7+
"source": [
8+
"# Point Cloud Data Visualization with a classes slider\n",
9+
"\n",
10+
"* Download point cloud data\n",
11+
"* Create a sparse TileDB array\n",
12+
"* Visualize the point cloud with a classes slider\n",
13+
"* Customize with optional parameters"
14+
]
15+
},
16+
{
17+
"cell_type": "code",
18+
"execution_count": null,
19+
"id": "c33b9bc9-cb24-4064-b8ec-61b1b332a266",
20+
"metadata": {},
21+
"outputs": [],
22+
"source": [
23+
"import requests\n",
24+
"\n",
25+
"import pdal\n",
26+
"from pybabylonjs import Show as show\n",
27+
"import tiledb"
28+
]
29+
},
30+
{
31+
"cell_type": "markdown",
32+
"id": "fb67c477-5b04-4fd8-bec7-a286e7ae92a2",
33+
"metadata": {},
34+
"source": [
35+
"## Optional: create a sparse TileDB array from a LAZ file"
36+
]
37+
},
38+
{
39+
"cell_type": "code",
40+
"execution_count": null,
41+
"id": "f9eb5905-32a5-49e6-9b96-d89a701f91f9",
42+
"metadata": {},
43+
"outputs": [],
44+
"source": [
45+
"!wget -nc \"https://github.com/PDAL/data/blob/master/autzen/autzen-classified.laz?raw=true\" -O \"autzen-classified.laz\""
46+
]
47+
},
48+
{
49+
"cell_type": "code",
50+
"execution_count": null,
51+
"id": "d878a610-ad6f-4796-bf25-1c2f1c4d31c9",
52+
"metadata": {},
53+
"outputs": [],
54+
"source": [
55+
"pipeline = (\n",
56+
" pdal.Reader(\"autzen-classified.laz\") |\n",
57+
" pdal.Filter.stats() |\n",
58+
" pdal.Writer.tiledb(array_name=\"autzen-classified\",chunk_size=100000)\n",
59+
")\n",
60+
"\n",
61+
"count = pipeline.execute() "
62+
]
63+
},
64+
{
65+
"cell_type": "code",
66+
"execution_count": null,
67+
"id": "77cd7fd4-9e77-4307-bb7a-c828a9395530",
68+
"metadata": {},
69+
"outputs": [],
70+
"source": [
71+
"lidar_array = \"autzen-classified\""
72+
]
73+
},
74+
{
75+
"cell_type": "markdown",
76+
"id": "300faf9b-716e-4c3c-af00-86d9cf118b39",
77+
"metadata": {},
78+
"source": [
79+
"To load and display a slice of the data a bounding box with the minimum and maximum values of X, Y and Z are needed:"
80+
]
81+
},
82+
{
83+
"cell_type": "code",
84+
"execution_count": null,
85+
"id": "7aa48a9d-9aba-4919-8ed6-3fea268b5bf4",
86+
"metadata": {},
87+
"outputs": [],
88+
"source": [
89+
"bbox = {\n",
90+
" 'X': [636800, 637800],\n",
91+
" 'Y': [851000, 853000],\n",
92+
" 'Z': [406.14, 615.26]\n",
93+
"}"
94+
]
95+
},
96+
{
97+
"cell_type": "markdown",
98+
"id": "e179da13-10d4-42c6-ad8e-7850339eee2e",
99+
"metadata": {},
100+
"source": [
101+
"### Visualize the point cloud with a classes slider\n",
102+
"\n",
103+
"*The below example loads the data from a local array, but a time slider can be added to point clouds from all data sources: `local`, `cloud` and `dict`.*\n",
104+
"\n",
105+
"Point cloud data from the local array can be loaded and displayed with the below, where `uri` is the location of the array:"
106+
]
107+
},
108+
{
109+
"cell_type": "code",
110+
"execution_count": null,
111+
"id": "29b8b806-b785-4784-a802-d5d7d735a12a",
112+
"metadata": {},
113+
"outputs": [],
114+
"source": [
115+
"show.point_cloud(source=\"local\",\n",
116+
" mode=\"default\",\n",
117+
" uri=lidar_array,\n",
118+
" bbox = bbox)"
119+
]
120+
},
121+
{
122+
"cell_type": "markdown",
123+
"id": "e06eaa47-7277-419f-b204-69c8418628ee",
124+
"metadata": {},
125+
"source": [
126+
"To add a time slider change the mode from `default` to `classes` and add the `classes` variable that contains the names for each class. Also make sure there is an attribute `Classification` in the array:"
127+
]
128+
},
129+
{
130+
"cell_type": "code",
131+
"execution_count": null,
132+
"id": "95fc9ca9-19b5-4872-9369-3473bd286442",
133+
"metadata": {},
134+
"outputs": [],
135+
"source": [
136+
"classes = {\n",
137+
" 'numbers': [0,2,5,6,9,15,17,19,64,65,66,67,68,69,70,71,72,73,74,75,76,77],\n",
138+
" 'names': ['None','Ground','Vegetation','Building','Water','Transmission Tower',\n",
139+
" 'Bridge Deck','Overhead Structure','Wire','Car','Truck','Boat',\n",
140+
" 'Barrier','Railroad car','Elevated Walkway','Covered Walkway',\n",
141+
" 'Pier/Dock','Fence','Tower','Crane','Silo/Storage Tank','Bridge Structure']\n",
142+
"}\n",
143+
"\n",
144+
"show.point_cloud(source=\"local\",\n",
145+
" mode=\"classes\",\n",
146+
" uri=lidar_array,\n",
147+
" bbox = bbox,\n",
148+
" classes=classes)"
149+
]
150+
},
151+
{
152+
"cell_type": "markdown",
153+
"id": "435491c9-1093-4c6a-b67f-6f35047e7b15",
154+
"metadata": {},
155+
"source": [
156+
"## Customize with optional parameters"
157+
]
158+
},
159+
{
160+
"cell_type": "code",
161+
"execution_count": null,
162+
"id": "c54a3e7a-7edf-4412-a018-b570481f9381",
163+
"metadata": {},
164+
"outputs": [],
165+
"source": [
166+
"show.point_cloud(source=\"local\",\n",
167+
" mode=\"classes\",\n",
168+
" uri=lidar_array,\n",
169+
" bbox = bbox,\n",
170+
" classes=classes,\n",
171+
" width=1200,\n",
172+
" height=800,\n",
173+
" z_scale=1.5,\n",
174+
" color_scheme=\"blue\")"
175+
]
176+
},
177+
{
178+
"cell_type": "code",
179+
"execution_count": null,
180+
"id": "3f29c476-0dfa-43e8-8eb2-9b680a04da4d",
181+
"metadata": {},
182+
"outputs": [],
183+
"source": []
184+
}
185+
],
186+
"metadata": {
187+
"kernelspec": {
188+
"display_name": "Python 3 (ipykernel)",
189+
"language": "python",
190+
"name": "python3"
191+
},
192+
"language_info": {
193+
"codemirror_mode": {
194+
"name": "ipython",
195+
"version": 3
196+
},
197+
"file_extension": ".py",
198+
"mimetype": "text/x-python",
199+
"name": "python",
200+
"nbconvert_exporter": "python",
201+
"pygments_lexer": "ipython3",
202+
"version": "3.7.10"
203+
}
204+
},
205+
"nbformat": 4,
206+
"nbformat_minor": 5
207+
}

0 commit comments

Comments
 (0)