File size: 5,511 Bytes
7454832
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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
import os

import datasets
import h5py
import hdf5plugin
import pandas as pd
import pyarrow

pyarrow.PyExtensionType.set_auto_load(True)

_CITATION = """\
@misc{cambrin2025texttoremotesensingimageretrievalrgbsources,
      title={Text-to-Remote-Sensing-Image Retrieval beyond RGB Sources}, 
      author={Daniele Rege Cambrin and Lorenzo Vaiani and Giuseppe Gallipoli and Luca Cagliero and Paolo Garza},
      year={2025},
      eprint={2507.10403},
      archivePrefix={arXiv},
      primaryClass={cs.CV},
      url={https://arxiv.org/abs/2507.10403}, 
}
"""

_DESCRIPTION = """\
CrisisLandMark is a large-scale, multimodal corpus for Text-to-Remote-Sensing-Image Retrieval (T2RSIR). 
It contains over 647,000 Sentinel-1 (SAR) and Sentinel-2 (multispectral optical) images enriched with 
structured textual and geospatial annotations. The dataset is designed to move beyond standard RGB imagery, 
enabling the development of retrieval systems that can leverage the rich physical information from different 
satellite sensors for applications in Land Use/Land Cover (LULC) mapping and crisis management.
"""

_HOMEPAGE = "https://github.com/DarthReca/closp"  # Replace with your actual project page if different

_LICENSE = "Creative Commons Attribution Non Commercial 4.0"

# Define the satellite data sources as in the original script
_SATELLITE_DATASETS = {
    "s2": ["benv2s2", "cabuar", "sen2flood"],
    "s1": ["benv2s1", "mmflood", "sen1flood", "quakeset"],
}

_URLS = {"main": "crisislandmark.h5", "metadata": "metadata.parquet"}


class CrisisLandMarkConfig(datasets.BuilderConfig):
    """BuilderConfig for CrisisLandMark."""

    def __init__(self, satellite_type, **kwargs):
        """
        Args:
            satellite_type (str): Type of satellite data to load ('s1', 's2', or 'all').
            **kwargs: keyword arguments forwarded to super.
        """
        super(CrisisLandMarkConfig, self).__init__(**kwargs)
        self.satellite_type = satellite_type


class CrisisLandMark(datasets.GeneratorBasedBuilder):
    """CrisisLandMark Dataset."""

    VERSION = datasets.Version("1.0.0")

    # Configure for different satellite types
    BUILDER_CONFIGS = [
        CrisisLandMarkConfig(
            name="s1",
            version=VERSION,
            description="Load only Sentinel-1 (SAR) images.",
            satellite_type="s1",
        ),
        CrisisLandMarkConfig(
            name="s2",
            version=VERSION,
            description="Load only Sentinel-2 (Optical) images.",
            satellite_type="s2",
        ),
        CrisisLandMarkConfig(
            name="all",
            version=VERSION,
            description="Load all images (Sentinel-1 and Sentinel-2).",
            satellite_type="all",
        ),
    ]

    DEFAULT_CONFIG_NAME = "s2"

    def _info(self):
        # Define the features of the dataset
        features = datasets.Features(
            {
                "key": datasets.Value("string"),
                "image": datasets.Array3D(shape=(None, 120, 120), dtype="float32"),
                "coords": datasets.Array3D(shape=(2, 120, 120), dtype="float32"),
                "labels": datasets.Sequence(datasets.Value("string")),
                "crs": datasets.Value("int64"),
                "timestamp": datasets.Value("string"),
            }
        )
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=features,
            homepage=_HOMEPAGE,
            license=_LICENSE,
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager):
        """Returns SplitGenerators."""
        files = dl_manager.download(_URLS)

        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={"split": "train"} | files,
            ),
            datasets.SplitGenerator(
                name=datasets.Split.TEST,
                gen_kwargs={"split": "corpus"} | files,
            ),
        ]

    def _generate_examples(self, split, metadata, main, **kwargs):
        """Yields examples."""

        # --- Load and filter metadata ---
        metadata_df = pd.read_parquet(metadata)
        metadata_df = metadata_df[metadata_df["split"] == split]

        # Filter by satellite type based on the config
        satellite_type = self.config.satellite_type
        if satellite_type != "all":
            satellite_filter = "|".join(_SATELLITE_DATASETS[satellite_type])
            metadata_df = metadata_df[
                metadata_df["key"].str.contains(satellite_filter, regex=True)
            ]

        sample_keys = metadata_df[["key", "labels"]].to_records(index=False)
        # Open the HDF5 file once and yield examples
        with h5py.File(main, "r") as f:
            for key, labels in sample_keys:
                sample_group = f[key]

                # Read data
                image_np = sample_group["image"][:].astype("float32")
                coords_np = sample_group["coords"][:].astype("float32")

                # Read attributes
                crs = sample_group.attrs["crs"]
                timestamp = sample_group.attrs["timestamp"]

                sample = {
                    "key": key,
                    "image": image_np,
                    "coords": coords_np,
                    "labels": list(labels),  # Ensure it's a list
                    "crs": crs,
                    "timestamp": timestamp,
                }

                yield (key, sample)