TexturedGlobe#
Drape a pyramids raster — or a whole-world tile basemap — over a 3-D sphere on a matplotlib Axes3D.
TexturedGlobe wraps cleopatra's TexturedGlobeGlyph, which is deliberately geometry-only: it paints an
equirectangular array onto a tilted, spinnable sphere and knows nothing about rasters, CRSes or nodata. This
class owns the geospatial half of that seam — building the texture from geodata, and mapping lon/lat back
onto the drawn surface so vector overlays land where they belong at any spin.
digitalearth.static.globe.textured_globe.TexturedGlobe
#
Bases: WatermarkMixin
A 3-D textured globe built from geospatial data.
Inherits cleopatra's WatermarkMixin, whose surface comes with it as-is: :meth:stamp below is this
package's documented spelling for the logo stamp, and stamp_watermark(text) is available unchanged
from upstream, documented there rather than here.
Wraps cleopatra.glyphs.globe.TexturedGlobeGlyph: this class owns the data → texture conversion and
the lon/lat overlay maths, the glyph owns the sphere, the tilt, the lighting and the render.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
texture
|
ndarray
|
An equirectangular |
required |
**kwargs
|
Any
|
Forwarded to |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
glyph |
The underlying cleopatra |
|
fig |
Any
|
The matplotlib figure, once :meth: |
ax |
Any
|
The matplotlib |
Examples:
- Build a globe from a two-tone synthetic texture and draw it:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import numpy as np >>> from digitalearth.static import TexturedGlobe >>> texture = np.zeros((90, 180, 3), dtype=np.uint8) >>> texture[:45] = (40, 90, 180) >>> texture[45:] = (180, 120, 40) >>> globe = TexturedGlobe(texture, n_lon=36, n_lat=18) >>> fig, ax = globe.draw(spin=45.0) >>> ax.name '3d' - The north pole sits on the tilted polar axis, not straight up:
Source code in src/digitalearth/static/globe/textured_globe.py
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 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 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 1131 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 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 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 1357 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 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 1484 1485 1486 1487 1488 1489 1490 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 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 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 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 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 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 | |
__enter__()
#
Enter the runtime context, returning the globe so with TexturedGlobe(...) as g: binds it.
Returns:
| Type | Description |
|---|---|
TexturedGlobe
|
This globe. |
__exit__(exc_type, exc, tb)
#
Close the figure on exit so a long run of globes stays memory-bounded.
Mirrors :class:~digitalearth.static.core.scene.Scene: the figure is closed whether or not the body
raised, and any exception propagates (__exit__ returns False), so with never swallows an
error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exc_type
|
Any
|
Exception class raised in the body, if any. |
required |
exc
|
Any
|
The exception instance, if any. |
required |
tb
|
Any
|
The traceback, if any. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in src/digitalearth/static/globe/textured_globe.py
__init__(texture, **kwargs)
#
Wrap an equirectangular texture in a cleopatra globe glyph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
texture
|
ndarray
|
An equirectangular |
required |
**kwargs
|
Any
|
Forwarded to |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/digitalearth/static/globe/textured_globe.py
animate(stack, *, ax=None, band=DEFAULT_BAND, cmap='viridis', vmin=None, vmax=None, shape=DEFAULT_TEXTURE_SHAPE, resampling='nearest', titles=None, spin=None, interval=_DEFAULT_INTERVAL_MS, **kwargs)
#
Step a series of rasters across the globe, returning a matplotlib FuncAnimation.
The globe counterpart of :meth:~digitalearth.static.builders.animation.AnimationMixin.animate on the
2-D tier: the camera holds still and the data changes, which is what a time series of a global
field — sea-surface temperature, sea ice, an anomaly field — wants. To turn the viewpoint around one
fixed texture instead, use :meth:spin.
One colour scale across the whole stack. The scale is settled before any frame is drawn and they
all share it, so a change on screen is a change in the data. Per-frame normalisation would make a
constant field shimmer and an outlier frame rescale the rest; pass vmin/vmax to pin the scale
yourself, and either one alone fixes that end and measures the other. The scale is measured from an
evenly-spread sample of at most DEFAULT_CLIM_SCAN_CAP (24) frames, as the 2-D tier measures its
own — a long series does not read every frame into memory just to find its limits.
Memory is bounded by one frame, not the stack. Frames are read and colourised one at a time, as
each is drawn, never all held at once; a 624-band series animates in roughly the footprint of a
single frame. The default shape is a 1440x2880 texture (~17 MB each), so a coarser shape= is
worth passing when the output is small.
Overlays come along. Anything added with :meth:points, :meth:coastlines, :meth:borders or
:meth:land is re-placed on every frame, so a coastline stays registered to the ground while the
field beneath it changes. That is the whole reason this is a method rather than something a caller
assembles: stepping the texture by hand means rebuilding the globe per frame, and clearing the axes
to do so throws the overlays away.
Each frame is read through :meth:_global_values, the same path :meth:from_dataset takes, so a
frame is placed exactly as a single raster would be. cleopatra's texture is a read-only property,
so each frame builds a glyph around its own texture from the options this globe was constructed with.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stack
|
Any
|
The rasters to step, one per frame — a sequence of pyramids |
required |
ax
|
Any
|
An existing |
None
|
band
|
int
|
1-based index of the band to read from every frame. |
DEFAULT_BAND
|
cmap
|
Any
|
Colormap name or object, resolved by cleopatra for all frames alike. |
'viridis'
|
vmin
|
float | None
|
Low end of the shared colour scale; |
None
|
vmax
|
float | None
|
High end of the shared colour scale; |
None
|
shape
|
tuple[int, int]
|
The |
DEFAULT_TEXTURE_SHAPE
|
resampling
|
str
|
The pyramids resampling method for that align. |
'nearest'
|
titles
|
Sequence[Any] | None
|
One title per frame, set on the axes as it is drawn; |
None
|
spin
|
float | None
|
The spin to hold the camera at, in degrees — the same |
None
|
interval
|
float
|
Milliseconds between frames. |
_DEFAULT_INTERVAL_MS
|
**kwargs
|
Any
|
Forwarded to the glyph's |
{}
|
Returns:
| Type | Description |
|---|---|
FuncAnimation
|
The |
FuncAnimation
|
garbage-collected before you save or display it. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
- Step a two-frame stack; the colour scale is measured across both, so the second frame being
warmer is visible rather than normalised away:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import numpy as np >>> from pyramids.dataset import Dataset, GeoReference >>> from digitalearth.static import TexturedGlobe >>> ref = GeoReference(geo=(-180.0, 2.0, 0.0, 90.0, 0.0, -2.0), epsg=4326) >>> cool = Dataset.from_array(np.zeros((90, 180), "float32"), geo_ref=ref) >>> warm = Dataset.from_array(np.ones((90, 180), "float32"), geo_ref=ref) >>> globe = TexturedGlobe.from_dataset(cool, shape=(90, 180), n_lon=16, n_lat=8) >>> anim = globe.animate([cool, warm], shape=(90, 180), interval=100) >>> len(list(anim.new_frame_seq())) 2 - A stack with a title per frame:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import numpy as np >>> from pyramids.dataset import Dataset, GeoReference >>> from digitalearth.static import TexturedGlobe >>> ref = GeoReference(geo=(-180.0, 2.0, 0.0, 90.0, 0.0, -2.0), epsg=4326) >>> frames = [ ... Dataset.from_array(np.full((90, 180), v, "float32"), geo_ref=ref) ... for v in (1.0, 2.0) ... ] >>> globe = TexturedGlobe.from_dataset(frames[0], shape=(90, 180), n_lon=16, n_lat=8) >>> _ = globe.animate(frames, shape=(90, 180), titles=["Jan", "Feb"], interval=100) >>> globe.ax.get_title() 'Jan'
Source code in src/digitalearth/static/globe/textured_globe.py
2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 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 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 | |
borders(resolution='110m', *, spin=None, altitude=0.002, **kwargs)
#
Draw Natural-Earth country borders on the globe, split at the visible limb.
The counterpart of :meth:~digitalearth.static.Map.borders, same spelling and same default
styling, so a globe and a flat map can be given the same reference geography.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resolution
|
str
|
Natural-Earth resolution — |
'110m'
|
spin
|
float | None
|
Pin the borders to this spin, in degrees. Omitted, they follow the globe. |
None
|
altitude
|
float
|
Radial lift above the surface. |
0.002
|
**kwargs
|
Any
|
Line styling forwarded to matplotlib, as for :meth: |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
The |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
if the globe has not been drawn yet. |
Examples:
- Borders draw in their own default grey, thinner than the coastlines. The vectors are
fetched (and cached) by
cleopatra, so this needs a network on first use:>>> import matplotlib # doctest: +SKIP >>> matplotlib.use("Agg") # doctest: +SKIP >>> import numpy as np # doctest: +SKIP >>> from digitalearth.static import TexturedGlobe # doctest: +SKIP >>> globe = TexturedGlobe(np.zeros((8, 16, 3), np.uint8)) # doctest: +SKIP >>> _ = globe.draw(elev=0.0, azim=0.0) # doctest: +SKIP >>> float(globe.borders().get_linewidth()[0]) # doctest: +SKIP 0.4 - Ask for the finer cut when the globe is drawn large:
>>> import matplotlib # doctest: +SKIP >>> matplotlib.use("Agg") # doctest: +SKIP >>> import numpy as np # doctest: +SKIP >>> from digitalearth.static import TexturedGlobe # doctest: +SKIP >>> globe = TexturedGlobe(np.zeros((8, 16, 3), np.uint8)) # doctest: +SKIP >>> _ = globe.draw(elev=0.0, azim=0.0) # doctest: +SKIP >>> fine, coarse = globe.borders("50m"), globe.borders("110m") # doctest: +SKIP >>> globe.fig.canvas.draw() # doctest: +SKIP >>> len(fine.get_segments()) > len(coarse.get_segments()) # doctest: +SKIP True - Asking before the globe is drawn is refused — there is no camera yet to clip against:
Source code in src/digitalearth/static/globe/textured_globe.py
1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 | |
close()
#
Close the globe's figure, drop the animation reference, and forget the overlays.
Every :meth:draw, :meth:spin or :meth:animate that is not handed an existing axes creates a pyplot figure,
and pyplot keeps a reference to it forever. A loop that builds many globes therefore grows without
bound and eventually trips matplotlib's open-figure warning. Closing releases both the figure and the
retained animation.
Only a figure this globe created is closed. An axes handed in by the caller — to __init__,
draw(ax=...) or animate(ax=...) — belongs to the caller, who may well have other subplots on
it, so its figure is left alone.
The overlays are forgotten either way, so a later draw — on any axes — starts without them rather than turning markers that belong to a figure the caller has finished with.
Safe to call more than once, and on a globe that was never drawn.
Examples:
- Close a drawn globe and see the figure released:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import matplotlib.pyplot as plt >>> import numpy as np >>> from digitalearth.static import TexturedGlobe >>> plt.close("all") >>> globe = TexturedGlobe(np.zeros((8, 16, 3), dtype=np.uint8), n_lon=8, n_lat=4) >>> fig, ax = globe.draw() >>> len(plt.get_fignums()) 1 >>> globe.close() >>> len(plt.get_fignums()) 0
Source code in src/digitalearth/static/globe/textured_globe.py
coastlines(resolution='110m', *, spin=None, altitude=0.002, **kwargs)
#
Draw Natural-Earth coastlines on the globe, split at the visible limb.
Named and styled to match :meth:~digitalearth.static.Map.coastlines on the 2-D globe, so the two
tiers read alike. Each coastline is placed on the sphere and broken into the arcs that face the
camera, each carried out to the horizon; without that split every line crossing the limb would be
drawn as a chord through the planet. The split is redone at every draw, for the spin and the camera
of that moment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resolution
|
str
|
Natural-Earth resolution — |
'110m'
|
spin
|
float | None
|
Pin the coastlines to this spin, in degrees. Omitted, they follow the globe and are redrawn at each animation frame's spin. |
None
|
altitude
|
float
|
Radial lift above the surface, so the lines are not z-fought by it. |
0.002
|
**kwargs
|
Any
|
Line styling forwarded to matplotlib ( |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
The |
Any
|
The arcs are worked out when the figure is drawn, so |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
if the globe has not been drawn yet. |
Examples:
- Coastlines land on the sphere as a set of near-side arcs. The vectors are fetched (and
cached) by
cleopatra, so this needs a network on first use:>>> import matplotlib # doctest: +SKIP >>> matplotlib.use("Agg") # doctest: +SKIP >>> import numpy as np # doctest: +SKIP >>> from digitalearth.static import TexturedGlobe # doctest: +SKIP >>> globe = TexturedGlobe(np.zeros((8, 16, 3), np.uint8)) # doctest: +SKIP >>> _ = globe.draw(elev=0.0, azim=0.0) # doctest: +SKIP >>> lines = globe.coastlines() # doctest: +SKIP >>> globe.fig.canvas.draw() # doctest: +SKIP >>> len(lines.get_segments()) # doctest: +SKIP 57 - Restyle them like any matplotlib line, and pin them to one spin so they stay put while the
globe turns:
>>> import matplotlib # doctest: +SKIP >>> matplotlib.use("Agg") # doctest: +SKIP >>> import numpy as np # doctest: +SKIP >>> from digitalearth.static import TexturedGlobe # doctest: +SKIP >>> globe = TexturedGlobe(np.zeros((8, 16, 3), np.uint8)) # doctest: +SKIP >>> _ = globe.draw(elev=0.0, azim=0.0) # doctest: +SKIP >>> lines = globe.coastlines(color="white", lw=1.2, spin=0.0) # doctest: +SKIP >>> float(lines.get_linewidth()[0]) # doctest: +SKIP 1.2 - Asking before the globe is drawn is refused — there is no camera yet to clip against:
Source code in src/digitalearth/static/globe/textured_globe.py
1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 | |
draw(ax=None, *, spin=0.0, **kwargs)
#
Draw the globe, returning the matplotlib (fig, ax) and recording them on the instance.
A globe keeps drawing where it already is: called without an ax, this reuses the axes it owns, so
overlays added since the last draw — :meth:points, :meth:coastlines, :meth:borders,
:meth:land without a spin= — turn to the new spin and stay. figsize resizes that
figure. Pass an ax to draw somewhere else instead; overlays stay behind with the axes they
were drawn on, and a figure this globe owned and is leaving is closed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Any
|
An existing |
None
|
spin
|
float
|
Rotation about the polar axis, in degrees. |
0.0
|
**kwargs
|
Any
|
Forwarded to the glyph's |
{}
|
Returns:
| Type | Description |
|---|---|
tuple[Any, Any]
|
The |
Examples:
- Draw the globe and keep the axes for further decoration:
- Draw several spins onto axes you own, to build a contact sheet:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import numpy as np >>> from digitalearth.static import TexturedGlobe >>> import matplotlib.pyplot as plt >>> globe = TexturedGlobe(np.zeros((8, 16, 3), dtype=np.uint8), n_lon=8, n_lat=4) >>> fig, axes = plt.subplots(1, 3, subplot_kw={"projection": "3d"}) >>> for spin, sub in zip([0.0, 120.0, 240.0], axes): ... _ = globe.draw(ax=sub, spin=spin) >>> len(fig.axes) 3
Source code in src/digitalearth/static/globe/textured_globe.py
1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 | |
from_dataset(dataset, *, band=DEFAULT_BAND, cmap='viridis', vmin=None, vmax=None, shape=DEFAULT_TEXTURE_SHAPE, resampling='nearest', **kwargs)
classmethod
#
Build a globe from a pyramids Dataset, draped at the raster's true lon/lat position.
pyramids does the geospatial work: the raster is aligned onto a global EPSG:4326 grid, which
reprojects it and resamples it in one step, and settles the longitude frame along the way. Its band is
then read with nodata masked to NaN and colour-mapped through cleopatra's colormap resolver. Cells
the raster does not cover — and its nodata cells — stay fully transparent, so a regional dataset shows
as a patch on the globe rather than being smeared over it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
Any
|
A pyramids |
required |
band
|
int
|
1-based band index to draw. |
DEFAULT_BAND
|
cmap
|
Any
|
Colormap name or |
'viridis'
|
vmin
|
float | None
|
Lower bound of the colour scale; defaults to the band's finite minimum. |
None
|
vmax
|
float | None
|
Upper bound of the colour scale; defaults to the band's finite maximum. |
None
|
shape
|
tuple[int, int]
|
|
DEFAULT_TEXTURE_SHAPE
|
resampling
|
str
|
How pyramids resamples the raster onto that grid — |
'nearest'
|
**kwargs
|
Any
|
Forwarded to :class: |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
TexturedGlobe |
TexturedGlobe
|
a globe whose texture carries the dataset. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
Warns:
| Type | Description |
|---|---|
RuntimeWarning
|
If nothing survives the resample onto the texture, or if what does is finer than
the sphere mesh and so would not be drawn — see :meth: |
Examples:
- Drape a whole-globe raster and inspect the texture it produced:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import numpy as np >>> from digitalearth.static import TexturedGlobe >>> from pyramids.dataset import Dataset, GeoReference >>> arr = np.arange(8, dtype="float32").reshape(2, 4) >>> ds = Dataset.from_array( ... arr=arr, geo_ref=GeoReference(geo=(-180.0, 90.0, 0.0, 90.0, 0.0, -90.0), epsg=4326)) >>> globe = TexturedGlobe.from_dataset(ds, shape=(90, 180)) >>> globe.glyph.texture.shape (90, 180, 4) >>> bool((globe.glyph.texture[..., 3] > 0).mean() > 0.98) True - A raster covering only part of the world leaves the rest transparent:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import numpy as np >>> from digitalearth.static import TexturedGlobe >>> from pyramids.dataset import Dataset, GeoReference >>> arr = np.ones((2, 2), dtype="float32") >>> ds = Dataset.from_array( ... arr=arr, geo_ref=GeoReference(geo=(0.0, 10.0, 0.0, 20.0, 0.0, -10.0), epsg=4326)) >>> globe = TexturedGlobe.from_dataset(ds, shape=(90, 180)) >>> opaque = globe.glyph.texture[..., 3] > 0 >>> bool(opaque.any()), bool(opaque.all()) (True, False)
Source code in src/digitalearth/static/globe/textured_globe.py
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 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 | |
from_provider(provider='Esri.WorldImagery', **kwargs)
classmethod
#
Build a globe from a whole-world XYZ tile basemap (delegates to cleopatra's world_texture).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider
|
Any
|
An |
'Esri.WorldImagery'
|
**kwargs
|
Any
|
The fetch options |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
TexturedGlobe |
TexturedGlobe
|
a globe textured with the provider's imagery. |
Note
n_lon / n_lat always mean the sphere mesh, here as everywhere else in this class.
The texture grid — which world_texture also calls n_lon / n_lat — is set with
texture_n_lon / texture_n_lat, so the same keyword never means two different things.
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
OSError
|
if the tiles cannot be fetched — the whole-world grid is pulled over the network on first use, so a connection failure or an unreachable provider surfaces here. |
Examples:
- Build a photographic Earth and spin it (needs the network on first use; the texture is then cached on disk):
- Size the fetched texture and the sphere mesh independently:
Source code in src/digitalearth/static/globe/textured_globe.py
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 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 | |
land(resolution='110m', *, spin=None, altitude=0.001, **kwargs)
#
Fill Natural-Earth land polygons on the globe.
The counterpart of :meth:~digitalearth.static.Map.land. Each land ring is clipped to the
hemisphere facing the camera and re-closed along the limb, so a continent running off the edge is
filled to the horizon instead of having a chord cut across the disc. This is what turns an ocean
product — SST, sea ice, chlorophyll — from a ball of colour with white holes into a readable map.
Interior rings (holes) are dropped, as they are on the 2-D globe. A ring that runs off the near side is closed along the horizon the way its own winding leads, so a landmass reaching past the horizon in several places fills each of its visible pieces and not the sea between them, however far round the horizon that takes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resolution
|
str
|
Natural-Earth resolution — |
'110m'
|
spin
|
float | None
|
Pin the fill to this spin, in degrees. Omitted, it follows the globe. |
None
|
altitude
|
float
|
Radial lift above the surface. The fill sorts under the line layers by the depth it reports rather than by its radius, so this only has to clear the sphere itself. |
0.001
|
**kwargs
|
Any
|
Patch styling forwarded to matplotlib ( |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
The |
Any
|
re-projected at each draw; at a camera that shows no land it simply has no faces, and the faces |
Any
|
are worked out when the figure is drawn, so |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
if the globe has not been drawn yet. |
Examples:
- The fill arrives as one collection holding every visible land ring. The vectors are fetched
(and cached) by
cleopatra, so this needs a network on first use:>>> import matplotlib # doctest: +SKIP >>> matplotlib.use("Agg") # doctest: +SKIP >>> import numpy as np # doctest: +SKIP >>> from digitalearth.static import TexturedGlobe # doctest: +SKIP >>> globe = TexturedGlobe(np.zeros((8, 16, 3), np.uint8)) # doctest: +SKIP >>> _ = globe.draw(elev=0.0, azim=0.0) # doctest: +SKIP >>> patch = globe.land() # doctest: +SKIP >>> patch in globe.ax.collections # doctest: +SKIP True - Colour it like any patch — a translucent fill still lets the texture read through:
>>> import matplotlib # doctest: +SKIP >>> matplotlib.use("Agg") # doctest: +SKIP >>> import numpy as np # doctest: +SKIP >>> from digitalearth.static import TexturedGlobe # doctest: +SKIP >>> globe = TexturedGlobe(np.zeros((8, 16, 3), np.uint8)) # doctest: +SKIP >>> _ = globe.draw(elev=0.0, azim=0.0) # doctest: +SKIP >>> patch = globe.land(color="0.4", alpha=0.5) # doctest: +SKIP >>> round(float(patch.get_facecolor()[0][3]), 2) # doctest: +SKIP 0.5 - Asking before the globe is drawn is refused — there is no camera yet to clip against:
Source code in src/digitalearth/static/globe/textured_globe.py
2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 | |
points(data, *, lat=None, spin=None, altitude=0.01, hide_far_side=True, **kwargs)
#
Scatter lon/lat points onto the globe's surface.
Accepts either a pyramids FeatureCollection / geopandas GeoDataFrame of points (its geometry
is reprojected to lon/lat when needed) or a pair of lon/lat array-likes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
A point |
required |
lat
|
Any
|
Latitudes, when |
None
|
spin
|
float | None
|
Pin the points to this spin, in degrees. Omitted (the default), they follow the globe: they are drawn at the spin it was last drawn at, and redrawn at each animation frame's spin so they turn with the surface. Giving a value opts out of that and fixes them there. |
None
|
altitude
|
float
|
Radial lift above the surface, to avoid z-fighting with it. |
0.01
|
hide_far_side
|
bool
|
When True (default), hide the markers on the hemisphere facing away from the camera, which matplotlib would otherwise draw straight through the sphere. Decided at each draw, against the camera as it is then, so a camera move re-decides it. With False every marker is drawn and the collection is depth-sorted like any other artist, so markers near the limb can be painted over by the sphere. |
True
|
**kwargs
|
Any
|
Forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
The scatter collection on the axes. It stays there as the globe turns — re-placed at each draw, |
Any
|
never replaced — so restyling it, removing it, or keying a colorbar to it keeps working. |
Any
|
It holds every point, which is a change: a hidden marker is drawn at size zero rather than |
Any
|
left out of the collection. That is what keeps each per-point value with its own point and fits |
Any
|
the colour scale to all of them, and it means |
Any
|
given rather than the ones on show — ask :meth: |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
if the globe has not been drawn yet. |
ValueError
|
if |
Note
Non-point geometry (polygons, lines) is reduced to its centroids rather than rejected, so a polygon layer can be marked on the globe without converting it first.
Examples:
- Scatter lon/lat points; the ones behind the globe are drawn at size zero:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import numpy as np >>> from digitalearth.static import TexturedGlobe >>> globe = TexturedGlobe(np.zeros((8, 16, 3), dtype=np.uint8), tilt_deg=0.0, ... n_lon=8, n_lat=4) >>> fig, ax = globe.draw(elev=0.0, azim=0.0) >>> scatter = globe.points([0.0, 180.0], lat=[0.0, 0.0]) >>> len(scatter.get_offsets()) 2 >>> globe.visible(globe.project([0.0, 180.0], [0.0, 0.0])).tolist() [True, False] - Keep the far side when you want the full set drawn:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import numpy as np >>> from digitalearth.static import TexturedGlobe >>> globe = TexturedGlobe(np.zeros((8, 16, 3), dtype=np.uint8), tilt_deg=0.0, ... n_lon=8, n_lat=4) >>> fig, ax = globe.draw(elev=0.0, azim=0.0) >>> scatter = globe.points([0.0, 180.0], lat=[0.0, 0.0], hide_far_side=False) >>> fig.canvas.draw() >>> len(scatter.get_offsets()) 2 - Points follow the globe unless pinned; turning it half-way takes the follower out of sight:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import matplotlib.pyplot as plt >>> import numpy as np >>> from digitalearth.static import TexturedGlobe >>> globe = TexturedGlobe(np.zeros((8, 16, 3), dtype=np.uint8), tilt_deg=0.0, ... n_lon=8, n_lat=4) >>> ax = plt.figure().add_subplot(projection="3d") >>> _ = globe.draw(ax, elev=0.0, azim=0.0) >>> follower = globe.points([0.0], lat=[0.0]) >>> pinned = globe.points([0.0], lat=[0.0], spin=0.0) >>> _ = globe.draw(ax, elev=0.0, azim=0.0, spin=180.0) >>> bool(globe.visible(globe.project([0.0], [0.0]))[0]) False >>> bool(globe.visible(globe.project([0.0], [0.0], spin=0.0))[0]) True >>> follower in ax.collections True
Source code in src/digitalearth/static/globe/textured_globe.py
1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 | |
project(lon, lat, *, spin=None, altitude=0.0)
#
Map lon/lat degrees onto the drawn sphere, returning world-space (N, 3) coordinates.
Pushes the points through the glyph's own transform, so they carry the same spin and axial
tilt as the rendered surface — the reason this is exact rather than an approximation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lon
|
Any
|
Longitude(s) in degrees (scalar or array-like). |
required |
lat
|
Any
|
Latitude(s) in degrees, same shape as |
required |
spin
|
float | None
|
The spin, in degrees, to place the points at. Defaults to the spin the globe was last drawn at, so an overlay lands on the surface the reader can actually see. |
None
|
altitude
|
float
|
Radial offset from the unit surface. A small positive value (e.g. |
0.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: an |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
Examples:
- With no tilt the body frame is the world frame, so the cardinal points are exact:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import numpy as np >>> from digitalearth.static import TexturedGlobe >>> globe = TexturedGlobe(np.zeros((8, 16, 3), dtype=np.uint8), tilt_deg=0.0, ... n_lon=8, n_lat=4) >>> np.round(globe.project(0.0, 0.0), 6) array([[1., 0., 0.]]) >>> np.round(globe.project(90.0, 0.0), 6) array([[0., 1., 0.]]) >>> np.round(globe.project(0.0, 90.0), 6) array([[0., 0., 1.]]) - Points land on the unit sphere;
altitudelifts an overlay clear of the surface:>>> import matplotlib >>> matplotlib.use("Agg") >>> import numpy as np >>> from digitalearth.static import TexturedGlobe >>> globe = TexturedGlobe(np.zeros((8, 16, 3), dtype=np.uint8), n_lon=8, n_lat=4) >>> world = globe.project([0.0, 45.0], [10.0, -20.0], spin=30.0) >>> world.shape (2, 3) >>> [round(float(r), 6) for r in np.linalg.norm(world, axis=1)] [1.0, 1.0] >>> round(float(np.linalg.norm(globe.project(0.0, 0.0, altitude=0.05))), 6) 1.05
Source code in src/digitalearth/static/globe/textured_globe.py
save(path, **kwargs)
#
Save the drawn figure to path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | PathLike[str]
|
Destination file path. |
required |
**kwargs
|
Any
|
Forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
Path
|
The path that was written, as a :class: |
Path
|
backend's |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
if the globe has not been drawn yet. |
Examples:
- Draw, then write the figure to disk:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import numpy as np >>> from digitalearth.static import TexturedGlobe >>> import tempfile >>> from pathlib import Path >>> globe = TexturedGlobe(np.zeros((8, 16, 3), dtype=np.uint8), n_lon=8, n_lat=4) >>> fig, ax = globe.draw() >>> out = Path(tempfile.mkdtemp()) / "globe.png" >>> written = globe.save(str(out)) >>> written == out True >>> out.exists() and out.stat().st_size > 0 True - Saving before drawing is refused, rather than writing an empty figure:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import numpy as np >>> from digitalearth.static import TexturedGlobe >>> globe = TexturedGlobe(np.zeros((8, 16, 3), dtype=np.uint8), n_lon=8, n_lat=4) >>> globe.save("globe.png") Traceback (most recent call last): ... RuntimeError: draw() the globe before saving it
Source code in src/digitalearth/static/globe/textured_globe.py
save_animation(path, *, fps=None, gif=None, **kwargs)
#
Save the animation built by :meth:spin or :meth:animate, optionally also deriving a GIF.
A textured globe is exactly the case the derive-a-GIF path exists for: every frame is a full 3-D surface redraw, so encoding twice off one render is far cheaper than rendering twice.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Output path; the extension picks the format. |
required |
fps
|
float | None
|
Frames per second. Defaults to the animation's own interval. |
None
|
gif
|
str | None
|
Optional second path to derive a GIF at. Requires |
None
|
**kwargs
|
Any
|
Forwarded to :func: |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
The written path, or a |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
if no animation has been built yet — call :meth: |
Examples:
- Animate, then write the rotation straight to a GIF:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import numpy as np >>> from digitalearth.static import TexturedGlobe >>> import tempfile >>> from pathlib import Path >>> globe = TexturedGlobe(np.zeros((8, 16, 3), dtype=np.uint8), n_lon=8, n_lat=4) >>> anim = globe.spin(n_frames=2, interval=200) >>> out = Path(tempfile.mkdtemp()) / "globe.gif" >>> written = globe.save_animation(str(out)) >>> Path(written).exists() True - Render once and deliver both a video and a GIF derived from it:
Source code in src/digitalearth/static/globe/textured_globe.py
spin(ax=None, **kwargs)
#
Animate a full rotation of the camera, returning a matplotlib FuncAnimation.
This turns the viewpoint around one fixed texture. To step a series of rasters instead,
holding the camera still, use :meth:animate — the two are deliberately separate, because
spinning while stepping time conflates them and a viewer cannot tell whether a change on screen
is the data or the vantage point.
When no ax is given the 3-D axes is created here rather than inside the glyph, so :attr:fig and
:attr:ax are known without reaching into the animation's internals — which is what lets
:meth:save_animation and :meth:stamp work on an animated globe.
Overlays turn with the sphere. Anything added with :meth:points, :meth:coastlines,
:meth:borders or :meth:land is turned to each frame's spin, so markers and coastlines stay
attached to the ground; pass spin= to one of those to pin it in place instead. Called without
an ax, this animates on the axes the globe already owns, so a globe that was drawn and
decorated keeps its overlays.
The rotation is swept here rather than by the glyph's own animate, which is how each frame's
spin is known; it sweeps the same one, start_spin plus revolutions whole turns spread over
n_frames frames. The first frame is drawn by this call, so a bad render option is refused here
rather than from inside the frame loop — at the cost of one render, about half a second on the
default mesh, before the animation comes back.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Any
|
An existing |
None
|
**kwargs
|
Any
|
|
{}
|
Returns:
| Type | Description |
|---|---|
FuncAnimation
|
The |
FuncAnimation
|
garbage-collected before you save or display it. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
- Animate a rotation; the figure and axes are recorded for saving or stamping afterwards:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import numpy as np >>> from digitalearth.static import TexturedGlobe >>> globe = TexturedGlobe(np.zeros((8, 16, 3), dtype=np.uint8), n_lon=8, n_lat=4) >>> anim = globe.spin(n_frames=4, interval=100) >>> globe.ax.name '3d' >>> globe.fig is globe.ax.get_figure() True - Animate onto an axes you already own:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import numpy as np >>> from digitalearth.static import TexturedGlobe >>> import matplotlib.pyplot as plt >>> globe = TexturedGlobe(np.zeros((8, 16, 3), dtype=np.uint8), n_lon=8, n_lat=4) >>> ax = plt.figure().add_subplot(projection="3d") >>> anim = globe.spin(ax, n_frames=2, interval=200) >>> globe.ax is ax True
Source code in src/digitalearth/static/globe/textured_globe.py
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 | |
stamp(mark, **kwargs)
#
Stamp a logo / watermark onto the globe's figure.
The same figure-level mark as :meth:digitalearth.static.core.scene.Scene.stamp, and it carries the same
two caveats: stamp last, because the mark is baked from the figure's current size, and note that
a bbox_inches="tight" save crops surrounding whitespace and so shifts the mark's margin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mark
|
Any
|
The mark image — a file path or an |
required |
**kwargs
|
Any
|
Forwarded to cleopatra's |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
The frameless inset |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
if the globe has not been drawn yet. |
Examples:
- Stamp a mark onto the drawn globe; it arrives as an extra axes on the figure:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import numpy as np >>> from digitalearth.static import TexturedGlobe >>> globe = TexturedGlobe(np.zeros((8, 16, 3), dtype=np.uint8), n_lon=8, n_lat=4) >>> fig, ax = globe.draw() >>> mark = np.full((8, 16, 4), 255, dtype=np.uint8) >>> mark_ax = globe.stamp(mark, frac=0.2, shadow=False) >>> len(fig.axes) 2 >>> round(float(mark_ax.get_position().bounds[2]), 3) 0.2 - Stamping before drawing is refused:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import numpy as np >>> from digitalearth.static import TexturedGlobe >>> globe = TexturedGlobe(np.zeros((8, 16, 3), dtype=np.uint8), n_lon=8, n_lat=4) >>> globe.stamp(np.full((8, 16, 4), 255, dtype=np.uint8)) Traceback (most recent call last): ... RuntimeError: draw() the globe before stamping it
Source code in src/digitalearth/static/globe/textured_globe.py
visible(world_xyz)
#
Boolean mask of which world-space points face the camera (i.e. are on the near side).
A point on a unit sphere is its own outward normal, so it is visible exactly when it points toward
the camera. Uses the axes' current elev/azim, so call it after :meth:draw.
A point sitting exactly on the limb is a tie, and floating point decides it: at lon=90 with the
camera at azim=0, cos(90°) evaluates to 6.1e-17 rather than 0, so the point reads as
(barely) visible. Do not rely on the classification of points within rounding distance of the limb.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
world_xyz
|
ndarray
|
An |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: an |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
if the globe has not been drawn yet (there is no camera to test against). |
Examples:
- The hemisphere facing the camera is visible; the one behind it is not:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import numpy as np >>> from digitalearth.static import TexturedGlobe >>> globe = TexturedGlobe(np.zeros((8, 16, 3), dtype=np.uint8), tilt_deg=0.0, ... n_lon=8, n_lat=4) >>> fig, ax = globe.draw(elev=0.0, azim=0.0) >>> globe.visible(globe.project(0.0, 0.0)).tolist() [True] >>> globe.visible(globe.project(180.0, 0.0)).tolist() [False] - Use it to label only the points a reader can actually see:
>>> import matplotlib >>> matplotlib.use("Agg") >>> import numpy as np >>> from digitalearth.static import TexturedGlobe >>> globe = TexturedGlobe(np.zeros((8, 16, 3), dtype=np.uint8), tilt_deg=0.0, ... n_lon=8, n_lat=4) >>> fig, ax = globe.draw(elev=0.0, azim=0.0) >>> lon, lat = [0.0, 45.0, 180.0, 225.0], [0.0, 0.0, 0.0, 0.0] >>> int(globe.visible(globe.project(lon, lat)).sum()) 2