"""Validate manifest coverage, labels, folds, HDF5 schema, and file checksums.""" import csv import hashlib from collections import Counter from pathlib import Path import h5py def main(): root = Path(__file__).resolve().parents[1] with (root / 'manifest.csv').open(newline='') as f: rows = list(csv.DictReader(f)) paths = [r['path'] for r in rows] assert len(rows) == 38180 and len(set(paths)) == len(rows) assert len({r['sample_id'] for r in rows}) == len(rows) assert set(paths) == {str(p.relative_to(root)) for p in (root / 'data').rglob('*.h5')} counts = Counter() for row in rows: path = Path(row['path']) assert not path.is_absolute() and '..' not in path.parts assert row['label'] == {'negative': '0', 'positive': '1'}[row['label_name']] assert row['label_name'] in path.name counts[row['source'], row['split'], row['fold'], row['label_name']] += 1 filename = root / path assert hashlib.sha256(filename.read_bytes()).hexdigest() == row['sha256'], path with h5py.File(filename) as f: d = f[row['h5_key']] assert d.shape == tuple(int(row[k]) for k in ('height', 'width', 'bins')), path assert str(d.dtype) == row['dtype'], path assert Counter(r['split'] for r in rows) == { 'train': 26600, 'validation': 5700, 'test': 5700, 'unassigned': 180} for i in range(1, 10): for label in ('negative', 'positive'): assert counts['experimental', 'unassigned', f'fold_{i}', label] == 10 for split in ('train', 'validation', 'test'): with (root / f'metadata/synthetic_{split}.csv').open(newline='') as f: assert list(csv.DictReader(f)) == [r for r in rows if r['split'] == split] expected = [r for r in rows if r['source'] == 'experimental'] for name in ('metadata/experimental.csv', 'data/experiment_data/manifest.csv'): with (root / name).open(newline='') as f: assert list(csv.DictReader(f)) == expected assert (root / 'SHA256SUMS').read_text() == ''.join( f"{r['sha256']} {r['path']}\n" for r in rows) print('PASS: 38,180 files, hashes, schemas, portable paths, split manifests, and nine balanced folds') if __name__ == '__main__': main()