Reference
disfor
get(name)
Function to get data paths
This function fetches the paths to the raw data provided in DISFOR.
If the data is not available locally, it uses pooch to fetch the data from huggingface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
Literal['samples.parquet', 'labels.parquet', 'pixel_data.parquet', 'tiffs', 'train_ids.json', 'val_ids.json', 'classes.json']
|
Name of the file to fetch. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Path to the file on local storage |
Source code in src/disfor/io.py
datasets
GenericDataset
A generic class which serves to load, filter and pre-process the raw data.
There are two classes which then bring the filtered and pre-processed data into formats which
can be used with pytorch (disfor.datasets.MonoTemporalClassification) and sklearn style classifiers (disfor.datasets.TabularDataset) respectively.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_folder
|
str | None
|
Path to root data folder containing pixel_data.parquet, labels.parquet and samples.parquet,
if not specified, data will be fetched using |
None
|
target_classes
|
List[Literal[100, 110, 120, 121, 122, 123, 200, 210, 211, 212, 213, 220, 221, 222, 230, 231, 232, 240, 241, 242, 243, 244, 245]] | None
|
Which classes should be included |
None
|
class_mapping_overrides
|
Dict[int, int] | None
|
Map classes to other classes for example {221: 211, 222: 211} would map both of the salvage classes to clear cut.
This remapping happens before filtering of |
None
|
confidence
|
List[Literal['high', 'medium']] | None
|
Filters dataset to only include logged confidence of label interpretation. |
None
|
valid_scl_values
|
List[Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]] | None
|
List of valid SCL values. Used to filter out cloudy or otherwise unusable observations |
None
|
chip_size
|
Literal[32, 16, 8, 4]
|
Size of the image chip. Maximum of 32x32. Used in |
32
|
min_clear_percentage_chip
|
int | None
|
Minimum percent (0-100) of pixels in the chip that has to be clear (SCL in 4,5,6) to be included. |
None
|
months
|
List[Literal[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]] | None
|
List of months to include acquisitions from. January is 1, December is 12. |
None
|
max_days_since_event
|
int | dict | None
|
Either an integer specifying the maximum duration in days to the start label. This can also be set separately for each target_class. For example if target_classes is [110, 211] (Mature Forest, Clear Cut) we can specify a maximum number of 90 days after a Clear Cut by passing a dictionary with {211: 90} |
None
|
sample_datasets
|
List[Literal[1, 2, 3]] | None
|
Data from which sampling campaign should be included. Includes data from all by default (None) |
None
|
max_samples_per_event
|
int | None
|
Maximum number of acquisitions to include per event. Can be used to reduce number of samples drawn from segments with long durations. For example to reduce the number of healthy acquistions |
None
|
random_seed
|
int | None
|
Random seed used for reproducible subsampling operations |
None
|
apply_downsampling
|
bool
|
Flag if downsampling sampling of the majority class should be used. |
False
|
target_majority_samples
|
int | None
|
How many samples the majority class should have after balancing. If None, the majority class will be reduced to 2 times the samples of the second largest class, or 500, whichever is less. |
None
|
omit_border
|
bool
|
Omit samples which have "border" in the comment. These are usually samples where the sample is a mixed pixel |
True
|
omit_low_tcd
|
bool
|
Omit samples which have "TCD" in the comment. These are usually samples where the forest has a low tree cover density (for example olive plantations) |
True
|
bands
|
List[Literal['B02', 'B03', 'B04', 'B05', 'B06', 'B07', 'B08', 'B8A', 'B11', 'B12', 'SCL']] | None
|
Spectral bands to include |
None
|
remove_outliers
|
bool
|
Flag if outliers should be removed. This is used to remove clouds or other data artifacts which were not masked through the SCL values. |
False
|
outlier_method
|
Literal['iqr', 'zscore', 'modified_zscore']
|
Statistical method used to determine outliers. This statistical measure is calculated for each unique
|
'iqr'
|
outlier_threshold
|
float
|
Which threshold to apply, acquisitions greater than |
1.5
|
outlier_columns
|
List[Literal['B02', 'B03', 'B04', 'B05', 'B06', 'B07', 'B08', 'B8A', 'B11', 'B12', 'SCL']] | None
|
Which columns (bands) to search for outliers. If an outlier is detected in any of the bands
it will be removed. Default is all bands which are defined in the parameter |
None
|
label_strategy
|
Literal['LabelEncoder', 'LabelBinarizer', 'Hierarchical']
|
How the values in |
'LabelEncoder'
|
Attributes:
| Name | Type | Description |
|---|---|---|
pixel_data |
Polars dataframe containing filtered and pre-processed data. |
Source code in src/disfor/datasets/generic.py
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 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 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 | |
TabularDataset
Bases: GenericDataset
Class providing data for sklearn style models
For usage see the dataloaders usage page.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Unpack[DatasetParams]
|
keyword arguments being passed to disfor.datasets.GenericDataset |
{}
|
Source code in src/disfor/datasets/tabular.py
utils
HierarchicalLabelEncoder
Sklearn-style encoder for hierarchical multi-class labels with multi-hot encoding.
Assumes a 3-level hierarchy where: - Level 1: First digit (e.g., 1xx, 2xx) - Level 2: First two digits (e.g., 11x, 12x, 21x) - Level 3: All three digits (e.g., 110, 111, 211)
Source code in src/disfor/utils.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 | |
fit(y)
Fit the encoder by discovering all unique classes at each hierarchy level.
Parameters:
y : List[int] List of integer class labels
Returns:
self : HierarchicalLabelEncoder
Source code in src/disfor/utils.py
fit_transform(y)
Fit the encoder and transform labels in one step.
Parameters:
y : List[int] List of integer class labels
Returns:
encoded : np.ndarray Multi-hot encoded array
Source code in src/disfor/utils.py
get_feature_names()
Get feature names for the encoded output.
Returns:
names : List[str] List of feature names in format "level1_X", "level2_XX", "level3_XXX"
Source code in src/disfor/utils.py
inverse_transform(encoded)
Transform multi-hot encoded labels back to original labels.
Parameters:
encoded : np.ndarray Multi-hot encoded array of shape (n_samples, n_features)
Returns:
labels : List[int] List of integer class labels
Source code in src/disfor/utils.py
transform(y)
Transform labels to hierarchical multi-hot encoding.
Parameters:
y : List[int] List of integer class labels
Returns:
encoded : np.ndarray Multi-hot encoded array of shape (n_samples, n_features) where n_features = len(level1) + len(level2) + len(level3)