Combined Reference¶
All references on one page
darts
¶
DARTS processing pipeline.
__version__ = version('darts-nextgen')
module-attribute
¶
run_native_planet_pipeline(orthotiles_dir, scenes_dir, output_data_dir, arcticdem_slope_vrt, arcticdem_elevation_vrt, model_dir, tcvis_model_name='RTS_v6_tcvis.pt', notcvis_model_name='RTS_v6_notcvis.pt', cache_dir=None, ee_project=None, patch_size=1024, overlap=16, batch_size=8, reflection=0)
¶
Search for all PlanetScope scenes in the given directory and runs the segmentation pipeline on them.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
orthotiles_dir
|
Path
|
The directory containing the PlanetScope orthotiles. |
required |
scenes_dir
|
Path
|
The directory containing the PlanetScope scenes. |
required |
output_data_dir
|
Path
|
The "output" directory. |
required |
arcticdem_slope_vrt
|
Path
|
The path to the ArcticDEM slope VRT file. |
required |
arcticdem_elevation_vrt
|
Path
|
The path to the ArcticDEM elevation VRT file. |
required |
model_dir
|
Path
|
The path to the models to use for segmentation. |
required |
tcvis_model_name
|
str
|
The name of the model to use for TCVis. Defaults to "RTS_v6_tcvis.pt". |
'RTS_v6_tcvis.pt'
|
notcvis_model_name
|
str
|
The name of the model to use for not TCVis. Defaults to "RTS_v6_notcvis.pt". |
'RTS_v6_notcvis.pt'
|
cache_dir
|
Path | None
|
The cache directory. If None, no caching will be used. Defaults to None. |
None
|
ee_project
|
str
|
The Earth Engine project ID or number to use. May be omitted if
project is defined within persistent API credentials obtained via |
None
|
patch_size
|
int
|
The patch size to use for inference. Defaults to 1024. |
1024
|
overlap
|
int
|
The overlap to use for inference. Defaults to 16. |
16
|
batch_size
|
int
|
The batch size to use for inference. Defaults to 8. |
8
|
reflection
|
int
|
The reflection padding to use for inference. Defaults to 0. |
0
|
Todo
Document the structure of the input data dir.
Source code in darts/src/darts/native.py
run_native_sentinel2_pipeline(sentinel2_dir, output_data_dir, arcticdem_slope_vrt, arcticdem_elevation_vrt, model_dir, tcvis_model_name='RTS_v6_tcvis.pt', notcvis_model_name='RTS_v6_notcvis.pt', cache_dir=None, ee_project=None, patch_size=1024, overlap=16, batch_size=8, reflection=0)
¶
Search for all PlanetScope scenes in the given directory and runs the segmentation pipeline on them.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sentinel2_dir
|
Path
|
The directory containing the Sentinel 2 scenes. |
required |
output_data_dir
|
Path
|
The "output" directory. |
required |
arcticdem_slope_vrt
|
Path
|
The path to the ArcticDEM slope VRT file. |
required |
arcticdem_elevation_vrt
|
Path
|
The path to the ArcticDEM elevation VRT file. |
required |
model_dir
|
Path
|
The path to the models to use for segmentation. |
required |
tcvis_model_name
|
str
|
The name of the model to use for TCVis. Defaults to "RTS_v6_tcvis.pt". |
'RTS_v6_tcvis.pt'
|
notcvis_model_name
|
str
|
The name of the model to use for not TCVis. Defaults to "RTS_v6_notcvis.pt". |
'RTS_v6_notcvis.pt'
|
cache_dir
|
Path | None
|
The cache directory. If None, no caching will be used. Defaults to None. |
None
|
ee_project
|
str
|
The Earth Engine project ID or number to use. May be omitted if
project is defined within persistent API credentials obtained via |
None
|
patch_size
|
int
|
The patch size to use for inference. Defaults to 1024. |
1024
|
overlap
|
int
|
The overlap to use for inference. Defaults to 16. |
16
|
batch_size
|
int
|
The batch size to use for inference. Defaults to 8. |
8
|
reflection
|
int
|
The reflection padding to use for inference. Defaults to 0. |
0
|
Todo
Document the structure of the input data dir.
Source code in darts/src/darts/native.py
darts_acquisition
¶
Acquisition of data from various sources for the DARTS dataset.
hello(name)
¶
Say hello to the user.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the user. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Greating message. |
darts_ensemble
¶
Inference and model ensembling for the DARTS dataset.
darts_export
¶
Dataset export for the DARTS dataset.
InferenceResultWriter
¶
Writer class to export inference result datasets.
Source code in darts-export/src/darts_export/inference.py
ds: xarray.Dataset = ds
instance-attribute
¶
__init__(ds)
¶
export_binarized(path, filename='pred_binarized.tif', tags={})
¶
Export the binarized segmentation result of the inference Result.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Path
|
The path where to export to. |
required |
filename
|
str
|
the filename. Defaults to "pred_binarized.tif". |
'pred_binarized.tif'
|
tags
|
dict
|
optional GeoTIFF metadate to be written. Defaults to no additional metadata. |
{}
|
Returns:
Type | Description |
---|---|
the Path of the written file |
Source code in darts-export/src/darts_export/inference.py
export_polygonized(path, filename_prefix='pred_segments', minimum_mapping_unit=32)
¶
Export the binarized probabilities as a vector dataset in GeoPackage and GeoParquet format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Path
|
The path where to export the files |
required |
filename_prefix
|
str
|
the file prefix of the exported files. Defaults to "pred_segments". |
'pred_segments'
|
minimum_mapping_unit
|
int
|
segments covering less pixel are removed. Defaults to 32. |
32
|
Source code in darts-export/src/darts_export/inference.py
export_probabilities(path, filename='pred_probabilities.tif', tags={})
¶
Export the probabilities layer to a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Path
|
The path where to export to. |
required |
filename
|
str
|
the filename. Defaults to "pred_probabilities.tif". |
'pred_probabilities.tif'
|
tags
|
dict
|
optional GeoTIFF metadate to be written. Defaults to no additional metadata. |
{}
|
Returns:
Type | Description |
---|---|
the Path of the written file |
Source code in darts-export/src/darts_export/inference.py
darts_postprocessing
¶
Postprocessing steps for the DARTS dataset.
darts_preprocessing
¶
Data preprocessing and feature engineering for the DARTS dataset.
load_and_preprocess_planet_scene(planet_scene_path, slope_vrt, elevation_vrt, cache_dir=None)
¶
Load and preprocess a Planet Scene (PSOrthoTile or PSScene) into an xr.Dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
planet_scene_path
|
Path
|
path to the Planet Scene |
required |
slope_vrt
|
Path
|
path to the ArcticDEM slope VRT file |
required |
elevation_vrt
|
Path
|
path to the ArcticDEM elevation VRT file |
required |
cache_dir
|
Path | None
|
The cache directory. If None, no caching will be used. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
Dataset
|
xr.Dataset: preprocessed Planet Scene |
Examples:
PS Orthotile¶
Data directory structure:
data/input
├── ArcticDEM
│ ├── elevation.vrt
│ ├── slope.vrt
│ ├── relative_elevation
│ │ └── 4372514_relative_elevation_100.tif
│ └── slope
│ └── 4372514_slope.tif
└── planet
└── PSOrthoTile
└── 4372514/5790392_4372514_2022-07-16_2459
├── 5790392_4372514_2022-07-16_2459_BGRN_Analytic_metadata.xml
├── 5790392_4372514_2022-07-16_2459_BGRN_DN_udm.tif
├── 5790392_4372514_2022-07-16_2459_BGRN_SR.tif
├── 5790392_4372514_2022-07-16_2459_metadata.json
└── 5790392_4372514_2022-07-16_2459_udm2.tif
Load and preprocess a Planet Scene:
from pathlib import Path
from darts_preprocessing.preprocess import load_and_preprocess_planet_scene
fpath = Path("data/input/planet/PSOrthoTile/4372514/5790392_4372514_2022-07-16_2459")
arcticdem_dir = input_data_dir / "ArcticDEM"
tile = load_and_preprocess_planet_scene(fpath, arcticdem_dir / "slope.vrt", arcticdem_dir / "elevation.vrt")
PS Scene¶
Data directory structure:
data/input
├── ArcticDEM
│ ├── elevation.vrt
│ ├── slope.vrt
│ ├── relative_elevation
│ │ └── 4372514_relative_elevation_100.tif
│ └── slope
│ └── 4372514_slope.tif
└── planet
└── PSScene
└── 20230703_194241_43_2427
├── 20230703_194241_43_2427_3B_AnalyticMS_metadata.xml
├── 20230703_194241_43_2427_3B_AnalyticMS_SR.tif
├── 20230703_194241_43_2427_3B_udm2.tif
├── 20230703_194241_43_2427_metadata.json
└── 20230703_194241_43_2427.json
Load and preprocess a Planet Scene:
from pathlib import Path
from darts_preprocessing.preprocess import load_and_preprocess_planet_scene
fpath = Path("data/input/planet/PSOrthoTile/20230703_194241_43_2427")
arcticdem_dir = input_data_dir / "ArcticDEM"
tile = load_and_preprocess_planet_scene(fpath, arcticdem_dir / "slope.vrt", arcticdem_dir / "elevation.vrt")
Source code in darts-preprocessing/src/darts_preprocessing/preprocess.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
|
load_and_preprocess_sentinel2_scene(s2_scene_path, slope_vrt, elevation_vrt, cache_dir=None)
¶
Load and preprocess a Sentinel 2 scene into an xr.Dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s2_scene_path
|
Path
|
path to the Sentinel 2 Scene |
required |
slope_vrt
|
Path
|
path to the ArcticDEM slope VRT file |
required |
elevation_vrt
|
Path
|
path to the ArcticDEM elevation VRT file |
required |
cache_dir
|
Path | None
|
The cache directory. If None, no caching will be used. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
Dataset
|
xr.Dataset: preprocessed Sentinel Scene |
Examples:
Data directory structure:
data/input
├── ArcticDEM
│ ├── elevation.vrt
│ ├── slope.vrt
│ ├── relative_elevation
│ │ └── 4372514_relative_elevation_100.tif
│ └── slope
│ └── 4372514_slope.tif
└── sentinel2
└── 20220826T200911_20220826T200905_T17XMJ/
├── 20220826T200911_20220826T200905_T17XMJ_SCL_clip.tif
└── 20220826T200911_20220826T200905_T17XMJ_SR_clip.tif
Load and preprocess a Sentinel Scene:
from pathlib import Path
from darts_preprocessing.preprocess import load_and_preprocess_sentinel2_scene
fpath = Path("data/input/sentinel2/20220826T200911_20220826T200905_T17XMJ")
arcticdem_dir = input_data_dir / "ArcticDEM"
tile = load_and_preprocess_planet_scene(fpath, arcticdem_dir / "slope.vrt", arcticdem_dir / "elevation.vrt")
Source code in darts-preprocessing/src/darts_preprocessing/preprocess.py
darts_segmentation
¶
Image segmentation of thaw-slumps for the DARTS dataset.
SMPSegmenter
¶
An actor that keeps a model as its state and segments tiles.
Source code in darts-segmentation/src/darts_segmentation/segment.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 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 |
|
config: SMPSegmenterConfig = validate_config(ckpt['config'])
instance-attribute
¶
device: torch.device = torch.device('cpu') if not torch.cuda.is_available() else torch.device('cuda')
instance-attribute
¶
model: nn.Module = smp.create_model(**self.config['model'], encoder_weights=None)
instance-attribute
¶
__call__(input, patch_size=1024, overlap=16, batch_size=8, reflection=0)
¶
Run inference on a single tile or a list of tiles.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input
|
Dataset | list[Dataset]
|
A single tile or a list of tiles. |
required |
patch_size
|
int
|
The size of the patches. Defaults to 1024. |
1024
|
overlap
|
int
|
The size of the overlap. Defaults to 16. |
16
|
batch_size
|
int
|
The batch size for the prediction, NOT the batch_size of input tiles. |
8
|
reflection
|
int
|
Reflection-Padding which will be applied to the edges of the tensor. Defaults to 0. |
0
|
Returns:
Type | Description |
---|---|
Dataset | list[Dataset]
|
A single tile or a list of tiles augmented by a predicted |
Dataset | list[Dataset]
|
Each |
Raises:
Type | Description |
---|---|
ValueError
|
in case the input is not an xr.Dataset or a list of xr.Dataset |
Source code in darts-segmentation/src/darts_segmentation/segment.py
__init__(model_checkpoint)
¶
Initialize the segmenter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_checkpoint
|
Path
|
The path to the model checkpoint. |
required |
Source code in darts-segmentation/src/darts_segmentation/segment.py
segment_tile(tile, patch_size=1024, overlap=16, batch_size=8, reflection=0)
¶
Run inference on a tile.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tile
|
Dataset
|
The input tile, containing preprocessed, harmonized data. |
required |
patch_size
|
int
|
The size of the patches. Defaults to 1024. |
1024
|
overlap
|
int
|
The size of the overlap. Defaults to 16. |
16
|
batch_size
|
int
|
The batch size for the prediction, NOT the batch_size of input tiles. |
8
|
reflection
|
int
|
Reflection-Padding which will be applied to the edges of the tensor. Defaults to 0. |
0
|
Returns:
Type | Description |
---|---|
Dataset
|
Input tile augmented by a predicted |
Source code in darts-segmentation/src/darts_segmentation/segment.py
segment_tile_batched(tiles, patch_size=1024, overlap=16, batch_size=8, reflection=0)
¶
Run inference on a list of tiles.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tiles
|
list[Dataset]
|
The input tiles, containing preprocessed, harmonized data. |
required |
patch_size
|
int
|
The size of the patches. Defaults to 1024. |
1024
|
overlap
|
int
|
The size of the overlap. Defaults to 16. |
16
|
batch_size
|
int
|
The batch size for the prediction, NOT the batch_size of input tiles. |
8
|
reflection
|
int
|
Reflection-Padding which will be applied to the edges of the tensor. Defaults to 0. |
0
|
Returns:
Type | Description |
---|---|
list[Dataset]
|
A list of input tiles augmented by a predicted |
Source code in darts-segmentation/src/darts_segmentation/segment.py
tile2tensor(tile)
¶
Take a tile and convert it to a pytorch tensor.
Respects the input combination from the config.
Returns:
Type | Description |
---|---|
Tensor
|
A torch tensor for the full tile consisting of the bands specified in |
Source code in darts-segmentation/src/darts_segmentation/segment.py
tile2tensor_batched(tiles)
¶
Take a list of tiles and convert them to a pytorch tensor.
Respects the the input combination from the config.
Returns:
Type | Description |
---|---|
Tensor
|
A torch tensor for the full tile consisting of the bands specified in |
Source code in darts-segmentation/src/darts_segmentation/segment.py
SMPSegmenterConfig
¶
Bases: TypedDict
Configuration for the segmentor.
Source code in darts-segmentation/src/darts_segmentation/segment.py
create_patches(tensor_tiles, patch_size, overlap, return_coords=False)
¶
Create patches from a tensor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tensor_tiles
|
Tensor
|
The input tensor. Shape: (BS, C, H, W). |
required |
patch_size
|
int
|
The size of the patches. |
required |
overlap
|
int
|
The size of the overlap. |
required |
return_coords
|
bool
|
Whether to return the coordinates of the patches. Can be used for debugging. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor: The patches. Shape: (BS, N_h, N_w, C, patch_size, patch_size). |
Source code in darts-segmentation/src/darts_segmentation/utils.py
patch_coords(h, w, patch_size, overlap)
¶
Yield patch coordinates based on height, width, patch size and margin size.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
h
|
int
|
Height of the image. |
required |
w
|
int
|
Width of the image. |
required |
patch_size
|
int
|
Patch size. |
required |
overlap
|
int
|
Margin size. |
required |
Yields:
Type | Description |
---|---|
tuple[int, int, int, int]
|
tuple[int, int, int, int]: The patch coordinates y, x, patch_idx_y and patch_idx_x. |
Source code in darts-segmentation/src/darts_segmentation/utils.py
predict_in_patches(model, tensor_tiles, patch_size, overlap, batch_size, reflection, device=torch.device, return_weights=False)
¶
Predict on a tensor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
Module
|
The model to use for prediction. |
required |
tensor_tiles
|
Tensor
|
The input tensor. Shape: (BS, C, H, W). |
required |
patch_size
|
int
|
The size of the patches. |
required |
overlap
|
int
|
The size of the overlap. |
required |
batch_size
|
int
|
The batch size for the prediction, NOT the batch_size of input tiles. Tensor will be sliced into patches and these again will be infered in batches. |
required |
reflection
|
int
|
Reflection-Padding which will be applied to the edges of the tensor. |
required |
device
|
device
|
The device to use for the prediction. |
device
|
return_weights
|
bool
|
Whether to return the weights. Can be used for debugging. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
Tensor
|
The predicted tensor. |
Source code in darts-segmentation/src/darts_segmentation/utils.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
|