File size: 11,440 Bytes
505117b | 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 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | """Build manifest.csv and data_dictionary.json for a BubbleID-Flow release."""
from __future__ import annotations
import argparse
import csv
import hashlib
import json
import re
from pathlib import Path
import pandas as pd
RELEASE_VERSION = "1.0.0"
MANIFEST_NAME = "manifest.csv"
def sha256(path: Path) -> str:
digest = hashlib.sha256()
with path.open("rb") as stream:
for chunk in iter(lambda: stream.read(1024 * 1024), b""):
digest.update(chunk)
return digest.hexdigest()
def canonical_case(path: str) -> str:
for case in ("5gs_22C", "10gs_22C", "15gs_20C", "25gs_20C"):
if case in path:
return case
if "15gs_22C" in path:
return "15gs_20C"
if "25gs_22C" in path:
return "25gs_20C"
return "all_cases"
def file_class(path: str) -> str:
lower = path.lower()
if lower.startswith("annotatedimages/"):
return "annotation_image" if lower.endswith(".bmp") else "labelme_annotation"
if lower.startswith("modelweights/"):
return "model_checkpoint"
if "/images/" in lower:
return "raw_optical_image" if lower.endswith(".bmp") else "camera_metadata"
if "/flowloopthermaldata/" in lower:
return "derived_thermal_plot" if lower.endswith(".png") else "thermal_workbook"
if "/acousticdatta/" in lower:
if lower.endswith(".wfs"):
return "raw_ae_waveform"
if lower.endswith(".dta"):
return "ae_acquisition_export"
if lower.endswith(".txt") and "/plot_" not in lower:
return "ae_text_record"
if lower.endswith(".png"):
return "derived_ae_plot"
if lower.startswith("videos/"):
return "derived_presentation_video" if lower.endswith(".mp4") else "video_provenance"
if lower.startswith("processing/"):
return "processing_snapshot"
if lower.startswith("calibration/"):
return "calibration_evidence_record"
return "release_metadata"
def thermal_field_definition(name: str) -> dict[str, str]:
unit_match = re.search(r"\[([^]]+)\]", name)
unit = unit_match.group(1) if unit_match else "dimensionless or not stated"
if name.startswith("Time"):
meaning = "Source time field; its absolute origin is not documented."
elif "Mass Flow" in name:
meaning = "Measured or source-reduced mass-flow field."
elif "Pressure" in name:
meaning = "Measured or source-reduced pressure field."
elif "Temperature" in name or "Subcooling" in name or "Saturation" in name:
meaning = "Measured or source-reduced temperature-related field."
elif "Heat Flux" in name or "Heat Transfer" in name or "Heat Rate" in name or "Power" in name:
meaning = "Source-reduced thermal performance field; calibration and heat-loss evidence are not included."
elif "Quality" in name:
meaning = "Source-reduced vapor-quality field; its reconstruction assumptions are not documented in this release."
elif "Friction" in name:
meaning = "Source-reduced friction-factor field; not used as a validated manuscript endpoint."
else:
meaning = "Source workbook field; see the original header for its source label."
return {"name": name, "dtype": "numeric unless source cell is blank", "unit": unit, "definition": meaning}
def read_thermal_schemas(root: Path) -> list[dict[str, object]]:
schemas: list[dict[str, object]] = []
seen: set[str] = set()
for workbook in sorted(root.rglob("*.xlsx")):
if workbook.name.endswith("_IN_with_units.xlsx"):
kind = "thermal_input_workbook"
elif workbook.name.endswith("_u_with_units.xlsx"):
kind = "thermal_auxiliary_workbook"
else:
kind = "thermal_reduced_workbook"
if kind in seen:
continue
frame = pd.read_excel(workbook)
schemas.append(
{
"file_class": kind,
"example_path": workbook.relative_to(root.parent.parent).as_posix(),
"shape": f"variable rows x {len(frame.columns)} columns",
"missing_value_rule": "Blank Excel cells represent missing source values; no numeric sentinel is documented.",
"fields": [thermal_field_definition(str(column)) for column in frame.columns],
}
)
seen.add(kind)
return schemas
def build_dictionary(root: Path) -> dict[str, object]:
thermal_root = root / "MultimodalData" / "FlowLoopThermalData"
return {
"title": "BubbleID-Flow Multimodal Flow-Boiling Dataset Data Dictionary",
"schema_version": RELEASE_VERSION,
"global_missing_value_rule": "No dataset-wide numeric sentinel is defined. Blank spreadsheet cells and absent optional JSON keys are missing values.",
"schemas": [
{
"file_class": "annotation_image",
"paths": ["AnnotatedImages/*.bmp"],
"format": "BMP grayscale image",
"shape": "1024 x 1024 pixels",
"fields": [],
},
{
"file_class": "labelme_annotation",
"paths": ["AnnotatedImages/*.json"],
"format": "LabelMe JSON",
"fields": [
{"name": "version", "dtype": "string", "unit": "not applicable", "definition": "LabelMe file-format version."},
{"name": "flags", "dtype": "object", "unit": "not applicable", "definition": "Optional LabelMe image-level flags."},
{"name": "shapes[].label", "dtype": "string", "unit": "not applicable", "definition": "Manual region label: bubble or bubble_cluster."},
{"name": "shapes[].points", "dtype": "array[vertex,2]", "unit": "pixel", "definition": "Polygon vertices in source-image pixel coordinates."},
{"name": "shapes[].shape_type", "dtype": "string", "unit": "not applicable", "definition": "LabelMe geometry type."},
{"name": "imagePath", "dtype": "string", "unit": "not applicable", "definition": "Paired source BMP filename."},
{"name": "imageHeight", "dtype": "integer", "unit": "pixel", "definition": "Source-image height."},
{"name": "imageWidth", "dtype": "integer", "unit": "pixel", "definition": "Source-image width."},
],
},
{
"file_class": "raw_optical_image",
"paths": ["MultimodalData/Images/<case>/<state>/*.bmp"],
"format": "BMP grayscale image",
"shape": "1024 x 1024 pixels",
"fields": [],
},
{
"file_class": "camera_metadata",
"paths": ["MultimodalData/Images/<case>/<state>/*.cihx"],
"format": "camera metadata XML",
"fields": [],
"missing_value_rule": "Use camera-vendor metadata fields as supplied; no normalized schema is released.",
},
*read_thermal_schemas(thermal_root),
{
"file_class": "ae_text_record",
"paths": ["MultimodalData/AcousticDatta/<case>/HIT_*.TXT", "MultimodalData/AcousticDatta/<case>/TIME_*.TXT"],
"format": "EasyAE fixed-width text export",
"shape": "variable rows x vendor-defined fields",
"missing_value_rule": "No numeric sentinel is documented by the export.",
"fields": [
{"name": "ID", "dtype": "integer", "unit": "not applicable", "definition": "EasyAE record identifier."},
{"name": "SSSSSSSS.mmmuuun", "dtype": "float", "unit": "s", "definition": "EasyAE source time field; absolute origin is not documented."},
{"name": "PARA1, PARA2", "dtype": "float", "unit": "vendor-defined", "definition": "EasyAE source fields; units are not documented in this release."},
{"name": "CH", "dtype": "integer", "unit": "channel", "definition": "EasyAE acquisition channel identifier."},
{"name": "RISE, COUN, ENER, DURATION, A-FRQ, RMS, PCNTS, THR, R-FRQ, I-FRQ, SIG STRNGTH, ABS-ENERGY, FRQ-C, P-FRQ, AMP, ASL", "dtype": "numeric", "unit": "vendor-defined", "definition": "EasyAE event or continuous-summary fields retained with the vendor labels; calibration and unit definitions are not included."},
],
},
{
"file_class": "raw_ae_waveform",
"paths": ["MultimodalData/AcousticDatta/<case>/Raw Data/*.wfs"],
"format": "EasyAE waveform binary",
"shape": "vendor-defined binary waveform sequence",
"fields": [],
"missing_value_rule": "Not applicable; decode with a compatible WFS decoder.",
},
{
"file_class": "ae_acquisition_export",
"paths": ["MultimodalData/AcousticDatta/<case>/Raw Data/*.DTA"],
"format": "EasyAE text acquisition export",
"shape": "variable rows x vendor-defined fields",
"fields": [],
},
{
"file_class": "model_checkpoint",
"paths": ["ModelWeights/model_final.pth"],
"format": "PyTorch checkpoint",
"shape": "model parameter tensors",
"fields": [],
},
{
"file_class": "derived_presentation_video",
"paths": ["Videos/*.mp4"],
"format": "MP4 presentation video",
"shape": "1920 x 720 pixels, 5 frames/s, 80 frames for the included 45 V videos",
"fields": [],
"missing_value_rule": "Not applicable; the videos are derived visual summaries, not native-time records.",
},
],
}
def write_manifest(root: Path, version: str) -> int:
output = root / MANIFEST_NAME
files = [path for path in root.rglob("*") if path.is_file() and path != output]
with output.open("w", newline="", encoding="utf-8") as stream:
writer = csv.DictWriter(stream, fieldnames=["path", "case_identifier", "file_class", "byte_size", "sha256", "release_version"])
writer.writeheader()
for path in sorted(files):
relative = path.relative_to(root).as_posix()
writer.writerow(
{
"path": relative,
"case_identifier": canonical_case(relative),
"file_class": file_class(relative),
"byte_size": path.stat().st_size,
"sha256": sha256(path),
"release_version": version,
}
)
return len(files)
def main() -> None:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--dataset-root", type=Path, required=True)
parser.add_argument("--version", default=RELEASE_VERSION)
args = parser.parse_args()
root = args.dataset_root
if not root.is_dir():
raise FileNotFoundError(root)
(root / "data_dictionary.json").write_text(json.dumps(build_dictionary(root), indent=2), encoding="utf-8")
count = write_manifest(root, args.version)
print(f"Wrote data_dictionary.json and {MANIFEST_NAME} for {count} files.")
if __name__ == "__main__":
main()
|