preprocess_planet_v2_pingo
darts.training.preprocess_planet_v2_pingo
¶
PLANET preprocessing functions for training with the v2 data preprocessing.
_get_region_name
¶
_get_region_name(
footprint: geopandas.GeoSeries,
admin2: geopandas.GeoDataFrame,
) -> str
Source code in darts/src/darts/training/preprocess_planet_v2_pingo.py
_path_gen
¶
preprocess_planet_train_data_pingo
¶
preprocess_planet_train_data_pingo(
*,
data_dir: pathlib.Path,
labels_dir: pathlib.Path,
train_data_dir: pathlib.Path,
arcticdem_dir: pathlib.Path,
tcvis_dir: pathlib.Path,
admin_dir: pathlib.Path,
preprocess_cache: pathlib.Path | None = None,
force_preprocess: bool = False,
device: typing.Literal["cuda", "cpu", "auto"]
| int
| None = None,
ee_project: str | None = None,
ee_use_highvolume: bool = True,
tpi_outer_radius: int = 100,
tpi_inner_radius: int = 0,
patch_size: int = 1024,
overlap: int = 16,
exclude_nopositive: bool = False,
exclude_nan: bool = True,
)
Preprocess Planet data for training (Pingo version).
This function preprocesses Planet scenes into a training-ready format by creating fixed-size patches and storing them in a zarr array for efficient random access during training. All data is stored in a single zarr group with associated metadata.
The preprocessing creates patches of the specified size from each Planet scene and stores them as: - A zarr group containing 'x' (input data) and 'y' (labels) arrays - A geopandas dataframe with metadata including region, position, and label statistics - A configuration file with preprocessing parameters
The x dataarray contains the input data with shape (n_patches, n_bands, patch_size, patch_size). The y dataarray contains the labels with shape (n_patches, patch_size, patch_size). Both dataarrays are chunked along the n_patches dimension with chunk size 1, resulting in each patch being stored in a separate file for super fast random access.
The metadata dataframe contains information about each patch including: - sample_id: Identifier for the source Planet scene - region: Administrative region name - geometry: Spatial extent of the patch - empty: Whether the patch contains positive labeled pixels - Additional metadata as specified
Through exclude_nopositive
and exclude_nan
, respective patches can be excluded from the final data.
A config.toml
file is saved in the train_data_dir
containing the configuration used for the
preprocessing. Additionally, a timestamp-based CLI configuration file is saved for reproducibility.
The final directory structure of train_data_dir
will look like this:
train_data_dir/
├── config.toml
├── data.zarr/
│ ├── x/ # Input patches [n_patches, n_bands, patch_size, patch_size]
│ └── y/ # Label patches [n_patches, patch_size, patch_size]
├── metadata.parquet
└── {timestamp}.cli.json
Parameters:
-
data_dir
(pathlib.Path
) –The directory containing the Planet scenes and orthotiles.
-
labels_dir
(pathlib.Path
) –The directory containing the labels and footprints / extents.
-
train_data_dir
(pathlib.Path
) –The "output" directory where the tensors are written to.
-
arcticdem_dir
(pathlib.Path
) –The directory containing the ArcticDEM data (the datacube and the extent files). Will be created and downloaded if it does not exist.
-
tcvis_dir
(pathlib.Path
) –The directory containing the TCVis data.
-
admin_dir
(pathlib.Path
) –The directory containing the admin files.
-
preprocess_cache
(pathlib.Path
, default:None
) –The directory to store the preprocessed data. Defaults to None.
-
force_preprocess
(bool
, default:False
) –Whether to force the preprocessing of the data. Defaults to False.
-
device
(typing.Literal['cuda', 'cpu'] | int
, default:None
) –The device to run the model on. If "cuda" take the first device (0), if int take the specified device. If "auto" try to automatically select a free GPU (<50% memory usage). Defaults to "cuda" if available, else "cpu".
-
ee_project
(str
, default:None
) –The Earth Engine project ID or number to use. May be omitted if project is defined within persistent API credentials obtained via
earthengine authenticate
. -
ee_use_highvolume
(bool
, default:True
) –Whether to use the high volume server (https://earthengine-highvolume.googleapis.com).
-
tpi_outer_radius
(int
, default:100
) –The outer radius of the annulus kernel for the tpi calculation in m. Defaults to 100m.
-
tpi_inner_radius
(int
, default:0
) –The inner radius of the annulus kernel for the tpi calculation in m. Defaults to 0.
-
patch_size
(int
, default:1024
) –The patch size to use for inference. Defaults to 1024.
-
overlap
(int
, default:16
) –The overlap to use for inference. Defaults to 16.
-
exclude_nopositive
(bool
, default:False
) –Whether to exclude patches where the labels do not contain positives. Defaults to False.
-
exclude_nan
(bool
, default:True
) –Whether to exclude patches where the input data has nan values. Defaults to True.
Source code in darts/src/darts/training/preprocess_planet_v2_pingo.py
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 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 251 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 |
|