WorldPop — API reference#
WorldPop open population data hub source subpackage —
earthlens.worldpop. Background, usage, the available product/sub-alias
matrix, and the optional WorldPopPy path are covered under the other pages
in this section; this page is the rendered API.
earthlens.worldpop
#
WorldPop backend — open population data hub over anonymous HTTPS.
earthlens.worldpop wraps the WorldPop open population data hub
(hub.worldpop.org): global gridded population counts, density, age/sex
structures, births, pregnancies, dependency ratios, urban change,
built-settlement growth, and forward projections — per country (ISO3) and
as global mosaics, at 100 m / 1 km, in constrained and unconstrained
variants. A request is an AOI (ISO3 / bbox / GeoDataFrame) + time window +
a list of WorldPop product aliases; the backend queries the WorldPop REST
API for the matching GeoTIFF URLs, downloads them over anonymous HTTPS, and
uses pyramids to mosaic + crop to the AOI — writing population GeoTIFFs
and, for demographic products, a tidy age/sex table. OUTPUT_KIND="mixed".
The provider is open + CC-BY-4.0, so WorldPopAuth is a no-op kept for
conformance with the package's AbstractAuth shape. The default REST path
needs only the core dependencies; the optional WorldPopPy path imports
worldpoppy lazily (consuming only its file cache, never its xarray
return), so the package imports without the [worldpop] extra.
AuthenticationError
#
Bases: Exception
Raised when a backend cannot establish an authenticated session.
Subclasses re-raise this with backend-specific context (missing
~/.cdsapirc, unregistered Earth Engine project, expired CDSE
token, missing Earthdata Login). Every backend's auth class
catches the underlying SDK / HTTP exception and wraps it with
an actionable message — never propagates a raw
cdsapi.api.Exception or ee.EEException to the user.
The class is intentionally a flat Exception subclass and not
ConnectionError because half the failure modes are not
network errors (no credentials at all, malformed key file,
misconfigured project IAM). Callers should catch
AuthenticationError directly rather than its causes.
Examples:
- The error preserves its constructor message:
- Catch every backend's auth failure with one clause:
Source code in src/earthlens/base/auth.py
Catalog
#
Bases: AbstractCatalog
Product / sub-alias availability catalog for the WorldPop backend.
Reads the bundled worldpop_data_catalog.yaml and exposes its
products: block as a map of Product rows keyed by canonical alias
under the inherited datasets field (giving cat["pop"], "pop" in
cat, len(cat), and the did-you-mean error for free). Instantiate
with no arguments (Catalog()); model_post_init loads and validates
the YAML.
Attributes:
| Name | Type | Description |
|---|---|---|
datasets |
dict[str, Product]
|
Map from canonical product alias to its |
available_datasets |
list[str]
|
Every curated product alias, sorted. |
Source code in src/earthlens/worldpop/catalog.py
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 | |
describe(product)
#
Return a structured introspection record for a product.
Mirrors earthlens.ecmwf.Catalog.describe / the tropycal catalog: a
runtime "what does product X expose?" helper a CLI / notebook can
dump without walking the YAML.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
product
|
str
|
A product key or friendly alias (resolved first). |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Keys |
dict[str, Any]
|
|
dict[str, Any]
|
per-variant dicts with |
dict[str, Any]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
- Describe the population product at a glance:
Source code in src/earthlens/worldpop/catalog.py
get(alias)
#
Return the Product for a canonical alias, did-you-mean on miss.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alias
|
str
|
A canonical product alias ( |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Product |
Product
|
The matching row. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/earthlens/worldpop/catalog.py
health()
#
Report structural hygiene issues across the loaded catalog.
Mirrors earthlens.ecmwf.Catalog.health / earthlens.gee.Catalog.health:
returns a mapping check_name -> sorted list of offenders. An empty
list means the check passes. Schema-level invariants (duplicate keys,
unknown fields) are already enforced at load time — these are the
residual data-quality checks the pydantic schema cannot express.
Checks reported:
product_without_subaliases— products carrying zero sub-aliases.demographic_not_mixed— products flaggeddemographicwhosekindis not"mixed".subalias_unknown_generation—"<product>:<id>"whosegenerationis not inGENERATIONS.subalias_bad_years—"<product>:<id>"whoseyearsspec does not parse.
Returns:
| Type | Description |
|---|---|
dict[str, list[str]]
|
dict[str, list[str]]: The per-check offender lists. |
Examples:
- The bundled catalog is clean:
Source code in src/earthlens/worldpop/catalog.py
load(catalog_path=None)
classmethod
#
Read the WorldPop product catalog from disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catalog_path
|
Path | None
|
Path to the catalog YAML. Defaults to the
module-level |
None
|
Returns:
| Type | Description |
|---|---|
Catalog
|
A fully-populated |
Catalog
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the file has no |
Source code in src/earthlens/worldpop/catalog.py
model_post_init(__context)
#
Auto-load the bundled catalog when no products were supplied.
Catalog() with no args reads CATALOG_PATH; passing
datasets=... skips the disk read (used in tests).
Raises:
| Type | Description |
|---|---|
ValueError
|
Propagated from |
Source code in src/earthlens/worldpop/catalog.py
pick_subalias(product, *, constrained=False, unadjusted=True, resolution='100m', scope='countries', generation='R2021', level='national')
#
Resolve the selector kwargs to a single REST sub-alias id.
A product with exactly one sub-alias (births, urban_change, …)
returns it directly — the selector kwargs do not apply, since there
is only one variant. As a guard against a silently-ignored request,
a resolution that differs from the sole sub-alias's resolution
emits a UserWarning (the other selectors are product-intrinsic for
single-variant products and are not warned on). Otherwise the kwargs
must match one sub-alias's
(constrained, unadjusted, resolution, scope, generation, level)
tuple exactly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
product
|
str
|
A product key or alias (resolved first). |
required |
constrained
|
bool
|
Settlement-masked variant ( |
False
|
unadjusted
|
bool
|
Raw ( |
True
|
resolution
|
str
|
|
'100m'
|
scope
|
str
|
|
'countries'
|
generation
|
str
|
One of |
'R2021'
|
level
|
str
|
|
'national'
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The matching sub-alias id (e.g. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no sub-alias matches the selector; the message lists the product's available sub-alias tuples. |
Examples:
- The classic unconstrained 100 m country series resolves to
wpgp:
Source code in src/earthlens/worldpop/catalog.py
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 | |
resolve(key)
#
Resolve a product key or friendly alias to its canonical alias.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
A canonical alias ( |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The canonical product alias. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
- A friendly alias and a canonical key both resolve:
Source code in src/earthlens/worldpop/catalog.py
subalias(product, subalias_id)
#
Return the SubAlias row of a product by its REST id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
product
|
str
|
A product key or alias (resolved first). |
required |
subalias_id
|
str
|
A sub-alias id belonging to that product. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
SubAlias |
SubAlias
|
The matching sub-alias row. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
- Look up a sub-alias and read its scope / resolution:
Source code in src/earthlens/worldpop/catalog.py
validate(product, *, constrained=False, unadjusted=True, resolution='100m', scope='countries', generation='R2021', level='national', year=None)
#
Validate a full request and return (product, subalias_id).
Resolves the product, picks the sub-alias from the selectors, and —
when year is given — checks the sub-alias offers it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
product
|
str
|
A product key or alias. |
required |
constrained
|
bool
|
See |
False
|
unadjusted
|
bool
|
See |
True
|
resolution
|
str
|
See |
'100m'
|
scope
|
str
|
See |
'countries'
|
generation
|
str
|
See |
'R2021'
|
level
|
str
|
See |
'national'
|
year
|
int | None
|
Optional year to check against the sub-alias's |
None
|
Returns:
| Type | Description |
|---|---|
tuple[str, str]
|
tuple[str, str]: The canonical |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the selector matches no sub-alias, or |
Source code in src/earthlens/worldpop/catalog.py
Product
#
Bases: BaseModel
One curated WorldPop product family (a top-level REST alias).
Attributes:
| Name | Type | Description |
|---|---|---|
alias |
str
|
Canonical product alias ( |
friendly |
list[str]
|
Friendly names that also resolve to this product
( |
kind |
str
|
|
demographic |
bool
|
Whether the product ships per-cohort age/sex rasters
that earthlens tabularises (only |
unit |
str
|
Human-readable unit of the values ( |
worldpoppy_id |
str | None
|
The matching WorldPopPy product id for the optional
|
rest_alias |
str
|
The top-level REST alias to query when it differs from
the catalog key. Empty (the default) means "use the key". The
covariate products set this to |
description |
str
|
Human-readable description of the product (the hub's
title), shown in docs / |
subaliases |
list[SubAlias]
|
The concrete variants this product offers. |
Source code in src/earthlens/worldpop/catalog.py
selectors()
#
Return every sub-alias selector tuple (for did-you-mean listings).
SubAlias
#
Bases: BaseModel
One concrete WorldPop variant under a product alias.
Maps the selector tuple (constrained, unadjusted, resolution, scope,
generation) to a REST sub-alias id and the years it offers. The tuple
is unique within a product, so Catalog.pick_subalias can resolve a
request to exactly one sub-alias.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
The real REST sub-alias id ( |
constrained |
bool
|
Whether this is the settlement-masked constrained
variant ( |
unadjusted |
bool
|
|
resolution |
str
|
Pixel size — |
scope |
str
|
|
generation |
str
|
The product generation ( |
level |
str
|
Aggregation level for products that publish both
( |
archive |
str
|
The archive format the product is distributed in, or |
years |
str
|
The years this sub-alias offers, as a single year
( |
Source code in src/earthlens/worldpop/catalog.py
selector()
#
Return the selector key.
The key is (constrained, unadjusted, resolution, scope, generation,
level) — unique within a product.
Source code in src/earthlens/worldpop/catalog.py
WorldPop
#
Bases: AbstractDataSource
Download WorldPop population + demographic products, localised via pyramids.
Attributes:
| Name | Type | Description |
|---|---|---|
OUTPUT_KIND |
OutputKind
|
Fixed |
Source code in src/earthlens/worldpop/backend.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 | |
__init__(start, end, variables, lat_lim, lon_lim, temporal_resolution='yearly', path='', fmt='%Y-%m-%d', *, aoi=None, constrained=False, unadjusted=True, resolution='100m', scope='countries', generation='R2021', level='national', year=None, years=None, crs='EPSG:4326', api='rest', ssp='SSP2', allow_large_archive=False, catalog=None)
#
Initialise a WorldPop backend instance.
Resolves and statically validates every requested product +
sub-alias selector against the catalog before the parent
constructor runs (the parent calls _initialize first). The AOI is
resolved to a set of ISO3 codes here too, since _initialize
receives no bbox.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
str
|
Inclusive start of the date window (parsed with |
required |
end
|
str
|
Inclusive end of the date window. |
required |
variables
|
list[str]
|
WorldPop product keys — canonical ( |
required |
lat_lim
|
list[float]
|
|
required |
lon_lim
|
list[float]
|
|
required |
temporal_resolution
|
str
|
Advisory label only (WorldPop years are
annual points); accepted for facade parity. Defaults to
|
'yearly'
|
path
|
Path | str
|
Output directory. Created by the parent class. |
''
|
fmt
|
str
|
|
'%Y-%m-%d'
|
aoi
|
str | list[str] | list[float] | object | None
|
Explicit AOI — an ISO3 string, a list of ISO3 strings, a
|
None
|
constrained
|
bool
|
Settlement-masked constrained variant ( |
False
|
unadjusted
|
bool
|
Raw variant ( |
True
|
resolution
|
str
|
|
'100m'
|
scope
|
str
|
|
'countries'
|
generation
|
str
|
Product generation — |
'R2021'
|
level
|
str
|
|
'national'
|
year
|
int | None
|
A single year to fetch (overrides the date window). |
None
|
years
|
list[int] | None
|
An explicit list of years (overrides the date window
and |
None
|
crs
|
str
|
Output CRS as an EPSG string / code (default
|
'EPSG:4326'
|
api
|
str
|
Access path — |
'rest'
|
ssp
|
str
|
SSP scenario for the |
'SSP2'
|
allow_large_archive
|
bool
|
Opt-in required to download the multi-GB
|
False
|
catalog
|
Catalog | None
|
Optional pre-built |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
ImportError
|
When |
Source code in src/earthlens/worldpop/backend.py
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 | |
download(progress_bar=True, aggregate=None)
#
Fetch the requested products as AOI-cropped GeoTIFFs (+ tables).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
progress_bar
|
bool
|
Whether per-download progress is shown. |
True
|
aggregate
|
Optional |
None
|
Returns:
| Type | Description |
|---|---|
list[Path]
|
list[Path]: The written GeoTIFF / table paths. |
Source code in src/earthlens/worldpop/backend.py
WorldPopAuth
#
Bases: AbstractAuth[WorldPopCredentials]
No-op auth for the open, attribution-only WorldPop data.
Kept for conformance with the AbstractAuth shape the other
backends follow; WorldPop reads no credentials. configure()
flips an internal flag and is_authenticated() is always
True, so the context-manager form (with WorldPopAuth() as
auth: ...) works like any other backend's.
Examples:
- It is always authenticated, with nothing to configure:
Source code in src/earthlens/worldpop/auth.py
__init__(credentials=None)
#
Store the (empty) credentials; default to a fresh WorldPopCredentials.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
credentials
|
WorldPopCredentials | None
|
Optional empty credentials object. Defaults to a
fresh |
None
|
Source code in src/earthlens/worldpop/auth.py
WorldPopCredentials
#
Bases: BaseModel
Empty credentials value object for the open WorldPop backend.
WorldPop needs no secrets; this exists only to satisfy the
earthlens.base.auth.AbstractAuth generic contract that every
backend's auth class binds a pydantic.BaseModel credentials
type. It carries no fields.
Examples:
- Construct the empty credentials:
Source code in src/earthlens/worldpop/auth.py
clear_catalog_cache()
#
Empty the module-level product parse cache.
Useful in tests that rewrite the catalog on disk and want to force a
re-parse. Production callers do not need this — the cache key includes
st_mtime_ns, so any real file mutation invalidates the entry on its
own.
Source code in src/earthlens/worldpop/catalog.py
earthlens.worldpop.backend
#
WorldPop backend — open population data hub over anonymous HTTPS.
WorldPop is a download-and-localise backend (OUTPUT_KIND="mixed"). A
request is an AOI (ISO3 / bbox / GeoDataFrame) + time window + a list of
WorldPop product aliases (variables=["pop", ...], canonical or
friendly) plus constrained / unadjusted / resolution / scope /
generation / year(s) / crs / api selectors. The backend resolves
each product to a concrete REST sub-alias against the bundled catalog,
queries the WorldPop REST API for the matching per-country GeoTIFF URLs,
downloads them over anonymous HTTPS, and uses pyramids to mosaic + crop
(and reproject only when crs != 4326) — writing population GeoTIFFs and,
for demographic products (age_structures), per-cohort rasters plus a tidy
age/sex table.
The provider is open, CC-BY-4.0 — no credentials (see
earthlens.worldpop.auth). The default api="rest" path needs only the
core dependencies (requests + pyramids); the optional
api="worldpoppy" path imports worldpoppy lazily and consumes only its
file cache (never its xarray return), so the package imports without
the [worldpop] extra.
WorldPop
#
Bases: AbstractDataSource
Download WorldPop population + demographic products, localised via pyramids.
Attributes:
| Name | Type | Description |
|---|---|---|
OUTPUT_KIND |
OutputKind
|
Fixed |
Source code in src/earthlens/worldpop/backend.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 | |
__init__(start, end, variables, lat_lim, lon_lim, temporal_resolution='yearly', path='', fmt='%Y-%m-%d', *, aoi=None, constrained=False, unadjusted=True, resolution='100m', scope='countries', generation='R2021', level='national', year=None, years=None, crs='EPSG:4326', api='rest', ssp='SSP2', allow_large_archive=False, catalog=None)
#
Initialise a WorldPop backend instance.
Resolves and statically validates every requested product +
sub-alias selector against the catalog before the parent
constructor runs (the parent calls _initialize first). The AOI is
resolved to a set of ISO3 codes here too, since _initialize
receives no bbox.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
str
|
Inclusive start of the date window (parsed with |
required |
end
|
str
|
Inclusive end of the date window. |
required |
variables
|
list[str]
|
WorldPop product keys — canonical ( |
required |
lat_lim
|
list[float]
|
|
required |
lon_lim
|
list[float]
|
|
required |
temporal_resolution
|
str
|
Advisory label only (WorldPop years are
annual points); accepted for facade parity. Defaults to
|
'yearly'
|
path
|
Path | str
|
Output directory. Created by the parent class. |
''
|
fmt
|
str
|
|
'%Y-%m-%d'
|
aoi
|
str | list[str] | list[float] | object | None
|
Explicit AOI — an ISO3 string, a list of ISO3 strings, a
|
None
|
constrained
|
bool
|
Settlement-masked constrained variant ( |
False
|
unadjusted
|
bool
|
Raw variant ( |
True
|
resolution
|
str
|
|
'100m'
|
scope
|
str
|
|
'countries'
|
generation
|
str
|
Product generation — |
'R2021'
|
level
|
str
|
|
'national'
|
year
|
int | None
|
A single year to fetch (overrides the date window). |
None
|
years
|
list[int] | None
|
An explicit list of years (overrides the date window
and |
None
|
crs
|
str
|
Output CRS as an EPSG string / code (default
|
'EPSG:4326'
|
api
|
str
|
Access path — |
'rest'
|
ssp
|
str
|
SSP scenario for the |
'SSP2'
|
allow_large_archive
|
bool
|
Opt-in required to download the multi-GB
|
False
|
catalog
|
Catalog | None
|
Optional pre-built |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
ImportError
|
When |
Source code in src/earthlens/worldpop/backend.py
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 | |
download(progress_bar=True, aggregate=None)
#
Fetch the requested products as AOI-cropped GeoTIFFs (+ tables).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
progress_bar
|
bool
|
Whether per-download progress is shown. |
True
|
aggregate
|
Optional |
None
|
Returns:
| Type | Description |
|---|---|
list[Path]
|
list[Path]: The written GeoTIFF / table paths. |
Source code in src/earthlens/worldpop/backend.py
earthlens.worldpop.catalog
#
Product / sub-alias / availability catalog for the WorldPop backend.
The WorldPop hub exposes a three-level REST scheme: a top-level product
alias (pop, age_structures, births, …), each with a set of
sub-aliases that pin a concrete variant (constrained vs unconstrained,
100 m vs 1 km, per-country vs global mosaic, and the product generation —
the classic R2021 line vs the newer Global-2 G2_* lines). A sub-alias
maps to a …/{alias}/{subalias} REST path that lists one GeoTIFF record
per year.
That matrix is small and slow-changing, so it is curated as config-as-code
in the bundled worldpop_data_catalog.yaml and validated here against typed
pydantic rows. A request names one or more product keys — canonical
("pop") or a friendly alias ("population") — plus
constrained / unadjusted / resolution / scope / generation
selectors; Catalog.resolve maps an alias to its canonical product and
Catalog.pick_subalias resolves the selectors to a single sub-alias id,
raising a ValueError that lists the valid options for the product when no
sub-alias matches (did-you-mean).
Catalog
#
Bases: AbstractCatalog
Product / sub-alias availability catalog for the WorldPop backend.
Reads the bundled worldpop_data_catalog.yaml and exposes its
products: block as a map of Product rows keyed by canonical alias
under the inherited datasets field (giving cat["pop"], "pop" in
cat, len(cat), and the did-you-mean error for free). Instantiate
with no arguments (Catalog()); model_post_init loads and validates
the YAML.
Attributes:
| Name | Type | Description |
|---|---|---|
datasets |
dict[str, Product]
|
Map from canonical product alias to its |
available_datasets |
list[str]
|
Every curated product alias, sorted. |
Source code in src/earthlens/worldpop/catalog.py
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 | |
describe(product)
#
Return a structured introspection record for a product.
Mirrors earthlens.ecmwf.Catalog.describe / the tropycal catalog: a
runtime "what does product X expose?" helper a CLI / notebook can
dump without walking the YAML.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
product
|
str
|
A product key or friendly alias (resolved first). |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Keys |
dict[str, Any]
|
|
dict[str, Any]
|
per-variant dicts with |
dict[str, Any]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
- Describe the population product at a glance:
Source code in src/earthlens/worldpop/catalog.py
get(alias)
#
Return the Product for a canonical alias, did-you-mean on miss.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alias
|
str
|
A canonical product alias ( |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Product |
Product
|
The matching row. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/earthlens/worldpop/catalog.py
health()
#
Report structural hygiene issues across the loaded catalog.
Mirrors earthlens.ecmwf.Catalog.health / earthlens.gee.Catalog.health:
returns a mapping check_name -> sorted list of offenders. An empty
list means the check passes. Schema-level invariants (duplicate keys,
unknown fields) are already enforced at load time — these are the
residual data-quality checks the pydantic schema cannot express.
Checks reported:
product_without_subaliases— products carrying zero sub-aliases.demographic_not_mixed— products flaggeddemographicwhosekindis not"mixed".subalias_unknown_generation—"<product>:<id>"whosegenerationis not inGENERATIONS.subalias_bad_years—"<product>:<id>"whoseyearsspec does not parse.
Returns:
| Type | Description |
|---|---|
dict[str, list[str]]
|
dict[str, list[str]]: The per-check offender lists. |
Examples:
- The bundled catalog is clean:
Source code in src/earthlens/worldpop/catalog.py
load(catalog_path=None)
classmethod
#
Read the WorldPop product catalog from disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catalog_path
|
Path | None
|
Path to the catalog YAML. Defaults to the
module-level |
None
|
Returns:
| Type | Description |
|---|---|
Catalog
|
A fully-populated |
Catalog
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the file has no |
Source code in src/earthlens/worldpop/catalog.py
model_post_init(__context)
#
Auto-load the bundled catalog when no products were supplied.
Catalog() with no args reads CATALOG_PATH; passing
datasets=... skips the disk read (used in tests).
Raises:
| Type | Description |
|---|---|
ValueError
|
Propagated from |
Source code in src/earthlens/worldpop/catalog.py
pick_subalias(product, *, constrained=False, unadjusted=True, resolution='100m', scope='countries', generation='R2021', level='national')
#
Resolve the selector kwargs to a single REST sub-alias id.
A product with exactly one sub-alias (births, urban_change, …)
returns it directly — the selector kwargs do not apply, since there
is only one variant. As a guard against a silently-ignored request,
a resolution that differs from the sole sub-alias's resolution
emits a UserWarning (the other selectors are product-intrinsic for
single-variant products and are not warned on). Otherwise the kwargs
must match one sub-alias's
(constrained, unadjusted, resolution, scope, generation, level)
tuple exactly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
product
|
str
|
A product key or alias (resolved first). |
required |
constrained
|
bool
|
Settlement-masked variant ( |
False
|
unadjusted
|
bool
|
Raw ( |
True
|
resolution
|
str
|
|
'100m'
|
scope
|
str
|
|
'countries'
|
generation
|
str
|
One of |
'R2021'
|
level
|
str
|
|
'national'
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The matching sub-alias id (e.g. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no sub-alias matches the selector; the message lists the product's available sub-alias tuples. |
Examples:
- The classic unconstrained 100 m country series resolves to
wpgp:
Source code in src/earthlens/worldpop/catalog.py
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 | |
resolve(key)
#
Resolve a product key or friendly alias to its canonical alias.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
A canonical alias ( |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The canonical product alias. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
- A friendly alias and a canonical key both resolve:
Source code in src/earthlens/worldpop/catalog.py
subalias(product, subalias_id)
#
Return the SubAlias row of a product by its REST id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
product
|
str
|
A product key or alias (resolved first). |
required |
subalias_id
|
str
|
A sub-alias id belonging to that product. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
SubAlias |
SubAlias
|
The matching sub-alias row. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
- Look up a sub-alias and read its scope / resolution:
Source code in src/earthlens/worldpop/catalog.py
validate(product, *, constrained=False, unadjusted=True, resolution='100m', scope='countries', generation='R2021', level='national', year=None)
#
Validate a full request and return (product, subalias_id).
Resolves the product, picks the sub-alias from the selectors, and —
when year is given — checks the sub-alias offers it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
product
|
str
|
A product key or alias. |
required |
constrained
|
bool
|
See |
False
|
unadjusted
|
bool
|
See |
True
|
resolution
|
str
|
See |
'100m'
|
scope
|
str
|
See |
'countries'
|
generation
|
str
|
See |
'R2021'
|
level
|
str
|
See |
'national'
|
year
|
int | None
|
Optional year to check against the sub-alias's |
None
|
Returns:
| Type | Description |
|---|---|
tuple[str, str]
|
tuple[str, str]: The canonical |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the selector matches no sub-alias, or |
Source code in src/earthlens/worldpop/catalog.py
Product
#
Bases: BaseModel
One curated WorldPop product family (a top-level REST alias).
Attributes:
| Name | Type | Description |
|---|---|---|
alias |
str
|
Canonical product alias ( |
friendly |
list[str]
|
Friendly names that also resolve to this product
( |
kind |
str
|
|
demographic |
bool
|
Whether the product ships per-cohort age/sex rasters
that earthlens tabularises (only |
unit |
str
|
Human-readable unit of the values ( |
worldpoppy_id |
str | None
|
The matching WorldPopPy product id for the optional
|
rest_alias |
str
|
The top-level REST alias to query when it differs from
the catalog key. Empty (the default) means "use the key". The
covariate products set this to |
description |
str
|
Human-readable description of the product (the hub's
title), shown in docs / |
subaliases |
list[SubAlias]
|
The concrete variants this product offers. |
Source code in src/earthlens/worldpop/catalog.py
selectors()
#
Return every sub-alias selector tuple (for did-you-mean listings).
SubAlias
#
Bases: BaseModel
One concrete WorldPop variant under a product alias.
Maps the selector tuple (constrained, unadjusted, resolution, scope,
generation) to a REST sub-alias id and the years it offers. The tuple
is unique within a product, so Catalog.pick_subalias can resolve a
request to exactly one sub-alias.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
The real REST sub-alias id ( |
constrained |
bool
|
Whether this is the settlement-masked constrained
variant ( |
unadjusted |
bool
|
|
resolution |
str
|
Pixel size — |
scope |
str
|
|
generation |
str
|
The product generation ( |
level |
str
|
Aggregation level for products that publish both
( |
archive |
str
|
The archive format the product is distributed in, or |
years |
str
|
The years this sub-alias offers, as a single year
( |
Source code in src/earthlens/worldpop/catalog.py
selector()
#
Return the selector key.
The key is (constrained, unadjusted, resolution, scope, generation,
level) — unique within a product.
Source code in src/earthlens/worldpop/catalog.py
clear_catalog_cache()
#
Empty the module-level product parse cache.
Useful in tests that rewrite the catalog on disk and want to force a
re-parse. Production callers do not need this — the cache key includes
st_mtime_ns, so any real file mutation invalidates the entry on its
own.
Source code in src/earthlens/worldpop/catalog.py
earthlens.worldpop.rest
#
WorldPop REST query layer.
Thin requests-based client over hub.worldpop.org/rest/data. The hub's
three-level scheme is: /rest/data (product aliases) →
/rest/data/{alias} (sub-aliases) → /rest/data/{alias}/{subalias}?iso3=…
(one JSON record per year, each carrying a files array of GeoTIFF URLs).
Year filtering is client-side on popyear — the query returns every
year for the (alias, subalias, iso3) triple, so the caller picks the
record whose popyear matches.
files_for_year(records, year)
#
Return the GeoTIFF URLs for the record whose popyear matches year.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
records
|
list[dict[str, Any]]
|
The list returned by |
required |
year
|
int | None
|
The wanted year. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: The matching record's GeoTIFF URLs (one for plain
population products; many — one per age/sex cohort — for
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/earthlens/worldpop/rest.py
global_files_for_year(alias, subalias_id, year, *, base_url=BASE_URL, session=None, timeout=_TIMEOUT)
#
Return the global GeoTIFF URLs for one (alias, subalias, year).
Lists the global records, picks the one whose popyear matches year
(or the latest when year is None), then resolves its files via the
?id= detail endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alias
|
str
|
Top-level product alias. |
required |
subalias_id
|
str
|
A global-scope sub-alias id. |
required |
year
|
int | None
|
The wanted year, or |
required |
base_url
|
str
|
REST base URL (overridable for tests). |
BASE_URL
|
session
|
Session | None
|
Optional |
None
|
timeout
|
int
|
Per-request timeout in seconds. |
_TIMEOUT
|
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: The matching record's GeoTIFF URLs (one global mosaic for
plain population; one per age/sex cohort for |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no records exist, the year is unavailable, or the matched record carries no GeoTIFF (e.g. an archive-only product). |
Source code in src/earthlens/worldpop/rest.py
global_records(alias, subalias_id, *, base_url=BASE_URL, session=None, timeout=_TIMEOUT)
#
Return the index records for a global / non-ISO3 sub-alias.
Global mosaics (wpgp1km, aswpgponekm, …) are queried without
iso3. The listing carries one summary record per popyear (id,
popyear, title) but no files — fetch those per record via
record_files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alias
|
str
|
Top-level product alias ( |
required |
subalias_id
|
str
|
A global-scope sub-alias id ( |
required |
base_url
|
str
|
REST base URL (overridable for tests). |
BASE_URL
|
session
|
Session | None
|
Optional |
None
|
timeout
|
int
|
Per-request timeout in seconds. |
_TIMEOUT
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
list[dict]: The |
Raises:
| Type | Description |
|---|---|
HTTPError
|
If the endpoint returns a non-2xx status. |
Source code in src/earthlens/worldpop/rest.py
record_archive_files(alias, subalias_id, record_id, fmt, *, base_url=BASE_URL, session=None, timeout=_TIMEOUT)
#
Return a record's archive URLs (.zip / .7z) via the ?id= detail.
The archive products (future_pop per-SSP .zip, dependency_ratios
per-continent .7z) carry their downloads as archives, not GeoTIFFs;
this returns the URLs ending in .{fmt}.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alias
|
str
|
Top-level product alias. |
required |
subalias_id
|
str
|
The sub-alias id. |
required |
record_id
|
str
|
The |
required |
fmt
|
str
|
Archive extension to keep — |
required |
base_url
|
str
|
REST base URL (overridable for tests). |
BASE_URL
|
session
|
Session | None
|
Optional |
None
|
timeout
|
int
|
Per-request timeout in seconds. |
_TIMEOUT
|
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: The record's archive URLs ending in |
Raises:
| Type | Description |
|---|---|
HTTPError
|
If the endpoint returns a non-2xx status. |
Source code in src/earthlens/worldpop/rest.py
record_citation(records)
#
Return the citation of the first record, or None if absent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
records
|
list[dict[str, Any]]
|
The list returned by |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: The CC-BY-4.0 citation text WorldPop attaches to the dataset, used to stamp output sidecars. |
Source code in src/earthlens/worldpop/rest.py
record_files(alias, subalias_id, record_id, *, base_url=BASE_URL, session=None, timeout=_TIMEOUT)
#
Return the GeoTIFF URLs of one record via the ?id= detail endpoint.
The summary listing omits files; querying ?id={record_id} returns the
full record (a dict) whose files array holds the download URLs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alias
|
str
|
Top-level product alias. |
required |
subalias_id
|
str
|
The sub-alias id. |
required |
record_id
|
str
|
The |
required |
base_url
|
str
|
REST base URL (overridable for tests). |
BASE_URL
|
session
|
Session | None
|
Optional |
None
|
timeout
|
int
|
Per-request timeout in seconds. |
_TIMEOUT
|
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: The record's GeoTIFF URLs (non-raster entries — e.g. the
|
Raises:
| Type | Description |
|---|---|
HTTPError
|
If the endpoint returns a non-2xx status. |
Source code in src/earthlens/worldpop/rest.py
rest_records(alias, subalias_id, iso3, *, base_url=BASE_URL, session=None, timeout=_TIMEOUT)
#
Return the WorldPop records for one (alias, subalias, iso3) triple.
The endpoint returns every year as one record each; year filtering
happens client-side in files_for_year.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alias
|
str
|
Top-level product alias ( |
required |
subalias_id
|
str
|
The concrete REST sub-alias id ( |
required |
iso3
|
str
|
An ISO 3166-1 alpha-3 country code. |
required |
base_url
|
str
|
REST base URL (overridable for tests). |
BASE_URL
|
session
|
Session | None
|
Optional |
None
|
timeout
|
int
|
Per-request timeout in seconds. |
_TIMEOUT
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
list[dict]: The |
Raises:
| Type | Description |
|---|---|
HTTPError
|
If the endpoint returns a non-2xx status. |
Source code in src/earthlens/worldpop/rest.py
earthlens.worldpop.auth
#
Authentication placeholder for the WorldPop backend.
The WorldPop open population data hub (hub.worldpop.org) is open
data, attribution only — every dataset is licensed CC-BY-4.0 and
served over plain anonymous HTTPS from data.worldpop.org, so
WorldPop performs no login:
earthlens.worldpop.backend.WorldPop._initialize reads no credentials
and the backend works with no key, env var, or config file.
WorldPopAuth exists so the package mirrors the layout of the
authenticated backends (each has an auth.py with an AbstractAuth
subclass). It is a no-op: configure() does nothing and
is_authenticated() is always True. It carries the required
attribution string so the backend can stamp it into output
metadata / a sidecar.
WorldPopAuth
#
Bases: AbstractAuth[WorldPopCredentials]
No-op auth for the open, attribution-only WorldPop data.
Kept for conformance with the AbstractAuth shape the other
backends follow; WorldPop reads no credentials. configure()
flips an internal flag and is_authenticated() is always
True, so the context-manager form (with WorldPopAuth() as
auth: ...) works like any other backend's.
Examples:
- It is always authenticated, with nothing to configure:
Source code in src/earthlens/worldpop/auth.py
__init__(credentials=None)
#
Store the (empty) credentials; default to a fresh WorldPopCredentials.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
credentials
|
WorldPopCredentials | None
|
Optional empty credentials object. Defaults to a
fresh |
None
|
Source code in src/earthlens/worldpop/auth.py
WorldPopCredentials
#
Bases: BaseModel
Empty credentials value object for the open WorldPop backend.
WorldPop needs no secrets; this exists only to satisfy the
earthlens.base.auth.AbstractAuth generic contract that every
backend's auth class binds a pydantic.BaseModel credentials
type. It carries no fields.
Examples:
- Construct the empty credentials: