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