Datasets:

Modalities:
Geospatial
Languages:
English
DOI:
Libraries:
License:
File size: 3,793 Bytes
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
import os
import datasets
import rasterio
import tqdm

class SSL4EOEUForest(datasets.GeneratorBasedBuilder):
    def _info(self):
        return datasets.DatasetInfo(
            description="SSL4EO-EU Forest dataset with four-season of Sentinel-2 timestamps and bounding box metadata extracted from image folders.",
            features=datasets.Features({
                "image_path": datasets.Value("string"),
                "mask_path": datasets.Value("string"),
                "start_timestamp": datasets.Value("string"),
                "end_timestamp": datasets.Value("string"),
                "sentinel_tile_id": datasets.Value("string"),
                "bbox": {
                    "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 tqdm.tqdm(sample_id_list, desc="Indexing samples", unit="sample"):
            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

            for ts in timestamp_dirs:
                parts = ts.split("_")
                if len(parts) != 3:
                    continue

                start_ts, end_ts, tile_id = parts
                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

                yield key, {
                    "image_path": image_path,
                    "mask_path": mask_path,
                    "start_timestamp": start_ts,
                    "end_timestamp": end_ts,
                    "sentinel_tile_id": tile_id,
                    "bbox": {
                        "minx": bounds.left,
                        "maxx": bounds.right,
                        "miny": bounds.bottom,
                        "maxy": bounds.top
                    }
                }
                key += 1