API Reference
Core Modules
IO Module
Input/Output module for ShallowLearn. Handles loading and writing satellite data with VRT generation and metadata preservation.
GeoTIFFCollection
Collection manager for multiple GeoTIFF files.
Useful for handling datasets like Planetscope with multiple single-band files or collections of classification/analysis results.
Source code in ShallowLearn/io/satellite_data.py
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 | |
__getitem__(index)
Get image by index, loading if necessary.
Source code in ShallowLearn/io/satellite_data.py
__init__(directory, pattern='*.tif')
Initialize collection from directory.
Parameters:
directory : str Directory containing GeoTIFF files pattern : str, default "*.tif" Glob pattern to match files
Source code in ShallowLearn/io/satellite_data.py
get_file_list()
load_all()
Load all GeoTIFF files in the collection.
Returns:
List[GeoTIFFImage] List of loaded GeoTIFF images
Source code in ShallowLearn/io/satellite_data.py
stack_images()
Stack all images into a single array.
Returns:
np.ndarray Stacked images with shape (n_images, bands, height, width)
Source code in ShallowLearn/io/satellite_data.py
GeoTIFFImage
Generic GeoTIFF loader with backwards compatibility to LoadGeoTIFF.
Supports various GeoTIFF types including: - Planetscope individual band files - GBR benthic classification data - Generic single/multi-band GeoTIFF files
Source code in ShallowLearn/io/satellite_data.py
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 | |
dtype
property
Get image data type without loading full data.
shape
property
Get image shape without loading full data.
__init__(file_path)
Initialize GeoTIFF loader.
Parameters:
file_path : str Path to the GeoTIFF file
Source code in ShallowLearn/io/satellite_data.py
get_bounds()
Get spatial bounds of the GeoTIFF file.
Returns:
rasterio.coords.BoundingBox Bounding box (left, bottom, right, top)
Source code in ShallowLearn/io/satellite_data.py
get_crs()
Get coordinate reference system.
Returns:
rasterio.crs.CRS Coordinate reference system
Source code in ShallowLearn/io/satellite_data.py
get_metadata()
Get rasterio metadata for the GeoTIFF file.
Returns:
dict Rasterio metadata dictionary
Source code in ShallowLearn/io/satellite_data.py
get_transform()
Get affine transform.
Returns:
rasterio.Affine Affine transformation
Source code in ShallowLearn/io/satellite_data.py
load()
Load GeoTIFF data with backwards compatibility.
Returns:
np.ndarray Image data with shape (bands, height, width)
Source code in ShallowLearn/io/satellite_data.py
LandsatImage
Bases: SatelliteImage
Landsat image with strict band ordering and missing band handling.
Source code in ShallowLearn/io/satellite_data.py
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 | |
band_order
property
Canonical Landsat band order with index mapping.
get_rgb_bands()
get_spectral_bands()
Get list of spectral bands (excluding QA and angle bands).
Source code in ShallowLearn/io/satellite_data.py
LandsatImageCollection
Bases: SatelliteImageCollection
Managed collection of Landsat images with date sorting and strict band order.
Source code in ShallowLearn/io/satellite_data.py
SatelliteImage
Bases: ABC
Abstract base class for satellite images with consistent interface.
Source code in ShallowLearn/io/satellite_data.py
band_order
abstractmethod
property
Define the canonical band order for this satellite type.
get_band_data(band_name)
Get data for a specific band.
Source code in ShallowLearn/io/satellite_data.py
get_bounds()
Get image bounds.
Source code in ShallowLearn/io/satellite_data.py
get_metadata()
get_rgb_bands()
Get the typical RGB band combination for this satellite.
SatelliteImageCollection
Bases: ABC
Abstract base class for collections of satellite images.
Source code in ShallowLearn/io/satellite_data.py
common_bands()
get_common_bands_array()
Get array of common bands across all images with consistent spatial dimensions.
Source code in ShallowLearn/io/satellite_data.py
Sentinel2Image
Bases: SatelliteImage
Sentinel-2 image with band ordering and missing band handling.
Source code in ShallowLearn/io/satellite_data.py
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 | |
band_order
property
Canonical Sentinel-2 band order with index mapping.
__init__(file_path, load_all_bands=False, target_resolution='10m', clip_geometry=None, buffer_meters=0)
Initialize Sentinel-2 image.
Parameters:
file_path : str Path to Sentinel-2 file (.SAFE directory, .zip file, or MTD XML file) load_all_bands : bool If True, loads all 13 bands by resampling from different resolution subdatasets. If False, loads only the native resolution bands (default: 4 bands at 10m) target_resolution : str Target resolution when load_all_bands=True ("10m", "20m", "60m") clip_geometry : shapely geometry or GeoDataFrame, optional Geometry to clip to during loading for efficiency buffer_meters : float Buffer distance in meters to add around clip_geometry
Source code in ShallowLearn/io/satellite_data.py
clip_to_bounds(bounds, buffer_pixels=0)
Clip image data to specified bounds.
Parameters:
bounds : tuple or BoundingBox Bounds to clip to (left, bottom, right, top) or rasterio BoundingBox buffer_pixels : int Number of pixels to add as buffer around the clipped area
Returns:
Sentinel2Image New Sentinel2Image instance with clipped data
Source code in ShallowLearn/io/satellite_data.py
clip_to_geometry(geometry, buffer_meters=0)
Clip image data to a geometry (e.g., from a GeoDataFrame).
Parameters:
geometry : shapely geometry or GeoDataFrame Geometry to clip to buffer_meters : float Buffer distance in meters to add around the geometry
Returns:
Sentinel2Image New Sentinel2Image instance with clipped data
Source code in ShallowLearn/io/satellite_data.py
get_resolution_groups()
Get bands grouped by native resolution.
Source code in ShallowLearn/io/satellite_data.py
get_rgb_bands()
Sentinel2ImageCollection
Bases: SatelliteImageCollection
Managed collection of Sentinel-2 images with date sorting.
Source code in ShallowLearn/io/satellite_data.py
batch_compile_geotiffs(source_list, output_dir, satellite_type=None, **kwargs)
Batch compile multiple satellite sources to GeoTIFF files.
Parameters:
source_list : List[str] List of source file/directory paths output_dir : str Output directory for GeoTIFF files satellite_type : str, optional Force specific satellite type **kwargs Additional arguments for compiler
Returns:
List[str] List of created GeoTIFF file paths
Source code in ShallowLearn/io/geotiff_compiler.py
batch_process_archives(archive_list, output_dir, bounds=None, satellite_type=None, **kwargs)
Batch process multiple satellite archives to VRTs.
Parameters:
archive_list : List[str] List of archive file paths output_dir : str Output directory for VRT files bounds : gpd.GeoDataFrame, optional Geographic bounds for cropping satellite_type : str, optional Force specific satellite type **kwargs Additional arguments for VRT builder
Source code in ShallowLearn/io/vrt_builder.py
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 | |
create_geotiff_compiler(satellite_type, output_dir, **kwargs)
Factory function to create appropriate GeoTIFF compiler.
Parameters:
satellite_type : str Type of satellite ("landsat" or "sentinel2") output_dir : str Output directory for GeoTIFF files **kwargs Additional arguments for compiler
Returns:
GeoTIFFCompiler Appropriate GeoTIFF compiler instance
Source code in ShallowLearn/io/geotiff_compiler.py
create_satellite_collection(directory, satellite_type=None)
Factory function to create appropriate satellite image collection.
Parameters:
directory : str Directory containing satellite images satellite_type : str, optional Force specific satellite type ('landsat' or 'sentinel2')
Returns:
SatelliteImageCollection Appropriate satellite image collection
Source code in ShallowLearn/io/satellite_data.py
create_satellite_image(file_path)
Factory function to create appropriate satellite image based on file path.
Parameters:
file_path : str Path to the satellite image file
Returns:
SatelliteImage Appropriate satellite image instance
Source code in ShallowLearn/io/satellite_data.py
create_vrt_builder(satellite_type, output_dir, **kwargs)
Factory function to create appropriate VRT builder.
Parameters:
satellite_type : str Type of satellite ("landsat" or "sentinel2") output_dir : str Output directory for VRT files **kwargs Additional arguments for VRT builder
Returns:
VRTBuilder Appropriate VRT builder instance
Source code in ShallowLearn/io/vrt_builder.py
load_image(path, return_meta=False, clip=False, file_format=None, gdf_clip=None)
High-level image loading function with auto-detection and proper orientation.
This function serves as a replacement for ImageHelper.load_img with enhanced capabilities for handling different satellite data formats and file types.
Parameters:
path : str or Path Path to the image file return_meta : bool, default False Whether to return metadata and bounds along with the image clip : bool, default False Whether to clip values to 0-10000 range file_format : str, optional Force specific format handling ('geotiff', 'sentinel2', 'landsat') If None, format is auto-detected gdf_clip : GeoDataFrame, optional GeoDataFrame with geometries for clipping the image. If provided, the image will be clipped to the geometries
Returns:
np.ndarray or tuple If return_meta=False: Image array with shape (height, width, bands) If return_meta=True: Tuple of (image, metadata, bounds)
Raises:
FileNotFoundError If the specified file does not exist ValueError If the file format is not supported or auto-detection fails
Source code in ShallowLearn/io/image_loader.py
load_image_collection(directory, pattern='*.tif', **load_kwargs)
Load multiple images from a directory.
Parameters:
directory : str or Path Directory containing image files pattern : str, default ".tif" Glob pattern to match files *load_kwargs Additional arguments passed to load_image()
Returns:
list List of loaded image arrays
Source code in ShallowLearn/io/image_loader.py
ML Module
Machine Learning module for ShallowLearn Contains dimensionality reduction, clustering, and analysis components
DimensionalityReducer
Bases: ABC
Abstract base for dimensionality reduction methods
Source code in ShallowLearn/ml/quicklook_ml.py
QuickLookConfig
dataclass
Configuration for QuickLook processing
Source code in ShallowLearn/ml/quicklook_ml.py
QuickLookFilter
Main QuickLook filtering system for satellite products
Source code in ShallowLearn/ml/quicklook_ml.py
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 | |
get_clear_sky_products()
Get products classified as clear sky
Source code in ShallowLearn/ml/quicklook_ml.py
get_clustering_summary()
Get summary of clustering results
Source code in ShallowLearn/ml/quicklook_ml.py
process_products(products)
Process satellite products through QuickLook pipeline
Returns:
| Type | Description |
|---|---|
Dict[str, List]
|
Dictionary with cluster labels as keys and filtered product lists as values |
Source code in ShallowLearn/ml/quicklook_ml.py
ThumbnailLoader
Handles thumbnail/PVI loading for different satellite types
Source code in ShallowLearn/ml/quicklook_ml.py
load_thumbnail(product, target_size=(343, 343))
Load thumbnail for a satellite product
Source code in ShallowLearn/ml/quicklook_ml.py
Core Module
API Module
API module for satellite data access
LandsatUSGSDownloader
Landsat downloader using USGS M2M API - matches existing BarAlHikman implementation
Source code in ShallowLearn/api/unified_satellite_api.py
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 | |
download_product(product, output_dir)
Download a Landsat product using USGS M2M API - matches BarAlHikman implementation
Source code in ShallowLearn/api/unified_satellite_api.py
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 | |
search(query)
Search Landsat scenes - matches existing BarAlHikman data_download.py logic
Source code in ShallowLearn/api/unified_satellite_api.py
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 | |
SatelliteProduct
dataclass
Standardized satellite product representation
Source code in ShallowLearn/api/unified_satellite_api.py
SatelliteQuery
dataclass
Unified query parameters for satellite data
Source code in ShallowLearn/api/unified_satellite_api.py
Sentinel2CDSEDownloader
Sentinel-2 downloader using CDSE API - matches existing ShallowLearn implementation
Source code in ShallowLearn/api/unified_satellite_api.py
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 | |
download_product(product, output_dir)
Download a Sentinel-2 product using CDSE API - matches ShallowLearn implementation
Source code in ShallowLearn/api/unified_satellite_api.py
search(query)
Search Sentinel-2 scenes - matches existing ShallowLearn DownloadData.py logic
Source code in ShallowLearn/api/unified_satellite_api.py
UnifiedSatelliteAPI
Unified interface for both Landsat and Sentinel-2 APIs
Source code in ShallowLearn/api/unified_satellite_api.py
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 | |
create_download_manifest(products, output_path='download_manifest.csv')
Create a CSV manifest of products for download tracking
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
products
|
List[SatelliteProduct]
|
List of products to include in manifest |
required |
output_path
|
str
|
Path to save the manifest CSV file |
'download_manifest.csv'
|
Returns:
| Type | Description |
|---|---|
str
|
Path to the created manifest file |
Source code in ShallowLearn/api/unified_satellite_api.py
download(products, output_dir, max_concurrent=3)
Download satellite products to specified directory
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
products
|
List[SatelliteProduct]
|
List of SatelliteProduct objects to download |
required |
output_dir
|
str
|
Directory to save downloaded files |
required |
max_concurrent
|
int
|
Maximum concurrent downloads |
3
|
Returns:
| Type | Description |
|---|---|
Dict[str, str]
|
Dictionary mapping product_id to local file path (or error message) |
Source code in ShallowLearn/api/unified_satellite_api.py
filter_by_clusters(products, clusters, target_clusters)
Filter products by specific cluster names
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
products
|
List[SatelliteProduct]
|
Original list of products |
required |
clusters
|
Dict[str, List[SatelliteProduct]]
|
Dictionary with cluster names as keys and product lists as values |
required |
target_clusters
|
List[str]
|
List of cluster names to include |
required |
Returns:
| Type | Description |
|---|---|
List[SatelliteProduct]
|
Filtered list of products from selected clusters |
Source code in ShallowLearn/api/unified_satellite_api.py
products_to_dataframe(products)
Convert list of satellite products to pandas DataFrame for analysis
Source code in ShallowLearn/api/unified_satellite_api.py
quicklook_filter(products, config=None)
Apply QuickLook filtering to products based on thumbnails
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
products
|
List[SatelliteProduct]
|
List of SatelliteProduct objects |
required |
config
|
Optional QuickLookConfig for customization |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, List[SatelliteProduct]]
|
Dictionary with cluster names as keys and filtered product lists as values |
Source code in ShallowLearn/api/unified_satellite_api.py
search(query)
Search all requested satellites independently
Source code in ShallowLearn/api/unified_satellite_api.py
search_and_filter(query, quicklook_config=None)
Combined search and QuickLook filtering workflow
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
SatelliteQuery
|
SatelliteQuery object |
required |
quicklook_config
|
Optional QuickLookConfig |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, List[SatelliteProduct]]
|
Dictionary with cluster names as keys and filtered product lists as values |
Source code in ShallowLearn/api/unified_satellite_api.py
Features Module
Spectral analysis utilities for ShallowLearn. Contains water quality and marine remote sensing indices.
Segmentation Module
Visualization Module
Visualization utilities for ShallowLearn. Clean plotting and display functions for remote sensing data.
plot_rgb = plot_rgb_enhanced
module-attribute
Plots an RGB image using specified band indices.
Parameters:
img : np.ndarray Input image array with shape (height, width, bands) band_indices : List[int] List of 3 band indices for R, G, B channels title : str, default="RGB Image" Title for the plot figsize : Tuple[int, int], default=(8, 8) Figure size show : bool, default=True Whether to display the plot
Returns:
plt.Figure or None Figure object if show=False, otherwise None
QuickLookVisualizer
Handles visualization of QuickLook results - separated from ML processing
Source code in ShallowLearn/visualization/quicklook_viz.py
18 19 20 21 22 23 24 25 26 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 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 | |
__init__(quicklook_processor)
Initialize with a QuickLookProcessor instance from ml module
Source code in ShallowLearn/visualization/quicklook_viz.py
create_cloudcover_meshgrid(ax, resolution=50, alpha=0.3)
Create a cloud cover background meshgrid
Source code in ShallowLearn/visualization/quicklook_viz.py
generate_all_plots(output_dir='publication_plots', dpi=300)
Generate all possible visualization plots
Source code in ShallowLearn/visualization/quicklook_viz.py
plot_cluster_statistics(figsize=(12, 8), save_path=None)
Plot statistics about each cluster
Source code in ShallowLearn/visualization/quicklook_viz.py
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 | |
plot_clusters_scatter(figsize_base=8, save_path=None)
Create scatter plot of clusters in reduced dimensional space
Source code in ShallowLearn/visualization/quicklook_viz.py
plot_publication_quality(method_name='PCA', show_thumbnails=True, show_meshgrid=True, thumbnail_sample='cluster', figsize=(7, 4), dpi=300, save_path=None)
Create publication-quality plot with all enhancements
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method_name
|
Name of dimensionality reduction method |
'PCA'
|
|
show_thumbnails
|
Whether to overlay thumbnails |
True
|
|
show_meshgrid
|
Whether to show cloud cover background |
True
|
|
thumbnail_sample
|
'cluster', 'random', or 'all' |
'cluster'
|
|
figsize
|
Figure size |
(7, 4)
|
|
dpi
|
Resolution for saving |
300
|
|
save_path
|
Path to save the plot |
None
|
Source code in ShallowLearn/visualization/quicklook_viz.py
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 | |
plot_temporal_distribution(figsize=(14, 8), save_path=None)
Plot temporal distribution of products by cluster
Source code in ShallowLearn/visualization/quicklook_viz.py
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 | |
plot_thumbnails_on_scatter(show_points=True, show_thumbnails=True, zoom=0.1, figsize_base=10, max_images=50, sample_method='random', add_borders=True, save_path=None)
Plot thumbnail images on their cluster coordinates with flexible options
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
show_points
|
Whether to show scatter points underneath thumbnails |
True
|
|
show_thumbnails
|
Whether to show thumbnail images |
True
|
|
zoom
|
Zoom level for thumbnails (0.05-0.2 recommended) |
0.1
|
|
figsize_base
|
Base size for square figure |
10
|
|
max_images
|
Maximum number of thumbnails to show (None = all) |
50
|
|
sample_method
|
'random', 'cluster' (sample from each cluster), or 'all' |
'random'
|
|
add_borders
|
Whether to add colored borders to thumbnails matching clusters |
True
|
|
save_path
|
Path to save the plot |
None
|
Source code in ShallowLearn/visualization/quicklook_viz.py
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 | |
add_north_arrow_to_axis(ax, relative_position=(0.05, 0.05), arrow_length=0.05, text_offset=-0.02)
Adds a north arrow to an axis.
Parameters:
ax : plt.Axes Matplotlib axis object relative_position : Tuple[float, float], default=(0.05, 0.05) Relative position of the arrow (0-1 range) arrow_length : float, default=0.05 Length of the arrow relative to axis size text_offset : float, default=-0.02 Text offset relative to axis size
Source code in ShallowLearn/visualization/display.py
create_rgb_image(img, band_indices, stretch=True)
Creates an RGB image from multispectral data using specified band indices.
Parameters:
img : np.ndarray Input image array with shape (height, width, bands) band_indices : List[int] List of 3 band indices for R, G, B channels stretch : bool, default=True Whether to apply min-max stretch to each channel
Returns:
np.ndarray RGB image array with shape (height, width, 3) and dtype uint8
Source code in ShallowLearn/visualization/display.py
plot_color_space(img, color_space='hsv', band_indices=None, band_mapping=None, band_names=None, plot=False, title=None, figsize=(10, 8))
Convert image to different color spaces with flexible band selection.
This function replaces ImageHelper functions like plot_hsv, plot_lab, plot_ycbcr with a unified interface.
Parameters:
img : np.ndarray
Input image array with shape (height, width, bands)
color_space : str, default='hsv'
Target color space ('hsv', 'lab', 'ycbcr')
band_indices : List[int], optional
List of 3 band indices for R, G, B channels used in conversion
band_mapping : Dict, optional
Band mapping dictionary for converting band names to indices
band_names : List[str], optional
List of 3 band names to use with band_mapping
plot : bool, default=False
Whether to display the converted image
title : str, optional
Title for the plot. If None, auto-generated based on color_space
figsize : Tuple[int, int], default=(10, 8)
Figure size if plotting
Returns:
np.ndarray or None Converted image array if plot=False, otherwise None
Raises:
ValueError If color_space is not supported
Source code in ShallowLearn/visualization/display.py
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 | |
plot_discrete_image(arr, value_labels=None, colors=None, pixel_scale=10, title='Discrete Image', figsize=(10, 8), show=True)
Plots a discrete array with custom colors and labels.
Parameters:
arr : np.ndarray Input discrete array value_labels : Dict, optional Dictionary mapping values to labels colors : List, optional List of colors for each unique value pixel_scale : float, default=10 Scale for the scale bar (pixels per km) title : str, default="Discrete Image" Title for the plot figsize : Tuple[int, int], default=(10, 8) Figure size show : bool, default=True Whether to display the plot
Returns:
plt.Figure or None Figure object if show=False, otherwise None
Source code in ShallowLearn/visualization/display.py
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 | |
plot_histogram(img, channels=None, bins=50, min_value=1, channel_names=None, title='Histogram', figsize=(10, 6), show=True)
Plots histograms for specified channels.
Parameters:
img : np.ndarray Input image array channels : List[int], optional List of channel indices to plot. If None, plots all channels bins : int, default=50 Number of bins for histogram min_value : float, default=1 Minimum value threshold for filtering channel_names : List[str], optional Names for channels in legend title : str, default="Histogram" Title for the plot figsize : Tuple[int, int], default=(10, 6) Figure size show : bool, default=True Whether to display the plot
Returns:
plt.Figure or None Figure object if show=False, otherwise None
Source code in ShallowLearn/visualization/display.py
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 | |
plot_rgb_enhanced(img, band_indices=None, band_mapping=None, band_names=None, stretch=True, plot=False, title='RGB Image', figsize=(10, 8))
Enhanced RGB plotting function with flexible band selection and reduced hardcoding.
This function replaces ImageHelper.plot_rgb with improved flexibility and reduced dependency on hardcoded band mappings.
Parameters:
img : np.ndarray
Input image array with shape (height, width, bands)
band_indices : List[int], optional
List of 3 band indices for R, G, B channels. If None, defaults to [3, 2, 1]
(which corresponds to typical Red, Green, Blue for Sentinel-2)
band_mapping : Dict, optional
Band mapping dictionary for converting band names to indices
band_names : List[str], optional
List of 3 band names (e.g., ['B04', 'B03', 'B02']) to use with band_mapping
stretch : bool, default=True
Whether to apply min-max stretch to enhance contrast
plot : bool, default=False
Whether to display the image plot using matplotlib
title : str, default="RGB Image"
Title for the plot
figsize : Tuple[int, int], default=(10, 8)
Figure size if plotting
Returns:
np.ndarray or None RGB image array with shape (height, width, 3) and dtype uint8 if plot=False, otherwise None
Source code in ShallowLearn/visualization/display.py
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 | |
plot_with_legend(array, value_dict, title='Classified Image', figsize=(10, 8), show=True)
Plots a 2D array with a legend using distinct colors for discrete class labels.
Parameters:
array : np.ndarray 2D array to be plotted value_dict : Dict Dictionary mapping values in the array to labels title : str, default="Classified Image" Title for the plot figsize : Tuple[int, int], default=(10, 8) Figure size show : bool, default=True Whether to display the plot
Returns:
plt.Figure or None Figure object if show=False, otherwise None
Source code in ShallowLearn/visualization/display.py
Utilities Module
ShallowLearn utilities module Contains cross-cutting utility functions for file operations, etc.
find_files_in_directory(directory, max_files=5)
Find Sentinel-2 files in directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory
|
str
|
Directory path to search |
required |
max_files
|
int
|
Maximum number of files to return |
5
|
Returns:
| Type | Description |
|---|---|
List[str]
|
List of file paths as strings |
Source code in ShallowLearn/utilities/file_discovery.py
find_matching_files_by_date(list1, list2)
Match files from two lists based on identical acquisition dates. Typically used for matching L1C and L2A Sentinel-2 files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
list1
|
List[str]
|
First list of file paths |
required |
list2
|
List[str]
|
Second list of file paths |
required |
Returns:
| Type | Description |
|---|---|
List[Tuple[datetime, str, str]]
|
List of tuples containing (date, file1, file2) for matching dates |
Source code in ShallowLearn/utilities/file_discovery.py
process_reef_data(files, reef_gdf, reef_indices, data_type='L1C', buffer_meters=100)
Process satellite files for multiple reefs separately.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
files
|
List of satellite file paths |
required | |
reef_gdf
|
GeoDataFrame containing reef polygons |
required | |
reef_indices
|
List of reef indices to process |
required | |
data_type
|
'L1C' or 'L2A' |
'L1C'
|
|
buffer_meters
|
Buffer size for clipping |
100
|
Returns:
| Type | Description |
|---|---|
|
Dict mapping reef names to lists of processed images |