Skip to content

Commit 9bc8f9e

Browse files
adjusted function descriptions
1 parent 29b904c commit 9bc8f9e

File tree

1 file changed

+80
-57
lines changed

1 file changed

+80
-57
lines changed

detectree2/preprocessing/tiling.py

Lines changed: 80 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,22 @@ def process_tile(img_path: str,
101101
"""Process a single tile for making predictions.
102102
103103
Args:
104-
img_path: Path to the orthomosaic
105-
out_dir: Output directory
106-
buffer: Overlapping buffer of tiles in meters (UTM)
107-
tile_width: Tile width in meters
108-
tile_height: Tile height in meters
109-
dtype_bool: Flag to edit dtype to prevent black tiles
110-
minx: Minimum x coordinate of tile
111-
miny: Minimum y coordinate of tile
112-
crs: Coordinate reference system
113-
tilename: Name of the tile
104+
img_path: Path to the orthomosaic.
105+
out_dir: Output directory.
106+
buffer: Overlapping buffer of tiles in meters (UTM).
107+
tile_width: Tile width in meters.
108+
tile_height: Tile height in meters.
109+
dtype_bool: Flag to edit dtype to prevent black tiles.
110+
minx: Minimum x coordinate of the tile.
111+
miny: Minimum y coordinate of the tile.
112+
crs: Coordinate reference system.
113+
tilename: Name of the tile.
114+
crowns: Crown polygons as a GeoDataFrame used to skip tiles if coverage is below `threshold`.
115+
threshold: Minimum fraction [0,1] of tile coverage by `crowns` required to avoid skipping the tile.
116+
nan_threshold: Maximum proportion [0,1] of the tile that can be nodata or NaN values before skipping.
117+
mask_gdf: A GeoDataFrame containing polygons tile act as masks for the tile. Only the interior is kept, the rest of the image will become nodata.
118+
additional_nodata: List of additional pixel values to treat as nodata.
119+
image_statistics: A list of dictionaries where each dictionary contains information about the pixel distribution of that band. One list element per band.
114120
115121
Returns:
116122
None
@@ -229,19 +235,25 @@ def process_tile_ms(img_path: str,
229235
nan_threshold: float = 0,
230236
additional_nodata: List[Any] = [],
231237
image_statistics: List[Dict[str, float]] = None):
232-
"""Process a single tile for making predictions.
238+
"""Process a single multispectral tile for making predictions.
233239
234240
Args:
235-
img_path: Path to the orthomosaic
236-
out_dir: Output directory
237-
buffer: Overlapping buffer of tiles in meters (UTM)
238-
tile_width: Tile width in meters
239-
tile_height: Tile height in meters
240-
dtype_bool: Flag to edit dtype to prevent black tiles
241-
minx: Minimum x coordinate of tile
242-
miny: Minimum y coordinate of tile
243-
crs: Coordinate reference system
244-
tilename: Name of the tile
241+
img_path: Path to the orthomosaic.
242+
out_dir: Output directory.
243+
buffer: Overlapping buffer of tiles in meters (UTM).
244+
tile_width: Tile width in meters.
245+
tile_height: Tile height in meters.
246+
dtype_bool: Flag to edit dtype to prevent black tiles.
247+
minx: Minimum x coordinate of the tile.
248+
miny: Minimum y coordinate of the tile.
249+
crs: Coordinate reference system.
250+
tilename: Name of the tile.
251+
crowns: Crown polygons as a GeoDataFrame used to skip tiles if coverage is below `threshold`.
252+
threshold: Minimum fraction [0,1] of tile coverage by `crowns` required to avoid skipping the tile.
253+
nan_threshold: Maximum proportion [0,1] of the tile that can be nodata or NaN values before skipping.
254+
mask_gdf: A GeoDataFrame containing polygons tile act as masks for the tile. Only the interior is kept, the rest of the image will become nodata.
255+
additional_nodata: List of additional pixel values to treat as nodata.
256+
image_statistics: A list of dictionaries where each dictionary contains information about the pixel distribution of that band. One list element per band.
245257
246258
Returns:
247259
None
@@ -356,19 +368,24 @@ def process_tile_train(
356368
"""Process a single tile for training data.
357369
358370
Args:
359-
img_path: Path to the orthomosaic
360-
out_dir: Output directory
361-
buffer: Overlapping buffer of tiles in meters (UTM)
362-
tile_width: Tile width in meters
363-
tile_height: Tile height in meters
364-
dtype_bool: Flag to edit dtype to prevent black tiles
365-
minx: Minimum x coordinate of tile
366-
miny: Minimum y coordinate of tile
367-
crs: Coordinate reference system
368-
tilename: Name of the tile
369-
crowns: Crown polygons as a geopandas dataframe
370-
threshold: Min proportion of the tile covered by crowns to be accepted {0,1}
371-
nan_theshold: Max proportion of tile covered by nans
371+
img_path: Path to the orthomosaic.
372+
out_dir: Output directory.
373+
buffer: Overlapping buffer of tiles in meters (UTM).
374+
tile_width: Tile width in meters.
375+
tile_height: Tile height in meters.
376+
dtype_bool: Flag to edit dtype to prevent black tiles.
377+
minx: Minimum x coordinate of tile.
378+
miny: Minimum y coordinate of tile.
379+
crs: Coordinate reference system.
380+
tilename: Name of the tile.
381+
crowns: Crown polygons as a geopandas DataFrame.
382+
threshold: Min proportion of the tile covered by crowns to be accepted {0,1}.
383+
nan_threshold: Max proportion of tile covered by NaNs.
384+
mode: Type of the raster data ("rgb" or "ms").
385+
class_column: Name of the column in `crowns` DataFrame for class-based tiling.
386+
mask_gdf: A GeoDataFrame containing polygons tile act as masks for the tile. Only the interior is kept, the rest of the image will become nodata.
387+
additional_nodata: List of additional pixel values to treat as nodata.
388+
image_statistics: A list of dictionaries where each dictionary contains information about the pixel distribution of that band. One list element per band.
372389
373390
Returns:
374391
None
@@ -514,17 +531,17 @@ def _calculate_tile_placements(
514531

515532

516533
def calculate_image_statistics(file_path, values_to_ignore=None, window_size=64, min_windows=100, mode="rgb"):
517-
"""
518-
Calculate statistics for a raster using either whole image or sampled windows.
534+
"""Calculate statistics for a raster using either whole image or sampled windows.
519535
520-
Parameters:
521-
- file_path: str, path to the raster file.
522-
- values_to_ignore: list, values to ignore in statistics (e.g., NaN, custom values).
523-
- window_size: int, size of square window for sampling.
524-
- min_windows: int, minimum number of valid windows to include in statistics.
536+
Args:
537+
file_path: str, path to the raster file.
538+
values_to_ignore: list, values to ignore in statistics (e.g., NaN, custom values).
539+
window_size: int, size of square window for sampling.
540+
min_windows: int, minimum number of valid windows to include in statistics.
541+
mode: str, type of the raster data ("rgb" or "ms").
525542
526543
Returns:
527-
- List of dictionaries containing statistics for each band.
544+
List of dictionaries containing statistics for each band.
528545
"""
529546
if values_to_ignore is None:
530547
values_to_ignore = []
@@ -632,26 +649,32 @@ def tile_data(
632649
) -> None:
633650
"""Tiles up orthomosaic and corresponding crowns (if supplied) into training/prediction tiles.
634651
635-
Tiles up large rasters into manageable tiles for training and prediction. If crowns are not supplied, the function
636-
will tile up the entire landscape for prediction. If crowns are supplied, the function will tile these with the image
637-
and skip tiles without a minimum coverage of crowns. The 'threshold' can be varied to ensure good coverage of
638-
crowns across a training tile. Tiles that do not have sufficient coverage are skipped.
652+
Tiles up large rasters into manageable tiles for training and prediction. If crowns are not
653+
supplied, the function will tile up the entire landscape for prediction. If crowns are supplied,
654+
the function will tile these with the image and skip tiles without a minimum coverage of crowns.
655+
The 'threshold' can be varied to ensure good coverage of crowns across a training tile. Tiles
656+
that do not have sufficient coverage are skipped.
639657
640658
Args:
641-
img_path: Path to the orthomosaic
642-
out_dir: Output directory
643-
buffer: Overlapping buffer of tiles in meters (UTM)
644-
tile_width: Tile width in meters
645-
tile_height: Tile height in meters
646-
crowns: Crown polygons as a GeoPandas DataFrame
647-
threshold: Minimum proportion of the tile covered by crowns to be accepted [0,1]
648-
nan_threshold: Maximum proportion of tile covered by NaNs [0,1]
649-
dtype_bool: Flag to edit dtype to prevent black tiles
650-
mode: Type of the raster data ("rgb" or "ms")
651-
class_column: Name of the column in `crowns` DataFrame for class-based tiling
659+
img_path: Path to the orthomosaic.
660+
out_dir: Output directory.
661+
buffer: Overlapping buffer of tiles in meters (UTM).
662+
tile_width: Tile width in meters.
663+
tile_height: Tile height in meters.
664+
crowns: Crown polygons as a GeoDataFrame.
665+
threshold: Minimum proportion of the tile covered by crowns to be accepted [0,1].
666+
nan_threshold: Maximum proportion of the tile covered by NaNs [0,1].
667+
dtype_bool: Flag to edit dtype to prevent black tiles.
668+
mode: Type of the raster data ("rgb" or "ms").
669+
class_column: Name of the column in `crowns` DataFrame for class-based tiling.
652670
tile_placement: Strategy for placing tiles.
653671
"grid" for fixed grid placement based on the bounds of the input image, optimized for speed.
654672
"adaptive" for dynamic placement of tiles based on crowns, adjusts based on data features for better coverage.
673+
mask_path: Path to a mask file to use for tiling.
674+
multithreaded: Flag to enable multithreaded processing.
675+
random_subset: Number of random tiles it will try to process per image. If -1, all tiles are processed.
676+
additional_nodata: List of additional pixel values to treat as nodata.
677+
overlapping_tiles: Flag to enable overlapping tiles for more training data generation. More useful for training the detection part of the Mask R-CNN model.
655678
656679
Returns:
657680
None

0 commit comments

Comments
 (0)