Load — geocatalog.load¶
Materialise the pixels a catalog covers on a GeoSlice: raster mosaics
(sync + async), daily time series, xarray cubes and vector layers.
Raster¶
geocatalog.load.load_raster(catalog, slice_, *, band_indexes=None, resampling=None, merge_method='last', nodata=None, retries=3, max_open_workers=8, storage_options=None)
¶
Read + mosaic the catalog rows matching slice_ into one GeoArray.
Filters the catalog with catalog.query(slice_), opens every
surviving row, and calls rasterio.merge.merge to produce a single
array clipped to slice_.bounds at slice_.resolution. The
returned geoarray.GeoArray is on the slice grid (slice_.grid),
ready for downstream operators.
Sources whose CRS differs from slice_.crs are warped on the fly
(rasterio.vrt.WarpedVRT with resampling), so the output is
always on the slice grid in the slice CRS, and files in different
CRSs mosaic together. Overlaps are resolved in catalog row order
(with merge_method="last", later rows win). The output dtype is
the common type of all sources.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catalog
|
InMemoryGeoCatalog
|
A raster-backend catalog. |
required |
slice_
|
GeoSlice
|
The window to read. Bounds may be in a different CRS than the catalog; the loader reprojects internally on the query. |
required |
band_indexes
|
Sequence[int] | None
|
1-indexed bands to keep, in the order requested.
|
None
|
resampling
|
Any | None
|
A |
None
|
merge_method
|
_RasterMergeMethod
|
How to combine overlapping pixels from multiple
source files. One of |
'last'
|
nodata
|
float | None
|
Override the nodata value used in the mosaic. |
None
|
retries
|
int
|
Number of retries for transient remote I/O failures.
|
3
|
max_open_workers
|
int
|
Thread-pool width for the file-open phase.
Remote (S3/HTTP) opens are latency-bound metadata round
trips and rasterio releases the GIL during them, so opening
concurrently cuts the open phase from |
8
|
storage_options
|
dict[str, Any] | None
|
obstore store options for cloud/HTTP URIs
(e.g. |
None
|
Returns:
| Type | Description |
|---|---|
GeoArray
|
A |
GeoArray
|
(its |
nodata value the mosaic actually used
|
|
GeoArray
|
else the first source nodata found, else 0 (what the mosaic |
GeoArray
|
writes where no source covers a pixel). Its dims are |
GeoArray
|
|
GeoArray
|
GeoTIFF band descriptions) the same way, those names are a |
GeoArray
|
|
Example
The hits of a query, mosaicked onto the slice grid::
scene = load_raster(catalog, slice_, band_indexes=[1, 2, 3])
scene.shape, scene.grid == slice_.grid # (3, H, W), True
Raises:
| Type | Description |
|---|---|
ValueError
|
If no catalog rows match the slice, if
|
TypeError
|
If the catalog's backend tag is not |
Source code in packages/geotoolz-catalog/src/geocatalog/_src/formats/raster.py
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 | |
geocatalog.load.aload_raster(catalog, slice_, *, band_indexes=None, resampling=None, merge_method='last', nodata=None, retries=3, max_open_workers=8, storage_options=None)
async
¶
Async mirror of load_raster for event-loop consumers.
Runs load_raster in a worker thread via asyncio.to_thread so the
event loop stays responsive during rasterio I/O (which releases the
GIL), with the file-open phase parallelised to max_open_workers
threads inside the worker. Same arguments and return value as
load_raster. (concurrency is the deprecated name of
max_open_workers; concurrency names the build strategy.)
Source code in packages/geotoolz-catalog/src/geocatalog/_src/formats/raster.py
geocatalog.load.load_raster_timeseries(catalog, slice_, *, band_indexes=None, resampling=None, nodata=None, n_workers=4, on_missing_day='skip', storage_options=None)
¶
Stack daily mosaics across the slice's interval into (time, b, h, w).
For each distinct day on which a matching row's time window begins
inside slice_.interval (a row that began earlier counts from the
slice start), runs load_raster for that day's sub-slice, clipped to
the slice interval, and stacks the results along a new leading time
axis in chronological order. Rows of time-invariant files (the
1900-2100 sentinel interval) create no step of their own but are
mosaicked into every step; if only such rows match, there is one
step at the slice start. By
default, days whose per-day load raises ValueError are dropped —
the time axis is the observed day count, not a dense calendar.
The transform / CRS come from the chronologically last successful
day's load (same for every day since the slice is fixed).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catalog
|
InMemoryGeoCatalog
|
A raster-backend catalog with at least one row in
|
required |
slice_
|
GeoSlice
|
Window to read for each day. The same |
required |
band_indexes
|
Sequence[int] | None
|
Forwarded to per-day |
None
|
resampling
|
Any | None
|
Forwarded to per-day |
None
|
nodata
|
float | None
|
Forwarded to per-day |
None
|
n_workers
|
int
|
Thread-pool size for per-day |
4
|
on_missing_day
|
Literal['skip', 'raise']
|
|
'skip'
|
Returns:
| Type | Description |
|---|---|
GeoArray
|
A |
GeoArray
|
grid, where |
GeoArray
|
its |
GeoArray
|
|
each step's start
|
the earliest matching row's time that day, |
GeoArray
|
clipped to the slice (the row's own time when a day has one row). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no catalog rows match the slice, or if every matching day failed to produce a usable mosaic. |
Source code in packages/geotoolz-catalog/src/geocatalog/_src/formats/raster.py
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 | |
Xarray (extras: [xarray-raster])¶
geocatalog.load.load_xarray(catalog, slice_, *, data_vars=None, storage_options=None)
¶
Load + concat the catalog rows matching slice_ into an xr.Dataset.
For each matching file, opens it inside a context manager, clips to
slice_.bounds along the spatial coords and to
slice_.interval along the time coord, .load()s the clipped
piece so the data persists after the file handle closes, and
concatenates the pieces along the time coordinate. Single-file
results skip the concat.
The time-clip is what makes this loader honest for files that span many years — without it, a query for one month against a multi-year NetCDF would return every timestep in the file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catalog
|
InMemoryGeoCatalog
|
An xarray-backend catalog. |
required |
slice_
|
GeoSlice
|
Window to read. Bounds may be in a different CRS than the catalog; they are reprojected into the catalog CRS for both the row query and the coordinate selection. Ascending and descending coordinate axes are both handled. |
required |
data_vars
|
Sequence[str] | None
|
Subset of data variables to keep per file. |
None
|
Returns:
| Type | Description |
|---|---|
Dataset
|
An |
Dataset
|
duplicate timesteps dropped), or a single-file Dataset if only |
Dataset
|
one row matched. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If xarray is not installed ( |
TypeError
|
If the catalog's backend tag is not |
ValueError
|
If no catalog rows match the slice. |
Source code in packages/geotoolz-catalog/src/geocatalog/_src/formats/xarray_backend.py
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 | |
Vector¶
geocatalog.load.load_vector(catalog, slice_, *, task='semantic_segmentation', label_field=None, burn_value=None, fill=0, storage_options=None, retries=3)
¶
Rasterise the catalog's vector rows matching slice_ into a GeoArray.
Filters the catalog with catalog.query(slice_), opens every
matching vector file, clips its features to slice_.bounds (in
slice_.crs), and burns them into a single-channel int64 raster
via rasterio.features.rasterize. The output's transform / CRS
come straight from slice_, so the result aligns pixel-for-pixel
with whatever the matching imagery loader produces for the same
slice.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catalog
|
InMemoryGeoCatalog
|
A vector-backend catalog. |
required |
slice_
|
GeoSlice
|
Window to rasterise into. The result is on
|
required |
task
|
_VectorTask
|
Which ML target shape to produce:
|
'semantic_segmentation'
|
label_field
|
str | None
|
Column in the vector file to read class IDs from
for |
None
|
burn_value
|
int | None
|
The value burnt in for |
None
|
fill
|
int
|
Background value written outside any feature, and the
result's |
0
|
storage_options
|
dict[str, Any] | None
|
obstore store options for cloud/HTTP URIs, read
through |
None
|
retries
|
int
|
Retries for transient I/O failures per file open. |
3
|
Returns:
| Type | Description |
|---|---|
A `GeoMap`
|
a |
GeoArray
|
|
GeoArray
|
equals |
GeoArray
|
labels is a map, not an image, so there is no band axis. |
Example
Class labels aligned with the imagery of the same slice::
labels = load_vector(catalog, slice_, label_field="class_id")
labels.shape, labels.grid == slice_.grid # (H, W), True
Raises:
| Type | Description |
|---|---|
TypeError
|
If the catalog's backend tag is not |
NotImplementedError
|
For |
ValueError
|
If no catalog rows match the slice. |
Source code in packages/geotoolz-catalog/src/geocatalog/_src/formats/vector.py
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 | |