"""Audit the GINO paper's ShapeNet files and the processed Zenodo v2 archive.""" import argparse import hashlib import io import json from pathlib import Path, PurePosixPath import tarfile from zipfile import ZipFile import numpy as np ZENODO_MD5 = "24a46fe791085201d48ee5db7b6cfc86" LOADER_COMMIT = "a4133fc897dd3a2d01fb33b81bdfe63c3031c725" RETAINED_PRESSURE_SLICES = [[0, 16], [112, None]] def digest(contents): return hashlib.sha256(contents).hexdigest() def read_member(archive, member): if not member.isfile(): raise ValueError(f"Not a regular file: {member.name}") with archive.extractfile(member) as stream: return stream.read() def manifest_ids(contents): # The official loader reads the first line, splits on commas and strips # trailing whitespace without sorting or reshuffling the case IDs. with io.StringIO(contents.decode("utf-8")) as stream: ids = [case.rstrip() for case in stream.readline().split(",")] if not all(case and PurePosixPath(case).name == case and case not in (".", "..") for case in ids): raise ValueError("Invalid case ID in original manifest") if len(set(ids)) != len(ids): raise ValueError("Duplicate case ID in original manifest") return ids def vertex_count(contents): with io.BytesIO(contents) as ply: if ply.readline().strip() != b"ply": raise ValueError("Invalid PLY signature") counts = [] for line in ply: fields = line.split() if fields[:2] == [b"element", b"vertex"]: counts.append(int(fields[2])) if fields == [b"end_header"]: if len(counts) == 1 and counts[0] > 0 and ply.read(1): return counts[0] break raise ValueError("Missing or invalid PLY vertex count") def pressure_mapping(contents, vertices): raw = np.load(io.BytesIO(contents), allow_pickle=False) if raw.ndim == 2 and raw.shape[0] == 1: raw = raw[0] if raw.ndim != 1 or len(raw) <= 112 or not np.issubdtype(raw.dtype, np.floating): raise ValueError("Unexpected original pressure shape or dtype") # #518 removes precisely these extra pressure entries, after normalization. # Applying the same index selection to raw values identifies their mapping. retained = np.concatenate([raw[:16], raw[112:]]) retained32 = np.asarray(retained, dtype=" row["mesh_vertices"] for row in rows.values() ): raise ValueError("Mesh and corrected pressure support differ") return dict(status="V2_OFFICIAL_LOADER_MAPPING_AUDITED", zenodo_record="13936501", archive_md5=ZENODO_MD5, archive_sha256=archive_sha, official_loader_commit=LOADER_COMMIT, original_paper_case_ids_verified=False, pressure_selection=RETAINED_PRESSURE_SLICES, manifest_sha256={"train": digest(raw_train), "test": digest(raw_test)}, manifest_counts={"train": len(train), "test": len(test)}, selected_counts={"train": 500, "test": 111}, rows=[rows[case] for case in train[:500] + test[:111]]) if __name__ == "__main__": parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("archive", type=Path) parser.add_argument("receipt", type=Path) parser.add_argument("--format", choices=("paper", "zenodo"), default="zenodo") parser.add_argument("--paper-receipt", type=Path) args = parser.parse_args() receipt = audit_paper(args.archive) if args.format == "paper" else audit(args.archive) if args.paper_receipt: if args.format != "zenodo": parser.error("--paper-receipt applies to a Zenodo audit") original = json.loads(args.paper_receipt.read_bytes()) if original.get("status") != "PAPER_ARCHIVE_SPLIT_AND_MAPPING_AUDITED": raise ValueError("Original paper audit required for comparison") receipt["paper_comparison"] = compare(original, receipt) receipt["original_paper_case_ids_verified"] = receipt["paper_comparison"]["original_paper_case_ids_verified"] with args.receipt.open("x") as stream: json.dump(receipt, stream, indent=2, allow_nan=False) stream.write("\n")