The figure vocabulary#
A bare [float, float, float, float] cannot say whether it is [xmin, xmax, ymin, ymax] or
[xmin, ymin, xmax, ymax], and this package existed because both spellings were live in one tier at once. A
bare band=1 cannot say what to do when a composite needs three bands, the 3-D tier needs a vertical level
and an animation needs frames. digitalearth.base.spec is the answer to both: a small set of value
objects — frozen, comparable, renderer-free — that a figure is described in.
They are engine-neutral by construction. Nothing here imports matplotlib, pyvista, holoviews or maplibre, and
tests/test_base_is_engine_neutral.py enforces it by reading the source, so even a lazy import inside a
function fails the build. Where the vocabulary genuinely needs a renderer's arithmetic — classification lives
in cleopatra — it declares a seam instead and something above base/ fills it.
Bounds — one rectangle, with its ordering named#
Two orderings were live in the static tier at once, plus a third convention that hid an EPSG:4326 assumption
inside a bare tuple. Bounds carries its own CRS and makes each ordering a method, so a call site states
which it wants rather than leaving it to position.
digitalearth.base.spec.bounds.Bounds
dataclass
#
An axis-aligned rectangle in one CRS.
Attributes:
| Name | Type | Description |
|---|---|---|
xmin |
float
|
Western edge, in |
ymin |
float
|
Southern edge. |
xmax |
float
|
Eastern edge. |
ymax |
float
|
Northern edge. |
crs |
Any
|
The CRS the four values are expressed in — an EPSG code, a WKT string, or anything pyramids
resolves. Kept with the numbers so a rectangle cannot be measured against the wrong one. A CRS object
is held in the spelling it is written in — |
Raises:
| Type | Description |
|---|---|
ValueError
|
if any edge is not finite, or if an edge pair is inverted ( |
Examples:
- Build one and read back the two orderings that used to be positional conventions:
- The union of two rectangles is what auto-framing needs:
- An inverted rectangle is refused rather than drawn empty:
Source code in src/digitalearth/base/spec/bounds.py
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 | |
__post_init__()
#
Refuse a rectangle that cannot bound anything.
Raises:
| Type | Description |
|---|---|
ValueError
|
for a non-finite edge, an inverted pair, or a CRS with no written form. |
Source code in src/digitalearth/base/spec/bounds.py
as_bbox()
#
Return [xmin, ymin, xmax, ymax] — the order cleopatra and pyramids take.
Returns:
| Type | Description |
|---|---|
list[float]
|
The four edges in bbox order. |
Examples:
- The corners come back in the order a bounding box is written in:
- Which is what a pyramids call wants, unpacked:
Source code in src/digitalearth/base/spec/bounds.py
as_mpl()
#
Return [xmin, xmax, ymin, ymax] — the order matplotlib's axes take.
Returns:
| Type | Description |
|---|---|
list[float]
|
The four edges in matplotlib axes order. |
Examples:
- The x pair comes first here, unlike :meth:
as_bbox: - The two orderings disagree for the same rectangle, which is the bug this type removes:
Source code in src/digitalearth/base/spec/bounds.py
cell_edges(x, y, crs, *, step=None)
classmethod
#
Return the rectangle a raster's cells cover, from the axes through their centres.
A raster is a grid of cells, and its coordinates name the middle of each one. An extent taken from the
smallest and largest of those stops half a cell short on every side: the image is one cell narrower and
one shorter than the data, and every pixel is drawn at (n - 1) / n of its size. On
examples/data/acc4000.tif — 14 by 13 cells of 4,000 m — that is 2,000 m missing from each edge, and
the picture is wrong by exactly the amount nobody notices.
This is the rule that places one: half the outermost spacing outward on each side.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Any
|
The cell-centre x coordinates, ascending or descending. |
required |
y
|
Any
|
The cell-centre y coordinates, ascending or descending. |
required |
crs
|
Any
|
What they are measured in, stored as given. |
required |
step
|
Any
|
|
None
|
Returns:
| Type | Description |
|---|---|
Bounds
|
The rectangle, ascending in both axes whichever way the axes run. |
Raises:
| Type | Description |
|---|---|
ValueError
|
for an empty axis, for coordinates that are not numbers, or for a |
Examples:
- Three cells of 10,000 m, centred at 5,000/15,000/25,000, cover 0 to 30,000:
- A descending axis — the row order a north-up raster is stored in — covers the same rectangle:
- A single cell has no spacing to read, so its width is given or it stays a line:
Source code in src/digitalearth/base/spec/bounds.py
from_bbox(bbox, crs)
classmethod
#
Build from the [xmin, ymin, xmax, ymax] order cleopatra and pyramids use.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bbox
|
Sequence[float]
|
Four edges in bbox order. |
required |
crs
|
Any
|
The CRS they are expressed in. |
required |
Returns:
| Type | Description |
|---|---|
Bounds
|
The rectangle. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
Examples:
- The order pyramids hands back:
Source code in src/digitalearth/base/spec/bounds.py
from_dict(data)
classmethod
#
Rebuild a rectangle from its dict form.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Mapping[str, Any]
|
A mapping as produced by :meth: |
required |
Returns:
| Type | Description |
|---|---|
Bounds
|
The rectangle, validated as the constructor validates it. |
Raises:
| Type | Description |
|---|---|
TypeError
|
if |
ValueError
|
if an edge is missing or is not a finite number — |
Examples:
- A stored rectangle reads back to the same value:
- A missing edge is named:
Source code in src/digitalearth/base/spec/bounds.py
from_mpl(extent, crs)
classmethod
#
Build from the [xmin, xmax, ymin, ymax] order matplotlib's axes use.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
extent
|
Sequence[float]
|
Four edges in matplotlib axes order. |
required |
crs
|
Any
|
The CRS they are expressed in. |
required |
Returns:
| Type | Description |
|---|---|
Bounds
|
The rectangle. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
Examples:
- The order
set_xlim/set_ylimread:
Source code in src/digitalearth/base/spec/bounds.py
from_points(x, y, crs)
classmethod
#
Build the rectangle enclosing coordinate arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Any
|
X coordinates, any sequence or array. |
required |
y
|
Any
|
Y coordinates. |
required |
crs
|
Any
|
The CRS they are expressed in. |
required |
Returns:
| Type | Description |
|---|---|
Bounds
|
The enclosing rectangle. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if either array is empty, or the rectangle is invalid. |
Examples:
- Enclose a scattering of points:
Source code in src/digitalearth/base/spec/bounds.py
padded(fraction)
#
Return this rectangle grown by fraction of its own span on every side.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fraction
|
float
|
How much to grow, as a proportion of width and height. |
required |
Returns:
| Type | Description |
|---|---|
Bounds
|
The padded rectangle. |
Raises:
| Type | Description |
|---|---|
ValueError
|
from :func: |
Examples:
- A 10% margin around the data:
Source code in src/digitalearth/base/spec/bounds.py
to_crs(crs)
#
Return this rectangle expressed in another CRS.
The corner transform is pyramids' (pyramids.base.crs.reproject_coordinates); this package does no
coordinate maths of its own, per CLAUDE.md. The result is the enclosing rectangle of the
transformed corners: a warped rectangle is not a rectangle, so its axis-aligned hull is what an extent
can hold.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
crs
|
Any
|
The target CRS. |
required |
Returns:
| Type | Description |
|---|---|
Bounds
|
The enclosing rectangle in |
Bounds
|
given as |
Raises:
| Type | Description |
|---|---|
ValueError
|
naming the rectangle and both CRSs, when a corner falls outside the area |
Examples:
- Reprojecting to the CRS it already has is a no-op:
- A rectangle on the far side of an orthographic globe has no corners to enclose:
Source code in src/digitalearth/base/spec/bounds.py
to_dict()
#
Return the plain-dict form a figure stores.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The four edges as Python floats, and the CRS as held: |
dict[str, Any]
|
checked. The constructor has already turned a CRS object into |
dict[str, Any]
|
definition carries no EPSG code) and refused a CRS with no written form, so writing a rectangle does |
dict[str, Any]
|
not fail on its CRS. |
Examples:
- The edges keep their names, so the ordering cannot be misread:
- A CRS object is written by the EPSG code it is held as:
Source code in src/digitalearth/base/spec/bounds.py
union(other)
#
Return the smallest rectangle containing both.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Bounds
|
The rectangle to merge in. Must already be in the same CRS — reproject it first with
:meth: |
required |
Returns:
| Type | Description |
|---|---|
Bounds
|
The enclosing rectangle, in this rectangle's CRS. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the two carry different CRSs. Unioning across CRSs by ignoring them is how an extent ends up describing a region nobody asked for. |
Examples:
- Two layers' extents, framed together:
Source code in src/digitalearth/base/spec/bounds.py
Scale — how a value becomes a colour#
The limits were derived in several places, the "a constant band has no range" guard was written out five
times, and three tiers each called cleopatra's classifier with their own error handling. The copies agreed by
luck and drifted where they did not. A Scale derived once and reused across frames is what stops an
animation's colours flickering, and what lets a legend show the colours that were actually drawn.
It also states what the ramp cannot colour: missing for a value it cannot place, and over/under for one
past either end of the domain. All three travel in the stored form, so a tier that reads a figure back can agree
with the tier that drew it on the colour of a nodata cell and of a clipped value — see with_extremes to state
them and extremes to read back only the ones that were stated. The static tier is the only one that reads them
back so far; the other three do not.
straddles answers the one question a diverging ramp has to pass: does the domain run on both sides of the
value the ramp would be centred on? Centred outside it, one arm is never drawn and the other carries every
value — so a backend offers divergence and declines it from the same reader, with the same strict comparison
cleopatra validates a diverging center with.
digitalearth.base.spec.scale.Scale
dataclass
#
A resolved mapping from values to colours, and the domain it covers.
Attributes:
| Name | Type | Description |
|---|---|---|
vmin |
float
|
Lower limit of the domain. |
vmax |
float
|
Upper limit. Always strictly greater than |
scheme |
str | tuple[float, ...] | None
|
Classification scheme name ( |
breaks |
tuple[float, ...]
|
Class edges when |
categories |
tuple[Any, ...]
|
The distinct values a categorical scale colours, in the order their colours were assigned. |
missing |
str | None
|
Colour for a value the scale cannot place — nodata, or a category it never saw. |
over |
str | None
|
Colour for a value above |
under |
str | None
|
Colour for a value below |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
Examples:
- Derive a continuous scale from data, and read back the limits it settled on:
- A constant band is widened rather than dividing by zero:
- Nothing finite falls back to the unit range, so a builder still has limits to hand a colormap:
Source code in src/digitalearth/base/spec/scale.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 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 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 | |
is_categorical
property
#
Whether this scale colours unordered categories rather than a numeric range.
Returns:
| Type | Description |
|---|---|
bool
|
|
Examples:
- A categorical scale knows its categories by name:
- A numeric scale is not categorical, however few values it saw:
is_classified
property
#
Whether this scale cuts classes rather than running a continuous ramp.
Returns:
| Type | Description |
|---|---|
bool
|
|
Examples:
- A scheme cuts classes, and the scale says so:
- Without one it runs a continuous ramp and cuts nothing:
__post_init__()
#
Refuse a domain nothing can be normalised against.
Raises:
| Type | Description |
|---|---|
ValueError
|
for a non-finite or degenerate domain, or for class edges that bound no class. |
Source code in src/digitalearth/base/spec/scale.py
as_limits()
#
Return the (vmin, vmax) pair a renderer's normaliser takes.
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
The domain, with |
Examples:
- The pair a normaliser is built from, ready to unpack:
- A constant band still yields a usable span rather than a zero-width one:
Source code in src/digitalearth/base/spec/scale.py
breaks_of(values, scheme, k=DEFAULT_CLASS_COUNT, *, clip=None)
classmethod
#
Cut class edges without deriving a domain, for a caller that only wants the classes.
The three classification sites read .breaks and nothing else, so measuring the domain for them —
a full pass over the data plus a compacted copy of every finite value — is work whose result is
discarded. This is the same classifier, the same error, and no measurement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Any
|
The data to classify. |
required |
scheme
|
str
|
Classification scheme name. |
required |
k
|
int
|
Number of classes. |
DEFAULT_CLASS_COUNT
|
clip
|
tuple[float | None, float | None] | None
|
An optional |
None
|
Returns:
| Type | Description |
|---|---|
tuple[float, ...]
|
The class edges, |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the scheme is unknown to the classifier, |
Examples:
- Three classes, four edges, and no domain derived:
- An
equal_intervalwindow is split into equal parts of the window; the 999 outlier lands in the top class rather than stretching the edges:
Source code in src/digitalearth/base/spec/scale.py
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 | |
categorical(categories, colors, *, missing=None)
classmethod
#
Build a scale over unordered categories rather than a numeric range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
categories
|
Sequence[Any]
|
The distinct values, in the order their colours were assigned. |
required |
colors
|
Sequence[str]
|
One colour per category. |
required |
missing
|
str | None
|
Colour for a value that is not one of |
None
|
Returns:
| Type | Description |
|---|---|
Scale
|
The categorical scale. Its numeric domain is the category index range, which is what a renderer |
Scale
|
needs to place a swatch; |
Raises:
| Type | Description |
|---|---|
ValueError
|
if there are no categories, or the counts do not match. |
Examples:
- Three categories and their colours:
Source code in src/digitalearth/base/spec/scale.py
class_of(value)
#
Return the 0-based class a value falls in, for a classified scale.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
The value to place. |
required |
Returns:
| Type | Description |
|---|---|
int | None
|
Its class index, or |
int | None
|
outside the edges is clamped to the first or last class rather than dropped, matching what a |
int | None
|
renderer does with a value outside its domain. |
Examples:
- Three classes cut from ten values, and where 5 lands:
Source code in src/digitalearth/base/spec/scale.py
class_ranges()
#
Return each class as a (low, high) pair, which is what a legend row shows.
Returns:
| Type | Description |
|---|---|
list[tuple[float, float]]
|
One pair per class, empty when the scale is not classified. |
Examples:
- Two classes give two ranges:
Source code in src/digitalearth/base/spec/scale.py
color_for(category)
#
Return the colour assigned to one category.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
category
|
Any
|
The category to look up. Categories are labels: a boolean — Python's, or numpy's |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Its colour, or :attr: |
Examples:
- An unseen category gets the missing colour, not a wrong one:
- A numpy boolean finds the boolean category; the integer
1does not:
Source code in src/digitalearth/base/spec/scale.py
extremes()
#
Return only the extreme colours this scale states, keyed by which extreme they colour.
The keys absent from the mapping are exactly the extremes a renderer must not overwrite, which is what makes "did the caller state any?" one test and keeps a tier from pushing a default colour onto a colormap the caller built themselves.
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
A new plain |
dict[str, str]
|
— empty when the scale states none. The keys come in that order, whatever order they were |
dict[str, str]
|
stated in, so |
Examples:
- A scale that states nothing reports nothing, so the mapping itself is the "any?" test:
- A half-stated scale reports its half:
- All three come back in the fixed
missing,over,underorder, not the stated one:
Source code in src/digitalearth/base/spec/scale.py
freeze()
#
Return a scale whose domain will not be re-derived from later data.
Scale is already immutable, so this returns self; it exists to say at a call site that the range
is deliberately fixed — the thing a time sequence needs so its colours do not move between frames.
Returns:
| Type | Description |
|---|---|
Scale
|
This scale. |
Examples:
- Freezing is explicit at the call site:
Source code in src/digitalearth/base/spec/scale.py
from_dict(data)
classmethod
#
Rebuild a scale from its dict form.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Mapping[str, Any]
|
A mapping as produced by :meth: |
required |
Returns:
| Type | Description |
|---|---|
Scale
|
The scale, validated as the constructor validates it. No classifier runs: the stored breaks are the |
Scale
|
breaks, which is what makes a frozen scale reproduce the colours it was drawn with. All three |
Scale
|
extreme colours are read back — |
Scale
|
and a key absent from the dict comes back as |
Raises:
| Type | Description |
|---|---|
TypeError
|
if |
ValueError
|
for a missing |
Examples:
- Stored class edges come back without re-classifying anything:
- A categorical scale keeps each category's colour across a round trip:
- A domain with no width is refused:
- The extreme colours survive the round trip, and the ones the dict leaves out stay unstated:
- matplotlib's spelling of the nodata colour is not this one, and is refused by name:
Source code in src/digitalearth/base/spec/scale.py
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 | |
from_finite(values, *, vmin=None, vmax=None, missing=None)
classmethod
#
Derive a scale from values the caller has already filtered to finite ones.
:meth:from_values filters first, which costs a full pass and a compacted copy of every finite
value. Several callers had just done exactly that and thrown the result away — on a 2160x4320 global
canvas that is a second ~75 MB allocation for an answer already in hand. This is the same rule
without the second pass.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Any
|
Finite values only. Passing non-finite ones here produces a NaN domain rather than an
error, which is the price of skipping the check — use :meth: |
required |
vmin
|
float | None
|
Explicit lower limit, overriding the measured one. |
None
|
vmax
|
float | None
|
Explicit upper limit. |
None
|
missing
|
str | None
|
Colour for values the scale cannot place. |
None
|
Returns:
| Type | Description |
|---|---|
Scale
|
The resolved scale. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if both limits are given the wrong way round. |
Examples:
- The same domain as
from_values, without re-filtering: - An empty selection still yields limits a colormap can take:
Source code in src/digitalearth/base/spec/scale.py
from_limits(vmin, vmax, *, missing=None)
classmethod
#
Build from limits that were derived elsewhere — a frozen stack range, or a caller's clim=.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vmin
|
float
|
Lower limit. |
required |
vmax
|
float
|
Upper limit. |
required |
missing
|
str | None
|
Colour for values the scale cannot place. |
None
|
Returns:
| Type | Description |
|---|---|
Scale
|
The scale, with the same widening rule applied so a degenerate pair cannot get through. |
Examples:
- The frozen range of a time stack becomes a scale every frame shares:
- A degenerate pair is widened here too, rather than raising on the caller:
- A constant too large for
+ 1to move widens by one representable step instead:
Source code in src/digitalearth/base/spec/scale.py
from_values(values, *, vmin=None, vmax=None, scheme=None, k=DEFAULT_CLASS_COUNT, missing=None)
classmethod
#
Derive a scale from data, applying the one widening rule every tier used to write out.
Two degenerate cases are handled here rather than at five call sites:
- nothing finite — the domain falls back to
(0.0, 1.0). A builder still needs limits to hand a colormap, and a stack whose every frame is off the view has no range to report. - a constant domain —
vmaxbecomesvmin + 1. Normalising against a zero-width range divides by zero; the five copies of this rule all chose+ 1, so that is what is kept.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Any
|
The data to measure. Non-finite values are ignored. |
required |
vmin
|
float | None
|
Explicit lower limit, overriding the measured one. |
None
|
vmax
|
float | None
|
Explicit upper limit. |
None
|
scheme
|
str | None
|
Classification scheme to cut classes with, or |
None
|
k
|
int
|
Number of classes when |
DEFAULT_CLASS_COUNT
|
missing
|
str | None
|
Colour for values the scale cannot place. |
None
|
Returns:
| Type | Description |
|---|---|
Scale
|
The resolved scale. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
Examples:
- An explicit limit wins over the measured one:
Source code in src/digitalearth/base/spec/scale.py
straddles(center=0.0)
#
Whether this domain runs on both sides of center — the test a diverging ramp has to pass.
A diverging colormap puts a neutral colour at center and an arm on either side of it. Centred
outside the domain it is worse than a sequential ramp rather than better: one arm is never drawn, so
the other carries every value and the picture loses the contrast the ramp was chosen for. Asking the
domain first is what lets a tier offer divergence and decline it on the same call.
The comparison is strict, deliberately: a centre sitting exactly on vmin or vmax leaves one
arm holding a single value, and it is also the comparison cleopatra validates a diverging center
with — not (vmin < center < vmax) raises
"diverging 'center' (0.0) must lie strictly between vmin (...) and vmax (...)" there — so a
centre this reader called straddled but cleopatra refuses cannot happen.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
center
|
float
|
The value a diverging ramp would be centred on. Zero by default, which is the centre of
every anomaly, difference and trend field. A non-finite centre straddles nothing — answered
rather than compared, since |
0.0
|
Returns:
| Type | Description |
|---|---|
bool
|
|
Examples:
- An anomaly field with both signs straddles zero; a rainfall total does not:
- A centre need not be zero — a departure from a long-term mean sits wherever that mean does:
- The ends are not straddled, which is the comparison cleopatra makes too; and a non-finite centre is answered rather than compared:
Source code in src/digitalearth/base/spec/scale.py
to_dict()
#
Return the plain-dict form a figure stores.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
|
dict[str, Any]
|
extreme colours ( |
dict[str, Any]
|
categories and colours are written as lists. Every field goes through the JSON check, so a numpy |
dict[str, Any]
|
number is written as a plain Python one. An unstated extreme colour is absent rather than |
dict[str, Any]
|
written as |
Raises:
| Type | Description |
|---|---|
TypeError
|
if any field — |
Examples:
- A continuous scale is its domain:
- A categorical scale carries its colours:
- A classified scale carries its scheme and its class edges:
- The extreme colours travel too, and only the stated ones are written:
Source code in src/digitalearth/base/spec/scale.py
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 | |
with_extremes(*, missing=None, over=None, under=None)
#
Return this scale with the extreme colours a caller stated, leaving the rest as they were.
A scale is normally derived — from_values() measures the domain from the data — while the
colours for what falls outside it are the caller's styling and arrive separately. So stating them is
a step on an existing scale rather than three more arguments on every builder.
None means "leave this one alone", which is what lets two calls compose and matches
matplotlib.colors.Colormap.with_extremes, the method a renderer ends up handing these to: it copies
the colormap and delegates to Colormap._set_extremes, which is where the rule really lives — three
branches, if bad is not None / if under is not None / if over is not None, under a docstring
reading "Parameters that are None are left unchanged" (read off matplotlib 3.11.1). The public
Colormap.set_extremes is a one-line delegate to that helper and is pending-deprecated as of
matplotlib 3.11 (@_api.deprecated("3.11", pending=True, alternative="cmap.with_extremes(...)")), so
it is not what this rule is borrowed from. So None cannot
clear a colour already stated: with_extremes(over=None) on a scale whose over is '#ff0000'
answers {'over': '#ff0000'} again, and a call with no arguments at all is accepted and changes
nothing. Clearing one is :meth:without_extremes's job — two verbs rather than one keyword carrying a
sentinel, which keeps all three parameters a plain Optional[str] and keeps None meaning exactly
what it means in matplotlib. The scale itself is immutable, so the stated colours come back on a
new scale: a domain derived once and shared across an animation's frames must not pick up one
frame's styling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
missing
|
str | None
|
Colour for a value the scale cannot place, or |
None
|
over
|
str | None
|
Colour for a value above |
None
|
under
|
str | None
|
Colour for a value below |
None
|
Returns:
| Type | Description |
|---|---|
Scale
|
A new scale with the same domain, scheme, classes and categories, carrying the stated colours. |
Scale
|
Never |
Examples:
- State all three on a derived scale, and read them back:
- A colour stated earlier survives a later call that does not name it:
- The scale it was called on is unchanged, and the domain travels through:
Nonekeeps rather than clears, and a call that states nothing is still a new scale:>>> from digitalearth.base.spec import Scale >>> stated = Scale.from_limits(0.0, 10.0).with_extremes(over="#ff0000") >>> stated.with_extremes(over=None).extremes() {'over': '#ff0000'} >>> bare = stated.with_extremes() >>> bare.extremes(), bare is stated ({'over': '#ff0000'}, False) >>> stated.without_extremes("over").extremes() {}
Source code in src/digitalearth/base/spec/scale.py
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 | |
without_extremes(*names)
#
Return this scale with the named extreme colours cleared, back to stating none of them.
The other direction of :meth:with_extremes, and a separate verb because None there already
means "keep this one" — the rule matplotlib's own with_extremes follows, through
Colormap._set_extremes. Overloading None to mean "clear" would break the composition two
with_extremes calls rely on; giving it a sentinel value instead would widen all three parameters
from Optional[str] to a union every caller and every type check has to carry. So the way back is a
call of its own, and dataclasses.replace stops being the only route to it.
What it is for: a stated extreme is styling, and a derived scale travels — a domain measured over a stack is handed to each frame, and a stored figure's scale is read back and reused. Handing one on without the previous caller's over colour is then a call rather than a rebuild.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*names
|
str
|
The extremes to clear, from |
()
|
Returns:
| Type | Description |
|---|---|
Scale
|
A new scale with the same domain, scheme, classes and categories, stating the extremes it was |
Scale
|
not asked to clear. Never |
Raises:
| Type | Description |
|---|---|
ValueError
|
for a name that is not one of the three, since a silently ignored name would read as a colour that had been cleared. |
Examples:
- A colour stated earlier is cleared by name, and the rest stay stated:
- Named nothing it clears all three, and the scale it was called on is unchanged:
- It is the clear
with_extremescannot express, sinceNonethere keeps: - A name that is not one of the three is refused rather than ignored:
- The domain and the classes travel through it:
Source code in src/digitalearth/base/spec/scale.py
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 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 | |
Selection — which slice of a dataset a layer draws#
band was one integer being asked several different questions, with each tier adding a parameter beside it
where it needed more. Here it is one value, and band is a tuple: a composite is not a special case of a
different parameter, it is a selection of three bands.
digitalearth.base.spec.selection.Selection
dataclass
#
A slice of a dataset: which bands, and which position along every other axis.
Attributes:
| Name | Type | Description |
|---|---|---|
band |
tuple[int, ...]
|
1-based band indices, as a tuple. A single band is a one-tuple; a composite is three. Ordered, because an RGB composite's order is the channel order. |
time |
Any
|
Time step or timestamp, or |
level |
Any
|
Vertical level, for a 3-D or atmospheric dataset. |
member |
Any
|
Ensemble member. A list in |
overview |
int | None
|
Overview/LOD level to read, where the source has a pyramid. |
budget |
int | None
|
Greatest number of cells or features the reader may return, for a large-data path. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
Examples:
- A scalar band is normalised to a one-tuple, so one code path serves both:
- A composite is a selection of three bands, not a different parameter:
- Narrowing to one band keeps everything else:
- A list and a tuple along a free-form axis make one selection:
Source code in src/digitalearth/base/spec/selection.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 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 | |
first_band
property
#
The single band a scalar-band renderer should read.
Returns:
| Type | Description |
|---|---|
int
|
The first band in the selection. A composite narrowed to one channel goes through |
int
|
meth: |
Examples:
- The band a single-band builder should read:
- For a composite it is the first channel, in the order the caller wrote them:
is_composite
property
#
Whether this selection names more than one band.
Returns:
| Type | Description |
|---|---|
bool
|
|
Examples:
- Three bands are a composite; one is not:
- Which is how a builder picks its path without inspecting the tuple itself:
__post_init__()
#
Refuse a selection that names no readable band.
Raises:
| Type | Description |
|---|---|
ValueError
|
for an empty band tuple or a non-positive index. |
Source code in src/digitalearth/base/spec/selection.py
frames()
#
Return one single-band selection per band, in order.
Returns:
| Type | Description |
|---|---|
Selection
|
One selection per band — for a single-band selection, one equal to this one; for a composite, the |
...
|
per-channel reads in channel order, each still carrying the shared axes. The entries are fresh |
tuple[Selection, ...]
|
values rather than |
Examples:
- An RGB composite becomes its three channel reads, in order:
Source code in src/digitalearth/base/spec/selection.py
from_dict(data)
classmethod
#
Rebuild a selection from its dict form.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Mapping[str, Any]
|
A mapping as produced by :meth: |
required |
Returns:
| Type | Description |
|---|---|
Selection
|
The selection, validated as the constructor validates it. |
Raises:
| Type | Description |
|---|---|
TypeError
|
if |
ValueError
|
for an unknown key, or a band the constructor refuses. |
Examples:
- A stored composite reads back as a band tuple:
- Without a
bandkey the default band is read, and the other axes come back as stored:
Source code in src/digitalearth/base/spec/selection.py
of(band=DEFAULT_BAND, **rest)
classmethod
#
Build a selection, accepting a band as either a scalar or a sequence.
The one constructor both spellings go through, so a builder that takes band=2 and one that takes
bands=(3, 2, 1) end up with the same kind of value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
band
|
int | Iterable[int]
|
A single 1-based band, or a sequence of them. |
DEFAULT_BAND
|
**rest
|
Any
|
Any other axis — |
{}
|
Returns:
| Type | Description |
|---|---|
Selection
|
The selection. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the bands are empty or not 1-based. |
Examples:
- Both spellings produce the same shape:
Source code in src/digitalearth/base/spec/selection.py
to_dict()
#
Return the plain-dict form a figure stores.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
|
dict[str, Any]
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
if an axis other than |
Examples:
- The default selection is one key:
- A slice through time and level keeps both:
- A live
datetimehas no JSON form and is refused where it is written:
Source code in src/digitalearth/base/spec/selection.py
with_band(band)
#
Return a copy naming different bands, keeping every other axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
band
|
int | Iterable[int]
|
The replacement band or bands. |
required |
Returns:
| Type | Description |
|---|---|
Selection
|
A new selection. The original is unchanged — this is how a composite iterates its channels without |
Selection
|
losing the level, member or budget that were chosen once. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the replacement is empty or not 1-based. |
Examples:
- The other axes survive the narrowing:
Source code in src/digitalearth/base/spec/selection.py
DataRef — where the data is, rather than the data#
A layer that owns its data object cannot be tiled, cannot decimate, cannot hold a point cloud too large to
read, and cannot round-trip through a dict. DataRef names the data; the registry opens it.
digitalearth.base.spec.dataref.DataRef
dataclass
#
Where a layer's data comes from, as a value rather than the data itself.
Attributes:
| Name | Type | Description |
|---|---|---|
uri |
str
|
What to open — a filesystem path, a URL, or an |
driver |
str | None
|
Optional reader hint, for a path whose extension does not settle which reader to use. |
version |
str | None
|
Optional version or revision, so a figure can record which vintage of a moving dataset it described. Carried, not interpreted — a resolver that understands versioning reads it. |
Examples:
- A path, and the dict a figure would store:
- A round trip through a dict, which is what makes a figure serialisable:
- An in-memory object is referenced without being written to disk:
Source code in src/digitalearth/base/spec/dataref.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 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 | |
__post_init__()
#
Refuse a reference that names nothing, or holds a hint a figure could not store.
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
Source code in src/digitalearth/base/spec/dataref.py
from_dict(data)
classmethod
#
Rebuild a reference from its dict form.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[str, Any]
|
A mapping as produced by :meth: |
required |
Returns:
| Type | Description |
|---|---|
DataRef
|
The reference. |
Raises:
| Type | Description |
|---|---|
TypeError
|
if |
ValueError
|
if |
Examples:
- Rebuild a reference a figure stored, and read its fields back:
- A key this version does not know is refused rather than dropped:
Source code in src/digitalearth/base/spec/dataref.py
of(data, *, name='')
classmethod
#
Return the reference a builder stores for whatever it was given.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
A path or URL, a |
required |
name
|
str
|
A stable id for an in-memory object; reusing one replaces what it points at. |
''
|
Returns:
| Type | Description |
|---|---|
DataRef
|
The reference as given for a |
DataRef
|
|
DataRef
|
otherwise, which resolves in this process only — a pyramids dataset does not know where it came |
DataRef
|
from, so that is the only honest reference to one. |
Examples:
- A path is referenced as a path, which a stored figure can carry:
- An object is registered, and the reference reaches it back:
- A reference already made is kept as it is:
Source code in src/digitalearth/base/spec/dataref.py
open()
#
Open the data this reference names.
Returns:
| Type | Description |
|---|---|
Any
|
Whatever the registered resolver returns for this URI's scheme — a pyramids |
Any
|
|
Raises:
| Type | Description |
|---|---|
KeyError
|
if no resolver is registered for the scheme, or an |
Examples:
- An in-memory reference hands back the data it names:
- A scheme nothing is registered for says so, and lists the ones that are — a plugin that failed to install looks exactly like a typo otherwise:
Source code in src/digitalearth/base/spec/dataref.py
to_dict()
#
Return the plain-dict form a figure stores.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The fields that are set, each as a Python |
dict[str, Any]
|
|
dict[str, Any]
|
nulls. |
Examples:
- The common case is a single key:
- Hints appear only when they were set:
Source code in src/digitalearth/base/spec/dataref.py
to_object(obj, *, name='', **rest)
classmethod
#
Register an in-memory object and return a reference to it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any
|
The object to reference — typically a pyramids |
required |
name
|
str
|
An optional stable id; reusing one replaces what it points at. |
''
|
**rest
|
Any
|
Any other field — |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
DataRef
|
A reference whose |
|
see |
DataRef
|
func: |
Examples:
- The reference reaches the same object back:
Source code in src/digitalearth/base/spec/dataref.py
Encoding and Symbology — how a layer looks#
Styling reached the renderers as undeclared keyword soup: 26 keys in the static tier alone, in no signature
anywhere, so a caller could not ask what a builder accepts and a typo was a silently ignored keyword rather
than an error. Encoding makes a visual channel a key rather than a parameter on every builder — which
is what makes size, width, extrusion and text cheap to add — and Symbology is a layer's style as a declared
value.
digitalearth.base.spec.encoding.Encoding
dataclass
#
What drives one visual channel: a constant, or a field read through a scale.
Attributes:
| Name | Type | Description |
|---|---|---|
channel |
str
|
Which channel this drives — a key of :data: |
value |
Any
|
The constant, when the channel does not vary with the data. A list in it, however nested, is stored
as a tuple, so |
field |
str | None
|
The column or band name the channel varies with. Exactly one of |
scale |
Scale | None
|
How a field's values map onto the channel. |
output_range |
tuple[float, float] | None
|
|
guide |
Optional[Guide]
|
How the channel is explained to the reader — a legend or a colorbar, titled and placed. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the channel is not declared, if neither or both of |
Examples:
- A constant, which is what a plain
color="#f00"means: - Driven by a field, resolving to ramp positions the backend colours:
- The same shape drives size, in real units — the reason a new channel costs a row, not a parameter:
Source code in src/digitalearth/base/spec/encoding.py
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 | |
is_constant
property
#
Whether this channel holds one value rather than varying with the data.
Returns:
| Type | Description |
|---|---|
bool
|
|
Examples:
- A constant is set once; a field-driven channel is not:
- Which is what lets a renderer take the cheap path when it can:
__hash__()
#
Hash by what drives the channel, with a mapping in the constant hashed as its items.
A frozen dataclass hashes its fields as they are, and value is free-form: a constant that holds a
mapping raised unhashable type: 'dict', and took every Symbology and LayerSpec holding it down
with it. :meth:~digitalearth.base.spec.style.Symbology.__hash__ had already answered that for its
properties, and says a mapping is hashed as its items wherever it sits — the constant beside them
is where else it sits (review L5).
Returns:
| Type | Description |
|---|---|
int
|
A hash over every field, each put through |
int
|
func: |
int
|
fields rather than named here, so a channel binding that gains a field is covered by it too. |
Raises:
| Type | Description |
|---|---|
TypeError
|
if a field holds a value that is unhashable for its own reasons. Neither a list, a numpy array nor a mapping is among them: the first two are stored as tuples, and the third is hashed as its items, however deeply it sits. |
Examples:
- A constant bound to a mapping hashes, and two spellings of it hash alike:
Source code in src/digitalearth/base/spec/encoding.py
__post_init__()
#
Refuse an encoding that names no channel, or names both a constant and a field.
Raises:
| Type | Description |
|---|---|
ValueError
|
for an undeclared channel, an ambiguous or empty binding, a field that is not a string, a
mapping attached to a constant, or a |
Source code in src/digitalearth/base/spec/encoding.py
by_field(channel, field, *, scale=None, output_range=None, guide=None)
classmethod
#
Bind a channel to a data field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channel
|
str
|
The channel to drive. |
required |
field
|
str
|
The column or band the channel varies with. |
required |
scale
|
Scale | None
|
How its values map onto the channel; |
None
|
output_range
|
tuple[float, float] | None
|
|
None
|
guide
|
Optional[Guide]
|
How the channel is explained to the reader — a legend or a colorbar, titled and placed. |
None
|
Returns:
| Type | Description |
|---|---|
Encoding
|
The encoding. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the channel is undeclared or |
Examples:
- Name the column the channel varies with, and read it back:
- With a scale and an output range, the values land in the channel's own units:
Source code in src/digitalearth/base/spec/encoding.py
constant(channel, value, *, guide=None)
classmethod
#
Bind a channel to one value for every feature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channel
|
str
|
The channel to drive. |
required |
value
|
Any
|
The constant. |
required |
guide
|
Optional[Guide]
|
How the channel is explained to the reader. A constant rarely needs one — there is nothing to read off — but a chosen colour that stands for something does. |
None
|
Returns:
| Type | Description |
|---|---|
Encoding
|
The encoding. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the channel is undeclared, or |
Examples:
- A constant colour, resolved back out:
- Any declared channel works the same way, and knows it does not vary:
Source code in src/digitalearth/base/spec/encoding.py
from_dict(data)
classmethod
#
Rebuild an encoding from its dict form.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Mapping[str, Any]
|
A mapping as produced by :meth: |
required |
Returns:
| Type | Description |
|---|---|
Encoding
|
The encoding, validated as the constructor validates it. |
Raises:
| Type | Description |
|---|---|
TypeError
|
if |
ValueError
|
for a missing channel, an unknown key, a scale |
Examples:
- A stored constant reads back and resolves as before:
- A stored field-driven size reads back with its scale and output range:
- A binding with both a constant and a field is refused:
Source code in src/digitalearth/base/spec/encoding.py
resolve(values=None)
#
Return what the channel should be, per datum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Any
|
The field's values, one per feature or cell. Required for a field-driven encoding; optional for a constant, where omitting it returns the constant itself rather than a list. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
For a constant with no |
Any
|
|
Any
|
|
Any
|
|
Any
|
A value the scale cannot place — not finite — resolves to |
Any
|
to draw it as missing rather than as some other class. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the encoding is field-driven and no |
Examples:
- A constant broadcasts when values are supplied, so one code path serves both bindings:
- A classified scale steps, so the drawn colours match the legend's classes:
Source code in src/digitalearth/base/spec/encoding.py
to_dict()
#
Return the plain-dict form a figure stores.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
as a plain Python one. |
Raises:
| Type | Description |
|---|---|
TypeError
|
if the constant, an |
Examples:
- A constant is its channel and its value:
- A field-driven channel carries its scale:
Source code in src/digitalearth/base/spec/encoding.py
digitalearth.base.spec.encoding.Channel
dataclass
#
One visual variable a layer can drive.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The channel's name, and the key it is stored under. |
kind |
str
|
What a resolved value is — |
doc |
str
|
One line saying what the channel controls, so the declared vocabulary is self-describing. |
Examples:
- Look a channel up and read what it controls:
- The table is the growth axis, so the channels a feature will need are already in it:
Source code in src/digitalearth/base/spec/encoding.py
The declared channels#
CHANNELS is the table a channel is a row in. It is the growth axis the whole type exists for: height
and text are already there, ahead of the extrusion and label features that will need them, because adding
a channel should cost a row plus a fold rule per backend — not a keyword on every builder on four tiers.
digitalearth.base.spec.style.Symbology
dataclass
#
The look of one layer: what drives each channel, plus the properties that drive nothing.
Attributes:
| Name | Type | Description |
|---|---|---|
encodings |
Mapping[str, Encoding]
|
Channel name -> :class: |
props |
Mapping[str, Any]
|
Static style properties that are not visual channels — a contour level list, a hillshade flag, a legend kwargs dict. Declared, unlike the keyword soup they replace, but not resolved per datum. Every list in a value, however nested, is stored as a tuple. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if an encoding is filed under a channel it does not drive. That mismatch would make
:meth: |
Examples:
- Constants, which is what plain styling keywords mean:
- Defaults fill the gaps a caller left, and never overwrite what they set:
Source code in src/digitalearth/base/spec/style.py
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 | |
__hash__()
#
Hash by the channels driven and the properties set, so a style can key a cache.
Returns:
| Type | Description |
|---|---|
int
|
A hash over the encodings and the properties. |
int
|
hash; a symbology that did not would be the odd one out the moment the data tier wants to key a set |
int
|
or a cache on a layer's style. |
Raises:
| Type | Description |
|---|---|
TypeError
|
if any value in it is itself unhashable — and that alone. Neither a list nor a dict is
among them: a list is stored as a tuple, so |
Source code in src/digitalearth/base/spec/style.py
__post_init__()
#
Check every encoding is filed under its own channel, then freeze both mappings.
The dataclass is frozen, but a plain dict field is not — a caller holding the dict it passed in
could still re-key the symbology afterwards. Holding both as a read-only
:class:~digitalearth.base.spec._serial.FrozenDict closes that at the top level, and still copies,
pickles and converts under dataclasses.asdict. A mapping stored inside a property is a plain dict,
so a caller who kept a reference to it can still write through it — and, since a property holding a
mapping is hashed (review L5/N1), change this symbology's hash under whoever is holding it.
Property values are stored in their canonical form: every list and tuple in them, however nested,
becomes a tuple (see :func:~digitalearth.base.spec._serial.frozen_value). That copies a caller's list —
appending to it afterwards no longer changes the symbology — and it is what lets a symbology written with
to_dict, where tuples become JSON lists, read back equal and hashable. A numpy array is stored as nested
tuples too, and a dict is rebuilt with each of its values frozen the same way — so the mapping stored is
never the mapping passed. Any other value, a custom object say, is held as given.
Raises:
| Type | Description |
|---|---|
ValueError
|
if a key does not match its encoding's channel. |
Source code in src/digitalearth/base/spec/style.py
__reduce__()
#
Pickle and copy by rebuilding through the constructor.
Returns:
| Type | Description |
|---|---|
Any
|
|
tuple[Any, ...]
|
Rebuilding from plain dicts goes through the same validation and freezing as any other construction. |
Examples:
- A copy is equal to the original, and is a separate object:
Source code in src/digitalearth/base/spec/style.py
encoding(channel)
#
Return what drives one channel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channel
|
str
|
The channel to look up. |
required |
Returns:
| Type | Description |
|---|---|
Encoding | None
|
Its encoding, or |
Encoding | None
|
cue to use its own default rather than to raise. |
Examples:
- Ask what drives a channel, then resolve it:
- An unstyled channel answers
None, so the renderer keeps its own default:
Source code in src/digitalearth/base/spec/style.py
from_dict(data)
classmethod
#
Rebuild a symbology from its dict form.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Mapping[str, Any]
|
A mapping as produced by :meth: |
required |
Returns:
| Type | Description |
|---|---|
Symbology
|
The symbology, with every encoding checked against the channel it is filed under. |
Raises:
| Type | Description |
|---|---|
TypeError
|
if |
ValueError
|
for an unknown key, an encoding |
Examples:
- A stored style reads back channel by channel:
- An encoding filed under a channel it does not drive is refused:
Source code in src/digitalearth/base/spec/style.py
guide(channel='color')
#
Return what explains one channel to the reader — the legend or colorbar asked for on it.
The read side of :meth:with_guide, and the reason a guide lives on the encoding rather than beside
it: a renderer asking "does this layer want a colour key, and what is it called?" asks the layer, so
the answer moves, hides and disappears with it (DE-48, order 24).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channel
|
str
|
The channel whose guide is wanted. Defaults to |
'color'
|
Returns:
| Name | Type | Description |
|---|---|---|
The |
Guide | None
|
class: |
Guide | None
|
both when nothing drives the channel and when something does and nobody asked for a guide. |
|
Guide | None
|
The two are one answer on purpose: a renderer's question is whether to draw a key, and there is |
|
Guide | None
|
nothing to draw in either case. |
Examples:
- A guide asked for on a channel is read back from it:
- A channel nobody asked a guide of, and a channel nothing drives, both answer
None:
Source code in src/digitalearth/base/spec/style.py
merged_over(defaults)
#
Return this symbology laid over defaults, channel by channel and property by property.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
defaults
|
Symbology
|
The symbology to fall back to — a theme, a layer-kind default, a figure-wide style. |
required |
Returns:
| Type | Description |
|---|---|
Symbology
|
A new symbology where this one wins every key it sets and |
Symbology
|
per key rather than per object is the point: a caller who names one colour must not lose the |
Symbology
|
theme's opacity. |
Examples:
- The caller's channel wins; the default's survives where the caller was silent:
Source code in src/digitalearth/base/spec/style.py
of(**channels)
classmethod
#
Build a symbology from constant channel values — the common, simple case.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**channels
|
Any
|
Channel name -> constant, or an already-built
:class: |
{}
|
Returns:
| Type | Description |
|---|---|
Symbology
|
The symbology. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if a name is not a declared channel. |
Examples:
- A constant and a field-driven encoding side by side:
Source code in src/digitalearth/base/spec/style.py
to_dict()
#
Return the plain-dict form a figure stores.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
|
dict[str, Any]
|
styling stores an empty dict. |
Raises:
| Type | Description |
|---|---|
TypeError
|
if a property, an encoding's constant, or the scheme or a category of an encoding's scale has no JSON form. |
Examples:
- Encodings are stored under the channel they drive:
- No styling at all is an empty dict:
Source code in src/digitalearth/base/spec/style.py
with_guide(guide, *, channel='color')
#
Return a copy whose channel encoding carries guide.
A guide explains an encoding, so it is attached to one rather than held beside it. That is the
whole of what order 24 changes: a colour key used to be figure decoration a tier drew when asked and
then forgot — keyed by position on the static tier, a show= toggle on the most recent layer on the
interactive one — so it could not move with its layer, could not go away with it, and could not be
written into a figure and read back. Attached here it does all three for free, because the layer's
Symbology is already what travels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
guide
|
Guide | None
|
What to say about the channel, or |
required |
channel
|
str
|
The channel being explained. Defaults to |
'color'
|
Returns:
| Type | Description |
|---|---|
Symbology
|
A new symbology; this one is unchanged, as every |
Symbology
|
channel nothing drives, an equal one — the detach is a no-op rather than a refusal. |
Raises:
| Type | Description |
|---|---|
ValueError
|
when nothing drives |
Examples:
- Attached to the colour a field drives, and read back off the layer:
Nonetakes it off again, so a caller does not have to rebuild the encoding to drop a key:- A channel nothing drives is refused, and the message says what the layer does drive:
- Taking a guide off that same channel is not, because there is none there to refuse:
Source code in src/digitalearth/base/spec/style.py
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 | |
with_props(**props)
#
Return a copy carrying extra static properties.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**props
|
Any
|
The properties to add or replace. |
{}
|
Returns:
| Type | Description |
|---|---|
Symbology
|
A new symbology; this one is unchanged. |
Examples:
- Properties accumulate, and the original is untouched:
- Naming a property again replaces it:
Source code in src/digitalearth/base/spec/style.py
digitalearth.base.spec.style.StyleSchema
dataclass
#
The declared style keywords of one builder surface, and the routing they enable.
Attributes:
| Name | Type | Description |
|---|---|---|
keys |
Mapping[str, StyleKey]
|
Keyword name -> :class: |
Examples:
- A declared channel keyword becomes an encoding; a declared property becomes a property; an
undeclared keyword is handed back rather than swallowed:
>>> from digitalearth.base.spec import StyleKey, StyleSchema >>> schema = StyleSchema.of( ... StyleKey("alpha", "Opacity.", channel="opacity"), ... StyleKey("hillshade", "Shade the surface."), ... ) >>> sym, leftover = schema.route({"alpha": 0.5, "hillshade": True, "cmpa": "viridis"}) >>> sym.encoding("opacity").resolve(), dict(sym.props), leftover (0.5, {'hillshade': True}, {'cmpa': 'viridis'}) - And the nearest declared name is available for the error a caller should get:
Source code in src/digitalearth/base/spec/style.py
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 | |
__post_init__()
#
Freeze the table, so a schema handed around cannot be extended behind a caller's back.
__reduce__()
#
Pickle and copy by rebuilding through the constructor.
Returns:
| Type | Description |
|---|---|
Any
|
|
tuple[Any, ...]
|
plain dict goes through the same freezing as any other construction. |
Examples:
- A copy is equal to the original, and is a separate object:
Source code in src/digitalearth/base/spec/style.py
channels()
#
Return the channels this surface can drive, sorted.
Returns:
| Type | Description |
|---|---|
tuple[str, ...]
|
The distinct channel names its keys point at. |
Examples:
- Only the keys that drive a channel are counted:
>>> from digitalearth.base.spec import StyleKey, StyleSchema >>> schema = StyleSchema.of( ... StyleKey("alpha", "Layer opacity.", channel="opacity"), ... StyleKey("size", "Marker size.", channel="size"), ... StyleKey("hillshade", "Shade the surface."), ... ) >>> schema.channels() ('opacity', 'size') - A surface of static properties alone drives nothing:
Source code in src/digitalearth/base/spec/style.py
names()
#
Return every declared keyword, sorted.
Returns:
| Type | Description |
|---|---|
str
|
The names a caller may pass — the answer to "what does this builder accept?" that did not exist |
...
|
before. |
Examples:
- The declared keywords, sorted:
- Which is enough to spot a keyword the surface does not accept:
Source code in src/digitalearth/base/spec/style.py
of(*keys)
classmethod
#
Build a schema from its keys.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*keys
|
StyleKey
|
The declared keywords. |
()
|
Returns:
| Type | Description |
|---|---|
StyleSchema
|
The schema. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if a name is declared twice — two rows for one keyword means one of them is dead, and which one wins would depend on argument order. |
Examples:
- Declare a surface, then ask what it accepts and what a keyword controls:
- Declaring one name twice is refused, because one of the two rows would be dead:
Source code in src/digitalearth/base/spec/style.py
route(flat)
#
Split flat keyword arguments into a declared symbology and whatever is left over.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flat
|
Mapping[str, Any]
|
The caller's keyword dict. Not mutated. |
required |
Returns:
| Type | Description |
|---|---|
Symbology
|
A |
dict[str, Any]
|
class: |
tuple[Symbology, dict[str, Any]]
|
a static property; anything undeclared is returned in |
tuple[Symbology, dict[str, Any]]
|
Leftovers are returned, not raised: this surface is not the only thing a builder's kwargs |
tuple[Symbology, dict[str, Any]]
|
feed (the glyph constructor takes its own), so deciding that a key is homeless needs more |
tuple[Symbology, dict[str, Any]]
|
knowledge than a schema has. :meth: |
tuple[Symbology, dict[str, Any]]
|
does reach it. |
Examples:
- A
Noneis a caller declining a key, so it routes nowhere rather than becoming a binding:
Source code in src/digitalearth/base/spec/style.py
suggest(name)
#
Return the declared keyword name was most likely meant to be.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The keyword a caller wrote. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The closest declared name, or |
str | None
|
guess is worse than none — it sends the caller to a key that was never their intent. |
Examples:
- A near miss is named, which is what turns a silently ignored typo into an answerable error:
- Something unlike every declared key is not guessed at:
Source code in src/digitalearth/base/spec/style.py
digitalearth.base.spec.style.StyleKey
dataclass
#
One declared style keyword: its name, what it does, and whether it drives a channel.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The public keyword, exactly as a caller writes it. |
doc |
str
|
One line saying what it controls. This is the text a discovery surface shows, so it is part of the declaration rather than a comment beside it. |
channel |
str | None
|
The visual channel the keyword sets, or |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
Examples:
- A keyword that drives a channel says which one:
- A static property declares no channel, and that is how routing tells the two apart:
Source code in src/digitalearth/base/spec/style.py
__post_init__()
#
Refuse a key pointing at a channel that does not exist.
Raises:
| Type | Description |
|---|---|
ValueError
|
for an undeclared channel name. |
Source code in src/digitalearth/base/spec/style.py
The shared defaults#
Constants that exist so a second value cannot appear. DEFAULT_BAND is the band a builder reads when the
caller names none; DEFAULT_CLASS_COUNT is the five classes a graduated scheme cuts by default, which every
tier had written out separately.
ViewRequest — how much to read, and how finely#
A DataRef says where data is and a Selection says which slice; neither says how much of it to read or
at what resolution. Three of the four backend studies invented this third question independently, which is
the usual sign a type is missing rather than optional.
digitalearth.base.spec.viewrequest.ViewRequest
dataclass
#
A request for a region of data at a resolution, bounded by a budget.
Attributes:
| Name | Type | Description |
|---|---|---|
bounds |
Bounds | None
|
The region wanted, in its own CRS — a reader reprojects if it must. |
width |
int | None
|
Target width in pixels, or |
height |
int | None
|
Target height in pixels, or |
pixel_ratio |
float
|
Device pixel ratio, so a HiDPI canvas can ask for the pixels it will actually draw. |
budget |
int | None
|
Greatest number of cells the reader may return. This is the honest limit — |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
Examples:
- A request for a region at a canvas size:
- A budget alone, with no canvas — what a decimating reader needs:
Source code in src/digitalearth/base/spec/viewrequest.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 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 | |
crs
property
#
The CRS the requested region is expressed in.
Returns:
| Type | Description |
|---|---|
Any
|
The bounds' CRS, or |
Examples:
- The CRS travels with the region:
pixels
property
#
How many device pixels the request covers, or None when it names no canvas.
Returns:
| Type | Description |
|---|---|
int | None
|
|
int | None
|
attr: |
Examples:
- A retina canvas asks for the pixels it will actually draw:
__post_init__()
#
Refuse a request that asks for nothing, or for a negative amount of something.
Raises:
| Type | Description |
|---|---|
ValueError
|
for a dimension or budget that is not a positive whole number, or a ratio that is not a positive finite number. |
Source code in src/digitalearth/base/spec/viewrequest.py
as_bbox()
#
Return the requested region as the bbox tuple a pyramids reader takes.
Returns:
| Name | Type | Description |
|---|---|---|
tuple[float, float, float, float] | None
|
|
|
from |
tuple[float, float, float, float] | None
|
meth: |
Examples:
- A region in bbox order, and no region at all:
Source code in src/digitalearth/base/spec/viewrequest.py
side(floor=64)
#
Return the square side a decimating reader should aim for.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
floor
|
int
|
Smallest side to return. A budget small enough to ask for a handful of cells produces an image nothing can be read from, so there is a lower bound. |
64
|
Returns:
| Name | Type | Description |
|---|---|---|
int
|
The larger of |
|
int
|
|
|
int
|
budget or the canvas's :attr: |
|
are |
int
|
the canvas says what is wanted and the budget what is affordable, and a read past the canvas |
int
|
fetches cells nothing draws. With neither, |
Examples:
- The budget sets the side, and a tiny one still floors:
- A canvas under the budget sizes the read; one over it is held to the budget:
Source code in src/digitalearth/base/spec/viewrequest.py
within_budget(cells)
#
Whether a read of cells cells is affordable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cells
|
int
|
How many cells the read would return. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Examples:
- No budget affords anything:
Source code in src/digitalearth/base/spec/viewrequest.py
SourceView — a view that remembers its own address#
A Source carries materialised data and forgets where it came from, so the only way to get different pixels
was to start again from the caller's object. That is what blocks dynamic tiling, level of detail and point
clouds too large to hold. SourceView keeps the reference and the slice, so it can be read again.
digitalearth.base.sources.view.SourceView
#
Bases: Source
A materialised view of data, carrying the reference and slice it was read from.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z
|
DimensionInfo | None
|
The data dimension, as :class: |
required |
x
|
DimensionInfo
|
The x / longitude axis. |
required |
y
|
DimensionInfo
|
The y / latitude axis. |
required |
crs
|
Any
|
The CRS the coordinates are expressed in. |
None
|
metadata
|
dict | None
|
Free-form metadata. |
None
|
units
|
str | None
|
Unit string for the values. |
None
|
ref
|
DataRef | None
|
Where the data came from. |
None
|
selection
|
Selection | None
|
Which slice was read. |
None
|
request
|
ViewRequest | None
|
The request this view answered, when it answered one. Kept so a caller can tell what it asked for from what it got — a reader may return fewer cells than the budget allowed. |
None
|
window
|
Bounds | None
|
The rectangle actually read, in the CRS its cells are measured in, for a windowed read;
|
None
|
Examples:
- A view knows its own address:
>>> import numpy as np >>> from digitalearth.base.sources import DimensionInfo >>> from digitalearth.base.sources.view import SourceView >>> from digitalearth.base.spec import DataRef, Selection >>> axis = DimensionInfo(np.array([0.0, 1.0]), "x") >>> view = SourceView(None, axis, axis, crs=4326, ... ref=DataRef("data/dem.tif"), selection=Selection.of(2)) >>> view.ref.uri, view.selection.first_band ('data/dem.tif', 2) - And is still an ordinary
Source, so every existing consumer takes it:
Source code in src/digitalearth/base/sources/view.py
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 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 | |
ref
property
#
Where this view's data came from, or None when it was built from a held object.
Returns:
| Type | Description |
|---|---|
DataRef | None
|
The reference. |
DataRef | None
|
and that view is perfectly usable; it just cannot be re-read from an address it never had. |
Examples:
- The address a view was read from:
>>> import numpy as np >>> from digitalearth.base.sources import DimensionInfo >>> from digitalearth.base.sources.view import SourceView >>> from digitalearth.base.spec import DataRef >>> axis = DimensionInfo(np.array([0.0]), "x") >>> SourceView(None, axis, axis, ref=DataRef("dem.tif")).ref.uri 'dem.tif'
request
property
#
The request this view answered, or None when it was not read against one.
Returns:
| Type | Description |
|---|---|
ViewRequest | None
|
The request, kept so a caller can compare what it asked for with what it got. |
Examples:
- A view not read against a request says so:
rereadable
property
#
Whether this view can be read again.
Returns:
| Name | Type | Description |
|---|---|---|
bool
|
|
|
and |
bool
|
meth: |
Examples:
- A view with no reference knows it cannot be re-read:
selection
property
#
window
property
#
of(data, *, ref=None, selection=None, request=None, crs=None)
classmethod
#
Materialise a view from an opened object, honouring the request where the reader supports it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
The opened data — a pyramids |
required |
ref
|
DataRef | None
|
The reference |
None
|
selection
|
Selection | None
|
Which slice to read. Defaults to the default band. Only its band and its |
None
|
request
|
ViewRequest | None
|
The region/resolution/budget wanted. Applied through pyramids' windowed read when the
object exposes one ( |
None
|
crs
|
Any
|
The CRS to record for the coordinates, passed through to the extractor. A windowed read records the window's CRS instead, when the window has one. |
None
|
Returns:
| Type | Description |
|---|---|
SourceView
|
The view, carrying |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
Exception
|
whatever the extractor raises for data it cannot read, or pyramids for a window it cannot read. |
Examples:
- A plain array becomes a view with no address, which is a legitimate state:
- A budget with no region windows the raster's own extent, labelled with real cell centres:
>>> import numpy as np >>> from pyramids.base.georeference import GeoReference >>> from pyramids.dataset import Dataset >>> from digitalearth.base.sources.view import SourceView >>> from digitalearth.base.spec import ViewRequest >>> dem = Dataset.from_array( ... np.arange(16.0).reshape(4, 4), ... geo_ref=GeoReference(top_left_corner=(0.0, 4.0), cell_size=1.0, epsg=4326), ... ) >>> view = SourceView.of(dem, request=ViewRequest(budget=4)) >>> view.z.values.shape, view.crs ((2, 2), 4326) >>> view.x.values.tolist(), view.y.values.tolist() ([1.0, 3.0], [3.0, 1.0]) - A budget on the selection is applied too, and the tighter of the two budgets wins:
>>> import numpy as np >>> from pyramids.base.georeference import GeoReference >>> from pyramids.dataset import Dataset >>> from digitalearth.base.sources.view import SourceView >>> from digitalearth.base.spec import Selection, ViewRequest >>> dem = Dataset.from_array( ... np.arange(16.0).reshape(4, 4), ... geo_ref=GeoReference(top_left_corner=(0.0, 4.0), cell_size=1.0, epsg=4326), ... ) >>> view = SourceView.of( ... dem, selection=Selection.of(1, budget=4), request=ViewRequest(budget=100) ... ) >>> view.request.budget, view.selection.budget, view.z.values.shape (4, 4, (2, 2))
Source code in src/digitalearth/base/sources/view.py
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 | |
reread(request)
#
Read the same slice again, for a different region or resolution.
This is what the address is for. The view re-opens its own
:class:~digitalearth.base.spec.dataref.DataRef, applies its own
:class:~digitalearth.base.spec.selection.Selection, and asks the reader for what request wants —
the loop interactive/raster.py currently drives by hand at one call site.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ViewRequest
|
The region, resolution and budget wanted. |
required |
Returns:
| Type | Description |
|---|---|
SourceView
|
A new view of the same slice, carrying the same reference and selection plus the request it |
SourceView
|
answered. Its metadata is the new read's, with each key in :data: |
SourceView
|
did not supply filled in from this view — see :meth: |
SourceView
|
when the new read found none. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
if this view has no reference to read from — see :attr: |
KeyError
|
if the reference no longer resolves — an |
ValueError
|
if this view's selection is one :meth: |
Examples:
- Re-reading within a budget keeps the address, and the band name the bare windowed array lacks:
>>> import numpy as np >>> from pyramids.base.georeference import GeoReference >>> from pyramids.dataset import Dataset >>> from digitalearth.base.sources.view import SourceView >>> from digitalearth.base.spec import DataRef, ViewRequest >>> dem = Dataset.from_array( ... np.arange(16.0).reshape(4, 4), ... geo_ref=GeoReference(top_left_corner=(0.0, 4.0), cell_size=1.0, epsg=4326), ... ) >>> ref = DataRef.to_object(dem, name="doc-reread") >>> view = SourceView.of(ref.open(), ref=ref) >>> view.z.values.shape, view.metadata("variable"), view.metadata("band") ((4, 4), 'Band_1', 1) >>> coarse = view.reread(ViewRequest(budget=4)) >>> coarse.z.values.shape, coarse.ref.uri, coarse.request.budget ((2, 2), 'object:doc-reread', 4) >>> coarse.x.values.tolist(), coarse.y.values.tolist() ([1.0, 3.0], [3.0, 1.0]) - Only the describing keys are carried;
bandbelongs to the first read, so it is not:>>> import numpy as np >>> from pyramids.base.georeference import GeoReference >>> from pyramids.dataset import Dataset >>> from digitalearth.base.sources.view import DESCRIBING_KEYS, SourceView >>> from digitalearth.base.spec import DataRef, ViewRequest >>> dem = Dataset.from_array( ... np.arange(16.0).reshape(4, 4), ... geo_ref=GeoReference(top_left_corner=(0.0, 4.0), cell_size=1.0, epsg=4326), ... ) >>> ref = DataRef.to_object(dem, name="doc-reread-keys") >>> coarse = SourceView.of(ref.open(), ref=ref).reread(ViewRequest(budget=4)) >>> DESCRIBING_KEYS ('variable', 'kind', 'standard_name') >>> coarse.metadata("variable"), coarse.metadata("kind"), coarse.metadata("band") ('Band_1', 'raster', None) - A view built from a held object refuses, and says why:
>>> import numpy as np >>> from digitalearth.base.sources import DimensionInfo >>> from digitalearth.base.sources.view import SourceView >>> from digitalearth.base.spec import ViewRequest >>> axis = DimensionInfo(np.array([0.0]), "x") >>> SourceView(None, axis, axis).reread(ViewRequest(budget=100)) Traceback (most recent call last): ... RuntimeError: this SourceView has no DataRef, so it cannot be re-read
Source code in src/digitalearth/base/sources/view.py
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 | |
LegendSpec — a legend derived from what was drawn#
Every tier built one its own way, and nothing structurally tied a swatch to the colour actually drawn.
Deriving the rows from the resolved Scale makes the agreement a construction rather than a maintenance
task.
digitalearth.base.spec.legend.LegendSpec
dataclass
#
A legend as a value: what it is called, what its rows are, and how it is laid out.
Attributes:
| Name | Type | Description |
|---|---|---|
entries |
tuple[LegendEntry, ...]
|
The rows, in the order they are drawn. |
kind |
str
|
|
title |
str | None
|
The legend's heading, usually the column name. |
units |
str | None
|
Unit string appended to the labels, or shown once as a subtitle. |
format |
str | None
|
Format spec for numeric labels, e.g. |
orientation |
str
|
|
Examples:
- A categorical legend takes its colours from the scale that drew them:
- A classified scale becomes one row per class, labelled by the range it covers:
Source code in src/digitalearth/base/spec/legend.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 | |
__post_init__()
#
Refuse a kind or orientation no tier can draw.
Raises:
| Type | Description |
|---|---|
ValueError
|
for an unknown |
Source code in src/digitalearth/base/spec/legend.py
from_scale(scale, *, colors=None, title=None, units=None, format=None, orientation='vertical', stops=DEFAULT_RAMP_STOPS, values=None)
classmethod
#
Build a legend from the scale a layer was drawn with.
This is the load-bearing method. Deriving the rows from the scale is what makes a swatch equal the colour that was drawn, instead of a second computation that happens to agree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scale
|
Scale
|
The resolved scale the layer used. |
required |
colors
|
Sequence[str] | None
|
The colours drawn, one per class or stop. Required for a graduated or continuous scale, where the colours come from the renderer's colormap rather than from the scale. Ignored for a categorical scale, which carries its own — passing them there would reintroduce exactly the second source of truth this removes. |
None
|
title
|
str | None
|
Legend heading, usually the column name. |
None
|
units
|
str | None
|
Unit string for the values. |
None
|
format
|
str | None
|
Format spec for numeric labels. |
None
|
orientation
|
str
|
|
'vertical'
|
stops
|
int
|
How many stops describe a continuous ramp, spaced evenly between the scale's limits.
Ignored for a categorical or graduated scale, and when |
DEFAULT_RAMP_STOPS
|
values
|
Sequence[float] | None
|
The stop values the ramp was actually drawn with, for the continuous arm; each becomes
one row, converted to |
None
|
Returns:
| Type | Description |
|---|---|
LegendSpec
|
The legend. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
Examples:
- A categorical scale needs no colours passed, because it has them:
- A graduated scale given the wrong number of colours is refused:
>>> from digitalearth.base.spec import LegendSpec, Scale >>> scale = Scale.from_values([0.0, 10.0], scheme="equal_interval", k=3) >>> LegendSpec.from_scale(scale, colors=["#eee", "#111"]) Traceback (most recent call last): ... ValueError: a graduated legend needs one colour per class; got 2 colours for 3 classes - A ramp's rows are exactly the stops passed in
values; without them,DEFAULT_RAMP_STOPSevenly spaced stops are computed from the limits instead:>>> from digitalearth.base.spec import DEFAULT_RAMP_STOPS, LegendSpec, Scale >>> scale = Scale.from_limits(0.0, 10.0) >>> drawn = LegendSpec.from_scale(scale, colors=["#000", "#888", "#fff"], values=[0.0, 2.5, 10.0]) >>> [entry.value for entry in drawn.entries], drawn.kind ([0.0, 2.5, 10.0], 'continuous') >>> computed = LegendSpec.from_scale(scale, colors=["#000"] * DEFAULT_RAMP_STOPS) >>> [entry.value for entry in computed.entries] [0.0, 2.5, 5.0, 7.5, 10.0]
Source code in src/digitalearth/base/spec/legend.py
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 | |
to_dict()
#
Return the plain-dict form a tier stores or serialises.
Every field is included, so the result is complete rather than the subset a particular tier happens
to read. It is not paired with a from_dict: a legend is derived from a Scale, and rebuilding one
from a dict would be a second way to construct it — the one thing :meth:from_scale exists to
prevent. Round-tripping belongs to whatever holds the scale, not to the legend.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The legend as |
dict[str, Any]
|
keeps in |
Examples:
- The three keys a tier reads back:
Source code in src/digitalearth/base/spec/legend.py
digitalearth.base.spec.legend.LegendEntry
dataclass
#
One row of a legend: a swatch, and what it means.
Attributes:
| Name | Type | Description |
|---|---|---|
label |
str
|
The text shown beside the swatch. |
color |
str | None
|
The colour drawn, as the renderer drew it. |
value |
Any
|
The underlying value or range this row stands for, kept so a tier can build an interactive
legend that filters or highlights. |
Examples:
- A row carries what it stands for, not just its label:
Source code in src/digitalearth/base/spec/legend.py
Guide — the colour key, attached to the encoding it explains#
LegendSpec says what a key contains. Guide says whether to draw one at all, what to call it, and which
corner it sits in — and it lives on the layer's Encoding rather than beside the figure.
That placement is the whole of it. A key used to be figure decoration each tier held its own way: drawn and
then forgotten on the static tier, keyed by position (layer=-1); a show= flag on whichever layer was
added last on the interactive tier; a dictionary beside the tree on the web tier, which went on describing a
layer after it was removed. None of the three could move with its layer, disappear with it, or survive being
written to a figure and read back.
Attached to the encoding, a guide gets all three for free, because the layer's Symbology is already what
the layer tree holds, what remove_layer drops, and what a figure writes:
m = Map()
m.choropleth(regions, column="pop", scheme="quantiles", k=5, name="people")
m.colorbar("people", label="People per km²") # records Guide(show=True, title=…) on the encoding
m.get_layer("people").symbology.guide().title # 'People per km²'
m.remove_layer("people") # the key goes with the layer
A channel that nothing drives is refused rather than given an empty encoding to hang the guide on: a key
over a colour that does not vary has no values to label and no scale to sample. That is why colorbar() asks
for a layer whose colour is driven by a field, and why a flat-coloured layer — or one built from a caller's
own artist — answers with a ValueError naming the layers that do have one.
digitalearth.base.spec.encoding.Guide
dataclass
#
What explains an encoding to the reader: whether to draw a legend or a colorbar for it, and where.
An encoding says what drives a channel; a guide says whether the reader is told. It lives on the encoding
because that is what it explains — one scale shared by several layers is one guide, and a channel nobody
needs explained (a constant colour chosen for contrast) simply carries show=False. The content stays in
:class:~digitalearth.base.spec.legend.LegendSpec, which a renderer computes from the data; nothing here
holds entries or colours.
Attributes:
| Name | Type | Description |
|---|---|---|
show |
bool
|
Whether to draw the guide at all. |
title |
str | None
|
What to call it. |
anchor |
str | None
|
Which corner of the panel it sits in — one of
:data: |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
Examples:
- Title a colorbar and put it where the data is not:
>>> from digitalearth.base.spec import Encoding, Guide, Scale >>> guide = Guide(title="Elevation (m)", anchor="bottom-right") >>> encoding = Encoding.by_field("color", "dem", scale=Scale.from_limits(0, 100), guide=guide) >>> encoding.guide.title, encoding.guide.anchor ('Elevation (m)', 'bottom-right') - Switch a guide off without losing what it would have said:
- A corner no tier could place is refused:
Source code in src/digitalearth/base/spec/encoding.py
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 | |
__post_init__()
#
Refuse a guide that could not be drawn.
Raises:
| Type | Description |
|---|---|
ValueError
|
as described on the class. |
Source code in src/digitalearth/base/spec/encoding.py
from_dict(data)
classmethod
#
Rebuild a guide from its dict form.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Mapping[str, Any]
|
A mapping as produced by :meth: |
required |
Returns:
| Type | Description |
|---|---|
Guide
|
The guide, validated as the constructor validates it. |
Raises:
| Type | Description |
|---|---|
TypeError
|
if |
ValueError
|
for an unknown key, or a guide the constructor refuses. |
Examples:
- A stored guide reads back with what it was given:
- An empty dict is the default guide:
Source code in src/digitalearth/base/spec/encoding.py
to_dict()
#
Return the plain-dict form a figure stores.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Only what was asked for: a guide left at its defaults stores |
dict[str, Any]
|
is no bigger in JSON than an encoding that does not. |
Examples:
- A default guide is an empty dict, and still reads back as a guide:
- What was set is written:
Source code in src/digitalearth/base/spec/encoding.py
digitalearth.base.spec.style.Symbology.with_guide(guide, *, channel='color')
#
Return a copy whose channel encoding carries guide.
A guide explains an encoding, so it is attached to one rather than held beside it. That is the
whole of what order 24 changes: a colour key used to be figure decoration a tier drew when asked and
then forgot — keyed by position on the static tier, a show= toggle on the most recent layer on the
interactive one — so it could not move with its layer, could not go away with it, and could not be
written into a figure and read back. Attached here it does all three for free, because the layer's
Symbology is already what travels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
guide
|
Guide | None
|
What to say about the channel, or |
required |
channel
|
str
|
The channel being explained. Defaults to |
'color'
|
Returns:
| Type | Description |
|---|---|
Symbology
|
A new symbology; this one is unchanged, as every |
Symbology
|
channel nothing drives, an equal one — the detach is a no-op rather than a refusal. |
Raises:
| Type | Description |
|---|---|
ValueError
|
when nothing drives |
Examples:
- Attached to the colour a field drives, and read back off the layer:
Nonetakes it off again, so a caller does not have to rebuild the encoding to drop a key:- A channel nothing drives is refused, and the message says what the layer does drive:
- Taking a guide off that same channel is not, because there is none there to refuse:
Source code in src/digitalearth/base/spec/style.py
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 | |
digitalearth.base.spec.style.Symbology.guide(channel='color')
#
Return what explains one channel to the reader — the legend or colorbar asked for on it.
The read side of :meth:with_guide, and the reason a guide lives on the encoding rather than beside
it: a renderer asking "does this layer want a colour key, and what is it called?" asks the layer, so
the answer moves, hides and disappears with it (DE-48, order 24).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channel
|
str
|
The channel whose guide is wanted. Defaults to |
'color'
|
Returns:
| Name | Type | Description |
|---|---|---|
The |
Guide | None
|
class: |
Guide | None
|
both when nothing drives the channel and when something does and nobody asked for a guide. |
|
Guide | None
|
The two are one answer on purpose: a renderer's question is whether to draw a key, and there is |
|
Guide | None
|
nothing to draw in either case. |
Examples:
- A guide asked for on a channel is read back from it:
- A channel nobody asked a guide of, and a channel nothing drives, both answer
None:
Source code in src/digitalearth/base/spec/style.py
PointArrays — geometry as coordinate arrays#
Turning a FeatureCollection into numpy arrays was written out 22 times across 9 files, in three spellings,
with inconsistent handling of non-finite coordinates — the ones a globe or clipped CRS produces for the far
side of the world.
digitalearth.base.points.PointArrays
dataclass
#
Point coordinates as parallel float arrays, with the CRS they are measured in.
Attributes:
| Name | Type | Description |
|---|---|---|
x |
ndarray
|
X coordinates, |
y |
ndarray
|
Y coordinates, |
z |
ndarray
|
Z coordinates, |
crs |
Any
|
What the coordinates are measured in, or |
The three arrays are copies, marked read-only. Building one from a caller's buffer and then sharing
memory with it would mean a "frozen" value that changes underneath whoever holds it, and x/y/z and
:meth:as_xy hand the arrays straight back out.
Raises:
| Type | Description |
|---|---|
ValueError
|
if the three arrays are not the same length. They are index-aligned with each other and with any attribute column a caller filters alongside them, so a mismatch is a defect that would otherwise surface as points drawn at another point's coordinates. |
Examples:
- Coordinates and a CRS, with z defaulting to zeros:
- Non-finite points are dropped, and anything aligned with them is dropped too:
Source code in src/digitalearth/base/points.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 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 | |
__eq__(other)
#
Compare by coordinates and CRS, element by element.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Any
|
The value to compare with. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
bool
|
The dataclass-generated |
bool
|
then raises "The truth value of an array with more than one element is ambiguous" — so two |
bool
|
perfectly ordinary instances could not be compared at all. Points are bulk data, so this type is |
bool
|
deliberately not hashable: |
Examples:
- Two identical readings compare equal:
Source code in src/digitalearth/base/points.py
__post_init__()
#
Refuse arrays that are not index-aligned.
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
Source code in src/digitalearth/base/points.py
as_columns()
#
Return the points as an (N, 3) array, the shape the 3-D tiers stack by hand.
Returns:
| Type | Description |
|---|---|
ndarray
|
One row per point, columns |
Examples:
- The shape PyVista and deck.gl both want:
Source code in src/digitalearth/base/points.py
as_xy()
#
Return [x, y] for the many 2-D consumers that want exactly that.
Returns:
| Type | Description |
|---|---|
list[ndarray]
|
The two coordinate arrays, so a 2-D call site never has to know |
Examples:
- Unpacked straight into a 2-D consumer:
Source code in src/digitalearth/base/points.py
finite(*aligned, dims='xy')
#
Drop points whose coordinates are not finite, taking aligned arrays with them.
The far side of a clipped or globe display CRS reprojects to inf/nan. Passing those on does
not raise where they are made — it fails later, inside a tessellator, a binner or matplotlib, with a
message about neither the points nor the projection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*aligned
|
Any
|
Optional per-point arrays to filter by the same mask — a value column, an id column.
A |
()
|
dims
|
str
|
Which coordinates have to be finite. The default |
'xy'
|
Returns:
| Type | Description |
|---|---|
tuple[PointArrays, tuple[ndarray | None, ...]]
|
A |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
IndexError
|
if an array in |
Examples:
- Points on the far side of a globe are removed:
- An unknown elevation does not remove a point a 2-D consumer can still draw:
- A repeated axis is refused rather than read as the axis the caller probably meant:
Source code in src/digitalearth/base/points.py
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 | |
from_features(features, *, centroids=True, crs=None)
classmethod
#
Extract coordinates from a pyramids FeatureCollection or a geopandas frame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
Any
|
The collection, frame or geometry series to read. A |
required |
centroids
|
bool
|
What to do with geometry that is not a point. |
True
|
crs
|
Any
|
Override the CRS to record. Defaults to whatever the input declares. |
None
|
Returns:
| Type | Description |
|---|---|
PointArrays
|
The coordinates, with |
PointArrays
|
otherwise. A frame mixing 2-D and 3-D points therefore reads as flat: |
PointArrays
|
geopandas can answer cheaply, and a partly-3-D frame has no elevation for some of its points |
PointArrays
|
anyway. |
PointArrays
|
A row whose geometry is missing reads as |
PointArrays
|
is ordinary in GeoJSON, and it is absent data rather than data of the wrong shape — so it is for |
PointArrays
|
meth: |
PointArrays
|
genuinely present is subject to the |
PointArrays
|
whether the frame is 3-D: a null among 3-D points keeps the others' heights, and its own |
PointArrays
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
if |
ValueError
|
if |
Examples:
- The CRS comes from the data unless overridden:
- A missing geometry reads as
NaNeven withcentroids=False, keeps the other points' heights, and is dropped by :meth:finite:>>> import geopandas as gpd >>> from shapely.geometry import Point >>> from digitalearth.base.points import PointArrays >>> gdf = gpd.GeoDataFrame(geometry=[Point(0, 1, 5), None, Point(2, 3, 7)]) >>> pts = PointArrays.from_features(gdf, centroids=False) >>> pts.x.tolist(), pts.z.tolist() ([0.0, nan, 2.0], [5.0, nan, 7.0]) >>> pts.finite()[0].z.tolist() [5.0, 7.0] - A polygon falls back to its centroid, or is refused when
centroids=False:>>> import geopandas as gpd >>> from shapely.geometry import Polygon >>> from digitalearth.base.points import PointArrays >>> square = gpd.GeoDataFrame(geometry=[Polygon([(0, 0), (2, 0), (2, 2), (0, 2)])]) >>> centre = PointArrays.from_features(square) >>> centre.x.tolist(), centre.y.tolist() ([1.0], [1.0]) >>> PointArrays.from_features(square, centroids=False) # doctest: +ELLIPSIS Traceback (most recent call last): ... ValueError: PointArrays.from_features got geometry that is not all points, and centroids=False...
Source code in src/digitalearth/base/points.py
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 | |
of(x, y, z=None, *, crs=None)
classmethod
#
Build from coordinate sequences, forcing the dtype every call site used to choose for itself.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Any
|
X coordinates. |
required |
y
|
Any
|
Y coordinates. |
required |
z
|
Any
|
Z coordinates, or |
None
|
crs
|
Any
|
What the coordinates are measured in. |
None
|
Returns:
| Type | Description |
|---|---|
PointArrays
|
The arrays as |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the sequences are not the same length. |
Examples:
- Integer input comes back as floats, with z filled in:
Source code in src/digitalearth/base/points.py
MeshSource — an unstructured mesh, with its own connectivity#
A raster Source carries a grid and two axis vectors; a point Source carries three parallel arrays. A UGRID
mesh is neither: its cells are listed rather than implied, so the geometry only exists once the connectivity
travels with the coordinates — together with where on it the values sit, since a variable may be given per
node or per face.
The triangles come from pyramids (Mesh2d.fan_triangles, which cuts every face — triangle, quad or larger
polygon — with pure numpy), not from a triangulation computed here. Re-triangulating the nodes would invent
faces the mesh does not have and paint face-located values onto them.
Which backends draw one. A MeshDataset is accepted by quickmap(backend="matplotlib"), which draws it
with tripcolor — each face shaded its own colour. The interactive, web and 3-D tiers have no triangular
render, so they refuse a mesh by name rather than drawing it as something else. Note this is about the mesh
input: the unstructured row of the support matrix is about the triangulated verbs
(tricontourf / tricontour / tripcolor), which the interactive tier does have for scattered points.
A mesh that declares a CRS is drawn in any display CRS pyproj.CRS.from_user_input accepts — an EPSG code, a
"+proj=..." string, WKT or an ESRI: code — because pyramids (since pyramids-core 0.73.0,
serapeum-org/pyramids-core#1404) warps a mesh to a CRS given in any form. An orthographic, Robinson or Mollweide
display CRS is drawn like any other: the warp sends nodes beyond a globe's limb to non-finite coordinates, and the
triangles leaning on them are then dropped, as off-view geometry is for every layer family.
digitalearth.base.sources.MeshSource
#
Bases: Source
An unstructured-mesh source: node coordinates, an explicit triangulation, and values on it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z
|
DimensionInfo | None
|
The values (a :class: |
required |
x
|
DimensionInfo
|
The node x / longitude coordinates (a :class: |
required |
y
|
DimensionInfo
|
The node y / latitude coordinates (a :class: |
required |
triangles
|
Any
|
The triangulation as an |
required |
location
|
str
|
|
required |
crs
|
Any
|
The CRS the coordinates are expressed in, as given. |
None
|
metadata
|
dict | None
|
Free-form metadata ( |
None
|
units
|
str | None
|
Unit string for the values, or |
None
|
Both shapes it documents are enforced in __init__: the triangulation must be (n_triangles, 3)
indices into the nodes it was given, and z must hold one value per node or per triangle. Checking
them is the point of the object — an invalid one otherwise surfaced as an IndexError from inside
matplotlib, several frames from the mistake.
Examples:
- A two-triangle mesh with a value on each face:
>>> import numpy as np >>> from digitalearth.base.sources import DimensionInfo, MeshSource >>> nodes_x = DimensionInfo(np.array([0.0, 1.0, 0.0, 1.0]), "x") >>> nodes_y = DimensionInfo(np.array([0.0, 0.0, 1.0, 1.0]), "y") >>> faces = np.array([[0, 1, 2], [1, 3, 2]]) >>> src = MeshSource(DimensionInfo(np.array([10.0, 20.0]), "z"), nodes_x, nodes_y, ... triangles=faces, location="face", crs=4326) >>> src.triangles.shape (2, 3) >>> src.location 'face' >>> src.n_triangles 2 - The values may instead sit on the nodes, in which case there is one per coordinate:
>>> import numpy as np >>> from digitalearth.base.sources import DimensionInfo, MeshSource >>> src = MeshSource(DimensionInfo(np.arange(4.0), "z"), ... DimensionInfo(np.zeros(4), "x"), DimensionInfo(np.zeros(4), "y"), ... triangles=np.array([[0, 1, 2]]), location="node") >>> src.location, src.z.values.size ('node', 4) - Values that do not line up with what
locationsays are refused:>>> import numpy as np >>> from digitalearth.base.sources import DimensionInfo, MeshSource >>> try: ... MeshSource(DimensionInfo(np.arange(9.0), "z"), ... DimensionInfo(np.zeros(4), "x"), DimensionInfo(np.zeros(4), "y"), ... triangles=np.array([[0, 1, 2]]), location="face") ... except ValueError as error: ... print(error) face-located values must be one per triangle (1 expected), got 9 - An unknown location is refused, because a renderer would otherwise guess which array to colour:
>>> import numpy as np >>> from digitalearth.base.sources import DimensionInfo, MeshSource >>> try: ... MeshSource(None, DimensionInfo(np.zeros(3), "x"), DimensionInfo(np.zeros(3), "y"), ... triangles=np.array([[0, 1, 2]]), location="edge") ... except ValueError as error: ... print(error) location='edge' is not one of ('node', 'face')
Source code in src/digitalearth/base/sources/mesh.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 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 | |
location
property
#
Which of :data:MESH_LOCATIONS the values in z are aligned with.
n_triangles
property
#
How many triangles the mesh draws as.
triangles
property
#
The triangulation as an (n_triangles, 3) array of node indices.
Getting data into the display CRS#
The three helpers each tier used to define for itself.
digitalearth.base.display.needs_reproject(data, crs)
#
Whether data must be reprojected to reach the display CRS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
A pyramids object — a |
required |
crs
|
Any
|
The display CRS, in any spelling pyramids reads: an EPSG |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
bool
|
including for data that declares no CRS at all. |
bool
|
The two are compared by meaning, through :func: |
bool
|
|
bool
|
|
bool
|
object — warped data that was already in EPSG:4326. |
bool
|
The data's CRS definition ( |
bool
|
EPSG code says nothing about a projection with no authority code, while the definition does: an |
bool
|
orthographic dataset still warps to EPSG:4326, and needs no warp to its own orthographic CRS. |
bool
|
Both attributes are read with |
bool
|
|
Examples:
- The same system needs no warp, however the display CRS is spelled:
- A different system warps, and so does data that declares no CRS:
Source code in src/digitalearth/base/display.py
digitalearth.base.display.to_display_source(data, crs, *, band=DEFAULT_BAND)
#
Reproject data into the display CRS through pyramids, and wrap it as a :class:Source.
The single display-CRS choke point a raster or vector builder calls. It settles the projection decision the same way on every tier: pre-reproject in pyramids, no cartopy anywhere. Data already in the display CRS passes through untouched.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
A pyramids |
required |
crs
|
Any
|
The display CRS. |
required |
band
|
int
|
1-based band to extract for raster inputs. |
DEFAULT_BAND
|
Returns:
| Type | Description |
|---|---|
Source
|
The display-CRS source. |
Raises:
| Type | Description |
|---|---|
Exception
|
whatever pyramids raises for a warp it cannot perform, or the extractor for data it cannot read. |
Examples:
- A plain array has no CRS to warp from, so it goes straight to extraction:
Source code in src/digitalearth/base/display.py
digitalearth.base.display.auto_cmap(source, cmap, fallback=DEFAULT_CMAP, *, lookup=None)
#
Return the colormap to draw source with, resolving from its variable when the caller named none.
Defers to lookup, which by default is :func:digitalearth.base.autostyle.auto_style — the same
variable→style table the static Map consults, ECMWF-Magics match included — so a recognised field is
coloured the same way whichever tier renders it. Neither source nor the lookup is consulted when the
caller named a colormap.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Any
|
The display-CRS source whose variable drives the lookup. |
required |
cmap
|
str | None
|
The caller's colormap, or |
required |
fallback
|
str
|
Colormap to use when the lookup's answer has no |
DEFAULT_CMAP
|
lookup
|
Callable[[Any], dict[str, Any]] | None
|
The style lookup to consult, taking |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The caller's |
str
|
The fallback is reached with |
str
|
same answer for every input the shipped library can produce — it seeds each result from a |
str
|
group carrying |
str
|
holds if a library ever answers with |
str
|
would hand back as the colormap. |
Examples:
- A caller's choice always wins:
- A tier hands in its own lookup, and the colormap is whatever that lookup answers:
fallbackis used only when the answer names no colormap; the default lookup always names one:
Source code in src/digitalearth/base/display.py
LayerSpec and LayerTree — a layer described, and addressed by id#
Every tier kept a list called layers, three of them addressed it by position, and none kept what a layer is.
LayerSpec is that description — kind, source, slice, style — with no data object, viewport or engine handle, and
LayerTree orders layers bottom first and addresses them by id. Every change to a tree returns a new tree.
digitalearth.base.spec.layer.LayerSpec
dataclass
#
What one layer draws, described without drawing it.
Where a decoration lives. Anything drawn in map coordinates is a layer, decoration included: a basemap,
coastlines, a graticule, a string placed at a coordinate. Its kind's band
(:data:~digitalearth.base.registry.KIND_BANDS) decides where in draw order it lands, so a graticule added
last is still drawn under the data. The three other homes are for what has no place on the ground: whatever
explains an encoding is a Guide on that :class:~digitalearth.base.spec.encoding.Encoding (a legend, a
colorbar), whatever is fixed to the frame is :class:~digitalearth.base.spec.furniture.Furniture on the
PanelSpec (a scale bar, a north arrow, a navigation control), and the panel's heading is its title.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
The layer's identity within its figure, unique within a :class: |
kind |
str
|
What sort of layer it is — |
source_id |
str | None
|
The key of the layer's data in the figure's sources, or |
selection |
Selection
|
Which slice of the source the layer draws. |
symbology |
Symbology
|
How the layer looks. |
z_source |
str | None
|
Where the layer's elevation comes from: |
visible |
bool
|
Whether the layer is drawn. A hidden layer stays in the tree, which is what lets a viewer turn it back on. |
label |
str | None
|
What a layer switcher calls it; |
group |
str | None
|
The group the layer belongs to, so a set of layers can be hidden together. |
band |
str | None
|
Where this layer is drawn, overriding the band its kind declares — one of
:data: |
filter |
str | None
|
A filter expression, carried for the renderer rather than interpreted here. A string — SQL-like,
as the static and interactive tiers write one — or a JSON expression, as MapLibre and deck.gl take
one ( |
Raises:
| Type | Description |
|---|---|
ValueError
|
for an id that is not a non-empty string, a kind that is not a
lowercase identifier, a non-boolean |
Examples:
- A raster layer over a source, drawn at 80% opacity:
- A layer can be drawn outside the band its kind declares, which is what a caller's own object needs:
- Imagery draped over that layer names it as its elevation source:
- A layer cannot drape itself over itself:
Source code in src/digitalearth/base/spec/layer.py
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 | |
display_label
property
#
What a layer switcher shows for this layer.
Returns:
| Type | Description |
|---|---|
str
|
|
Examples:
- The id stands in for a missing label:
z_layer
property
#
The id of the layer this one takes its elevation from, if it takes it from a layer.
Returns:
| Type | Description |
|---|---|
str | None
|
The layer id after |
Examples:
- A draped layer names the layer beneath it; a flat one names nothing:
__post_init__()
#
Refuse a layer that could not be addressed, looked up or drawn.
Raises:
| Type | Description |
|---|---|
ValueError
|
as described on the class. |
Source code in src/digitalearth/base/spec/layer.py
from_dict(data)
classmethod
#
Rebuild a layer from its dict form.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Mapping[str, Any]
|
A mapping as produced by :meth: |
required |
Returns:
| Type | Description |
|---|---|
LayerSpec
|
The layer, validated as the constructor validates it. |
Raises:
| Type | Description |
|---|---|
TypeError
|
if |
ValueError
|
for a missing id or kind, an unknown key, a |
Examples:
- A stored layer reads back with its slice:
- Z-order lives in the tree, so an
orderkey is unknown and refused rather than dropped:
Source code in src/digitalearth/base/spec/layer.py
to_dict()
#
Return the plain-dict form a figure stores.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
|
dict[str, Any]
|
source, slice or style stores two keys. |
Raises:
| Type | Description |
|---|---|
TypeError
|
if the selection or the symbology holds a value with no JSON form. |
Examples:
- Only what was set is written:
- A plain visible layer with no source, slice or style stores two keys:
Source code in src/digitalearth/base/spec/layer.py
digitalearth.base.spec.layer.LayerTree
dataclass
#
The layers of a figure, in draw order, addressed by id.
Every change returns a new tree of the same type — a subclass stays a subclass — and leaves this one as it was, so a renderer can compare the tree it drew with the tree it is asked to draw.
A layer is placed in the band its kind belongs to (:data:~digitalearth.base.registry.KIND_BANDS), not
simply where it was added: ground cover stays under the data, a graticule over the ground but under the data,
labels over everything. That is what every tier already does by hand — the web tier counts underlays onto its
queue, the interactive tier inserts at position 0, the static tier sets zorder — expressed once, so the tree
order is the draw order.
Attributes:
| Name | Type | Description |
|---|---|---|
layers |
tuple[LayerSpec, ...]
|
The layers, bottom first — the first is drawn first and so sits beneath the rest. |
hidden_groups |
frozenset[str]
|
The groups switched off. A layer in a hidden group is not drawn whatever its own |
Raises:
| Type | Description |
|---|---|
ValueError
|
for an entry that is not a |
Examples:
- Build a tree and address layers by id rather than by position:
- Hiding a group hides its layers without forgetting their own visibility:
>>> from digitalearth.base.spec import LayerSpec, LayerTree >>> tree = LayerTree().add(LayerSpec("a", "points", group="obs")).add(LayerSpec("b", "points")) >>> hidden = tree.set_group_visible("obs", False) >>> hidden.is_visible("a"), hidden.is_visible("b"), hidden.get("a").visible (False, True, True) - Draped layers that take their elevation from each other in a loop are refused:
Source code in src/digitalearth/base/spec/layer.py
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 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 | |
groups
property
#
The groups the layers belong to, in the order each first appears.
Returns:
| Type | Description |
|---|---|
tuple[str, ...]
|
The group names, without repeats. |
Examples:
- Groups are listed once, in draw order:
__contains__(layer_id)
#
Whether a layer with this id is in the tree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer_id
|
object
|
The id to look for. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
__iter__()
#
Iterate over the layers, bottom first.
Returns:
| Type | Description |
|---|---|
Iterator[LayerSpec]
|
An iterator over the layers in draw order. |
__post_init__()
#
Refuse a tree whose ids, references or hidden groups do not hold together.
Raises:
| Type | Description |
|---|---|
ValueError
|
as described on the class. |
Source code in src/digitalearth/base/spec/layer.py
add(layer, *, index=None)
#
Return a tree with layer added.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
LayerSpec
|
The layer to add. |
required |
index
|
int | None
|
Where it goes within its band. |
None
|
Returns:
| Type | Description |
|---|---|
LayerTree
|
The new tree. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
IndexError
|
if |
Examples:
- A basemap is ground cover, so it goes beneath the data wherever it is added:
- Kinds that draw over the data stay over it, and the order within a band is the order they arrived:
- A position that would take the layer out of its band is refused rather than clamped:
Source code in src/digitalearth/base/spec/layer.py
from_dict(data)
classmethod
#
Rebuild a tree from its dict form.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Mapping[str, Any]
|
A mapping as produced by :meth: |
required |
Returns:
| Type | Description |
|---|---|
LayerTree
|
The tree, validated as the constructor validates it. |
Raises:
| Type | Description |
|---|---|
TypeError
|
if |
ValueError
|
for an unknown key, a layer |
Examples:
- A stored tree reads back in the same order:
- A hidden group stays hidden across a round trip:
Source code in src/digitalearth/base/spec/layer.py
get(layer_id)
#
Return the layer with this id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer_id
|
str
|
The id to look up. |
required |
Returns:
| Type | Description |
|---|---|
LayerSpec
|
The layer. |
Raises:
| Type | Description |
|---|---|
KeyError
|
if no layer has that id, listing the ids that exist. |
Examples:
- Look a layer up by id:
- An id the tree does not hold is named beside the ids it does:
Source code in src/digitalearth/base/spec/layer.py
is_visible(layer_id)
#
Whether a layer is drawn: its own visible, and its group not hidden.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer_id
|
str
|
The layer to ask about. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Raises:
| Type | Description |
|---|---|
KeyError
|
if no layer has that id. |
Examples:
- A layer switched off is not drawn:
Source code in src/digitalearth/base/spec/layer.py
move(layer_id, index)
#
Return a tree with a layer moved to another position in draw order.
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 |
|---|---|
LayerTree
|
The new tree. Every other layer keeps its relative order. |
Raises:
| Type | Description |
|---|---|
KeyError
|
if no layer has that id. |
IndexError
|
if |
Examples:
- Bring a layer to the top:
- Send a layer to the bottom; the others keep their relative order:
- A layer cannot be moved out of its band; the message says where the band runs:
>>> from digitalearth.base.spec import LayerSpec, LayerTree >>> tree = LayerTree().add(LayerSpec("tiles", "basemap")).add(LayerSpec("dem", "raster")) >>> tree.move("tiles", -1) Traceback (most recent call last): ... IndexError: cannot move 'tiles' to position 1; the underlay band runs from position 0 to 0
Source code in src/digitalearth/base/spec/layer.py
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 | |
remove(layer_id)
#
Return a tree without the layer with this id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer_id
|
str
|
The layer to remove. |
required |
Returns:
| Type | Description |
|---|---|
LayerTree
|
The new tree. A hidden group left with no layers stops being hidden, since there is nothing left in it. |
Raises:
| Type | Description |
|---|---|
KeyError
|
if no layer has that id. |
ValueError
|
if another layer takes its elevation from this one — removing the surface would leave the draped layer pointing at nothing. |
Examples:
- Remove a layer by id:
- Removing the last layer of a hidden group un-hides the group:
- A surface another layer is draped over cannot be removed first:
>>> from digitalearth.base.spec import LayerSpec, LayerTree >>> draped = LayerSpec("img", "rgb", z_source="layer:dem") >>> tree = LayerTree().add(LayerSpec("dem", "raster")).add(draped) >>> tree.remove("dem") # doctest: +ELLIPSIS Traceback (most recent call last): ... ValueError: layer 'dem' cannot be removed while ['img'] take their elevation from it; ...
Source code in src/digitalearth/base/spec/layer.py
replace(layer)
#
Return a tree with the layer of the same id swapped for layer, in the same position.
This is how a layer is restyled or re-pointed after it has been added: the id and the position stay, the description changes.
A replacement that changes the layer's band is the exception: it takes the position add would
have given it, at the top of the band it now belongs to. Keeping the old position would put a
reference layer under the data or an overlay beneath it, which is the one thing the bands exist to
prevent — and which add and move both refuse to do.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
LayerSpec
|
The new description. Its id names the layer it replaces. |
required |
Returns:
| Type | Description |
|---|---|
LayerTree
|
The new tree. A hidden group the new description leaves with no layers stops being hidden, as |
LayerTree
|
meth: |
Raises:
| Type | Description |
|---|---|
KeyError
|
if no layer has that id. |
ValueError
|
if |
Examples:
- Restyle a layer without moving it:
>>> from digitalearth.base.spec import LayerSpec, LayerTree, Symbology >>> tree = LayerTree().add(LayerSpec("a", "points")).add(LayerSpec("b", "lines")) >>> restyled = tree.replace(LayerSpec("a", "points", symbology=Symbology.of(color="#f00"))) >>> restyled.ids, restyled.get("a").symbology.encoding("color").resolve() (('a', 'b'), '#f00') - Moving the last layer out of a hidden group un-hides the group, as removing it would:
>>> from digitalearth.base.spec import LayerSpec, LayerTree >>> tree = LayerTree().add(LayerSpec("a", "points", group="obs")).add(LayerSpec("b", "lines")) >>> hidden = tree.set_group_visible("obs", False) >>> hidden.hidden_groups, hidden.replace(LayerSpec("a", "points")).hidden_groups (frozenset({'obs'}), frozenset()) - Re-pointing a layer's elevation at a layer the tree lacks is refused:
>>> from digitalearth.base.spec import LayerSpec, LayerTree >>> tree = LayerTree().add(LayerSpec("dem", "raster")) >>> tree.replace(LayerSpec("dem", "raster", z_source="layer:nope")) # doctest: +ELLIPSIS Traceback (most recent call last): ... ValueError: layer 'dem' takes its elevation from layer 'nope', which is not in the tree; ...
Source code in src/digitalearth/base/spec/layer.py
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 | |
set_group_visible(group, visible)
#
Return a tree with a whole group switched on or off.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group
|
str
|
The group to change. |
required |
visible
|
bool
|
Whether its layers should be drawn. Each layer's own |
required |
Returns:
| Type | Description |
|---|---|
LayerTree
|
The new tree. |
Raises:
| Type | Description |
|---|---|
KeyError
|
if no layer belongs to that group. |
ValueError
|
if |
Examples:
- A group switched off hides every layer in it:
- Switching the group back on restores a layer that was hidden only by its group:
Source code in src/digitalearth/base/spec/layer.py
set_visible(layer_id, visible)
#
Return a tree with one layer switched on or off.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer_id
|
str
|
The layer to change. |
required |
visible
|
bool
|
Whether it should be drawn. |
required |
Returns:
| Type | Description |
|---|---|
LayerTree
|
The new tree. |
Raises:
| Type | Description |
|---|---|
KeyError
|
if no layer has that id. |
ValueError
|
if |
Examples:
- Switch a layer off and back on:
Source code in src/digitalearth/base/spec/layer.py
to_dict()
#
Return the plain-dict form a figure stores.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
if a layer holds a value with no JSON form. |
Examples:
- The layers are written bottom first:
- Hidden groups are written as a sorted list:
Source code in src/digitalearth/base/spec/layer.py
Viewport and Camera — the view as a value#
The view used to be loose state on each facade, mutated in place to animate. These are values: a change of view is a new view.
digitalearth.base.spec.viewport.Viewport
dataclass
#
What a flat map shows: the CRS it is drawn in, and optionally the region.
Attributes:
| Name | Type | Description |
|---|---|---|
crs |
Any
|
The display CRS every layer is drawn in — an EPSG integer or anything pyramids reads. Defaults to Web
Mercator, as the static |
bounds |
Bounds | None
|
The region shown, in |
domain |
str | tuple[float, float, float, float] | None
|
A named region ( |
globe |
bool
|
Whether the map is drawn on a globe frame rather than a flat projection. |
center |
tuple[float, float] | None
|
Where a pan-and-zoom map is looking, as |
zoom |
float | None
|
The zoom level of a pan-and-zoom map — MapLibre's, where each step doubles the scale. |
Raises:
| Type | Description |
|---|---|
ValueError
|
for a |
Examples:
- A map framed on a region, in the CRS it is drawn in:
- A pan-and-zoom map says where it is standing rather than what to fit:
- A named domain, as the static tier spells it:
- A region in another CRS is refused rather than drawn in the wrong place;
framedreprojects it:
Source code in src/digitalearth/base/spec/viewport.py
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 | |
__post_init__()
#
Refuse a view nothing could be drawn in.
Raises:
| Type | Description |
|---|---|
ValueError
|
as described on the class. |
Source code in src/digitalearth/base/spec/viewport.py
framed(bounds)
#
Return this view framed on bounds, reprojected into the view's CRS if they are in another.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bounds
|
Bounds
|
The region to show, in any CRS. |
required |
Returns:
| Type | Description |
|---|---|
Viewport
|
A new view. This one is unchanged — a change of view is a new value, never an edit of the old one. A |
Viewport
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
Examples:
- Frame a view without changing the one it came from:
- A region in another CRS is reprojected into the view's:
- Framing a view that has a named domain replaces the domain with the bounds:
Source code in src/digitalearth/base/spec/viewport.py
from_dict(data)
classmethod
#
Rebuild a view from its dict form.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Mapping[str, Any]
|
A mapping as produced by :meth: |
required |
Returns:
| Type | Description |
|---|---|
Viewport
|
The view, validated as the constructor validates it. |
Raises:
| Type | Description |
|---|---|
TypeError
|
if |
ValueError
|
for a missing CRS, an unknown key, bounds |
Examples:
- A stored globe view reads back:
- A stored domain box comes back as a tuple of floats:
- The CRS cannot be left out:
Source code in src/digitalearth/base/spec/viewport.py
needs_reproject(data)
#
Whether data has to be reprojected to be drawn in this view.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
A pyramids object exposing |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
bool
|
spelled — the rule every tier shares, from :func: |
Examples:
- Data already in the view's CRS needs no warp, whether the view holds a code or its string:
- Data in another system warps:
Source code in src/digitalearth/base/spec/viewport.py
to_dict()
#
Return the plain-dict form a figure stores.
Returns:
| Name | Type | Description |
|---|---|---|
dict[str, Any]
|
|
|
held |
dict[str, Any]
|
the constructor has already turned a CRS object into |
dict[str, Any]
|
with no stored form or one pyramids cannot read, so writing a view does not fail on its CRS. |
Examples:
- A default view is its CRS:
- A framed globe view writes its region as a dict of named edges:
Source code in src/digitalearth/base/spec/viewport.py
digitalearth.base.spec.viewport.Camera
dataclass
#
Where a 3-D scene is looked at from.
Attributes:
| Name | Type | Description |
|---|---|---|
position |
Vector3
|
The camera's location, in the scene's coordinates. |
focal_point |
Vector3
|
The point it looks at. |
view_up |
Vector3
|
Which way is up on the screen. It may not be zero or parallel to the line of sight. |
view_angle |
float
|
The vertical field of view in degrees, strictly between 0 and 180. Ignored by a parallel projection, which has no perspective. |
parallel |
bool
|
Whether the projection is parallel (orthographic) rather than perspective — for a figure whose distances should be measurable. |
parallel_scale |
float | None
|
How much of the scene a parallel projection shows: half the view's height, in scene units,
as VTK's |
vertical_exaggeration |
float | None
|
The factor applied to the z axis, strictly positive, or |
crs |
Any
|
The CRS |
Raises:
| Type | Description |
|---|---|
ValueError
|
for a vector that is not three finite numbers, a camera placed at its own focal point, a zero or
parallel |
Examples:
- A camera south-west of a scene, 30 degrees up:
- Fields left out look at the origin with
+zup and VTK's 30-degree view angle; vectors become floats: - Looking straight down with the default vertical
view_upleaves "up" undefined:
Source code in src/digitalearth/base/spec/viewport.py
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 | |
azimuth
property
#
The compass bearing from the focal point to the camera, in degrees.
Returns:
| Type | Description |
|---|---|
float
|
A bearing in |
float
|
point has no horizontal direction, so its bearing means nothing: it comes out as |
float
|
the y offset is a negative zero, because |
Examples:
- A camera due east of its focal point:
- Bearings run clockwise, so due west is 270 rather than -90:
- A camera a rounding error west of due north reads as due north, not as 360:
elevation
property
#
The angle of the camera above the horizontal, seen from the focal point.
Returns:
| Type | Description |
|---|---|
float
|
Degrees in |
Examples:
- A camera level with its focal point:
- A camera straight above, which needs a horizontal up vector:
__post_init__()
#
Refuse a camera that could not frame anything.
Raises:
| Type | Description |
|---|---|
ValueError
|
as described on the class. |
Source code in src/digitalearth/base/spec/viewport.py
from_dict(data)
classmethod
#
Rebuild a camera from its dict form.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Mapping[str, Any]
|
A mapping as produced by :meth: |
required |
Returns:
| Type | Description |
|---|---|
Camera
|
The camera, validated as the constructor validates it. |
Raises:
| Type | Description |
|---|---|
TypeError
|
if |
ValueError
|
for a missing position, an unknown key, or a camera the constructor refuses. |
Examples:
- A stored camera reads back with its exaggeration:
- Only the position is required; the rest takes the constructor's defaults:
- A missing position is named:
Source code in src/digitalearth/base/spec/viewport.py
look_at(focal_point, *, azimuth, elevation, distance, view_up=(0.0, 0.0, 1.0), view_angle=DEFAULT_VIEW_ANGLE, parallel=False, parallel_scale=None, vertical_exaggeration=None)
classmethod
#
Place a camera by the direction it looks from, in the terms a map reader uses.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
focal_point
|
Sequence[float]
|
The point to look at. |
required |
azimuth
|
float
|
The compass bearing, in degrees, from the focal point to the camera — clockwise from north,
with north along |
required |
elevation
|
float
|
Degrees above the horizontal, from |
required |
distance
|
float
|
How far the camera is from the focal point; strictly positive. |
required |
view_up
|
Sequence[float]
|
Which way is up on the screen. |
(0.0, 0.0, 1.0)
|
view_angle
|
float
|
The vertical field of view, in degrees. |
DEFAULT_VIEW_ANGLE
|
parallel
|
bool
|
Whether the projection is parallel rather than perspective. |
False
|
parallel_scale
|
float | None
|
Half the view's height in scene units, for a parallel projection; |
None
|
vertical_exaggeration
|
float | None
|
The z-axis factor, or |
None
|
Returns:
| Type | Description |
|---|---|
Camera
|
The camera. |
Raises:
| Type | Description |
|---|---|
ValueError
|
for a non-positive distance, an elevation outside |
Examples:
- Looking at a point from due south, level with it:
- Straight down needs a horizontal up vector:
- A parallel view stores how much of the scene it shows:
- An elevation past the vertical is refused rather than turning the camera round:
Source code in src/digitalearth/base/spec/viewport.py
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 | |
to_dict()
#
Return the plain-dict form a figure stores.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Every field, and |
dict[str, Any]
|
records the settings that were in force rather than relying on today's defaults. |
Examples:
- Every setting is written, defaults included:
- A CRS is written only when the camera has one:
- The dict survives a JSON round trip and rebuilds an equal camera:
Source code in src/digitalearth/base/spec/viewport.py
RenderTarget — the output owns the read budget#
A layer never chooses how much of its source to read; the output it is rendered to does, and view_request is how a
view becomes a ViewRequest.
digitalearth.base.spec.target.RenderTarget
dataclass
#
An output a figure is rendered to: its kind, its canvas and its read budget.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
str
|
One of :data: |
width |
int | None
|
Canvas width in CSS pixels, or |
height |
int | None
|
Canvas height in CSS pixels, or |
pixel_ratio |
float
|
Device pixels per CSS pixel — |
budget |
int | None
|
Cells the target may read per source. |
Raises:
| Type | Description |
|---|---|
ValueError
|
for an unknown kind (naming the kinds that exist), a non-positive or non-integer canvas or budget, or a pixel ratio that is a boolean, not a number, not finite or not positive. |
Examples:
- A page is lighter than a window by default:
- A whole-number pixel ratio is stored as a float:
- An unknown kind is refused, naming the kinds that exist:
Source code in src/digitalearth/base/spec/target.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 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 | |
effective_budget
property
#
The cells this target reads per source.
Returns:
| Type | Description |
|---|---|
int
|
|
Examples:
- An explicit budget wins over the kind's default:
- With no budget of its own, each kind reads its entry in
DEFAULT_BUDGETS:
__post_init__()
#
Refuse a target nothing could be rendered to.
Raises:
| Type | Description |
|---|---|
ValueError
|
as described on the class. |
Source code in src/digitalearth/base/spec/target.py
from_dict(data)
classmethod
#
Rebuild a target from its dict form.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Mapping[str, Any]
|
A mapping as produced by :meth: |
required |
Returns:
| Type | Description |
|---|---|
RenderTarget
|
The target, validated as the constructor validates it. |
Raises:
| Type | Description |
|---|---|
TypeError
|
if |
ValueError
|
for an unknown key, or a target the constructor refuses. |
Examples:
- A stored page target reads back with its budget:
- A key this version does not know is refused rather than dropped:
Source code in src/digitalearth/base/spec/target.py
to_dict()
#
Return the plain-dict form a figure stores.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
|
dict[str, Any]
|
unset, not as the kind's default, so a stored target keeps following the default if the default changes. |
Examples:
- A retina image target:
- The pixel ratio is written even at its default, and an unset budget stays unset:
Source code in src/digitalearth/base/spec/target.py
view_request(view=None, *, bounds=None)
#
Return the request a reader answers for this view on this target.
The region comes from the view and the canvas and budget from the target — the only way this package makes a
:class:~digitalearth.base.spec.viewrequest.ViewRequest from a view, so a layer never chooses its own budget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
view
|
Viewport | Camera | None
|
The view being rendered. A |
None
|
bounds
|
Bounds | None
|
A region to read instead of the view's. When a |
None
|
Returns:
| Type | Description |
|---|---|
ViewRequest
|
The request: region, canvas, pixel ratio and :attr: |
ViewRequest
|
|
ViewRequest
|
named, the request's :meth: |
ViewRequest
|
canvas, within the budget. The region is |
ViewRequest
|
unframed |
ViewRequest
|
source in its own CRS, and the renderer reprojects it into the view's. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
Examples:
- The view's region, the target's canvas and budget:
>>> from digitalearth.base.spec import Bounds, RenderTarget, Viewport >>> view = Viewport(4326, bounds=Bounds(0.0, 0.0, 10.0, 5.0, crs=4326)) >>> request = RenderTarget("html", width=800, height=400).view_request(view) >>> request.as_bbox(), request.width, request.budget ((0.0, 0.0, 10.0, 5.0), 800, 1000000) - A region given in another CRS is asked for in the view's:
- A view framed by a domain box asks for that box, in the view's CRS:
- A 3-D camera has no rectangle, so only the canvas and the budget are set:
Source code in src/digitalearth/base/spec/target.py
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 | |
digitalearth.base.spec.target.TARGET_KINDS = ('window', 'html', 'image', 'batch')
module-attribute
#
digitalearth.base.spec.target.DEFAULT_BUDGETS = MappingProxyType({'window': 4000000, 'html': 1000000, 'image': 4000000, 'batch': 4000000})
module-attribute
#
PanelSpec and FigureSpec — a figure that describes itself#
The whole figure — sources, one layer tree, panels with their own views — round-trips through to_dict and
from_dict with no renderer imported, and records the schema version it was written in.
digitalearth.base.spec.figure.FigureSpec
dataclass
#
A whole figure, described with no renderer present.
Attributes:
| Name | Type | Description |
|---|---|---|
panels |
tuple[PanelSpec, ...]
|
The panels, in reading order. At least one. |
sources |
Mapping[str, DataRef]
|
Source id -> :class: |
layers |
LayerTree
|
Every layer in the figure, in draw order. A panel shows the ones it names. |
size |
tuple[float, float] | None
|
|
title |
str | None
|
The figure's title, or |
schema_version |
int
|
The description's version. Only :data: |
Raises:
| Type | Description |
|---|---|
ValueError
|
for a schema version that is not :data: |
Examples:
- One source, one layer, one panel:
>>> from digitalearth.base.spec import DataRef, FigureSpec, LayerSpec, LayerTree, PanelSpec, Viewport >>> fig = FigureSpec( ... panels=(PanelSpec("main", Viewport(4326), layers=("dem",)),), ... sources={"srtm": DataRef("data/dem.tif")}, ... layers=LayerTree((LayerSpec("dem", "raster", source_id="srtm"),)), ... ) >>> [layer.id for layer in fig.layers_of("main")], fig.schema_version (['dem'], 1) - A panel may only show layers the figure holds:
- The version is the integer, not a float equal to it:
Source code in src/digitalearth/base/spec/figure.py
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 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 | |
__hash__()
#
Hash by value, like every other type in the vocabulary.
Returns:
| Type | Description |
|---|---|
int
|
A hash over every field. |
int
|
it is hashed as its sorted items — hashed as held, it raises |
int
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
if a part holds a value that is unhashable for its own reasons. A mapping is not among
them wherever a layer's style puts one — a property or a channel's constant, however deeply
nested — since |
Examples:
- Two figures built alike hash alike, so a figure can key a cache:
Source code in src/digitalearth/base/spec/figure.py
__post_init__()
#
Refuse a figure whose parts do not refer to each other correctly.
Raises:
| Type | Description |
|---|---|
ValueError
|
as described on the class. |
Source code in src/digitalearth/base/spec/figure.py
__reduce__()
#
Pickle and copy by rebuilding through the constructor.
Returns:
| Type | Description |
|---|---|
Any
|
|
tuple[Any, ...]
|
subclass, not |
tuple[Any, tuple[Any, ...]]
|
freezing as any other construction. |
Examples:
- A copy is equal to the original, and is a separate object:
Source code in src/digitalearth/base/spec/figure.py
diff(other)
#
Return what turns this figure into other, sorted into the updates a renderer makes.
Layers are matched by id. A layer on both sides is rebuilt when what it draws changed — its kind,
source, elevation source or selection, or the DataRef behind its source id — and restyled when only
its symbology, filter, label or group did. A new selection is a rebuild rather than a restyle: another band
or time step is other pixels to read. Visibility is effective visibility
(:meth:LayerTree.is_visible <digitalearth.base.spec.layer.LayerTree.is_visible>), so hiding a group
reports every layer it hides, and a change of a layer's own visible is reported only there.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
FigureSpec
|
The figure to compare with. |
required |
Returns:
| Type | Description |
|---|---|
FigureDiff
|
The changes, as a :class: |
Raises:
| Type | Description |
|---|---|
TypeError
|
if |
Examples:
- Hiding a group reports the layers it hides:
>>> from digitalearth.base.spec import FigureSpec, LayerSpec, LayerTree, PanelSpec >>> layers = (LayerSpec("s", "points", group="obs"), LayerSpec("t", "text")) >>> before = FigureSpec(panels=(PanelSpec("p", layers=("s", "t")),), layers=LayerTree(layers)) >>> after = FigureSpec( ... panels=(PanelSpec("p", layers=("s", "t")),), ... layers=LayerTree(layers, hidden_groups=frozenset({"obs"})), ... ) >>> before.diff(after).hidden ('s',) - Swapping two layers reports the whole new order:
>>> from digitalearth.base.spec import FigureSpec, LayerSpec, LayerTree, PanelSpec >>> a, b = LayerSpec("a", "text"), LayerSpec("b", "graticule") >>> panels = (PanelSpec("p", layers=("a", "b")),) >>> before = FigureSpec(panels=panels, layers=LayerTree((a, b))) >>> after = FigureSpec(panels=panels, layers=LayerTree((b, a))) >>> before.diff(after).order ('b', 'a')
Source code in src/digitalearth/base/spec/figure.py
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 | |
from_dict(data)
classmethod
#
Rebuild a figure from its dict form.
The version is read first: a figure written by a newer schema is refused by name before any of its fields is interpreted, since a field whose meaning changed would otherwise be read the old way without a word.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Mapping[str, Any]
|
A mapping as produced by :meth: |
required |
Returns:
| Type | Description |
|---|---|
FigureSpec
|
The figure, validated as the constructor validates it. |
Raises:
| Type | Description |
|---|---|
TypeError
|
if |
ValueError
|
for a missing or unknown schema version, a missing panel list, an unknown key, a part its own
|
Examples:
- A figure from a newer schema is refused before it is read:
- A broken entry deep in the figure is named by its path:
>>> from digitalearth.base.spec import FigureSpec >>> stored = {"schema_version": 1, "panels": [{"id": "p", "viewport": {"crs": True}}]} >>> FigureSpec.from_dict(stored) # doctest: +ELLIPSIS Traceback (most recent call last): ... ValueError: FigureSpec.from_dict panels[0]: PanelSpec.from_dict viewport: Viewport needs a display ...
Source code in src/digitalearth/base/spec/figure.py
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 | |
layers_of(panel_id)
#
Return the layers a panel shows, in draw order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
panel_id
|
str
|
The panel. |
required |
Returns:
| Type | Description |
|---|---|
LayerSpec
|
The panel's layers, ordered as the figure's tree orders them — so reordering the tree reorders every |
...
|
panel that shows those layers. |
Raises:
| Type | Description |
|---|---|
KeyError
|
if no panel has that id. |
Examples:
- A panel's layers follow the tree's order, not the order the panel listed them in:
>>> from digitalearth.base.spec import FigureSpec, LayerSpec, LayerTree, PanelSpec >>> tree = LayerTree((LayerSpec("base", "tiles"), LayerSpec("roads", "lines"))) >>> fig = FigureSpec(panels=(PanelSpec("p", layers=("roads", "base")),), layers=tree) >>> [layer.id for layer in fig.layers_of("p")] ['base', 'roads']
Source code in src/digitalearth/base/spec/figure.py
panel(panel_id)
#
Return the panel with this id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
panel_id
|
str
|
The id to look up. |
required |
Returns:
| Type | Description |
|---|---|
PanelSpec
|
The panel. |
Raises:
| Type | Description |
|---|---|
KeyError
|
if no panel has that id, listing the ids that exist. |
Examples:
- Look a panel up by id:
- An id no panel has is named beside the ids that exist:
Source code in src/digitalearth/base/spec/figure.py
to_dict()
#
Return the plain-dict form of the whole figure.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
|
dict[str, Any]
|
values — encoding constants, style properties, scale categories and schemes, selection axes — go |
dict[str, Any]
|
through the JSON check as they are written, so a figure built from plain, finite Python numbers, |
dict[str, Any]
|
strings, lists and dicts gives a dict |
Raises:
| Type | Description |
|---|---|
TypeError
|
if a free-form value has no JSON form. A view's CRS is checked when the view is built, so it is not a reason this can fail. |
ValueError
|
if a source is an |
Examples:
- The version is always written:
- A figure survives a JSON round trip, with no renderer involved:
>>> import json >>> from digitalearth.base.spec import DataRef, FigureSpec, LayerSpec, LayerTree, PanelSpec, Viewport >>> fig = FigureSpec( ... panels=(PanelSpec("main", Viewport(4326), layers=("dem",)),), ... sources={"srtm": DataRef("data/dem.tif")}, ... layers=LayerTree((LayerSpec("dem", "raster", source_id="srtm"),)), ... size=(8, 4), ... ) >>> text = json.dumps(fig.to_dict(), allow_nan=False) >>> back = FigureSpec.from_dict(json.loads(text)) >>> back == fig, back.size (True, (8.0, 4.0))
Source code in src/digitalearth/base/spec/figure.py
digitalearth.base.spec.figure.PanelSpec
dataclass
#
One panel of a figure: a view, and the layers it shows.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
The panel's identity within its figure. |
view |
Viewport | Camera
|
What the panel shows the layers through — a |
layers |
tuple[str, ...]
|
The ids of the layers the panel shows. The draw order is the figure's tree order, not this tuple's. |
title |
str | None
|
The panel's title, or |
furniture |
tuple[Furniture, ...]
|
What is fixed to the panel's frame rather than drawn on the ground — a scale bar, a north arrow, zoom buttons, a time slider. Each item names a registered kind and the corner it sits in; a tier that cannot draw one skips it. Anything with a place on the ground is a layer instead, and anything explaining an encoding is a guide on that encoding. |
Raises:
| Type | Description |
|---|---|
ValueError
|
for an id that is not a non-empty string, a view that is neither a
|
Examples:
- Two panels over the same layer, in two projections:
- A panel with no view named is a Web Mercator map, and a list of layer ids is stored as a tuple:
- Furniture is anchored to the frame, wherever the map is panned:
- A bare string is refused rather than read as one layer id per letter:
Source code in src/digitalearth/base/spec/figure.py
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 | |
__post_init__()
#
Refuse a panel that could not be drawn or addressed.
Raises:
| Type | Description |
|---|---|
ValueError
|
as described on the class. |
Source code in src/digitalearth/base/spec/figure.py
bounds_of(extents, *, padding=0.0)
#
Return the region this panel's own layers cover, in the CRS the panel draws in.
What a tier needs to frame a figure on its data, composed where both halves of the question are
already held: which layers count is this panel's layers, and which CRS they have to meet in is
its view. Neither is the figure's — a linked-view figure frames each panel on its own subset — and
neither is the tier's, which can measure a layer's extent but not decide those two things.
Nothing is computed here that :class:~digitalearth.base.spec.bounds.Bounds did not already do:
:meth:~digitalearth.base.spec.bounds.Bounds.to_crs converts,
:meth:~digitalearth.base.spec.bounds.Bounds.union merges and
:meth:~digitalearth.base.spec.bounds.Bounds.padded grows. This is the order they go in.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
extents
|
Mapping[str, Bounds | None]
|
What each layer covers, by layer id, as the tier measured it — from the artists or
elements it actually drew, in any CRS. It is read as what is known rather than as one
entry per layer: a layer with no key, and a layer whose value is |
required |
padding
|
float
|
Breathing room around the union, as a fraction of its own span — |
0.0
|
Returns:
| Type | Description |
|---|---|
Bounds | None
|
The padded union, in the view's CRS, or |
Bounds | None
|
give — which a caller has to be able to tell from a frame that came out empty. |
Raises:
| Type | Description |
|---|---|
TypeError
|
if |
ValueError
|
from |
Examples:
- Two layers, framed on the rectangle that holds both:
>>> from digitalearth.base.spec import Bounds, PanelSpec, Viewport >>> panel = PanelSpec("main", Viewport(3857), layers=("dem", "gauges")) >>> covers = { ... "dem": Bounds(0.0, 0.0, 10.0, 10.0, crs=3857), ... "gauges": Bounds(5.0, 20.0, 30.0, 40.0, crs=3857), ... } >>> panel.bounds_of(covers).as_bbox() [0.0, 0.0, 30.0, 40.0] - A layer measured in the data's CRS is converted into the panel's before it is merged:
- A panel whose layers measured nothing has no region to report:
Source code in src/digitalearth/base/spec/figure.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 | |
from_dict(data)
classmethod
#
Rebuild a panel from its dict form.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Mapping[str, Any]
|
A mapping as produced by :meth: |
required |
Returns:
| Type | Description |
|---|---|
PanelSpec
|
The panel, validated as the constructor validates it. |
Raises:
| Type | Description |
|---|---|
TypeError
|
if |
ValueError
|
for a missing id, an unknown key, both or neither of |
Examples:
- A stored 3-D panel reads back with its camera:
- A panel must say which kind of view it has:
Source code in src/digitalearth/base/spec/figure.py
to_dict()
#
Return the plain-dict form a figure stores.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
|
dict[str, Any]
|
field — plus |
Examples:
- The view is stored under the key that names its kind:
- A 3-D panel stores a camera, and its title:
Source code in src/digitalearth/base/spec/figure.py
The registries#
How a reference becomes data, without base/ knowing any reader — and how Scale reaches a classifier
without base/ importing the renderer it lives in.
digitalearth.base.registry.register_resolver(scheme, resolver)
#
Register the callable that opens URIs of one scheme.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scheme
|
str
|
The URI scheme, without |
required |
resolver
|
Callable[[str], Any]
|
Called with the full URI, returning the opened object. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
Examples:
- Register a resolver and reach it through the scheme it serves. A plain call is permanent —
there is no unregister — so this shows it inside :func:
temporary_resolver, which is what to reach for anywhere the registration should not outlive the code that made it:
Source code in src/digitalearth/base/registry.py
digitalearth.base.registry.resolvers()
#
Return the registered resolvers, keyed by scheme.
Returns:
| Type | Description |
|---|---|
dict[str, Callable[[str], Any]]
|
A copy of the table, so a caller inspecting it cannot edit the registry by accident. |
Examples:
- Reach the resolver a scheme is served by:
- Editing what comes back leaves the registry alone, because it is a copy:
Source code in src/digitalearth/base/registry.py
digitalearth.base.registry.temporary_resolver(scheme, resolver)
#
Register a resolver for the duration of a block, then put the table back as it was.
The registry is process-global and has no unregister, so a test or an example that registers a scheme changes what every later one sees. This is the scoped form, so demonstrating the registry does not leave a scheme behind in the session that ran the demonstration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scheme
|
str
|
The URI scheme to register under. |
required |
resolver
|
Callable[[str], Any]
|
The resolver to install for the block. |
required |
Yields:
| Type | Description |
|---|---|
None
|
Nothing; the registration is in effect inside the block. |
Examples:
- The scheme resolves inside the block and is gone afterwards:
Source code in src/digitalearth/base/registry.py
digitalearth.base.registry.register_object(obj, *, name='')
#
Hold an in-memory object in this process and return the URI that reaches it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any
|
The object to register — typically a pyramids |
required |
name
|
str
|
An optional stable id. Reusing one replaces what it pointed at, which is how a caller refreshes the data behind a figure without rebuilding the figure. Omitted, a unique id is generated. |
''
|
Returns:
| Type | Description |
|---|---|
str
|
An |
Examples:
- An object gets a URI without touching the filesystem:
Source code in src/digitalearth/base/registry.py
digitalearth.base.registry.clear_objects()
#
Forget every registered in-memory object.
The table is process-local and holds strong references, so a long-lived session that registers many datasets keeps them all alive. This is the release valve, and what a test suite calls between cases.
Examples:
- A cleared id no longer resolves:
>>> from digitalearth.base.registry import clear_objects, register_object, resolve_uri >>> uri = register_object([1, 2], name="doc-rows") >>> resolve_uri(uri) [1, 2] >>> clear_objects() >>> resolve_uri("object:doc-rows") Traceback (most recent call last): ... KeyError: "no object is registered as 'doc-rows'. An object: reference only resolves in the process that registered it — save the data and reference it by path to share the figure"
Source code in src/digitalearth/base/registry.py
digitalearth.base.registry.resolve_uri(uri)
#
Open a URI with the resolver registered for its scheme.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
str
|
The reference to open. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The opened object. |
Raises:
| Type | Description |
|---|---|
KeyError
|
if no resolver is registered for the scheme, listing the ones that are — a plugin that failed to install looks exactly like a typo otherwise. |
Examples:
- A bare path uses the default file resolver:
>>> from digitalearth.base.registry import resolve_uri >>> resolve_uri("object:missing-id") Traceback (most recent call last): ... KeyError: "no object is registered as 'missing-id'. An object: reference only resolves in the process that registered it — save the data and reference it by path to share the figure"
Source code in src/digitalearth/base/registry.py
digitalearth.base.registry.register_classifier(classifier)
#
Register the function that cuts class edges from values.
base/ may not import a renderer, and the classifier this package uses lives in cleopatra. So base/
declares the seam and something above it fills it — :mod:digitalearth registers a lazily-importing
adapter at package import. The policy around classification (the default class count, the error that
names the scheme and k, turning edges into classes) stays in
:class:~digitalearth.base.spec.scale.Scale; only the arithmetic is injected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
classifier
|
Callable[[Any, str, int], Any]
|
Called as |
required |
Examples:
- Swap in a classifier of your own. :func:
temporary_classifieris the form to reach for: there is one classifier for the whole process, so a replacement that is not restored silently changes every later classification:
Source code in src/digitalearth/base/registry.py
digitalearth.base.registry.get_classifier()
#
Return the registered classifier.
Returns:
| Type | Description |
|---|---|
Callable[..., Any]
|
The function registered by :func: |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
if none is registered. That means |
Examples:
- Cut class edges with whatever is registered —
kclasses givek + 1edges:
Source code in src/digitalearth/base/registry.py
digitalearth.base.registry.temporary_classifier(classifier)
#
Swap the registered classifier for the duration of a block.
There is one classifier for the process, so replacing it without restoring leaves every later classification using the replacement. Where that happens inside a doctest it is worse than a wrong answer: the failure surfaces in some unrelated example further down the session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
classifier
|
Callable[..., Any]
|
The |
required |
Yields:
| Type | Description |
|---|---|
None
|
Nothing; the classifier is in effect inside the block. |
Examples:
- The swap applies inside and is undone after, even if the block raises:
>>> import digitalearth # registers the real adapter >>> from digitalearth.base.registry import get_classifier, temporary_classifier >>> real = get_classifier() >>> with temporary_classifier(lambda values, scheme, k: ([0.0, 0.5, 1.0], None)): ... get_classifier()([0.0], "anything", 2)[0] [0.0, 0.5, 1.0] >>> get_classifier() is real True