Datasets:
ArXiv:
License:
file for loading data with HF datasets load_dataset() module
Browse files- hurricane/dataset.py +63 -0
hurricane/dataset.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import datasets
|
| 3 |
+
|
| 4 |
+
class HurricaneDetection(datasets.GeneratorBasedBuilder):
|
| 5 |
+
VERSION = datasets.Version("1.0.0")
|
| 6 |
+
|
| 7 |
+
def _info(self):
|
| 8 |
+
"""
|
| 9 |
+
Defines the dataset metadata and feature structure.
|
| 10 |
+
"""
|
| 11 |
+
return datasets.DatasetInfo(
|
| 12 |
+
description="Dataset containing .nc files for training.",
|
| 13 |
+
features=datasets.Features({
|
| 14 |
+
"file_path": datasets.Value("string"), # Store file paths
|
| 15 |
+
}),
|
| 16 |
+
supervised_keys=None, # Update if supervised task is defined
|
| 17 |
+
homepage="https://huggingface.co/datasets/nasa-impact/WINDSET/tree/main/hurricane",
|
| 18 |
+
license="MIT",
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
def _split_generators(self, dl_manager):
|
| 22 |
+
"""
|
| 23 |
+
Define the dataset splits for train.
|
| 24 |
+
"""
|
| 25 |
+
# Define the directory containing the dataset
|
| 26 |
+
data_dir = os.path.join(os.getcwd(), "hurricane") # Update with the actual directory
|
| 27 |
+
|
| 28 |
+
# Get the directory for the train split (no validation or test splits)
|
| 29 |
+
train_dir = os.path.join(data_dir)
|
| 30 |
+
|
| 31 |
+
return [
|
| 32 |
+
datasets.SplitGenerator(
|
| 33 |
+
name=datasets.Split.TRAIN,
|
| 34 |
+
gen_kwargs={"split_dir": train_dir},
|
| 35 |
+
),
|
| 36 |
+
]
|
| 37 |
+
|
| 38 |
+
def _generate_data_from_files(self, data_dir):
|
| 39 |
+
"""
|
| 40 |
+
Generate file paths for each .h5 file in the directory.
|
| 41 |
+
"""
|
| 42 |
+
example_id = 0
|
| 43 |
+
|
| 44 |
+
# Loop through the files in the directory
|
| 45 |
+
for h5_file in os.listdir(data_dir):
|
| 46 |
+
|
| 47 |
+
if h5_file.endswith(".h5"):
|
| 48 |
+
h5_file_path = os.path.join(data_dir, h5_file)
|
| 49 |
+
|
| 50 |
+
yield example_id, {
|
| 51 |
+
"file_path": h5_file_path,
|
| 52 |
+
}
|
| 53 |
+
example_id += 1
|
| 54 |
+
else:
|
| 55 |
+
pass
|
| 56 |
+
|
| 57 |
+
def _generate_examples(self, split_dir):
|
| 58 |
+
"""
|
| 59 |
+
Generates examples for the dataset from the split directory.
|
| 60 |
+
"""
|
| 61 |
+
# Call the data generator to get the file paths
|
| 62 |
+
for example_id, example in self._generate_data_from_files(split_dir):
|
| 63 |
+
yield example_id, example
|