Resources
This module performs static analysis on raster files and system hardware.
It checks two key aspects before processing: - Memory safety for loading into RAM (Memory Estimation) - Internal block/tile structure of the raster (Block Structure Analysis)
BlockStructure
dataclass
Analysis of a raster's internal storage layout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
is_tiled
|
bool
|
True if raster has native tiles (not full-width strips) |
required |
is_striped
|
bool
|
True if raster is structured as strips (full-width blocks) |
required |
block_shape
|
Tuple[int, int]
|
Tuple of (block_height, block_width) in pixels |
required |
Source code in src/phytospatial/raster/resources.py
block_shape
instance-attribute
Analysis of the raster's internal block structure, indicating if it's tiled or striped and the shape of the blocks.
MemoryEstimate
dataclass
"Estimation of memory requirements and safety for loading a raster.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
total_required_bytes
|
int
|
Total bytes required to load raster (with overhead) |
required |
available_system_bytes
|
int
|
Currently available system memory in bytes |
required |
is_safe
|
bool
|
Boolean indicating if loading is considered safe |
required |
reason
|
str
|
Explanation for the safety assessment |
required |
Source code in src/phytospatial/raster/resources.py
ProcessingMode
Bases: Enum
Strategic recommendation for how to process a raster.
Modes
IN_MEMORY: Load entire raster into RAM. Fastest but requires sufficient memory.
BLOCKED: Use raster's internal blocks/tiles for optimized streaming. Best for tiled files.
TILED: Use standard windowed reading. Safe fallback for large or scanline-based rasters.
Source code in src/phytospatial/raster/resources.py
StrategyReport
dataclass
Contains the decision (mode) and the full context (reason, stats).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
ProcessingMode
|
Recommended processing mode (ProcessingMode) |
required |
reason
|
str
|
Explanation for the recommendation |
required |
memory_stats
|
MemoryEstimate
|
MemoryEstimate object with details on memory safety |
required |
structure_stats
|
BlockStructure
|
BlockStructure object with details on raster structure |
required |
Source code in src/phytospatial/raster/resources.py
determine_strategy(raster_input, user_mode='auto')
Determines the optimal processing strategy for a raster based on memory and internal structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raster_input
|
Union[str, Path, DatasetReader]
|
Polymorphic input for the raster file to analyze (Path or rasterio DatasetReader) |
required |
user_mode
|
str
|
Defines available processing modes ('auto', 'in_memory', 'blocked', 'tiled') auto: Automatically determine best mode based on analysis in_memory: Force loading entire raster into RAM (only if safe) blocked: Force using BLOCKED mode (only if structure is suitable) tiled: Force using TILED mode (safe fallback) |
'auto'
|
Returns:
| Name | Type | Description |
|---|---|---|
StrategyReport |
StrategyReport
|
The determined processing strategy. |
Source code in src/phytospatial/raster/resources.py
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 | |