Polygon Extraction¶
Module: spectralbridge.polygon_extraction.
Direct-module reference; consult the linked workflow for processing context.
API glossary ยท Workflow / scientific context
Signatures and documentation below are collected from the current source. Advanced objects are not newly declared stable by inclusion here.
Audience: advanced.
validate_bands_in_dir ¶
validate_bands_in_dir(directory, expected_bands: int = 426, sample_rows: int = 4000, recursive: bool = True, value_range: tuple | None = (0.0, 1.0), eps_all_zero: float = 1e-12, show_preview: bool = True, meta_cols=('raster_file', 'crs', 'chunk', 'x', 'y', 'Raster_File', 'CRS', 'Chunk_Number', 'Pixel_X', 'Pixel_Y'))
Validate band layout and sample values for each Parquet file in directory.
Audience: advanced.
control_function_for_extraction ¶
control_function_for_extraction(directory, polygon_path: Optional[Path], max_workers: Optional[int] = None, *, overwrite: bool = False)
Finds and processes raster files in a directory. Processes data in chunks and saves output to Parquet.
When more than one raster file is found, the extractions run in parallel using a
process pool. The max_workers argument can be used to control the number of
concurrent processes. By default, existing extraction outputs are reused; pass
overwrite=True to regenerate them.
Audience: advanced.
plot_spectra_from_parquet_dir ¶
plot_spectra_from_parquet_dir(directory, output_dir: Optional[str] = None, recursive: bool = True, max_lines_per_file: int = 5000, median_sample_rows: int = 50000, sentinel_at_or_below: float = -9990, mask_integer_lo: int = 1, mask_integer_hi: int = 255, dpi: int = 200)
Generate spectral plots for each Parquet file within directory.
Audience: advanced.
select_best_files ¶
select_best_files(files: List[DataFile]) -> List[DataFile]
Choose one product per domain/site/date/time group, preferring masked and BRDF-corrected ENVI candidates.
Audience: advanced.
find_best_resampled_files ¶
find_best_resampled_files(directory: Path, suffix: str) -> List[NEONReflectanceResampledENVIFile]
Discover typed resampled products and apply the established per-flight product preference.
Audience: advanced.
get_all_priority_rasters ¶
get_all_priority_rasters(base_dir: Path, suffix: str = 'envi') -> List[DataFile]
Return all raster files in base_dir prioritising BRDF corrected files first.
Previously this function attempted to select a single "best" raster per (domain, site, date, time) combination which meant only one file was processed when multiple valid rasters were present in the directory. The polygon extraction workflow now requires that every available raster be processed, so we gather all matches while still preferring BRDF corrected rasters when duplicates exist.
Audience: advanced.
get_crs_from_hdr ¶
get_crs_from_hdr(hdr_path)
Reads an ENVI .hdr file and extracts the CRS as a Proj string or EPSG code.
Parameters: - hdr_path (str): Path to the .hdr file.
Returns: - crs (rasterio.crs.CRS or None): CRS object if found, else None.
Audience: advanced.
process_raster_in_chunks ¶
process_raster_in_chunks(raster_file: DataFile, polygon_path: Optional[Path], output_parquet_file: DataFile, chunk_size=100000, *, overwrite: bool = False)
Processes a raster file in chunks, intersects pixels with a polygon, and writes extracted
spectral and spatial data to a Parquet file. Existing outputs are reused unless
overwrite is True.