Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mg/examples readme #47

Merged
merged 3 commits into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 23 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,34 +65,36 @@ of those flags here.

#### TypeScript

If you use JupyterLab to develop then you can watch the source directory and run JupyterLab at the same time in different
terminals to watch for changes in the extension's source and automatically rebuild the widget.
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:

```bash
# Watch the source directory in one terminal, automatically rebuilding when needed
yarn run watch
# Run JupyterLab in another terminal
jupyter lab
```
`yarn build`

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

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

```bash
yarn add <package-name>
yarn add --dev <dev-package-name>
```
`yarn build`

And restart the notebook kernel.

#### Python

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

## Usage

Jupyter notebooks are provided in the [Examples](https://github.com/TileDB-Inc/TileDB-PyBabylonJS/tree/main/examples).
### Point clouds

Jupyter notebooks are provided in the [Examples folder](https://github.com/TileDB-Inc/TileDB-PyBabylonJS/tree/main/examples) for the following visualizations:

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:
* [Point cloud](/examples/point_cloud.ipynb)
* [Point cloud with a time slider](/examples/point-cloud-time.ipynb)
* [Point cloud with a classes slider](/examples/point-cloud-classes.ipynb)
* [Point cloud with a Mapbox base map](/examples/point-cloud-topo.ipynb)
* [Point cloud with gltf models](/examples/point-cloud-gltf.ipynb)
* [MBRS of a point cloud](/examples/mbrs.ipynb)

Display a point cloud visualization from a local sparse array by specifying the bounding box of a slice of the data:

```python
from pybabylonjs import Show as show
Expand All @@ -103,14 +105,13 @@ bbox = {
'Z': [406.14, 615.26]
}

lidar_array = "autzen-classified"

show.point_cloud(source="local",
mode="default",
uri="./data/autzen",
bbox=bbox)
uri=lidar_array,
bbox = bbox)
```

This creates an interactive visualization in a notebook widget of which the below is a screenshot:

<img src="examples/pointcloud.png" width="400" height="300" />

To add a slider over `GpsTime` change the `mode` to `time`:
Expand Down
13 changes: 1 addition & 12 deletions examples/mbrs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,10 @@
"source": [
"import os\n",
"import pdal\n",
"import pybabylonjs\n",
"from pybabylonjs import Show as show\n",
"import tiledb"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ee8f4ea7-1b51-43d9-ab4d-189149f40831",
"metadata": {},
"outputs": [],
"source": [
"pybabylonjs.__version__"
]
},
{
"cell_type": "markdown",
"id": "376c7606-efde-45b5-b512-39b6987fbbf2",
Expand Down Expand Up @@ -73,7 +62,7 @@
"id": "8fce1435-d6b6-4a9d-b961-c36416375a0e",
"metadata": {},
"source": [
"### MBRS\n",
"### MBRS visualization\n",
"\n",
"Detailed information about the fragments in the array is read with:"
]
Expand Down
207 changes: 207 additions & 0 deletions examples/point-cloud-classes.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "d4f53ca1-2726-4c0c-af0b-d39831237087",
"metadata": {},
"source": [
"# Point Cloud Data Visualization with a classes slider\n",
"\n",
"* Download point cloud data\n",
"* Create a sparse TileDB array\n",
"* Visualize the point cloud with a classes slider\n",
"* Customize with optional parameters"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c33b9bc9-cb24-4064-b8ec-61b1b332a266",
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"\n",
"import pdal\n",
"from pybabylonjs import Show as show\n",
"import tiledb"
]
},
{
"cell_type": "markdown",
"id": "fb67c477-5b04-4fd8-bec7-a286e7ae92a2",
"metadata": {},
"source": [
"## Optional: create a sparse TileDB array from a LAZ file"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f9eb5905-32a5-49e6-9b96-d89a701f91f9",
"metadata": {},
"outputs": [],
"source": [
"!wget -nc \"https://github.com/PDAL/data/blob/master/autzen/autzen-classified.laz?raw=true\" -O \"autzen-classified.laz\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d878a610-ad6f-4796-bf25-1c2f1c4d31c9",
"metadata": {},
"outputs": [],
"source": [
"pipeline = (\n",
" pdal.Reader(\"autzen-classified.laz\") |\n",
" pdal.Filter.stats() |\n",
" pdal.Writer.tiledb(array_name=\"autzen-classified\",chunk_size=100000)\n",
")\n",
"\n",
"count = pipeline.execute() "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "77cd7fd4-9e77-4307-bb7a-c828a9395530",
"metadata": {},
"outputs": [],
"source": [
"lidar_array = \"autzen-classified\""
]
},
{
"cell_type": "markdown",
"id": "300faf9b-716e-4c3c-af00-86d9cf118b39",
"metadata": {},
"source": [
"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:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7aa48a9d-9aba-4919-8ed6-3fea268b5bf4",
"metadata": {},
"outputs": [],
"source": [
"bbox = {\n",
" 'X': [636800, 637800],\n",
" 'Y': [851000, 853000],\n",
" 'Z': [406.14, 615.26]\n",
"}"
]
},
{
"cell_type": "markdown",
"id": "e179da13-10d4-42c6-ad8e-7850339eee2e",
"metadata": {},
"source": [
"### Visualize the point cloud with a classes slider\n",
"\n",
"*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",
"\n",
"Point cloud data from the local array can be loaded and displayed with the below, where `uri` is the location of the array:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "29b8b806-b785-4784-a802-d5d7d735a12a",
"metadata": {},
"outputs": [],
"source": [
"show.point_cloud(source=\"local\",\n",
" mode=\"default\",\n",
" uri=lidar_array,\n",
" bbox = bbox)"
]
},
{
"cell_type": "markdown",
"id": "e06eaa47-7277-419f-b204-69c8418628ee",
"metadata": {},
"source": [
"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:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "95fc9ca9-19b5-4872-9369-3473bd286442",
"metadata": {},
"outputs": [],
"source": [
"classes = {\n",
" 'numbers': [0,2,5,6,9,15,17,19,64,65,66,67,68,69,70,71,72,73,74,75,76,77],\n",
" 'names': ['None','Ground','Vegetation','Building','Water','Transmission Tower',\n",
" 'Bridge Deck','Overhead Structure','Wire','Car','Truck','Boat',\n",
" 'Barrier','Railroad car','Elevated Walkway','Covered Walkway',\n",
" 'Pier/Dock','Fence','Tower','Crane','Silo/Storage Tank','Bridge Structure']\n",
"}\n",
"\n",
"show.point_cloud(source=\"local\",\n",
" mode=\"classes\",\n",
" uri=lidar_array,\n",
" bbox = bbox,\n",
" classes=classes)"
]
},
{
"cell_type": "markdown",
"id": "435491c9-1093-4c6a-b67f-6f35047e7b15",
"metadata": {},
"source": [
"## Customize with optional parameters"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c54a3e7a-7edf-4412-a018-b570481f9381",
"metadata": {},
"outputs": [],
"source": [
"show.point_cloud(source=\"local\",\n",
" mode=\"classes\",\n",
" uri=lidar_array,\n",
" bbox = bbox,\n",
" classes=classes,\n",
" width=1200,\n",
" height=800,\n",
" z_scale=1.5,\n",
" color_scheme=\"blue\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3f29c476-0dfa-43e8-8eb2-9b680a04da4d",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.10"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading