Datasets:

Modalities:
Tabular
Text
Size:
< 1K
DOI:
License:
shakxy42 commited on
Commit
bc679d1
·
verified ·
1 Parent(s): 04e73e8

Upload 2 files

Browse files
Files changed (2) hide show
  1. BubbleML_2.py +198 -0
  2. dataset_dict.json +3 -0
BubbleML_2.py ADDED
@@ -0,0 +1,198 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # BubbleML_2.py
2
+
3
+ import os
4
+ import json
5
+ import h5py
6
+ import numpy as np
7
+
8
+ import datasets
9
+ from datasets import (
10
+ BuilderConfig,
11
+ GeneratorBasedBuilder,
12
+ DatasetInfo,
13
+ Features,
14
+ Array4D,
15
+ Sequence,
16
+ Value,
17
+ Split,
18
+ Version,
19
+ )
20
+
21
+ _CITATION = "" # optional
22
+ _DESCRIPTION = """
23
+ BubbleML: high-fidelity single-bubble boiling simulations (FC72 & R515B).
24
+ Pre-defined train/test splits across two directories.
25
+ """
26
+
27
+ class BubbleMLConfig(BuilderConfig):
28
+ """BuilderConfig for BubbleML_2 with fixed T, H, W."""
29
+ def __init__(
30
+ self,
31
+ *,
32
+ name: str,
33
+ description: str,
34
+ data_files: dict,
35
+ timesteps: int,
36
+ height: int,
37
+ width: int,
38
+ data_dir: str = "",
39
+ version: Version = Version("1.0.0"),
40
+ **kwargs,
41
+ ):
42
+ super().__init__(name=name, version=version, description=description, **kwargs)
43
+ self.data_files = data_files
44
+ self.data_dir = data_dir
45
+ self.timesteps = timesteps
46
+ self.height = height
47
+ self.width = width
48
+
49
+ class BubbleMLDataset(GeneratorBasedBuilder):
50
+ """BubbleML_2: combined single-bubble dataset."""
51
+ BUILDER_CONFIG_CLASS = BubbleMLConfig
52
+ DEFAULT_CONFIG_NAME = "single-bubble"
53
+ BUILDER_CONFIGS = [
54
+ BubbleMLConfig(
55
+ name="single-bubble",
56
+ description="Single-bubble (FC72 & R515B) train/test split",
57
+ data_dir="", # local root; overridden by --data_dir
58
+ timesteps=5,
59
+ height=288,
60
+ width=192,
61
+ data_files={
62
+ "train": [
63
+ # FC72 train
64
+ "SingleBubble-Saturated-FC72-2D/Twall_90.hdf5",
65
+ "SingleBubble-Saturated-FC72-2D/Twall_91.hdf5",
66
+ "SingleBubble-Saturated-FC72-2D/Twall_92.hdf5",
67
+ "SingleBubble-Saturated-FC72-2D/Twall_94.hdf5",
68
+ "SingleBubble-Saturated-FC72-2D/Twall_96.hdf5",
69
+ "SingleBubble-Saturated-FC72-2D/Twall_98.hdf5",
70
+ "SingleBubble-Saturated-FC72-2D/Twall_99.hdf5",
71
+ "SingleBubble-Saturated-FC72-2D/Twall_100.hdf5",
72
+ # R515B train
73
+ "SingleBubble-Saturated-R515B-2D/Twall_13.hdf5",
74
+ "SingleBubble-Saturated-R515B-2D/Twall_14.hdf5",
75
+ "SingleBubble-Saturated-R515B-2D/Twall_15.hdf5",
76
+ "SingleBubble-Saturated-R515B-2D/Twall_17.hdf5",
77
+ "SingleBubble-Saturated-R515B-2D/Twall_19.hdf5",
78
+ "SingleBubble-Saturated-R515B-2D/Twall_21.hdf5",
79
+ "SingleBubble-Saturated-R515B-2D/Twall_22.hdf5",
80
+ "SingleBubble-Saturated-R515B-2D/Twall_23.hdf5",
81
+ ],
82
+ "test": [
83
+ # FC72 test
84
+ "SingleBubble-Saturated-FC72-2D/Twall_87.hdf5",
85
+ "SingleBubble-Saturated-FC72-2D/Twall_95.hdf5",
86
+ "SingleBubble-Saturated-FC72-2D/Twall_103.hdf5",
87
+ # R515B test
88
+ "SingleBubble-Saturated-R515B-2D/Twall_10.hdf5",
89
+ "SingleBubble-Saturated-R515B-2D/Twall_18.hdf5",
90
+ "SingleBubble-Saturated-R515B-2D/Twall_26.hdf5",
91
+ ],
92
+ },
93
+ ),
94
+ ]
95
+
96
+ def _info(self) -> DatasetInfo:
97
+ cfg = self.config
98
+ # C = number of fields
99
+ C = 4
100
+ T, H, W = cfg.timesteps, cfg.height, cfg.width
101
+ features = Features({
102
+ "input": Array4D(dtype="float32", shape=(T, C, H, W)),
103
+ "output": Array4D(dtype="float32", shape=(T, C, H, W)),
104
+ "fluid_params": Sequence(Value("float32")),
105
+ "filename": Value("string"),
106
+ })
107
+ return DatasetInfo(
108
+ description=_DESCRIPTION,
109
+ features=features,
110
+ supervised_keys=None,
111
+ homepage="https://huggingface.co/datasets/hpcforge/BubbleML_2",
112
+ citation=_CITATION,
113
+ )
114
+
115
+ def _split_generators(self, dl_manager: datasets.DownloadManager):
116
+ cfg = self.config
117
+
118
+ if cfg.data_dir:
119
+ # Local: read files from disk
120
+ base_dir = cfg.data_dir
121
+ def resolve_local(split):
122
+ pairs = []
123
+ for rel in cfg.data_files[split]:
124
+ h5p = os.path.join(base_dir, rel)
125
+ jp = h5p.replace(".hdf5", ".json")
126
+ if not os.path.isfile(h5p):
127
+ raise FileNotFoundError(f"{h5p} not found.")
128
+ if not os.path.isfile(jp):
129
+ raise FileNotFoundError(f"{jp} not found.")
130
+ pairs.append((h5p, jp))
131
+ return pairs
132
+ train = resolve_local("train")
133
+ test = resolve_local("test")
134
+ else:
135
+ # Remote: download from Hub
136
+ base_url = "https://huggingface.co/datasets/hpcforge/BubbleML_2/resolve/main/"
137
+ url_map = {}
138
+ for split in ["train","test"]:
139
+ for rel in cfg.data_files[split]:
140
+ url_map[rel] = base_url + rel
141
+ url_map[rel.replace(".hdf5", ".json")] = base_url + rel.replace(".hdf5", ".json")
142
+ dl = dl_manager.download(url_map)
143
+ train, test = [], []
144
+ for split in ["train","test"]:
145
+ for rel in cfg.data_files[split]:
146
+ h5p = dl[rel]
147
+ jp = dl[rel.replace(".hdf5", ".json")]
148
+ (train if split=="train" else test).append((h5p,jp))
149
+
150
+ return [
151
+ datasets.SplitGenerator(name=Split.TRAIN, gen_kwargs={"file_pairs": train}),
152
+ datasets.SplitGenerator(name=Split.TEST, gen_kwargs={"file_pairs": test}),
153
+ ]
154
+
155
+ def _generate_examples(self, file_pairs):
156
+ """Yield sliding-window examples, yielding NumPy arrays directly."""
157
+ idx = 0
158
+ fields = ["dfun", "temperature", "velx", "vely"]
159
+ tw = self.config.timesteps
160
+ for h5_path, json_path in file_pairs:
161
+ with h5py.File(h5_path, "r") as h5f:
162
+ arrays = {k: h5f[k][...] for k in fields} # (T, H, W)
163
+ T = arrays[fields[0]].shape[0]
164
+ max_start = T - 2*tw + 1
165
+
166
+ # metadata
167
+ with open(json_path, "r") as jf:
168
+ p = json.load(jf)
169
+ fluid_params = [
170
+ p["inv_reynolds"],
171
+ p["cpgas"],
172
+ p["mugas"],
173
+ p["rhogas"],
174
+ p["thcogas"],
175
+ p.get("stefan", 0.0),
176
+ p["prandtl"],
177
+ p["heater"]["nucWaitTime"],
178
+ p["heater"].get("wallTemp", 0.0),
179
+ ]
180
+
181
+ for start in range(max_start):
182
+ ei = start + tw
183
+ eo = ei + tw
184
+
185
+ inp_c_t_h_w = np.stack([arrays[k][start:ei] for k in fields], axis=0)
186
+ out_c_t_h_w = np.stack([arrays[k][ei:eo] for k in fields], axis=0)
187
+
188
+ # transpose (C,T,H,W) -> (T,C,H,W)
189
+ inp = inp_c_t_h_w.transpose(1,0,2,3).astype("float32")
190
+ out = out_c_t_h_w.transpose(1,0,2,3).astype("float32")
191
+
192
+ yield idx, {
193
+ "input": inp,
194
+ "output": out,
195
+ "fluid_params": fluid_params,
196
+ "filename": os.path.basename(h5_path),
197
+ }
198
+ idx += 1
dataset_dict.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0dc68f752a9830c7aa2e1ce55ab1e524ba53f5ead708ffb8463abbb93c5be6c6
3
+ size 52