Combined Reference¶
All references on one page
darts
¶
DARTS processing pipeline.
__version__ = importlib.metadata.version('darts-nextgen')
module-attribute
¶
darts_acquisition
¶
Acquisition of data from various sources for the DARTS dataset.
__version__ = importlib.metadata.version('darts-nextgen')
module-attribute
¶
download_admin_files(admin_dir)
¶
Download the admin files for the regions.
Files will be stored under [admin_dir]/adm1.shp and [admin_dir]/adm2.shp.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
admin_dir
|
Path
|
The path to the admin files. |
required |
Source code in darts-acquisition/src/darts_acquisition/admin.py
load_arcticdem(geobox, data_dir, resolution, buffer=0, persist=True)
¶
Load the ArcticDEM for the given geobox, fetch new data from the STAC server if necessary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
geobox
|
GeoBox
|
The geobox for which the tile should be loaded. |
required |
data_dir
|
Path | str
|
The directory where the ArcticDEM data is stored. |
required |
resolution
|
Literal[2, 10, 32]
|
The resolution of the ArcticDEM data in m. |
required |
buffer
|
int
|
The buffer around the projected (epsg:3413) geobox in pixels. Defaults to 0. |
0
|
persist
|
bool
|
If the data should be persisted in memory. If not, this will return a Dask backed Dataset. Defaults to True. |
True
|
Returns:
Type | Description |
---|---|
Dataset
|
xr.Dataset: The ArcticDEM tile, with a buffer applied. Note: The buffer is applied in the arcticdem dataset's CRS, hence the orientation might be different. Final dataset is NOT matched to the reference CRS and resolution. |
Warning
Geobox must be in a meter based CRS.
Usage
Since the API of the load_arcticdem
is based on GeoBox, one can load a specific ROI based on an existing Xarray DataArray:
import xarray as xr
import odc.geo.xr
from darts_aquisition import load_arcticdem
# Assume "optical" is an already loaded s2 based dataarray
arcticdem = load_arcticdem(
optical.odc.geobox,
"/path/to/arcticdem-parent-directory",
resolution=2,
buffer=ceil(self.tpi_outer_radius / 2 * sqrt(2))
)
# Now we can for example match the resolution and extent of the optical data:
arcticdem = arcticdem.odc.reproject(optical.odc.geobox, resampling="cubic")
The buffer
parameter is used to extend the region of interest by a certain amount of pixels.
This comes handy when calculating e.g. the Topographic Position Index (TPI), which requires a buffer around the region of interest to remove edge effects.
Source code in darts-acquisition/src/darts_acquisition/arcticdem/datacube.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 |
|
load_arcticdem_from_vrt(slope_vrt, elevation_vrt, reference_dataset)
¶
Load ArcticDEM data and reproject it to match the reference dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slope_vrt
|
Path
|
Path to the ArcticDEM slope VRT file. |
required |
elevation_vrt
|
Path
|
Path to the ArcticDEM elevation VRT file. |
required |
reference_dataset
|
Dataset
|
The reference dataset to reproject, resampled and cropped the ArcticDEM data to. |
required |
Returns:
Type | Description |
---|---|
Dataset
|
xr.Dataset: The ArcticDEM data reprojected, resampled and cropped to match the reference dataset. |
Source code in darts-acquisition/src/darts_acquisition/arcticdem/vrt.py
load_planet_masks(fpath)
¶
Load the valid and quality data masks from a Planet scene.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fpath
|
str | Path
|
The file path to the Planet scene from which to derive the masks. |
required |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If no matching UDM-2 TIFF file is found in the specified path. |
Returns:
Type | Description |
---|---|
Dataset
|
xr.Dataset: A merged xarray Dataset containing two data masks: - 'valid_data_mask': A mask indicating valid (1) and no data (0). - 'quality_data_mask': A mask indicating high quality (1) and low quality (0). |
Source code in darts-acquisition/src/darts_acquisition/planet.py
load_planet_scene(fpath)
¶
Load a PlanetScope satellite GeoTIFF file and return it as an xarray datset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fpath
|
str | Path
|
The path to the directory containing the TIFF files or a specific path to the TIFF file. |
required |
Returns:
Type | Description |
---|---|
Dataset
|
xr.Dataset: The loaded dataset |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If no matching TIFF file is found in the specified path. |
Source code in darts-acquisition/src/darts_acquisition/planet.py
load_s2_masks(fpath, reference_geobox)
¶
Load the valid and quality data masks from a Sentinel 2 scene.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fpath
|
str | Path
|
The path to the directory containing the TIFF files. |
required |
reference_geobox
|
GeoBox
|
The reference geobox to reproject, resample and crop the masks data to. |
required |
Returns:
Type | Description |
---|---|
Dataset
|
xr.Dataset: A merged xarray Dataset containing two data masks: - 'valid_data_mask': A mask indicating valid (1) and no data (0). - 'quality_data_mask': A mask indicating high quality (1) and low quality (0). |
Source code in darts-acquisition/src/darts_acquisition/s2.py
load_s2_scene(fpath)
¶
Load a Sentinel 2 satellite GeoTIFF file and return it as an xarray datset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fpath
|
str | Path
|
The path to the directory containing the TIFF files. |
required |
Returns:
Type | Description |
---|---|
Dataset
|
xr.Dataset: The loaded dataset |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If no matching TIFF file is found in the specified path. |
Source code in darts-acquisition/src/darts_acquisition/s2.py
load_tcvis(geobox, data_dir, buffer=0, persist=True)
¶
Load the TCVIS for the given geobox, fetch new data from GEE if necessary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
geobox
|
GeoBox
|
The geobox to load the data for. |
required |
data_dir
|
Path | str
|
The directory to store the downloaded data for faster access for consecutive calls. |
required |
buffer
|
int
|
The buffer around the geobox in pixels. Defaults to 0. |
0
|
persist
|
bool
|
If the data should be persisted in memory. If not, this will return a Dask backed Dataset. Defaults to True. |
True
|
Returns:
Type | Description |
---|---|
Dataset
|
xr.Dataset: The TCVIS dataset. |
Usage
Since the API of the load_tcvis
is based on GeoBox, one can load a specific ROI based on an existing Xarray DataArray:
import xarray as xr
import odc.geo.xr
from darts_aquisition import load_tcvis
# Assume "optical" is an already loaded s2 based dataarray
tcvis = load_tcvis(
optical.odc.geobox,
"/path/to/tcvis-parent-directory",
)
# Now we can for example match the resolution and extent of the optical data:
tcvis = tcvis.odc.reproject(optical.odc.geobox, resampling="cubic")
Source code in darts-acquisition/src/darts_acquisition/tcvis.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 242 243 244 |
|
darts_ensemble
¶
Inference and model ensembling for the DARTS dataset.
__version__ = importlib.metadata.version('darts-nextgen')
module-attribute
¶
darts_export
¶
Dataset export for the DARTS dataset.
__version__ = importlib.metadata.version('darts-nextgen')
module-attribute
¶
export_arcticdem_datamask(tile, out_dir)
¶
Export the arcticdem data mask as a GeoTIFF file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tile
|
Dataset
|
The inference result. |
required |
out_dir
|
Path
|
The path where to export to. |
required |
Source code in darts-export/src/darts_export/inference.py
export_binarized(tile, out_dir, export_ensemble_inputs=False, tags={})
¶
Export the binarized segmentation layer to a file.
If export_ensemble_inputs
is set to True and the ensemble used at least two models for inference,
the binarized segmentation of the models will be written as individual files as well.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tile
|
Dataset
|
The inference result. |
required |
out_dir
|
Path
|
The path where to export to. |
required |
export_ensemble_inputs
|
bool
|
Also save the model outputs, not only the ensemble result. Only applies if the inference result is an ensemble result and has at least two inputs. Defaults to False. |
False
|
tags
|
dict
|
optional GeoTIFF metadata to be written. Defaults to no additional metadata. |
{}
|
Source code in darts-export/src/darts_export/inference.py
export_datamask(tile, out_dir)
¶
Export the data mask as a GeoTIFF file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tile
|
Dataset
|
The inference result. |
required |
out_dir
|
Path
|
The path where to export to. |
required |
Source code in darts-export/src/darts_export/inference.py
export_dem(tile, out_dir)
¶
Export the DEM data as a GeoTIFF file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tile
|
Dataset
|
The inference result. |
required |
out_dir
|
Path
|
The path where to export to. |
required |
Source code in darts-export/src/darts_export/inference.py
export_extent(tile, out_dir)
¶
Export the extent of the prediction as a vector dataset in GeoPackage and GeoParquet format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tile
|
Dataset
|
The inference result. |
required |
out_dir
|
Path
|
The path where to export to. |
required |
Source code in darts-export/src/darts_export/inference.py
export_optical(tile, out_dir)
¶
Export the optical data as a GeoTIFF file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tile
|
Dataset
|
The inference result. |
required |
out_dir
|
Path
|
The path where to export to. |
required |
Source code in darts-export/src/darts_export/inference.py
export_polygonized(tile, out_dir, export_ensemble_inputs=False, minimum_mapping_unit=32)
¶
Export the binarized probabilities as a vector dataset in GeoPackage and GeoParquet format.
If export_ensemble_inputs
is set to True and the ensemble used at least two models for inference,
the vectorized binarized segmentation of the models will be written as individual files as well.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tile
|
Dataset
|
The inference result. |
required |
out_dir
|
Path
|
The path where to export to. |
required |
export_ensemble_inputs
|
bool
|
Also save the model outputs, not only the ensemble result. Only applies if the inference result is an ensemble result and has at least two inputs. Defaults to False. |
False
|
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(tile, out_dir, export_ensemble_inputs=False, tags={})
¶
Export the probabilities layer to a file.
If export_ensemble_inputs
is set to True and the ensemble used at least two models for inference,
the probabilities of the models will be written as individual files as well.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tile
|
Dataset
|
The inference result. |
required |
out_dir
|
Path
|
The path where to export to. |
required |
export_ensemble_inputs
|
bool
|
Also save the model outputs, not only the ensemble result. Only applies if the inference result is an ensemble result and has at least two inputs. Defaults to False. |
False
|
tags
|
dict
|
optional GeoTIFF metadata to be written. Defaults to no additional metadata. |
{}
|
Source code in darts-export/src/darts_export/inference.py
export_tcvis(tile, out_dir)
¶
Export the TCVIS data as a GeoTIFF file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tile
|
Dataset
|
The inference result. |
required |
out_dir
|
Path
|
The path where to export to. |
required |
Source code in darts-export/src/darts_export/inference.py
export_thumbnail(tile, out_dir)
¶
Export a thumbnail of the optical data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tile
|
Dataset
|
The inference result. |
required |
out_dir
|
Path
|
The path where to export to. |
required |
Source code in darts-export/src/darts_export/inference.py
darts_postprocessing
¶
Postprocessing steps for the DARTS dataset.
__version__ = importlib.metadata.version('darts-nextgen')
module-attribute
¶
darts_preprocessing
¶
Data preprocessing and feature engineering for the DARTS dataset.
__version__ = importlib.metadata.version('darts-nextgen')
module-attribute
¶
preprocess_legacy(ds_optical, ds_arcticdem, ds_tcvis)
¶
Preprocess optical data with legacy (DARTS v1) preprocessing steps.
The processing steps are: - Calculate NDVI - Merge everything into a single ds.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ds_optical
|
Dataset
|
The Planet scene optical data or Sentinel 2 scene optical data. |
required |
ds_arcticdem
|
Dataset
|
The ArcticDEM data. |
required |
ds_tcvis
|
Dataset
|
The TCVIS data. |
required |
Returns:
Type | Description |
---|---|
Dataset
|
xr.Dataset: The preprocessed dataset. |
Source code in darts-preprocessing/src/darts_preprocessing/preprocess.py
preprocess_legacy_fast(ds_merged, ds_arcticdem, ds_tcvis, tpi_outer_radius=100, tpi_inner_radius=0, device=DEFAULT_DEVICE)
¶
Preprocess optical data with legacy (DARTS v1) preprocessing steps, but with new data concepts.
The processing steps are: - Calculate NDVI - Calculate slope and relative elevation from ArcticDEM - Merge everything into a single ds.
The main difference to preprocess_legacy is the new data concept of the arcticdem. Instead of using already preprocessed arcticdem data which are loaded from a VRT, this step expects the raw arcticdem data and calculates slope and relative elevation on the fly.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ds_merged
|
Dataset
|
The Planet scene optical data or Sentinel 2 scene optical dataset including data_masks. |
required |
ds_arcticdem
|
Dataset
|
The ArcticDEM dataset. |
required |
ds_tcvis
|
Dataset
|
The TCVIS dataset. |
required |
tpi_outer_radius
|
int
|
The outer radius of the annulus kernel for the tpi calculation in m. Defaults to 100m. |
100
|
tpi_inner_radius
|
int
|
The inner radius of the annulus kernel for the tpi calculation in m. Defaults to 0. |
0
|
device
|
Literal['cuda', 'cpu'] | int
|
The device to run the tpi and slope calculations on. If "cuda" take the first device (0), if int take the specified device. Defaults to "cuda" if cuda is available, else "cpu". |
DEFAULT_DEVICE
|
Returns:
Type | Description |
---|---|
Dataset
|
xr.Dataset: The preprocessed dataset. |
Source code in darts-preprocessing/src/darts_preprocessing/preprocess.py
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 |
|
darts_segmentation
¶
Image segmentation of thaw-slumps for the DARTS dataset.
__version__ = importlib.metadata.version('darts-nextgen')
module-attribute
¶
SMPSegmenter
¶
An actor that keeps a model as its state and segments tiles.
Source code in darts-segmentation/src/darts_segmentation/segment.py
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 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
|
config = validate_config(ckpt['config'])
instance-attribute
¶
device = device
instance-attribute
¶
model = smp.create_model(**self.config['model'])
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. Tensor will be sliced into patches and these again will be infered in batches. Defaults to 8. |
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, device=DEFAULT_DEVICE)
¶
Initialize the segmenter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_checkpoint
|
Path
|
The path to the model checkpoint. |
required |
device
|
device
|
The device to run the model on. Defaults to torch.device("cuda") if cuda is available, else torch.device("cpu"). |
DEFAULT_DEVICE
|
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. Tensor will be sliced into patches and these again will be infered in batches. Defaults to 8. |
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. Tensor will be sliced into patches and these again will be infered in batches. Defaults to 8. |
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
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 |
|