File size: 2,088 Bytes
56e2a90 |
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 |
import os
import datasets
class HurricaneDetection(datasets.GeneratorBasedBuilder):
VERSION = datasets.Version("1.0.0")
def _info(self):
"""
Defines the dataset metadata and feature structure.
"""
return datasets.DatasetInfo(
description="Dataset containing .nc files for training.",
features=datasets.Features({
"file_path": datasets.Value("string"), # Store file paths
}),
supervised_keys=None, # Update if supervised task is defined
homepage="https://huggingface.co/datasets/nasa-impact/WINDSET/tree/main/hurricane",
license="MIT",
)
def _split_generators(self, dl_manager):
"""
Define the dataset splits for train.
"""
# Define the directory containing the dataset
data_dir = os.path.join(os.getcwd(), "hurricane") # Update with the actual directory
# Get the directory for the train split (no validation or test splits)
train_dir = os.path.join(data_dir)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={"split_dir": train_dir},
),
]
def _generate_data_from_files(self, data_dir):
"""
Generate file paths for each .h5 file in the directory.
"""
example_id = 0
# Loop through the files in the directory
for h5_file in os.listdir(data_dir):
if h5_file.endswith(".h5"):
h5_file_path = os.path.join(data_dir, h5_file)
yield example_id, {
"file_path": h5_file_path,
}
example_id += 1
else:
pass
def _generate_examples(self, split_dir):
"""
Generates examples for the dataset from the split directory.
"""
# Call the data generator to get the file paths
for example_id, example in self._generate_data_from_files(split_dir):
yield example_id, example
|