Datasets:
File size: 4,532 Bytes
a248601 73c6f98 a248601 73c6f98 a248601 73c6f98 a248601 73c6f98 a248601 73c6f98 a248601 73c6f98 a248601 73c6f98 a248601 73c6f98 a248601 73c6f98 a248601 73c6f98 a248601 73c6f98 a248601 73c6f98 | 1 2 3 4 5 6 7 8 9 10 11 12 13 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 116 117 |
import os
import datasets
import rasterio
import tqdm
import datetime
class SSL4EOEUForest(datasets.GeneratorBasedBuilder):
def _info(self):
return datasets.DatasetInfo(
description="SSL4EO-EU Forest dataset with four-season Sentinel-2 timestamps and bounding box metadata extracted from image folders.",
features=datasets.Features({
"image_paths": datasets.Sequence(datasets.Value("string")),
"mask_path": datasets.Value("string"),
"start_timestamps": datasets.Sequence(datasets.Value("timestamp[ms]")),
"end_timestamps": datasets.Sequence(datasets.Value("timestamp[ms]")),
"sentinel_tile_ids": datasets.Sequence(datasets.Value("string")),
"bboxes": datasets.Sequence({
"minx": datasets.Value("float32"),
"maxx": datasets.Value("float32"),
"miny": datasets.Value("float32"),
"maxy": datasets.Value("float32"),
})
}),
citation="""@misc{ssl4eo_eu_forest,
author = {Nassim Ait Ali Braham and Conrad M Albrecht},
title = {SSL4EO-EU Forest Dataset},
year = {2025},
howpublished = {https://huggingface.co/datasets/dm4eo/ssl4eo-eu-forest},
note = {This work was carried under the EvoLand project, cf. https://www.evo-land.eu . This project has received funding from the European Union's Horizon Europe research and innovation programme under grant agreement No. 101082130.}
}""",
homepage="https://www.evo-land.eu",
license="CC-BY-4.0",
)
def _split_generators(self, dl_manager):
use_local = os.environ.get("HF_DATASET_LOCAL", "false").lower() == "true"
if use_local:
root = os.path.abspath(".")
else:
root = dl_manager.download_and_extract(".")
images_dir = os.path.join(root, "images")
masks_dir = os.path.join(root, "masks")
return [
datasets.SplitGenerator(name=datasets.Split("all"), gen_kwargs={
"images_dir": images_dir,
"masks_dir": masks_dir
})
]
def _generate_examples(self, images_dir, masks_dir):
sample_id_list = sorted(os.listdir(images_dir))
key = 0
for sample_id in sample_id_list:
sample_path = os.path.join(images_dir, sample_id)
if not os.path.isdir(sample_path):
continue
timestamp_dirs = sorted(os.listdir(sample_path))
mask_path = os.path.join(masks_dir, sample_id, "mask.tif")
if not os.path.exists(mask_path):
continue
image_paths = []
start_timestamps = []
end_timestamps = []
tile_ids = []
bboxes = []
for ts in timestamp_dirs:
parts = ts.split("_")
if len(parts) != 3:
continue
try:
start_ts = datetime.datetime.strptime(parts[0], "%Y%m%dT%H%M%S")
end_ts = datetime.datetime.strptime(parts[1], "%Y%m%dT%H%M%S")
except ValueError:
continue
tile_id = parts[2]
image_path = os.path.join(sample_path, ts, "all_bands.tif")
if not os.path.exists(image_path):
continue
try:
with rasterio.open(image_path) as src:
bounds = src.bounds
except Exception:
continue
image_paths.append(image_path)
start_timestamps.append(start_ts)
end_timestamps.append(end_ts)
tile_ids.append(tile_id)
bboxes.append({
"minx": bounds.left,
"maxx": bounds.right,
"miny": bounds.bottom,
"maxy": bounds.top
})
if image_paths:
yield key, {
"image_paths": image_paths,
"mask_path": mask_path,
"start_timestamps": start_timestamps,
"end_timestamps": end_timestamps,
"sentinel_tile_ids": tile_ids,
"bboxes": bboxes
}
key += 1
|