"""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///*.bmp"], "format": "BMP grayscale image", "shape": "1024 x 1024 pixels", "fields": [], }, { "file_class": "camera_metadata", "paths": ["MultimodalData/Images///*.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//HIT_*.TXT", "MultimodalData/AcousticDatta//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//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//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()