Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aplbrain/pytri
Python wrapper for Substrate
https://github.com/aplbrain/pytri
jhuapl jupyter-notebook pytri substrate threejs
Last synced: 3 months ago
JSON representation
Python wrapper for Substrate
- Host: GitHub
- URL: https://github.com/aplbrain/pytri
- Owner: aplbrain
- Created: 2017-10-06T15:03:36.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2021-12-02T03:48:05.000Z (about 3 years ago)
- Last Synced: 2024-05-16T01:13:40.433Z (8 months ago)
- Topics: jhuapl, jupyter-notebook, pytri, substrate, threejs
- Language: Python
- Homepage: https://aplbrain.github.io/pytri/
- Size: 37.5 MB
- Stars: 4
- Watchers: 6
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# pytri v2
> A Pytri redux, using the latest available THREE.js bindings and GPU-offloaded rendering of large scenes.
WARNING: `pytri` is currently untested. Use at your own risk.
## Installation
```shell
pip install pytri
# or:
# pip3 install git+https://github.com/aplbrain/pytri
```## Getting Started
Let's plot some scatterplot data in 3D. In your favorite Jupyter notebook or binder application, import pytri:
```python
from pytri import Figure
```We can now generate some sample data:
```python
import numpy as npfig = Figure()
xs = np.random.randn(100)
ys = np.random.randn(100)
zs = np.random.randn(100)fig.scatter(xs, ys, zs)
fig.show()
```## Examples
### Render a NetworkX Graph
Here's a crazy dense randomly-arranged graph with over a million edges. (You'll find the slowest part of this process is just generating that graph!)
This graph renders in realtime (60FPS) in Pytri.
```python
import networkx as nx
g = nx.fast_gnp_random_graph(50_000, 0.001)
pos = {k: [vv * 500 for vv in v] for k, v in nx.random_layout(g, dim=3).items()}f = Figure()
f.axes()
f.graph(g, pos=pos, edge_width=1, node_size=10)f.show()
```### Random color-changing edges
These edges are a different color on the left edge than on the right edge:
```python
f = Figure()
f.axes()
f.lines(
# 100 lines on the interval 0-100
np.random.random((100, 2, 3)) * 100,
# 200 colors, start/stop for each line
colors=np.random.random((100, 2, 3)),
width=4
)
f.show()
```### Lines and an image pulled from the internet
```python
f.imshow(
"https://i.imgur.com/VK8Tp5q.jpeg",
width=100, height=100,
rotation=(0, 3.14/2, 0)
)
f.show()
```### Rendering numpy arrays in RGB or Greyscale
```python
f.scatter(np.random.randint(-50, 50, (1_00_000,3)))
f.imshow(
# 3 dimensions, interpreted as RGB
np.random.random((1000, 1000, 3)),
width=200, height=200,
rotation=(0, 3.14/2, 0)
)
f.imshow(
# 2 dimensions, interpreted as grayscale
np.random.random((1000, 1000)),
width=200, height=200,
# omitting rotation, the plane faces "up" along Z
)
```### One way to (cheat) render a volume
```python
from pytri import Figure
import internmorgan2020 = intern.array("bossdb://morgan2020/lgn/em", resolution=2)
em_excerpt = morgan2020[1000:1050, 25000:25000+300, 25000:25000+300]
coords = []
for z in range(em_excerpt.shape[0]):
for y in range(em_excerpt.shape[1]):
for x in range(em_excerpt.shape[2]):
coords.append((x, y, z*10))f = Figure()
f.scatter(coords, color=[[i,i,i] for i in em_excerpt.ravel()], attenuate_size=True, size=5)
f.show()
```