TexturedGlobeGlyph Class#
The textured_globe_glyph module provides the TexturedGlobeGlyph class — cleopatra's one
deliberate 3-D glyph. It wraps an equirectangular (lon/lat) RGB(A) texture onto a tilted
sphere drawn on a matplotlib Axes3D, and can spin the globe frame-by-frame for animation.
It takes the same equirectangular layout as
cleopatra.basemap.reference.relief() — an (H, W, 3) (or (H, W, 4))
array with row 0 at the north pole (+90°) and column 0 at −180° — so you can drape a relief
raster (or any world texture) straight onto a globe. Like HistogramGlyph, it is a standalone
class, not a Glyph subclass, because the base class's 2-D figure/colorbar pipeline does not
apply to a sphere.
Resolution is the cost driver
matplotlib's 3-D surface is drawn on the CPU as one polygon per mesh face, so render time
grows with n_lon × n_lat. The default 180 × 90 (~16k faces) renders a recognisable globe
in ~1.5 s; 360 × 180 is ~7.7 s and 720 × 360 ~27 s. Raise the resolution for a sharper
still, lower it for a smooth animation.
Class Documentation#
cleopatra.glyphs.globe.textured_globe_glyph.TexturedGlobeGlyph
#
Wrap an equirectangular texture onto a tilted, spinnable 3-D sphere.
The glyph takes an equirectangular (plate-carree) (H, W, 3) or (H, W, 4) array -- rows running north (row 0,
+90 deg) to south (last row, -90 deg), columns running west (col 0, -180 deg) to east (last col, +180 deg), exactly
the layout of cleopatra.basemap.reference.relief() -- and paints it onto a unit sphere on a matplotlib Axes3D.
The polar axis is tilted tilt_deg from vertical, and draw(spin=...) rotates the sphere about that axis so the
same instance can render a whole rotation without re-sampling the texture (see the module docstring).
The sphere can be lit from a direction: pass a sun unit vector (in world space) to shade a lambertian day/night
terminator, with an ambient floor so the unlit side stays legible rather than going black. Lighting is applied
per frame from the already-rotated vertices (one dot product), so the sample-once/rotate-per-frame design is kept
-- the texture is never re-sampled and the facecolors cache is never mutated. sun=None (the default) renders
evenly, byte-identical to an unlit globe; a fixed sun with a spinning globe sweeps the terminator across the
surface as it turns.
Attributes:
| Name | Type | Description |
|---|---|---|
texture |
ndarray
|
The normalised RGBA texture, float in |
tilt_deg |
float
|
Axial tilt of the polar axis from vertical, in degrees. |
n_lon |
int
|
Number of longitude samples in the sphere mesh. |
n_lat |
int
|
Number of latitude samples in the sphere mesh. |
sampling |
str
|
How each face takes its colour from the texture ( |
brightness |
float
|
Multiplier applied to the RGB channels (clipped to |
sun |
ndarray | None
|
The unit light direction in world space, or |
ambient |
float
|
The ambient floor (fraction) kept on the unlit side. |
default_options |
dict
|
The resolved render options ( |
Methods:
| Name | Description |
|---|---|
draw |
Render the globe at a given spin angle. |
animate |
Return a |
rotation_matrix |
The |
transform |
Push your own |
Notes
TexturedGlobeGlyph is a standalone class, not a Glyph subclass (like HistogramGlyph). The accepted option
keys are exposed via the DEFAULT_OPTIONS class attribute and can be inspected/filtered with the option_keys
and filter_kwargs classmethods.
Examples:
Build a globe from a small synthetic texture and render it:
>>> import numpy as np
>>> from cleopatra.glyphs.globe.textured_globe_glyph import TexturedGlobeGlyph
>>> texture = np.zeros((16, 32, 3), dtype=np.uint8)
>>> texture[:8] = (40, 90, 180)
>>> globe = TexturedGlobeGlyph(texture, n_lon=48, n_lat=24)
>>> fig, ax = globe.draw(spin=45.0)
>>> ax.name
'3d'
>>> globe.surface is not None
True
Source code in src/cleopatra/glyphs/globe/textured_globe_glyph.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 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 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 407 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 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 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 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 | |
ambient
property
#
The ambient floor (fraction) kept on the unlit side under directional lighting.
brightness
property
#
The brightness multiplier applied to the RGB channels.
default_options
property
#
The resolved render options (figsize, elev, azim, background).
face_colors
property
#
The base per-face RGBA colours the mesh is filled with, (n_lat - 1, n_lon - 1, 4) float in [0, 1].
These are the sampled colours before any per-frame directional lighting (which only scales RGB and
never touches alpha), so a caller can check whether its data survived the texture sampling -- e.g. that a
small feature still lands on at least one face -- without a draw() and without reaching into
private state. Reading it samples the texture once (the sample-once contract); a copy is returned,
so mutating it never disturbs the glyph's cache.
Examples:
>>> import numpy as np
>>> from cleopatra.glyphs.globe.textured_globe_glyph import TexturedGlobeGlyph
>>> texture = np.zeros((90, 180, 4), dtype=np.uint8)
>>> texture[10:14, 20:24] = (255, 0, 0, 255) # a small opaque patch
>>> globe = TexturedGlobeGlyph(texture, n_lon=90, n_lat=45, sampling="area")
>>> painted = globe.face_colors
>>> painted.shape
(44, 89, 4)
>>> int((painted[..., 3] > 0).sum()) > 0 # the patch survived
True
n_lat
property
#
Number of latitude samples in the sphere mesh.
n_lon
property
#
Number of longitude samples in the sphere mesh.
sampling
property
#
How each face takes its colour from the texture ("point" or "area").
sun
property
#
The unit light direction in world space, or None for even (unlit) rendering.
surface
property
#
The Poly3DCollection from the most recent draw, or None before the first draw.
texture
property
#
The normalised RGBA texture (float (H, W, 4) in [0, 1]).
tilt_deg
property
#
Axial tilt of the polar axis from vertical, in degrees.
__init__(texture, *, tilt_deg=EARTH_TILT_DEG, n_lon=180, n_lat=90, sampling=SAMPLING_POINT, brightness=1.0, sun=None, ambient=DEFAULT_AMBIENT, fig=None, ax=None, **kwargs)
#
Initialize the globe from an equirectangular texture.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
texture
|
ndarray
|
An equirectangular RGB(A) array of shape |
required |
tilt_deg
|
float
|
Axial tilt of the polar axis from vertical, in degrees. Defaults to Earth's 23.44 deg. |
EARTH_TILT_DEG
|
n_lon
|
int
|
Longitude samples in the sphere mesh (>= 2). Higher is sharper but quadratically slower to draw. |
180
|
n_lat
|
int
|
Latitude samples in the sphere mesh (>= 2). Higher is sharper but quadratically slower to draw. |
90
|
sampling
|
str
|
How each mesh face takes its colour from the texture. |
SAMPLING_POINT
|
brightness
|
float
|
Multiplier applied to the RGB channels before clipping to |
1.0
|
sun
|
tuple[float, float, float] | None
|
Light direction as a length-3 |
None
|
ambient
|
float
|
Floor brightness (fraction in |
DEFAULT_AMBIENT
|
fig
|
Figure | None
|
Pre-existing matplotlib |
None
|
ax
|
Axes3D | None
|
Pre-existing 3-D matplotlib |
None
|
**kwargs
|
Render options overriding |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> import numpy as np
>>> from cleopatra.glyphs.globe.textured_globe_glyph import TexturedGlobeGlyph
>>> globe = TexturedGlobeGlyph(np.zeros((8, 16, 3), dtype=np.uint8), n_lon=24, n_lat=12)
>>> globe.n_lon, globe.n_lat
(24, 12)
Source code in src/cleopatra/glyphs/globe/textured_globe_glyph.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 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 | |
animate(ax=None, *, n_frames=60, revolutions=1.0, start_spin=0.0, sun=_INHERIT, ambient=_INHERIT, interval=50, **kwargs)
#
Return a FuncAnimation that spins the globe about its polar axis.
The texture is sampled once (via draw's cached _prepare); each frame only rotates the pre-computed vertices
and re-draws, so the per-frame cost is dominated by matplotlib's surface draw at the chosen mesh resolution.
Save it with cleopatra.glyphs.base.animation.save_animation (to a file) or to_gif/to_mp4 (to bytes),
or matplotlib's own writers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes3D | None
|
A 3-D axes to animate on, or |
None
|
n_frames
|
int
|
Number of frames in the animation. |
60
|
revolutions
|
float
|
How many full turns the globe makes over |
1.0
|
start_spin
|
float
|
Spin angle of the first frame, in degrees. |
0.0
|
sun
|
tuple[float, float, float] | None
|
Light direction forwarded to |
_INHERIT
|
ambient
|
float
|
Ambient floor forwarded to |
_INHERIT
|
interval
|
int
|
Delay between frames in milliseconds (matplotlib playback hint). |
50
|
**kwargs
|
Render options forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
FuncAnimation
|
matplotlib.animation.FuncAnimation: The animation, ready to save or embed. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> import numpy as np
>>> from cleopatra.glyphs.globe.textured_globe_glyph import TexturedGlobeGlyph
>>> globe = TexturedGlobeGlyph(np.zeros((8, 16, 3), dtype=np.uint8), n_lon=24, n_lat=12)
>>> anim = globe.animate(n_frames=4)
>>> list(anim.new_frame_seq()) # one entry per rendered frame
[0, 1, 2, 3]
Source code in src/cleopatra/glyphs/globe/textured_globe_glyph.py
866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 | |
draw(ax=None, *, spin=0.0, sun=_INHERIT, ambient=_INHERIT, **kwargs)
#
Render the textured globe onto a 3-D axes at a given spin angle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes3D | None
|
A 3-D matplotlib axes ( |
None
|
spin
|
float
|
Rotation of the globe about its tilted polar axis, in degrees. The camera stays put. |
0.0
|
sun
|
tuple[float, float, float] | None
|
Light direction for this call, overriding the instance's |
_INHERIT
|
ambient
|
float
|
Ambient floor for this call, overriding the instance's |
_INHERIT
|
**kwargs
|
Render options overriding the instance defaults for this call ( |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
tuple[Figure, Axes3D]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
- Render a spun frame:
- Light it from the
+xdirection for a day/night terminator:
Source code in src/cleopatra/glyphs/globe/textured_globe_glyph.py
778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 | |
filter_kwargs(kwargs)
classmethod
#
Return only the subset of kwargs whose keys this glyph accepts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kwargs
|
dict
|
A mapping of candidate option keys to values. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
The entries of |
Examples:
>>> from cleopatra.glyphs.globe.textured_globe_glyph import TexturedGlobeGlyph
>>> sorted(TexturedGlobeGlyph.filter_kwargs({"elev": 30, "bogus": 1}))
['elev']
Source code in src/cleopatra/glyphs/globe/textured_globe_glyph.py
option_keys()
classmethod
#
Return the keyword-argument keys this glyph accepts.
Resolves from the class-level DEFAULT_OPTIONS so the accepted keys can be inspected without constructing an
instance. Mirrors cleopatra.glyphs.base.glyph.Glyph.option_keys (TexturedGlobeGlyph is a standalone class,
not a Glyph subclass).
Returns:
| Name | Type | Description |
|---|---|---|
set |
set[str]
|
The accepted option keys for this glyph class. |
Examples:
>>> from cleopatra.glyphs.globe.textured_globe_glyph import TexturedGlobeGlyph
>>> "elev" in TexturedGlobeGlyph.option_keys()
True
Source code in src/cleopatra/glyphs/globe/textured_globe_glyph.py
rotation_matrix(spin=0.0)
#
Return the 3x3 body-to-world rotation the glyph applies at a given spin.
This is the exact transform draw(spin=...) uses to place the sphere: a rotation of spin degrees about
the body polar axis (z), then the fixed axial tilt of tilt_deg about the world x axis --
R_tilt(x) @ R_z(spin). Apply it (or transform) to your own scene geometry so it sits consistently with
the rendered globe without reimplementing the tilt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spin
|
float
|
Rotation about the polar axis, in degrees (matching |
0.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
numpy.ndarray: A |
Examples:
- Identity at
spin=0with no tilt:
See Also
transform: Apply this matrix to an (N, 3) array of points.
Source code in src/cleopatra/glyphs/globe/textured_globe_glyph.py
transform(points, spin=0.0)
#
Map body-frame point(s) into world space exactly as the glyph places its mesh.
Pushes points through rotation_matrix(spin) (spin about the polar axis, then the axial tilt). The body
frame is the same one the mesh is built in: a unit sphere with +z at the north pole, so a surface point at
(lon, lat) is [cos(lat) cos(lon), cos(lat) sin(lon), sin(lat)], the equatorial plane is z = 0, and the
polar axis is +z. Use it to place an eclipse marker, a geostationary ring, or an orbit plane so they align
with the rendered globe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
ArrayLike
|
A single |
required |
spin
|
float
|
Rotation about the polar axis, in degrees (matching |
0.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
numpy.ndarray: The transformed point(s), same shape as |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
- The north pole maps to the tilted axis; a 90 deg tilt lays it onto
-y:
See Also
rotation_matrix: The (3, 3) matrix this method applies.
Source code in src/cleopatra/glyphs/globe/textured_globe_glyph.py
Examples#
A still globe from a relief texture#
import matplotlib.pyplot as plt
from cleopatra.basemap.reference import relief
from cleopatra.glyphs.globe.textured_globe_glyph import TexturedGlobeGlyph
texture = relief("low") # (360, 720, 3) equirectangular RGB, north-up
globe = TexturedGlobeGlyph(texture, tilt_deg=23.44, brightness=1.1)
fig, ax = globe.draw(spin=60.0, elev=20, background="black")
plt.show()
A synthetic texture (no download)#
import numpy as np
import matplotlib.pyplot as plt
from cleopatra.glyphs.globe.textured_globe_glyph import TexturedGlobeGlyph
texture = np.zeros((180, 360, 3), dtype=np.uint8)
texture[:90] = (40, 90, 180) # northern hemisphere blue
texture[90:] = (180, 120, 40) # southern hemisphere ochre
fig, ax = TexturedGlobeGlyph(texture).draw(spin=45.0)
plt.show()
A day/night terminator (directional lighting)#
Pass a sun unit vector (in world space: +z is north/up, +x faces the viewer at spin=0) to
light the sphere from a direction. ambient is a floor so the night side stays legible. Lighting
is applied per frame from the already-rotated vertices — no texture re-sampling — so a fixed sun
with a spinning globe sweeps the terminator across the surface. sun=None (the default) renders
evenly.
Note
This is the 3-D globe's directional lighting (shading on a sphere). For a day/night
terminator on an ordinary flat (lon/lat) axes, use
cleopatra.basemap.solar — add_nightshade draws the terminator and night region
as lon/lat geometry rather than shading a sphere.
from cleopatra.basemap.reference import relief
from cleopatra.glyphs.globe.textured_globe_glyph import TexturedGlobeGlyph
globe = TexturedGlobeGlyph(relief("low"), sun=(0.0, 1.0, 0.3), ambient=0.13)
fig, ax = globe.draw(spin=40.0, background="black") # side-lit: one half in daylight, the other in night
A spinning animation#
The texture is sampled once; each frame only rotates the pre-computed mesh, so use a modest
resolution for smooth playback. Add sun=... for a lit globe whose terminator moves as it turns.
from cleopatra.basemap.reference import relief
from cleopatra.glyphs.globe.textured_globe_glyph import TexturedGlobeGlyph
globe = TexturedGlobeGlyph(relief("low"), n_lon=180, n_lat=90)
anim = globe.animate(n_frames=60, revolutions=1.0, interval=50, sun=(1.0, 0.0, 0.0))
# save with cleopatra.glyphs.base.animation.save_animation (or to_gif/to_mp4),
# or matplotlib's own writers:
# from cleopatra.glyphs.base.animation import save_animation
# save_animation(anim, "globe.gif")
Aligning your own geometry with the globe (the tilt transform)#
The glyph places the sphere with a fixed transform: it spins about the polar axis, then leans that
axis tilt_deg from vertical about the world x axis — exactly the R_tilt @ R_z matrix
rotation_matrix(spin) returns. To place your own scene geometry — a marker on the surface, a ring in
the equatorial plane, an orbit plane — so it sits consistently with the rendered globe, push it through
the same transform with
transform(points, spin=...) (or grab the (3, 3) matrix with rotation_matrix(spin)). The body
frame is the unit sphere: +z at the north pole, so a surface point at (lon, lat) is
[cos(lat)·cos(lon), cos(lat)·sin(lon), sin(lat)] and the equatorial plane is z = 0.
import numpy as np
from cleopatra.basemap.reference import relief
from cleopatra.glyphs.globe.textured_globe_glyph import TexturedGlobeGlyph
globe = TexturedGlobeGlyph(relief("low"), tilt_deg=23.44)
fig, ax = globe.draw(spin=40.0)
# a geostationary ring in the equatorial plane, tilted+spun to match the globe
theta = np.linspace(0, 2 * np.pi, 200)
ring = np.column_stack([1.3 * np.cos(theta), 1.3 * np.sin(theta), np.zeros_like(theta)])
ring = globe.transform(ring, spin=40.0)
ax.plot(ring[:, 0], ring[:, 1], ring[:, 2])
# draw() fixes the axis limits to the unit sphere; widen them so the ring is visible
for set_lim in (ax.set_xlim, ax.set_ylim, ax.set_zlim):
set_lim(-1.4, 1.4)