Io
This module handles all disk-based operations for raster data.
ensure_tiled_raster(path, output_dir=None, block_size=512)
Analyzes raster structure and translates striped or untiled files into optimized, tiled GeoTIFFs to prevent I/O thrashing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Union[str, Path]
|
Path to the input raster. |
required |
output_dir
|
Optional[Union[str, Path]]
|
Destination directory for the optimized file. |
None
|
block_size
|
int
|
Dimensions for the internal X and Y blocks. |
512
|
Returns:
| Name | Type | Description |
|---|---|---|
Path |
Path
|
Path to the optimally tiled raster (original path if no conversion was needed). |
Source code in src/phytospatial/raster/io.py
load(path, bands=None, window=None, driver=None)
Load a raster from disk into memory.
This function reads a geospatial raster file and returns a Raster object with data loaded into RAM. Supports loading all bands, specific bands, or a spatial subset via a window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Union[str, Path]
|
Path to raster file. All supported GDAL formats are accepted. |
required |
bands
|
Optional[Union[int, List[int]]]
|
Specific band(s) to load (None=all, int=single, list=subset). |
None
|
window
|
Optional[Window]
|
Optional rasterio Window object to load only a spatial subset. |
None
|
driver
|
Optional[str]
|
Optional GDAL driver name. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Raster |
Raster
|
In-memory Raster object |
Source code in src/phytospatial/raster/io.py
read_info(path)
Intelligently inspects a raster file, extracting spatial metadata, band descriptions, and spectral wavelengths in a single pass.
Source code in src/phytospatial/raster/io.py
resolve_raster(safe=True)
A signature-aware polymorphic decorator that resolves raster filepaths into in-memory Raster objects.
It selectively intercepts arguments passed as strings or Paths only if the target parameter's signature explicitly expects a 'Raster'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
safe
|
bool
|
Instructs the decorator to perform a preemptive memory safety assessment using the resource subpackage before loading. If True, it prevents Out-Of-Memory (OOM) errors by raising an exception if the raster exceeds safe capacity. Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
Callable[[Callable[..., Any]], Callable[..., Any]]
|
Callable[[Callable[..., Any]], Callable[..., Any]]: The wrapped function executed with fully resolved Raster dependencies. |
Raises:
| Type | Description |
|---|---|
MemoryError
|
If 'safe' is True and the target raster is evaluated as too large to safely fit within the available system RAM for an in-memory operation. |
Source code in src/phytospatial/raster/io.py
save(raster, path, **profile_kwargs)
Write a Raster object to disk. Creates a new geospatial raster file from the in-memory Raster object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raster
|
Raster
|
Raster object to save |
required |
path
|
Union[str, Path]
|
Output file path. All supported GDAL formats are accepted. |
required |
**profile_kwargs
|
Any
|
Override default rasterio profile settings. |
{}
|
Source code in src/phytospatial/raster/io.py
write_window(raster, path, window, indexes=None)
Write raster data to a specific window in an existing file.
Useful for tile stitching. Target file must exist and handle the same schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raster
|
Raster
|
Raster object containing data to write |
required |
path
|
Union[str, Path]
|
Path to EXISTING raster file. All supported GDAL formats are accepted. |
required |
window
|
Window
|
Window defining where to write. |
required |
indexes
|
Optional[List[int]]
|
Optional list of band indices to write to. |
None
|