Datasets:

Size:
n<1K
ArXiv:
DOI:
License:
File size: 5,095 Bytes
6b5bf53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fff0586
6b5bf53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6034380
6b5bf53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4851a70
6b5bf53
 
 
4274ecc
 
 
 
 
 
6b5bf53
 
4274ecc
 
 
87eaab2
4274ecc
6b5bf53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6034380
6b5bf53
 
6034380
6b5bf53
 
 
6034380
 
6b5bf53
 
 
6034380
6b5bf53
 
6034380
6b5bf53
 
 
 
 
 
 
 
 
 
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
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


from typing import List

import datasets
import h5py

# Find for instance the citation on arxiv or on the dataset repo/website
_CITATION = """\
@article{cabuar,
  title={Ca{B}u{A}r: California {B}urned {A}reas dataset for delineation},
  author={Rege Cambrin, Daniele and Colomba, Luca and Garza, Paolo},
  journal={IEEE Geoscience and Remote Sensing Magazine},
  doi={10.1109/MGRS.2023.3292467},
  year={2023} 
}
"""

# You can copy an official description
_DESCRIPTION = """\
CaBuAr dataset contains images from Sentinel-2 satellites taken before and after a wildfire. 
The ground truth masks are provided by the California Department of Forestry and Fire Protection and they are mapped on the images.
"""

_HOMEPAGE = "https://huggingface.co/datasets/DarthReca/california_burned_areas"

_LICENSE = "OPENRAIL"

_URLS = "raw/patched/512x512.hdf5"


class CaBuArConfig(datasets.BuilderConfig):
    """BuilderConfig for CaBuAr.

    Parameters
    ----------

    load_prefire: bool
        whether to load prefire data
    train_folds: List[int]
        list of folds to use for training
    validation_folds: List[int]
        list of folds to use for validation
    test_folds: List[int]
        list of folds to use for testing
    **kwargs
        keyword arguments forwarded to super.
    """

    def __init__(self, load_prefire: bool, **kwargs):
        super(CaBuArConfig, self).__init__(**kwargs)
        self.load_prefire = load_prefire


class CaBuAr(datasets.GeneratorBasedBuilder):
    """California Burned Areas dataset."""

    VERSION = datasets.Version("1.0.0")

    BUILDER_CONFIGS = [
        CaBuArConfig(
            name="post-fire",
            version=VERSION,
            description="Post-fire only version of the dataset",
            load_prefire=False,
        ),
        CaBuArConfig(
            name="pre-post-fire",
            version=VERSION,
            description="Pre-fire and post-fire version of the dataset",
            load_prefire=True,
        ),
    ]

    DEFAULT_CONFIG_NAME = "post-fire"
    BUILDER_CONFIG_CLASS = CaBuArConfig

    def _info(self):
        if self.config.name == "pre-post-fire":
            features = datasets.Features(
                {
                    "post_fire": datasets.Array3D((512, 512, 12), dtype="uint16"),
                    "pre_fire": datasets.Array3D((512, 512, 12), dtype="uint16"),
                    "mask": datasets.Array3D((512, 512, 1), dtype="uint16"),
                }
            )
        else:
            features = datasets.Features(
                {
                    "post_fire": datasets.Array3D((512, 512, 12), dtype="uint16"),
                    "mask": datasets.Array3D((512, 512, 1), dtype="uint16"),
                }
            )

        return datasets.DatasetInfo(
            # This is the description that will appear on the datasets page.
            description=_DESCRIPTION,
            # This defines the different columns of the dataset and their types
            features=features,
            # Homepage of the dataset for documentation
            homepage=_HOMEPAGE,
            # License for the dataset if available
            license=_LICENSE,
            # Citation for the dataset
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager):
        h5_file = dl_manager.download(_URLS)

        return [
            datasets.SplitGenerator(
                name=fold,
                # These kwargs will be passed to _generate_examples
                gen_kwargs={
                    "fold": fold,
                    "load_prefire": self.config.load_prefire,
                    "filepath": h5_file,
                },
            )
            for fold in range(0, 5)
        ]

    # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
    def _generate_examples(self, fold: int, load_prefire: bool, filepath):
        with h5py.File(filepath, "r") as f:
            for uuid, values in f.items():
                if values.attrs["fold"] != fold:
                    continue
                if load_prefire and "pre_fire" not in values:
                    continue
                sample = {
                    "post_fire": values["post_fire"][...],
                    "mask": values["mask"][...],
                }
                if load_prefire:
                    sample["pre_fire"] = values["pre_fire"][...]
                yield uuid, sample