Raster
raster
¶
Attributes¶
Functions:¶
get_heights_from_chm(coords, coords_crs, chm_path)
¶
Extract heights from a CHM for the given coordinates
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coords
|
ndarray
|
Coordinates in the form of an array of shape (n, 2) where n is the number of points |
required |
chm_path
|
PATH_TYPE
|
Path to the CHM raster file |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Heights at the given coordinates |
Source code in tree_detection_framework/utils/raster.py
get_valid_raster_region(raster_file)
¶
Compute a single-row geodataframe representing the extent of the valid pixels of a raster
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raster_file
|
PATH_TYPE
|
Path to the raster |
required |
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
gpd.GeoDataFrame: valid region |
Source code in tree_detection_framework/utils/raster.py
load_downsampled_raster_data(dataset_filename, downsample_factor)
¶
Load a raster file spatially downsampled
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
PATH_TYPE
|
Path to the raster |
required |
downsample_factor
|
float
|
Downsample factor of 10 means that pixels are 10 times larger |
required |
Returns:
| Type | Description |
|---|---|
|
np.array: The downsampled array in the rasterio (c, h, w) convention |
|
|
rasterio.DatasetReader: The reader with the transform updated |
|
|
rasterio.Transform: The updated transform |
Source code in tree_detection_framework/utils/raster.py
plot_from_dataloader(sample)
¶
Plots an image from the dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample
|
dict
|
A dictionary containing the tile to plot. The 'image' key should have a tensor of shape (C, H, W). |
required |
Returns:
| Type | Description |
|---|---|
|
matplotlib.figure.Figure: A figure containing the plotted image. |
Source code in tree_detection_framework/utils/raster.py
plot_ortho_chm_overlay(ortho_path, chm_path, chm_alpha=0.5, chm_cmap='viridis', chm_vmin=None, chm_vmax=None, figsize=(10, 10), title='CHM Overlay on Ortho')
¶
Plot a CHM raster overlaid on an ortho image, locked to the ortho's extent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ortho_path
|
str
|
Path to the orthophoto raster (RGB). |
required |
chm_path
|
str
|
Path to the CHM raster. |
required |
chm_alpha
|
float
|
Transparency of the CHM overlay. Defaults to 0.5. |
0.5
|
chm_cmap
|
str
|
Colormap for the CHM. Defaults to "viridis". |
'viridis'
|
chm_vmin
|
Optional[float]
|
Min value for CHM colormap scaling. Defaults to CHM min. |
None
|
chm_vmax
|
Optional[float]
|
Max value for CHM colormap scaling. Defaults to CHM max. |
None
|
figsize
|
tuple
|
Figure size. Defaults to (10, 10). |
(10, 10)
|
title
|
str
|
Plot title. Defaults to "CHM Overlay on Ortho". |
'CHM Overlay on Ortho'
|
Returns:
| Type | Description |
|---|---|
Figure
|
matplotlib Figure object. |
Source code in tree_detection_framework/utils/raster.py
reproject_raster(input_file, output_file, dst_crs)
¶
summary
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_file
|
PATH_TYPE
|
description |
required |
output_file
|
PATH_TYPE
|
description |
required |
dst_crs
|
PATH_TYPE
|
description |
required |
Returns:
| Name | Type | Description |
|---|---|---|
PATH_TYPE |
PATH_TYPE
|
description |
Source code in tree_detection_framework/utils/raster.py
show_raster(raster_file_path, downsample_factor=10.0, plt_ax=None, CRS=None)
¶
Show a raster, optionally downsampling or reprojecting it
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raster_file_path
|
PATH_TYPE
|
Path to the raster file |
required |
downsample_factor
|
float
|
How much to downsample the raster before visualization, this makes it faster and consume less memory |
10.0
|
plt_ax
|
Optional[axes]
|
Axes to plot on, otherwise the current ones are used. Defaults to None. |
None
|
CRS
|
Optional[CRS]
|
The CRS to reproject the data to if set. Defaults to None. |
None
|