3-D scenes (PyVista)#
Scene3D is the 3-D tier's host: one PyVista plotter and the layers drawn into it. It answers to the same
method names as the 2-D tiers wherever it can draw the same thing, and adds what only a 3-D scene has — relief,
volumes and isosurfaces, extruded polygons, a globe, and a camera that can orbit.
from digitalearth.three_d import Scene3D
with Scene3D(off_screen=True) as scene:
scene.terrain(dem, z_exaggeration=3.0)
scene.colorbar()
scene.screenshot("relief.png")
The tier needs the 3d extra (pip install digitalearth[3d]). On a Linux machine with no display, see
Headless 3-D rendering before the first render.
Where the methods come from#
Scene3D composes a base with one mixin per capability, mirroring how the static Map is built, and every
method below is listed on Scene3D itself whichever class defines it:
| Capability | Methods | Defined on |
|---|---|---|
| Relief | terrain |
TerrainMixin |
| Points | point_cloud |
PointCloudMixin |
| 3-D fields | volume, isosurface |
VolumeMixin |
| Vectors and extrusions | vectors, extruded_polygons |
VectorMixin |
| Data on a sphere | globe |
GlobeMixin |
| Decoration | set_title, text, axes, orientation_axes |
DecorationMixin |
| Colour keys | colorbar, legend |
GuideMixin |
| Camera motion | orbit, record, jupyter |
AnimationMixin |
| Layers, view and output | everything else | Scene3DBase |
The plotter is built on first use#
Creating a scene does not open a render window or import PyVista; the plotter is built the first time
something is drawn or the plotter property is read. A scene can therefore be described — its layers listed,
its figure_spec taken — without a renderer, and Scene3D.from_figure draws a figure described elsewhere.
digitalearth.three_d.scene3d.Scene3D
#
Bases: TerrainMixin, PointCloudMixin, FlatMixin, MeshMixin, VolumeMixin, VectorMixin, GlobeMixin, DecorationMixin, GuideMixin, InteractionMixin, ServeMixin, AnimationMixin, PhotorealMixin, Scene3DBase
A single-:class:pyvista.Plotter 3-D scene with geospatial plot verbs.
Inherits the plotter/layer/render lifecycle from :class:~digitalearth.three_d.core.base.Scene3DBase and the
plot methods from the capability mixins (:meth:terrain, :meth:point_cloud, :meth:volume,
:meth:isosurface, :meth:vectors, :meth:extruded_polygons, :meth:globe, :meth:set_title,
:meth:text, :meth:axes, :meth:orientation_axes, :meth:colorbar, :meth:legend, :meth:orbit,
:meth:record). See those classes for the full surface.
Examples:
- Create a headless scene, render a DEM as 3-D relief, screenshot it:
>>> import numpy as np >>> from digitalearth.three_d import Scene3D >>> from digitalearth.base.sources import get_source >>> dem = np.add.outer(np.linspace(0, 1, 8), np.linspace(0, 1, 8)) >>> scene = Scene3D(off_screen=True) >>> _ = scene.terrain(get_source(dem), z_exaggeration=3.0) >>> img = scene.screenshot() >>> img.shape[-1], bool(img.any()) (3, True) >>> scene.close()
Source code in src/digitalearth/three_d/scene3d.py
layer_ids
property
#
The ids of the scene's layers, in draw order.
Returns:
| Type | Description |
|---|---|
list[str]
|
The ids, bottom first. A builder that was given |
Examples:
- Two layers, each addressable by the name the scene gave it:
>>> import numpy as np >>> from digitalearth.base.sources import get_source >>> from digitalearth.three_d import Scene3D >>> scene = Scene3D(off_screen=True) >>> dem = get_source(np.add.outer(np.arange(4.0), np.arange(5.0))) >>> _ = scene.terrain(dem) >>> _ = scene.point_cloud(np.array([[0.0, 0.0, 9.0]]), name="peak") >>> scene.layer_ids ['terrain-1', 'peak'] >>> scene.close()
layers
property
#
The drawn (mesh, actor) pairs, in draw order — the view this tier has always exposed.
Returns:
| Type | Description |
|---|---|
list[tuple[Any, Any]]
|
One pair per layer that was actually drawn, ordered as :attr: |
list[tuple[Any, Any]]
|
was skipped (an empty raster, a missing custom object) has no pair. |
Note
This is a compatibility view of what the renderer holds, not the scene's state: the scene is
described by :attr:figure_spec, and layers are addressed by id through :attr:layer_ids,
:meth:mesh_of, :meth:actor_of, :meth:remove_layer and :meth:set_visible. It is kept
because it is what record's callback and a good deal of user code reach for.
figure_spec
property
#
What the scene draws, as data: its layers, their sources, and the camera it is seen from.
Returns:
| Name | Type | Description |
|---|---|---|
A |
FigureSpec
|
class: |
current |
FigureSpec
|
attr: |
FigureSpec
|
it is the scene's description rather than a report about it: written with |
|
FigureSpec
|
with |
|
FigureSpec
|
A scene built from data already in memory can be handed straight to :meth: |
|
written |
FigureSpec
|
|
FigureSpec
|
would be unreadable everywhere else. Give a builder a path to get a figure that can be stored. |
Examples:
- A built scene describes itself, and the description names what was drawn:
>>> import numpy as np >>> from digitalearth.base.sources import get_source >>> from digitalearth.three_d import Scene3D >>> scene = Scene3D(off_screen=True) >>> _ = scene.terrain(get_source(np.add.outer(np.arange(4.0), np.arange(5.0)))) >>> layer = scene.figure_spec.layers.get("terrain-1") >>> layer.kind, layer.symbology.props["scalars"] ('terrain', 'elevation') >>> scene.close()
held_objects
property
#
The engine objects a caller handed to :meth:add_mesh/:meth:add_volume, keyed by layer id.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The table the renderer looks a |
dict[str, Any]
|
never carries the object (:mod: |
camera
property
writable
#
Where the scene is looked at from, as a :class:~digitalearth.base.spec.Camera.
Reading it once the scene has rendered gives the live view — pan, zoom and orbit included — so a camera
found interactively can be written down, stored with to_dict() and set again later. Before the
plotter exists it is the camera that was set, or the scene's default isometric view.
Returns:
| Type | Description |
|---|---|
Camera
|
The camera, carrying the scene's vertical exaggeration and display CRS. |
Examples:
- A camera set on a scene is the camera it reports:
>>> from digitalearth.base.spec import Camera >>> from digitalearth.three_d import Scene3D >>> scene = Scene3D(off_screen=True) >>> scene.camera = Camera.look_at((0.0, 0.0, 0.0), azimuth=225.0, elevation=30.0, distance=10.0) >>> [round(value, 3) for value in scene.camera.position] [-6.124, -6.124, 5.0] >>> scene.close()
vertical_exaggeration
property
writable
#
The vertical (z) scale the whole scene is rendered at (1.0 = true scale).
Exaggeration is a property of the view, never of the geometry. PyVista applies it as a renderer
transform (:meth:pyvista.Plotter.set_scale), which scales every actor — including ones added after it
is set — so one scene has exactly one exaggeration, the value can be read back, and changing it costs a
camera reset rather than a mesh rebuild. :meth:digitalearth.three_d.Scene3D.terrain's
z_exaggeration argument sets this.
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
the current z scale. |
Examples:
- A fresh scene renders at true scale; the value set reads straight back:
- It is the view that stretches, not the mesh — and a layer added afterwards is stretched too:
>>> import pyvista as pv >>> from digitalearth.three_d.core.base import Scene3DBase >>> scene = Scene3DBase(off_screen=True) >>> scene.vertical_exaggeration = 4.0 >>> sphere = pv.Sphere() >>> actor = scene.add_mesh(sphere) >>> round(sphere.bounds[5] - sphere.bounds[4], 3) 1.0 >>> round(actor.scale[2], 3) 4.0 >>> scene.close()
plotter
property
writable
#
The PyVista plotter the scene draws on, built the first time it is asked for.
Building a scene opens no render window: describing layers needs none, and a scene that is only
described never pays for one. The settings given to the constructor are applied when the plotter is
built, with :func:house_theme when no theme was given.
Returns:
| Type | Description |
|---|---|
Plotter
|
The scene's |
Examples:
- The plotter carries the size the scene was built with:
- Asking twice returns the same plotter:
renderer
property
#
The renderer that draws this scene's figure, and holds what it drew.
Returns:
| Name | Type | Description |
|---|---|---|
The |
Renderer3D
|
class: |
Renderer3D
|
reaches the mesh and actor behind it. |
terrain(data, *, name=None, band=DEFAULT_BAND, z_exaggeration=None, cmap=None, scalars=ELEVATION, texture=None, big_data_threshold=None, **kwargs)
#
Render a raster/DEM as a 3-D relief surface and register it as a layer.
The raster is read through pyramids (via :func:~digitalearth.base.sources.get_source — numpy + coords +
CRS, no xarray), turned into a StructuredGrid, and added to the plotter. Colour by elevation
(default) or pass scalars=None to colour by something else / a uniform colour.
The raster is placed in the scene's display CRS: it sets that CRS when the scene has none, and is reprojected through pyramids when it is in another.
The surface spans the cell centres, not the cell edges. One height is set per node, at the middle of each cell, which is what a surface through sampled elevations means — so the mesh is half a cell narrower than the raster's own extent on each side. The 2-D tiers draw the cells themselves and cover that extent (#301); whether a draped surface should too is decided with draping (#202).
Metre elevations over a geographic scene are converted to degrees by the scene's CRS, not the raster's.
Vertical exaggeration is a property of the scene, not of this layer. z_exaggeration sets
:attr:~digitalearth.three_d.core.base.Scene3DBase.vertical_exaggeration, a PyVista view scale that applies
to every actor — so two terrains in one scene cannot disagree about it, the value can be read back off
the scene, and changing it needs no mesh rebuild. Leaving it None keeps whatever the scene is
already set to (1.0, true scale, on a fresh scene). The exaggeration property of the web tier's
MapLibre terrain behaves the same way.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
A pyramids |
required |
band
|
int
|
1-based band index to read. |
DEFAULT_BAND
|
z_exaggeration
|
float | None
|
Vertical exaggeration to render the scene at ( |
None
|
cmap
|
str | None
|
Matplotlib/colorcet colormap name for the elevation surface. |
None
|
scalars
|
str | None
|
Scalar array to colour by (default the elevation); |
ELEVATION
|
texture
|
Any
|
Imagery to drape over the relief (#202) — a path to an image file, a numpy
|
None
|
big_data_threshold
|
int | None
|
Cells above which the surface is simplified with |
None
|
**kwargs
|
Any
|
Forwarded to :meth: |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
The registered :class: |
Any
|
no elevation to build a surface from (see |
Any
|
class: |
Raises:
| Type | Description |
|---|---|
OffLimbError
|
only when the scene was built with |
ValueError
|
if |
Examples:
- A ramped DEM renders as a non-flat, correctly-oriented surface, and the exaggeration asked for is
readable back off the scene:
>>> import numpy as np, pyvista as pv >>> from digitalearth.three_d import Scene3D >>> from digitalearth.base.sources import get_source >>> dem = np.add.outer(np.linspace(0, 1, 8), np.linspace(0, 1, 8)) >>> scene = Scene3D(off_screen=True) >>> actor = scene.terrain(get_source(dem), z_exaggeration=3.0) >>> len(scene.layers) 1 >>> scene.vertical_exaggeration 3.0 >>> scene.close() - An all-nodata tile is skipped with a warning rather than rendered as a flat blank sheet; under
strict=Trueit raises instead:>>> import numpy as np >>> from digitalearth.three_d import Scene3D >>> from digitalearth.base.crs import OffLimbError >>> from digitalearth.base.sources import get_source >>> blank = get_source(np.full((4, 4), np.nan)) >>> scene = Scene3D(off_screen=True) >>> scene.terrain(blank) is None, len(scene.layers) (True, 0) >>> scene.close() >>> strict = Scene3D(off_screen=True, strict=True) >>> try: ... strict.terrain(blank) ... except OffLimbError as error: ... print(error) ... finally: ... strict.close() terrain: the raster holds no finite elevation
Source code in src/digitalearth/three_d/builders/terrain.py
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | |
point_cloud(data, *, name=None, values=None, value_column=None, size=5.0, scheme=None, k=5, render_points_as_spheres=True, eye_dome_lighting=True, cmap='viridis', big_data_threshold=None, **kwargs)
#
Render a point cloud (LiDAR / observations / raster cells) and register it as a layer.
A GeoDataFrame is placed in the scene's display CRS — setting it when the scene has none, reprojected through pyramids when it is in another. A numpy point table declares no CRS and is placed as given.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
A numpy |
required |
values
|
ndarray | None
|
Explicit per-point scalar array to colour by (overrides |
None
|
value_column
|
str | None
|
Column name to colour by when |
None
|
size
|
float
|
Marker size in pixels (default |
5.0
|
scheme
|
Any | None
|
How the colour values are classified, when the cloud is coloured at all. |
None
|
k
|
int
|
Number of classes for a graduated |
5
|
render_points_as_spheres
|
bool
|
Draw points as shaded spheres (cleaner than flat dots). |
True
|
eye_dome_lighting
|
bool
|
Enable depth-cueing eye-dome lighting (recommended for dense clouds). |
True
|
cmap
|
str
|
Colormap used when the cloud is coloured by a scalar. |
'viridis'
|
big_data_threshold
|
int | None
|
Points above which the cloud is subsampled (an even stride over the points)
before it is drawn (#207). |
None
|
**kwargs
|
Any
|
Forwarded to :meth: |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
The registered :class: |
Any
|
points (see |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
Examples:
- Render a coloured LiDAR-style xyz table:
- A 2-D table is lifted to z=0 and rendered uncoloured:
- Classify the colours into quantile classes instead of a continuous ramp:
>>> import numpy as np >>> from digitalearth.three_d import Scene3D >>> pts = np.column_stack([np.arange(20.0), np.arange(20.0), np.zeros(20)]) >>> scene = Scene3D(off_screen=True) >>> _ = scene.point_cloud(pts, values=pts[:, 0], scheme="quantiles", k=4) >>> sorted(set(int(v) for v in scene.layers[0][0]["scalar"])) [0, 1, 2, 3] >>> scene.close() - Read a LAS/LAZ survey from disk and colour it by ASPRS classification (needs the
3dextra):>>> from digitalearth.three_d import Scene3D # doctest: +SKIP >>> scene = Scene3D(off_screen=True) # doctest: +SKIP >>> _ = scene.point_cloud( # doctest: +SKIP ... "survey.laz", value_column="classification", scheme="categorical" ... ) >>> scene.display_crs # adopted from the file's header # doctest: +SKIP 28992 >>> scene.close() # doctest: +SKIP
Source code in src/digitalearth/three_d/builders/point_cloud.py
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 | |
volume(data, *, name=None, cmap='viridis', opacity='sigmoid', blending='composite', clim=None, shade=False, origin=None, spacing=None, big_data_threshold=None, **kwargs)
#
Ray-cast a 3-D scalar field as a volume and register it as a layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
A 3-D numpy cube, or a pyramids |
required |
cmap
|
str
|
Colormap for the field. |
'viridis'
|
opacity
|
Any
|
Opacity transfer function — a named ramp ( |
'sigmoid'
|
blending
|
str
|
How samples along each ray are combined — one of :data: |
'composite'
|
clim
|
tuple[float, float] | None
|
Fixed |
None
|
shade
|
bool
|
Whether the volume is lit (gradient shading). Off by default — shading a smooth field can read as noise — but on it gives solid-looking structure a surface-like relief. |
False
|
origin
|
tuple[float, float, float] | None
|
World |
None
|
spacing
|
tuple[float, float, float] | None
|
World cell size |
None
|
big_data_threshold
|
int | None
|
Voxels above which the cube is resampled to fewer per axis before it is
ray-cast (#207). |
None
|
**kwargs
|
Any
|
Forwarded to :meth: |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
The registered volume actor. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
Examples:
- Volume-render a synthetic 3-D Gaussian blob:
>>> import numpy as np >>> from digitalearth.three_d import Scene3D >>> ax = np.linspace(-2, 2, 12) >>> xx, yy, zz = np.meshgrid(ax, ax, ax, indexing="ij") >>> cube = np.exp(-(xx**2 + yy**2 + zz**2)) >>> scene = Scene3D(off_screen=True) >>> _ = scene.volume(cube, blending="maximum", clim=(0.0, 1.0)) >>> len(scene.layers) 1 >>> scene.close()
Source code in src/digitalearth/three_d/builders/volume.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | |
isosurface(data, *, name=None, isosurfaces=None, cmap='viridis', origin=None, spacing=None, big_data_threshold=None, **kwargs)
#
Extract and render isosurfaces (shells of constant value) from a 3-D field as a layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
A 3-D numpy cube, or a pyramids |
required |
isosurfaces
|
Sequence[float] | None
|
Iso-values to extract; |
None
|
cmap
|
str
|
Colormap for the extracted surfaces. |
'viridis'
|
origin
|
tuple[float, float, float] | None
|
World |
None
|
spacing
|
tuple[float, float, float] | None
|
World cell size |
None
|
big_data_threshold
|
int | None
|
Cells above which the extracted shells are simplified with |
None
|
**kwargs
|
Any
|
Forwarded to :meth: |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
The registered :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
Examples:
- Two iso-shells of a Gaussian blob:
>>> import numpy as np >>> from digitalearth.three_d import Scene3D >>> ax = np.linspace(-2, 2, 16) >>> xx, yy, zz = np.meshgrid(ax, ax, ax, indexing="ij") >>> cube = np.exp(-(xx**2 + yy**2 + zz**2)) >>> scene = Scene3D(off_screen=True) >>> actor = scene.isosurface(cube, isosurfaces=[0.3, 0.6]) >>> scene.layers[0][0].n_points > 0 True >>> scene.close()
Source code in src/digitalearth/three_d/builders/volume.py
vectors(points, vectors, *, name=None, factor=1.0, cmap='viridis', **kwargs)
#
Render a 3-D vector field as arrow glyphs (oriented + scaled by magnitude) and register it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
ndarray
|
|
required |
vectors
|
ndarray
|
|
required |
factor
|
float
|
Overall arrow length scale. |
1.0
|
cmap
|
str
|
Colormap applied to the arrow magnitudes. |
'viridis'
|
**kwargs
|
Any
|
Forwarded to :meth: |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
The registered :class: |
Any
|
to place a glyph at (see |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
Examples:
- A uniform eastward field renders as same-length arrows coloured by magnitude:
>>> import numpy as np >>> from digitalearth.three_d import Scene3D >>> ax = np.linspace(0, 1, 6) >>> xx, yy = np.meshgrid(ax, ax) >>> pts = np.column_stack([xx.ravel(), yy.ravel(), np.zeros(xx.size)]) >>> vec = np.column_stack([np.ones(pts.shape[0]), np.zeros(pts.shape[0]), np.zeros(pts.shape[0])]) >>> scene = Scene3D(off_screen=True) >>> _ = scene.vectors(pts, vec, factor=0.1) >>> len(scene.layers) 1 >>> scene.close()
Source code in src/digitalearth/three_d/builders/vector.py
extruded_polygons(gdf, *, name=None, height=1.0, column=None, scheme=None, k=5, cmap='viridis', **kwargs)
#
Extrude polygon footprints into 3-D prisms and register them as a single layer.
The footprints are placed in the scene's display CRS — setting it when the scene has none, reprojected through pyramids when they are in another.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
Any
|
A GeoDataFrame of |
required |
height
|
float | str
|
Uniform extrusion height ( |
1.0
|
column
|
str | None
|
Optional attribute column to colour the prisms by; |
None
|
scheme
|
Any | None
|
How |
None
|
k
|
int
|
Number of classes for a graduated |
5
|
cmap
|
str
|
Colormap used when colouring by |
'viridis'
|
**kwargs
|
Any
|
Forwarded to :meth: |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
The registered :class: |
Any
|
nothing to extrude (see |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
TypeError
|
if |
Examples:
- Extrude two squares to different heights and colour by an attribute (needs geopandas at the
call site — only ever as the type pyramids hands back):
>>> import geopandas as gpd >>> from shapely.geometry import Polygon >>> from digitalearth.three_d import Scene3D >>> gdf = gpd.GeoDataFrame( ... {"pop": [10.0, 20.0]}, ... geometry=[Polygon([(0, 0), (1, 0), (1, 1), (0, 1)]), ... Polygon([(2, 0), (3, 0), (3, 1), (2, 1)])], ... ) >>> scene = Scene3D(off_screen=True) >>> actor = scene.extruded_polygons(gdf, height="pop", column="pop") >>> scene.layers[0][0].n_cells > 0 True >>> scene.close() - Nothing to extrude is a skipped layer with a warning, not a dead scene — unless the scene was
built
strict=True:>>> import geopandas as gpd >>> from digitalearth.three_d import Scene3D >>> from digitalearth.base.crs import OffLimbError >>> empty = gpd.GeoDataFrame({"pop": []}, geometry=[]) >>> scene = Scene3D(off_screen=True) >>> scene.extruded_polygons(empty) is None, len(scene.layers) (True, 0) >>> scene.close() >>> strict = Scene3D(off_screen=True, strict=True) >>> try: ... strict.extruded_polygons(empty) ... except OffLimbError as error: ... print(error) ... finally: ... strict.close() extruded_polygons: no polygon geometries to extrude
Source code in src/digitalearth/three_d/builders/vector.py
562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 | |
globe(data, *, name=None, band=DEFAULT_BAND, cmap=None, coastlines=True, coastline_resolution='110m', coastline_color='black', **kwargs)
#
Drape a global field onto a 3-D sphere and register it as a layer.
Projected input is reprojected, not refused: a pyramids Dataset in any CRS is warped to
EPSG:4326 through pyramids (Dataset.to_crs) on the way in, exactly as the static, interactive and
web tiers do. Only input that cannot be reprojected — a bare
:class:~digitalearth.base.sources.Source or raw array carrying a projected CRS or none at all — is
rejected, with an error naming what is wrong.
A globe draws in EPSG:4326, and declares that as the scene's display CRS when the scene has none.
The sphere spans the cell centres, not the cell edges, as terrain does: geovista places one
vertex per lon/lat pair, so a global field is drawn half a cell inside its own extent at each pole and
meridian (#301).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
A pyramids |
required |
band
|
int
|
1-based band index to read. |
DEFAULT_BAND
|
cmap
|
str | None
|
Colormap for the draped field. |
None
|
coastlines
|
bool
|
Overlay Natural-Earth coastlines on the globe. |
True
|
coastline_resolution
|
str
|
Coastline detail ( |
'110m'
|
coastline_color
|
str
|
Colour of the coastline lines. |
'black'
|
**kwargs
|
Any
|
Forwarded to :meth: |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
The registered :class: |
Raises:
| Type | Description |
|---|---|
ImportError
|
if the optional |
ValueError
|
if |
Examples:
- Drape a cosine-of-latitude field on a globe with coastlines (needs the
3dextra / geovista):>>> import numpy as np >>> from digitalearth.three_d import Scene3D >>> from digitalearth.base.sources import get_source >>> lon = np.linspace(-180, 180, 37) >>> lat = np.linspace(-90, 90, 19) >>> field = np.add.outer(np.cos(np.deg2rad(lat)), np.zeros(len(lon))) >>> scene = Scene3D(off_screen=True) >>> actor = scene.globe(get_source(field, x=lon, y=lat), coastlines=False) >>> len(scene.layers) 1 >>> scene.close()
Source code in src/digitalearth/three_d/builders/globe.py
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
set_title(heading, *, subtitle=None, font_size=18, color=None)
#
Give the scene a heading, and record it on the figure.
The Core contract's Tier-2 set_title, with the subtitle it declares: the same name, the same
chainable return and the same meaning as on the other three tiers. A rendered scene travels alone —
a screenshot, an exported page — so whatever context the notebook around it had is gone, and the
heading has to be part of the picture.
The title is figure furniture, and described: it is the panel's own title, which PanelSpec
already carries, so it survives figure_spec.to_dict() and is drawn again by
:meth:~digitalearth.three_d.core.base.Scene3DBase.from_figure. It is not a layer — it has no place on the
ground, it is not in the layer tree, and removing a layer never takes it with it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
heading
|
str
|
The title text, drawn centred along the top of the render window. |
required |
subtitle
|
str | None
|
A smaller second line — a date, a source, a unit. Drawn in the upper-left corner rather than under the heading: a render window has one centred title band and the two lines in it cannot be sized apart. Recorded as drawing state rather than on the figure, exactly as the web tier records its own subtitle. |
None
|
font_size
|
int
|
Size of the heading in points; the subtitle is drawn at 60% of it. |
18
|
color
|
Any
|
Colour of both lines. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
This scene, so decoration chains. |
Raises:
| Type | Description |
|---|---|
TypeError
|
when |
Examples:
- A heading is drawn and is part of what the scene describes:
- The heading survives the round trip the seam exists for:
>>> from digitalearth.base.spec import FigureSpec >>> from digitalearth.three_d import Scene3D >>> first = Scene3D(off_screen=True) >>> stored = first.set_title("Elevation (m)").figure_spec.to_dict() >>> first.close() >>> second = Scene3D.from_figure(FigureSpec.from_dict(stored), off_screen=True) >>> second.figure_spec.panels[0].title 'Elevation (m)' >>> second.close()
See Also
digitalearth.web.decoration.decoration.DecorationMixin.set_title: the same name on the web tier.
Source code in src/digitalearth/three_d/decoration/decoration.py
1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 | |
text(lon, lat, s=None, *, z=0.0, crs=4326, text_size=14.0, color=None, name=None, **kwargs)
#
Place a single string at a coordinate, as a layer of its own.
The "label this spot" case, and the tier's answer to the Core contract's Tier-2 text: the same name,
the same s/crs/name arguments and the same meaning as on the static, interactive and web tiers,
plus the z a scene drawn in three dimensions needs.
The label is a layer, not furniture: it has an id, set_visible hides it, remove_layer takes it
off, and it is drawn again from figure_spec.to_dict(). It does not set the scene's display CRS —
an annotation is decoration, and decoration must not decide what coordinates the scene is drawn in — so
a label given in another CRS is reprojected into the display CRS the data established. Add it after the
layer that sets that CRS, or give the scene crs=, or there is nothing yet to reproject into.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lon
|
Any
|
X of the anchor, in |
required |
lat
|
Any
|
Y of the anchor, in |
required |
s
|
str | None
|
The string to draw. Named |
None
|
z
|
Any
|
Height of the anchor, in the scene's vertical units. |
0.0
|
crs
|
Any
|
What |
4326
|
text_size
|
float
|
Text size in points. Named for the text rather than |
14.0
|
color
|
Any
|
Text colour. |
None
|
name
|
Any
|
The caller's name for the layer, used as its id; |
None
|
**kwargs
|
Any
|
Forwarded to :meth: |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
This scene, so decoration chains. |
Raises:
| Type | Description |
|---|---|
TypeError
|
when the string to draw is not given. |
ValueError
|
when |
Examples:
- Label a peak, and the label is a layer with an id like any other:
- A label is hidden and taken off by id, as a data layer is:
See Also
digitalearth.static.builders.decoration.DecorationMixin.text: the same name on the static tier.
Source code in src/digitalearth/three_d/decoration/decoration.py
1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 | |
axes(show=True, *, xtitle=None, ytitle=None, ztitle=None, **kwargs)
#
Draw a labelled box round the data, so the scene says what its coordinates are.
A 3-D render is otherwise an object floating in space: nothing on the window says how wide the ground
is or how high the relief goes. This is PyVista's show_bounds — the box with ticks and axis titles —
reached in the tier's own vocabulary, and titled from the scene's display CRS rather than from
PyVista's X/Y/Z (see :func:axis_titles). The box's extent follows the renderer, so calling this
before the data is added is fine: the box grows with what is drawn.
It is figure furniture, not a layer: it frames the data rather than being data, so it is not in the
layer tree and removing a layer never takes it with it. It is not written into the figure either —
see the module docstring for the two base/ registrations that would let it be.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
show
|
bool
|
Whether the box is drawn. |
True
|
xtitle
|
str | None
|
What to call the x axis. |
None
|
ytitle
|
str | None
|
What to call the y axis. |
None
|
ztitle
|
str | None
|
What to call the z axis. |
None
|
**kwargs
|
Any
|
Forwarded to :meth: |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
This scene, so decoration chains. |
Examples:
- A projected scene names its own axes rather than showing letters:
- Off again, in one keyword rather than a second method:
See Also
orientation_axes: the corner triad, which says which way the axes point.
Source code in src/digitalearth/three_d/decoration/decoration.py
1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 | |
orientation_axes(show=True, *, xlabel=None, ylabel=None, zlabel=None, **kwargs)
#
Show the corner triad, so a reader can tell which way the scene is being looked at from.
A 3-D scene has no fixed orientation — the camera decides — so the triad shows all three axes at once:
three arrows in the corner of the window, turning with the camera, labelled for the CRS the scene
draws in rather than X/Y/Z (see :func:axis_labels). For the one direction a map most wants
named on its own, :meth:north_arrow draws a camera-aware single arrow instead.
Figure furniture, like :meth:axes: it sits in a corner of the window rather than in the scene's
coordinates, so it is not a layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
show
|
bool
|
Whether the triad is drawn. |
True
|
xlabel
|
str | None
|
What to label the x arrow. |
None
|
ylabel
|
str | None
|
What to label the y arrow. |
None
|
zlabel
|
str | None
|
What to label the z arrow. |
None
|
**kwargs
|
Any
|
Forwarded to :meth: |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
This scene, so decoration chains. |
Examples:
- A lon/lat scene's triad is labelled in its own terms:
See Also
axes: the labelled box, which says how far the coordinates reach.
Source code in src/digitalearth/three_d/decoration/decoration.py
colorbar(layer_id=None, *, label=None, visible=True)
#
Show the continuous colour key of a layer — PyVista's scalar bar, as a guide on its encoding.
The Core contract's colorbar, in the shape the web tier already answers to (#299, #261): the same
name, the same three keywords and the same meaning. What order 24 changes is where the key lives. It
is recorded on the layer's colour :class:~digitalearth.base.spec.encoding.Encoding and then
drawn from that record, so it moves with the layer, hides with it, goes away with it, and comes back
when the layer's description is drawn again.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer_id
|
str | None
|
Which layer's key to show. |
None
|
label
|
str | None
|
What to call the bar — the variable and its units, usually. |
None
|
visible
|
bool
|
|
True
|
Returns:
| Type | Description |
|---|---|
Self
|
This scene, so the call chains. |
Raises:
| Type | Description |
|---|---|
KeyError
|
when |
ValueError
|
when the named layer is not coloured by data; when none is and none was named; when
the layer is coloured by classes, whose key is :meth: |
Examples:
- A terrain's bar, titled, and recorded on the layer that carries it:
>>> import numpy as np >>> from digitalearth.base.sources import get_source >>> from digitalearth.three_d import Scene3D >>> dem = get_source(np.add.outer(np.arange(8.0), np.arange(8.0))) >>> scene = Scene3D(off_screen=True) >>> _ = scene.terrain(dem) >>> _ = scene.colorbar(label="Elevation (m)") >>> scene.get_layer("terrain-1").symbology.guide().title 'Elevation (m)' >>> "Elevation (m)" in scene.plotter.scalar_bars True >>> scene.close() - The key goes away with its layer:
>>> import numpy as np >>> from digitalearth.base.sources import get_source >>> from digitalearth.three_d import Scene3D >>> dem = get_source(np.add.outer(np.arange(8.0), np.arange(8.0))) >>> scene = Scene3D(off_screen=True) >>> _ = scene.terrain(dem) >>> _ = scene.colorbar(label="Elevation (m)") >>> _ = scene.remove_layer("terrain-1") >>> list(scene.plotter.scalar_bars.keys()) [] >>> scene.close()
See Also
legend: the keyed list, for a layer coloured by classes. digitalearth.web.core.base.WebMapBase.colorbar: the same name on the web tier.
Source code in src/digitalearth/three_d/legends/legend.py
1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 | |
legend(layer_id=None, *, title=None, labels=None, visible=True)
#
Show the keyed colour list of a layer — PyVista's legend box, as a guide on its encoding.
The Core contract's legend, and PENDING's "a keyed list beside a scene". The rows are derived
from the layer's own :class:~digitalearth.base.spec.scale.Scale through
:meth:~digitalearth.base.spec.legend.LegendSpec.from_scale, and their colours are read back off the
lookup table the layer is being drawn through — so a swatch cannot disagree with the picture,
which is the whole reason that type exists.
A render window holds one legend box, so the box is built from every layer that asks for one, in draw order, rather than the last caller replacing the previous one. Where more than one layer contributes, each row is prefixed with that layer's title, since an unprefixed box says nothing about which layer a swatch belongs to.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer_id
|
str | None
|
Which layer's classes to list. |
None
|
title
|
str | None
|
Heading for this layer's rows. |
None
|
labels
|
Sequence[str] | None
|
The caller's own row labels, replacing the derived ones — for units, or for renaming
categories. One per row: a list that does not number the classes this layer contributes is
refused, as it is on the other three tiers, because a short one leaves swatches unlabelled
and a long one labels swatches that are not drawn. Recorded as drawn state on the scene
rather than in the figure, exactly as
:meth: |
None
|
visible
|
bool
|
|
True
|
Returns:
| Type | Description |
|---|---|
Self
|
This scene, so the call chains. |
Raises:
| Type | Description |
|---|---|
KeyError
|
when |
ValueError
|
when the named layer is not coloured by data; when none is and none was named; when
the layer is coloured by a continuous ramp, which has no classes to list — its key is
:meth: |
Examples:
- A classified point cloud's classes, listed with the colours they were drawn in:
>>> import numpy as np >>> from digitalearth.three_d import Scene3D >>> points = np.column_stack([np.arange(20.0), np.arange(20.0), np.zeros(20)]) >>> scene = Scene3D(off_screen=True) >>> _ = scene.point_cloud(points, values=points[:, 0], scheme="quantiles", k=4) >>> _ = scene.legend(title="Distance") >>> scene.plotter.legend.GetNumberOfEntries() 4 >>> scene.close() - The caller's own labels replace the derived ranges:
>>> import numpy as np >>> from digitalearth.three_d import Scene3D >>> points = np.column_stack([np.arange(20.0), np.arange(20.0), np.zeros(20)]) >>> scene = Scene3D(off_screen=True) >>> _ = scene.point_cloud(points, values=points[:, 0], scheme="quantiles", k=2) >>> _ = scene.legend(labels=["low", "high"]) >>> scene.plotter.legend.GetEntryString(0) 'low' >>> scene.close()
See Also
colorbar: the scalar bar, for a layer coloured by a continuous ramp. digitalearth.web.legends.legend.LegendMixin.legend: the same name on the web tier.
Source code in src/digitalearth/three_d/legends/legend.py
1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 | |
orbit(path, *, n_frames=36, fps=DEFAULT_FPS, factor=3.0, shift=0.0, viewup=None, **orbit_kwargs)
#
Sweep the camera around the scene and write the fly-through to a GIF/MP4.
factor, shift and viewup shape the path the camera travels; the rest of orbit_kwargs
tunes how it is flown along that path. They belong to two different pyvista calls, which is why they
are separate arguments rather than one pass-through bag.
viewup shapes both — the circle the camera flies and the camera's own up vector. Before these
arguments existed it reached only the camera, so a caller who passed it got a path built around the
theme's up vector and a camera holding a different one, which rolls the horizon through the turn. That
is now a behaviour change for such a caller, and a deliberate one: the two cannot sensibly disagree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Output file. A video suffix ( |
required |
n_frames
|
int
|
Number of frames (camera positions) along the orbit. A whole number, at least 3. pyvista silently clamps a smaller value to 3, so fewer used to "work" and produce a three-frame clip; this rejects it instead, which is a narrowing of what the argument accepted before. |
36
|
fps
|
float
|
Frames per second of the output. Defaults to :data: |
DEFAULT_FPS
|
factor
|
float
|
Orbit radius as a multiple of the scene's bounding size. Smaller closes in on the data.
Must be positive and finite. Anything |
3.0
|
shift
|
float
|
How far to lift the orbit off the data's mid-plane, as an absolute offset along
|
0.0
|
viewup
|
UpVector | None
|
Up vector for the path and the camera alike, as three floats. |
None
|
**orbit_kwargs
|
Any
|
Forwarded to :meth: |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
The |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
TypeError
|
If |
Examples:
- Orbit a terrain scene to a GIF (needs the
3dextra for imageio):>>> import numpy as np, os, tempfile >>> from digitalearth.three_d import Scene3D >>> from digitalearth.base.sources import get_source >>> dem = np.add.outer(np.linspace(0, 1, 8), np.linspace(0, 1, 8)) >>> with tempfile.TemporaryDirectory() as folder, Scene3D(off_screen=True) as scene: ... _ = scene.terrain(get_source(dem), z_exaggeration=3.0) ... out = scene.orbit(os.path.join(folder, "spin.gif"), n_frames=6) ... size = os.path.getsize(out) >>> size > 0 True - Close the orbit in and lift it clear of the terrain, so a near-flat sheet is looked down on
rather than seen edge-on. The orbit sits at the middle of the data, so a shift greater than half
the vertical extent lifts the camera above it — 3.0 for this scene, whose z runs 0..6. Pick it
from your own data's extent, not from this example:
>>> import numpy as np, os, tempfile >>> from digitalearth.three_d import Scene3D >>> from digitalearth.base.sources import get_source >>> dem = np.add.outer(np.linspace(0, 1, 8), np.linspace(0, 1, 8)) >>> with tempfile.TemporaryDirectory() as folder, Scene3D(off_screen=True) as scene: ... _ = scene.terrain(get_source(dem), z_exaggeration=3.0) ... out = scene.orbit( ... os.path.join(folder, "spin.gif"), n_frames=4, factor=0.9, shift=8.0 ... ) ... size = os.path.getsize(out) >>> size > 0 True
Source code in src/digitalearth/three_d/temporal/animation.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 | |
record(frames, path, update, *, fps=DEFAULT_FPS, clim=None)
#
Render a frame-by-frame animation driven by update and write it to a GIF/MP4.
For each item in frames, update(self, frame) mutates the scene (e.g. swaps the active scalars or
re-adds a layer), then one frame is written. Typical frames is a DatasetCollection time stack.
Freeze the colour scale with clim so a time stack does not flicker (#210). When update
re-draws a layer each frame, each builder derives its own colour range from that frame's data, so the
range moves frame to frame and the clip flickers. Passing clim=(low, high) pins the colour range on
every drawn colour-mapped layer (the scalar bar follows its mapper) after each update, so one scale
spans the whole animation — compute it once over the full stack (e.g.
(stack.values.min(), stack.values.max())) and hand it in. None (the default) keeps the per-frame
behaviour. A ray-cast volume's range is :meth:~digitalearth.three_d.builders.volume.VolumeMixin.volume's own
clim= instead.
Scope: clim pins every colour-mapped layer in the scene, not only the one update animates.
That is what the time-stack use case wants (there is one data layer), but in a scene that holds a second
colour-mapped layer on a different scale, that layer is clamped to clim too for the recording. To hold
one layer while others keep their own range, build them in separate scenes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frames
|
Iterable[Any]
|
Iterable of per-frame states passed one at a time to |
required |
path
|
str
|
Output file. A video suffix writes a movie; anything else a GIF. |
required |
update
|
Callable[[AnimationMixin, Any], None]
|
Callback |
required |
fps
|
float
|
Frames per second of the output. Defaults to :data: |
DEFAULT_FPS
|
clim
|
tuple[float, float] | None
|
|
None
|
Returns:
| Type | Description |
|---|---|
str
|
The |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
Examples:
- Animate a growing terrain over three frames:
>>> import numpy as np, os, tempfile >>> from digitalearth.three_d import Scene3D >>> from digitalearth.base.sources import get_source >>> dem = np.add.outer(np.linspace(0, 1, 8), np.linspace(0, 1, 8)) >>> scene = Scene3D(off_screen=True) >>> _ = scene.terrain(get_source(dem)) >>> def grow(s, factor): ... s.layers[0][0].points[:, 2] *= factor >>> with tempfile.TemporaryDirectory() as folder: ... out = scene.record([1.1, 1.1, 1.1], os.path.join(folder, "grow.gif"), grow) ... size = os.path.getsize(out) >>> scene.close() >>> size > 0 True - Freeze the colour scale across frames whose data ranges differ, so a time stack does not
flicker: two frames (elevation ~0..2, then ~0..50) re-draw the layer, but
clim=(0, 50)keeps the drawn range fixed rather than letting it follow the last frame:>>> import numpy as np, os, tempfile >>> from digitalearth.three_d import Scene3D >>> from digitalearth.base.sources import get_source >>> def swap(s, array): ... s.remove_layer("dem") ... s.terrain(get_source(array), name="dem") >>> low = np.add.outer(np.linspace(0, 1, 8), np.linspace(0, 1, 8)) >>> high = low * 50.0 >>> scene = Scene3D(off_screen=True) >>> _ = scene.terrain(get_source(low), name="dem") >>> with tempfile.TemporaryDirectory() as folder: ... _ = scene.record( ... [low, high], os.path.join(folder, "stack.gif"), swap, clim=(0.0, 50.0) ... ) >>> tuple(scene.actor_of("dem").mapper.scalar_range) (0.0, 50.0) >>> scene.close()
Source code in src/digitalearth/three_d/temporal/animation.py
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 | |
jupyter(backend='trame')
#
Switch PyVista's rendering backend so the scene displays interactively in a notebook.
The backend is PyVista's, set process-wide rather than per scene, so it stays in force for every plotter until something changes it back.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
str
|
A PyVista Jupyter backend — |
'trame'
|
Examples:
- Switch to the static (screenshot) backend and read the change back. The restore is in a
finallybecause the backend is process-wide: doctests share one interpreter, and a failure between the switch and the restore would leave every later one on a renderer nobody chose:>>> import pyvista as pv >>> from digitalearth.three_d import Scene3D >>> scene = Scene3D(off_screen=True) >>> previous = pv.global_theme.jupyter_backend >>> try: ... scene.jupyter("static") ... pv.global_theme.jupyter_backend ... finally: ... scene.close() ... pv.set_jupyter_backend(previous) 'static'
See Also
orbit: writes a fly-through to a file instead, for when a notebook is not the destination.
Source code in src/digitalearth/three_d/temporal/animation.py
get_layer(layer_id)
#
Return the description of one layer, by id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer_id
|
str
|
The layer to look up. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Its |
LayerSpec
|
class: |
Raises:
| Type | Description |
|---|---|
KeyError
|
if no layer has that id, naming the ids that do. |
Examples:
- What a builder recorded, read back by id:
>>> import numpy as np >>> from digitalearth.base.sources import get_source >>> from digitalearth.three_d import Scene3D >>> scene = Scene3D(off_screen=True) >>> _ = scene.terrain(get_source(np.add.outer(np.arange(4.0), np.arange(5.0)))) >>> scene.get_layer("terrain-1").kind 'terrain' >>> scene.close()
Source code in src/digitalearth/three_d/core/base.py
move_layer(layer_id, index)
#
Move a layer in draw order, by id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer_id
|
str
|
The layer to move. |
required |
index
|
int
|
Its position afterwards, counted as a list index is — |
required |
Returns:
| Type | Description |
|---|---|
Self
|
This scene (chainable). |
Raises:
| Type | Description |
|---|---|
KeyError
|
if no layer has that id. |
IndexError
|
if the position is outside the scene, or outside the layer's band (#292). |
Note
VTK composites its actors by depth, so this changes the description rather than the picture. It is recorded because the figure is drawn by the other tiers too, where order decides what is on top.
Examples:
- Two layers, reordered by id:
>>> import numpy as np >>> from digitalearth.base.sources import get_source >>> from digitalearth.three_d import Scene3D >>> scene = Scene3D(off_screen=True) >>> dem = get_source(np.add.outer(np.arange(4.0), np.arange(5.0))) >>> _ = scene.terrain(dem, name="under") >>> _ = scene.terrain(dem, name="over") >>> scene.move_layer("over", 0).layer_ids ['over', 'under'] >>> scene.close()
Source code in src/digitalearth/three_d/core/base.py
remove_layer(layer_id)
#
Take a layer off the scene, by id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer_id
|
str
|
The layer to remove. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
This scene (chainable). |
Raises:
| Type | Description |
|---|---|
KeyError
|
if no layer has that id, naming the ids that do. |
Examples:
- A layer added and then removed leaves nothing behind:
>>> import numpy as np >>> from digitalearth.base.sources import get_source >>> from digitalearth.three_d import Scene3D >>> scene = Scene3D(off_screen=True) >>> _ = scene.terrain(get_source(np.add.outer(np.arange(4.0), np.arange(5.0)))) >>> scene.remove_layer("terrain-1").layer_ids [] >>> len(scene.layers) 0 >>> scene.close()
Source code in src/digitalearth/three_d/core/base.py
replace_layer(layer)
#
Swap a layer's description for another, keeping its id and its place in draw order.
This is how a layer is restyled or re-pointed after it has been added: the renderer draws it again from the new description, since VTK bakes a colormap into the mesh it built.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
LayerSpec
|
The new description. Its id names the layer it replaces. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
This scene (chainable). |
Raises:
| Type | Description |
|---|---|
CapabilityError
|
if the replacement names a kind this tier does not declare — a plugin's kind on a machine without the plugin reads as that. |
KeyError
|
if no layer has that id, naming the ids that do. |
ValueError
|
if |
Examples:
- A layer redrawn in another colormap keeps its id:
>>> import numpy as np >>> from dataclasses import replace >>> from digitalearth.base.spec import Symbology >>> from digitalearth.base.sources import get_source >>> from digitalearth.three_d import Scene3D >>> scene = Scene3D(off_screen=True) >>> _ = scene.terrain(get_source(np.add.outer(np.arange(4.0), np.arange(5.0)))) >>> held = scene.get_layer("terrain-1") >>> _ = scene.replace_layer(replace(held, symbology=Symbology(props={"cmap": "magma"}))) >>> scene.get_layer("terrain-1").symbology.props["cmap"] 'magma' >>> scene.close()
Source code in src/digitalearth/three_d/core/base.py
1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 | |
set_visible(layer_id, visible=True)
#
Show or hide a layer, by id.
The layer stays in the scene and in its description — which is what lets a viewer switch it back on, and what tells a saved figure that the layer is there but hidden.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer_id
|
str
|
The layer to toggle. |
required |
visible
|
bool
|
Whether it is drawn. |
True
|
Returns:
| Type | Description |
|---|---|
Self
|
This scene (chainable). |
Raises:
| Type | Description |
|---|---|
KeyError
|
if no layer has that id, naming the ids that do. |
Examples:
- A hidden layer is still described, and comes back on:
>>> import numpy as np >>> from digitalearth.base.sources import get_source >>> from digitalearth.three_d import Scene3D >>> scene = Scene3D(off_screen=True) >>> _ = scene.terrain(get_source(np.add.outer(np.arange(4.0), np.arange(5.0)))) >>> hidden = scene.set_visible("terrain-1", False) >>> hidden.figure_spec.layers.is_visible("terrain-1") False >>> scene.set_visible("terrain-1").figure_spec.layers.is_visible("terrain-1") True >>> scene.close()
Source code in src/digitalearth/three_d/core/base.py
from_figure(figure, **scene_kwargs)
classmethod
#
Build a scene and draw a figure into it.
This is the round trip the seam exists for: a scene describes itself with :attr:figure_spec, the
description survives to_dict()/from_dict(), and this draws it again.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
figure
|
FigureSpec
|
The figure to draw. |
required |
**scene_kwargs
|
Any
|
Passed to the constructor — |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
The scene, with every layer drawn. |
Examples:
- A figure written by one scene is drawn by another:
>>> from digitalearth.base.spec import FigureSpec >>> from digitalearth.three_d import Scene3D >>> first = Scene3D(off_screen=True) >>> _ = first.terrain("examples/data/acc4000.tif") >>> stored = first.figure_spec.to_dict() >>> first.close() >>> second = Scene3D.from_figure(FigureSpec.from_dict(stored), off_screen=True) >>> second.layer_ids ['terrain-1'] >>> second.close()
Source code in src/digitalearth/three_d/core/base.py
draw_figure(figure)
#
Draw a figure into this scene, bringing it from whatever it showed before.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
figure
|
FigureSpec
|
The figure to draw. Its one panel's camera becomes the scene's. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
This scene (chainable). |
Raises:
| Type | Description |
|---|---|
KeyError
|
when a layer names a kind this tier does not draw. |
OffLimbError
|
when a layer cannot be drawn and the scene is |
Source code in src/digitalearth/three_d/core/base.py
add_mesh(mesh, *, name=None, band=None, color_field=None, **kwargs)
#
Add a PyVista mesh to the scene and register it as a layer.
The low-level entry point the capability mixins build on. kwargs pass straight to
:meth:pyvista.Plotter.add_mesh (scalars, cmap, opacity, show_edges, pbr …).
An object you build yourself is a custom layer: what a figure keeps is its description — an id, the
kind custom:pyvista, a label, a band and whether it is visible — and never the object, which has no
description to write. The object stays with the scene that was handed it, so a figure saved and loaded
again names the layer but cannot rebuild it, and another backend cannot draw it at all
(:mod:digitalearth.base.custom says which case a reader is in). Name what the object's colour
encodes with color_field and the layer carries a colour key, published as
Encoding.by_field("color", color_field) the way a builder's is (#349).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mesh
|
Any
|
Any PyVista dataset ( |
required |
color_field
|
str | None
|
The name of the value the mesh's colour encodes. Names it so the custom layer carries
a colour key for :meth: |
None
|
**kwargs
|
Any
|
Forwarded to :meth: |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
The registered :class: |
Examples:
- Add one mesh and find it, paired with its actor, in the layer registry:
- Style the mesh through
kwargs, then tune the returned actor further:>>> import numpy as np, pyvista as pv >>> from digitalearth.three_d.core.base import Scene3DBase >>> grid = pv.ImageData(dimensions=(8, 8, 1)) >>> grid.point_data["z"] = np.linspace(0.0, 1.0, 64) >>> scene = Scene3DBase(off_screen=True) >>> actor = scene.add_mesh(grid, scalars="z", cmap="terrain", show_edges=True) >>> actor.prop.opacity = 0.5 >>> len(scene.layers) 1 >>> scene.close()
See Also
add_volume: the ray-cast counterpart, for scalar fields rather than surfaces.
Source code in src/digitalearth/three_d/core/base.py
1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 | |
add_volume(volume, *, name=None, band=None, color_field=None, **kwargs)
#
Add a volumetric volume (ray-cast rendering) and register it as a layer.
An object you build yourself is a custom layer: what a figure keeps is its description — an id, the
kind custom:pyvista, a label, a band and whether it is visible — and never the object, which has no
description to write. The object stays with the scene that was handed it, so a figure saved and loaded
again names the layer but cannot rebuild it, and another backend cannot draw it at all
(:mod:digitalearth.base.custom says which case a reader is in). Name what the object's colour
encodes with color_field and the layer carries a colour key, published as
Encoding.by_field("color", color_field) the way a builder's is (#349).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
volume
|
Any
|
An |
required |
color_field
|
str | None
|
The name of the value the volume's colour encodes. Names it so the custom layer
carries a colour key for :meth: |
None
|
**kwargs
|
Any
|
Forwarded to :meth: |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
The registered volume actor. |
Examples:
- Ray-cast a 3-D scalar field and see it registered as one layer:
>>> import numpy as np, pyvista as pv >>> from digitalearth.three_d.core.base import Scene3DBase >>> grid = pv.ImageData(dimensions=(6, 6, 6)) >>> grid.cell_data["v"] = np.linspace(0.0, 1.0, 125) >>> scene = Scene3DBase(off_screen=True) >>> _ = scene.add_volume(grid, cmap="viridis") >>> len(scene.layers) 1 >>> scene.close() - A volume and a surface share the one plotter, stacking in add order:
>>> import numpy as np, pyvista as pv >>> from digitalearth.three_d.core.base import Scene3DBase >>> grid = pv.ImageData(dimensions=(6, 6, 6)) >>> grid.cell_data["v"] = np.linspace(0.0, 1.0, 125) >>> scene = Scene3DBase(off_screen=True) >>> _ = scene.add_volume(grid) >>> _ = scene.add_mesh(pv.Sphere(radius=1.0, center=(2, 2, 2))) >>> len(scene.layers) 2 >>> scene.close()
See Also
add_mesh: the surface counterpart, and the method the capability mixins call.
Source code in src/digitalearth/three_d/core/base.py
1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 | |
actor_of(layer_id)
#
Return the actor drawn for a layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer_id
|
str
|
The layer to look up. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The PyVista actor, or |
Raises:
| Type | Description |
|---|---|
KeyError
|
if no layer has that id, naming the ids that do. |
Source code in src/digitalearth/three_d/core/base.py
mesh_of(layer_id)
#
Return the mesh drawn for a layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer_id
|
str
|
The layer to look up. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The PyVista mesh, or |
Raises:
| Type | Description |
|---|---|
KeyError
|
if no layer has that id, naming the ids that do. |
Examples:
- The mesh a builder produced, reached by the layer's id rather than by position:
Source code in src/digitalearth/three_d/core/base.py
view(name)
#
Look at the scene from a named view — "top", "front", "isometric", ….
The one-word half of the camera API. :attr:camera says exactly where to stand; this says it the way a
figure caption does, over PyVista's own view_* methods, which frame the scene's current bounds from
a direction. The names are a table a caller can add to
(:func:~digitalearth.three_d.view.views.register_view), not a fixed list of methods.
The view is captured, not only applied: PyVista aims its camera, the scene reads the result back as
a Camera and stores it. That is what makes the viewpoint survive the next render — which writes the
stored camera onto the plotter — and what puts it on the figure's panel, in to_dict(), and anywhere
else the view is read.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The view's name, as :func: |
required |
Returns:
| Type | Description |
|---|---|
Self
|
The scene, so a view chains with the builders. |
Raises:
| Type | Description |
|---|---|
KeyError
|
for a name nothing registered; the message lists the names that do exist. |
Examples:
- Look at a DEM from straight above, and read the viewpoint back:
>>> import numpy as np >>> from digitalearth.base.sources import get_source >>> from digitalearth.three_d import Scene3D >>> dem = np.add.outer(np.linspace(0, 1, 8), np.linspace(0, 1, 8)) >>> scene = Scene3D(off_screen=True) >>> _ = scene.terrain(get_source(dem)) >>> camera = scene.view("top").camera >>> camera.position[2] > camera.focal_point[2] True >>> scene.close() - The presets are absolute viewpoints, not turns, so the last one wins:
See Also
digitalearth.three_d.view.views: the table, and how to put a view of your own in it.
Source code in src/digitalearth/three_d/core/base.py
render()
#
Build and return the renderer's own object — this tier's plotter.
Every tier answers to render() with the thing its engine draws on, so a caller who wants to reach
past the facade has one name to learn. Here that is the pyvista.Plotter, built on first use (#290).
Returns:
| Type | Description |
|---|---|
Any
|
The scene's plotter, with every layer drawn on it. |
Examples:
- The plotter is what a 3-D scene renders to:
Source code in src/digitalearth/three_d/core/base.py
screenshot(path=None, **kwargs)
#
Render the scene off-screen and return the RGB image (optionally writing it to path).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Destination | None
|
Optional destination for the PNG, as a string or |
None
|
**kwargs
|
Any
|
Forwarded to :meth: |
{}
|
Returns:
| Type | Description |
|---|---|
ndarray
|
numpy.ndarray: the |
Examples:
- Render to memory and work with the frame as an array:
- Write a PNG to disk; the frame is still returned:
>>> import os, tempfile, pyvista as pv >>> from digitalearth.three_d.core.base import Scene3DBase >>> with tempfile.TemporaryDirectory() as folder: ... scene = Scene3DBase(off_screen=True) ... _ = scene.add_mesh(pv.Cube()) ... out = os.path.join(folder, "frame.png") ... frame = scene.screenshot(path=out) ... scene.close() ... os.path.getsize(out) > 0 True
See Also
save: dispatches here for the raster-frame suffixes (:data:IMAGE_SUFFIXES).
Source code in src/digitalearth/three_d/core/base.py
save(path, **kwargs)
#
Save the scene, dispatching on path's suffix — a rendered frame, or a scene export.
Two families share the one entry point, and the suffix decides which:
.html→ :meth:export_html, a self-contained interactive page (see there for why a heavy scene is better served by :meth:digitalearth.three_d.Scene3D.orbit, and for the suffix normalisation it applies).- :data:
IMAGE_SUFFIXES(.png.jpg.jpeg.bmp.tif.tiff) → :meth:screenshot, a rendered raster frame in the format the suffix names —.tifwrites a TIFF, not a PNG. - :data:
SCENE_EXPORTERS(.gltf.obj.vrml.wrl.vtksz) → the matching :class:pyvista.Plotterscene exporter, which writes the geometry itself rather than a picture of it. - :data:
VECTOR_SUFFIXES(.svg.pdf.eps.ps.tex) → :meth:export_vector, a vector graphic of the view (GL2PS), with textured surfaces embedded as raster insets. These take no**kwargs— passing any with a vector suffix is refused rather than dropped. - anything else — including a path with no suffix at all — raises. A format is never invented on
the caller's behalf, so
save("scene")no longer quietly writesscene.png.
The suffix match is case-insensitive throughout (SCENE.HTML exports a page).
It returns the path it wrote, like every other tier's save(), so a caller can chain on the
result without rebuilding the filename — and .html returns the normalised name, which is not
always the one passed in.
Changed, with no transition: it used to return the RGB frame for a raster suffix, and None
for an export — a return type that depended on the suffix, and gave the one branch producing a
useful value no counterpart on the others. Ask for the frame by name instead:
:meth:screenshot writes the same file and hands back the array, so frame = scene.save(out)
becomes frame = scene.screenshot(out) — one call, the same two effects. Unlike the renamed
keywords in this batch, which keep their old spelling for a release, a return type has no shim to
offer: a value contrived to read as both a Path and an array would be worse than the break, so
this one is announced rather than eased.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Destination
|
Output file, as a string or |
required |
**kwargs
|
Any
|
Forwarded to the branch that runs — :meth: |
{}
|
Returns:
| Type | Description |
|---|---|
Path
|
pathlib.Path: the file that was written — |
Path
|
returns the suffix-normalised name :meth: |
Raises:
| Type | Description |
|---|---|
ValueError
|
when |
Examples:
- A raster suffix screenshots, and hands back the path it wrote — not the frame:
>>> import os, tempfile, pyvista as pv >>> from digitalearth.three_d.core.base import Scene3DBase >>> with tempfile.TemporaryDirectory() as folder: ... scene = Scene3DBase(off_screen=True, window_size=(200, 150)) ... _ = scene.add_mesh(pv.Sphere()) ... out = os.path.join(folder, "scene.png") ... written = scene.save(out) ... scene.close() ... written.name, written.is_file() ('scene.png', True) - A scene-export suffix writes the geometry through PyVista's own exporter, and returns its path
the same way:
>>> import os, tempfile, pyvista as pv >>> from digitalearth.three_d.core.base import Scene3DBase >>> with tempfile.TemporaryDirectory() as folder: ... scene = Scene3DBase(off_screen=True) ... _ = scene.add_mesh(pv.Sphere()) ... written = scene.save(os.path.join(folder, "scene.gltf")) ... scene.close() ... written.suffix, written.stat().st_size > 0 ('.gltf', True) - An
.htmlsuffix exports an interactive page instead. The match is case-insensitive, and :meth:export_htmlnormalises the suffix it writes — soSCENE.HTMLlands asSCENE.htmland the returned path is the normalised one, not the name that was passed:>>> import os, tempfile, pyvista as pv >>> from digitalearth.three_d.core.base import Scene3DBase >>> with tempfile.TemporaryDirectory() as folder: ... scene = Scene3DBase(off_screen=True) ... _ = scene.add_mesh(pv.Sphere()) ... written = scene.save(os.path.join(folder, "SCENE.HTML")) ... scene.close() ... written.name, sorted(os.listdir(folder)) ('SCENE.html', ['SCENE.html']) - A suffix-less destination is an error, not a silent
.png:
See Also
screenshot: the raster-frame branch, where its **kwargs end up, and the only method that
returns the rendered array.
export_html: the interactive-page branch.
Source code in src/digitalearth/three_d/core/base.py
2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 | |
export_html(path)
#
Export the scene to a self-contained interactive HTML page (via trame/vtk.js).
The page embeds the whole mesh, so it grows with the geometry rather than with the rendered image: about
a 1 MB vtk.js floor plus ~19 bytes per point (a 12x12 grid gives 1.1 MB, 512x512 gives 6 MB, and a
4700x4700 DEM gives ~430 MB). Past a modest tile the result is technically interactive but too heavy to
sit beside a notebook or in docs — prefer :meth:digitalearth.three_d.Scene3D.orbit, which writes a
compact GIF/MP4 fly-through of the same scene.
The destination is normalised to a .html suffix before writing, and that normalised path is what
comes back. pyvista's own behaviour here differs by version — the trame-pyvista component used from
0.49 rewrites a non-.html suffix, while 0.48's native export honours the name it was given — so
normalising up front is what makes the two agree and keeps the returned path the file that exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Destination
|
Destination file. A suffix other than |
required |
Returns:
| Type | Description |
|---|---|
str
|
The |
Raises:
| Type | Description |
|---|---|
ImportError
|
If the trame/vtk.js export stack is missing. pyvista raises this itself and its message
names the package to install; the |
RuntimeError
|
If trame and pyvista are bound to different VTK builds — the message names
|
Examples:
- Export a small scene. Asking for
scene.HTMLwritesscene.html, and the returned path is the normalised one — the page that exists, on either pyvista — so it can be passed straight on:>>> import os, tempfile, pyvista as pv >>> from digitalearth.three_d.core.base import Scene3DBase >>> with tempfile.TemporaryDirectory() as folder: ... scene = Scene3DBase(off_screen=True) ... _ = scene.add_mesh(pv.Sphere()) ... out = scene.export_html(os.path.join(folder, "scene.HTML")) ... scene.close() ... os.path.basename(out), os.path.getsize(out) > 0, sorted(os.listdir(folder)) ('scene.html', True, ['scene.html'])
See Also
digitalearth.three_d.Scene3D.orbit: a compact GIF/MP4 fly-through, the better choice for a heavy
scene.
save: routes here automatically for a *.html destination.
Source code in src/digitalearth/three_d/core/base.py
2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 | |
show(**kwargs)
#
Display the scene interactively (or render a frame off-screen).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
Forwarded to :meth: |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Whatever |
Any
|
meth: |
Examples:
- Off-screen (as in CI, or under :data:
pyvista.OFF_SCREEN) it renders a frame and returns without opening a window. What comes back is pyvista's own return value, which itsreturn_cpostheme setting decides — do not rely on it: - Keyword arguments reach :meth:
pyvista.Plotter.show, so the camera can be framed on the way in:
See Also
screenshot: returns the rendered frame as an array instead of displaying it.
Source code in src/digitalearth/three_d/core/base.py
close()
#
Close the wrapped plotter and free its render window.
Closing twice is harmless, so a scene can be closed explicitly inside a with block that will close
it again on exit. A scene that never drew has no render window, and closing it opens none.
Examples:
- Free the render window when the scene is finished with:
- A second close is a no-op, not an error:
See Also
exit: calls this on the way out of a with block.