Kaphathy's picture
Add data processing, de-identification & quality control toolkit
d2ce7dd verified
Raw History Blame Contribute Delete
14.5 kB
"""Verified cohort registry for the h100 cross-center new-data consolidation (2026-06-30).
Single source of truth, encoding the 11-agent read-only recon (see memory reference_h100_newdata).
HARD RULES baked in: originals on /nfs01 are READ-ONLY and NEVER modified/deleted. Archives
extract ONLY to EXTRACT_ROOT (work dir on /data). Already-extracted dirs are read in place.
Dedup/skip is done at MANIFEST level (drop rows), never by touching files.
Each cohort dict:
key unique cohort id (also the manifest `cohort` namespace)
modality fundus_color | octa | ffa | bscan_us | ubm | uwf
center hospital/source (for multi-center splits)
src path to the extracted dir OR the archive
comp none | zip | targz | rar5 | 7z (archive type if not extracted)
extracted True -> read `src` in place (0 disk); False -> extract to EXTRACT_ROOT/key
extract_glob optional member filter for selective extraction (e.g. images only)
exts image extensions to enumerate
label_kind folder | json | jsonl | xlsx | none
label_path label file (abs), or None (folder labels come from dir names)
pii none | low | t1 (t1 = must strip identifiers before any export; see register)
dedup_group cohorts sharing a group are cross-checked for duplicates
role train | external_test (external_test = held out, never trained)
note
"""
import os
EXTRACT_ROOT = "/data/team/lisicheng/new_data_extracted" # all extraction lands here (/data, 2.9T free); /nfs01 is read-only
WORK = "/data/team/lisicheng"
NFS_BACKUP = "/nfs01/datasetsBackup"
NFS_FQ = "/nfs01/FQ_Datasets/data"
DATASETS = "/data/datasets"
UNRAR = "/data/team/lisicheng/miniconda3/envs/ocr/bin/unrar" # not on PATH; full path
IMG_EXTS = (".png", ".jpg", ".jpeg", ".tif", ".tiff", ".bmp")
def read_path(c):
"""Where images are actually read from."""
return c["src"] if c.get("extracted") else os.path.join(EXTRACT_ROOT, c["key"])
# ----------------------------------------------------------------------------- COHORTS
COHORTS = [
# ===================== FUNDUS (color fundus photography) =====================
dict(key="fundus90wer", modality="fundus_color", center="mixed_unlabeled",
src=f"{DATASETS}/fundus90wER", comp="none", extracted=True, exts=(".png", ".jpg"),
label_kind="none", label_path=None, pii="t1", dedup_group="fundus_pool", role="train",
note="899,266 (verified). Chinese names in filenames -> t1 (filename PII only, not in pixels). md5 in cleaning_report usable as dedup key."),
dict(key="fq_rawfundus", modality="fundus_color", center="fq_unlabeled",
src=f"{NFS_FQ}/rawFundus", comp="none", extracted=True, exts=(".png",),
label_kind="none", label_path=None, pii="low", dedup_group="fq_tongren_idname", role="train",
note="208,138 (verified). <id>-<n>.png. SKIP rawFundus_predicted (same imgs, quality-resorted)."),
dict(key="fq_testfundus", modality="fundus_color", center="fq_unlabeled",
src=f"{NFS_FQ}/testFundus", comp="none", extracted=True, exts=(".png",),
label_kind="none", label_path=None, pii="low", dedup_group="fq_tongren_idname", role="train",
note="52,034 (verified). SKIP testFundus_predicted."),
dict(key="fq_validfundus", modality="fundus_color", center="fq_unlabeled",
src=f"{NFS_FQ}/validFundus", comp="none", extracted=True, exts=(".png",),
label_kind="folder", label_path=None, pii="low", dedup_group="fq_tongren_idname", role="train",
note="4,000 (verified). quality=gradable (whole-dir tag)."),
dict(key="eryuan_t17_fundus", modality="fundus_color", center="eryuan",
src=f"{NFS_FQ}/eryuanFundusT17RDCls", comp="none", extracted=True, exts=(".tif",),
label_kind="folder", label_path=None, pii="low", dedup_group="eryuan_pool", role="train",
note="31,621 (verified). 17 disease classes; has train/val/test -> reserve its test split as INTERNAL test. class = immediate parent dir."),
dict(key="tongren_fundus", modality="fundus_color", center="tongren",
src=f"{WORK}/Dataser/shards_tongren", comp="none", extracted=True, exts=(".png",),
label_kind="json", label_path=None, pii="low", dedup_group="tongren_pool", role="train",
note="~628,392 WebDataset shards (de-id product, sex/age in per-image json). USE THIS, skip 同仁/fundus.zip. WebDataset -> needs wds reader (see build_manifest stub)."),
dict(key="tongren_external_fundus", modality="fundus_color", center="tongren",
src=f"{NFS_BACKUP}/同仁/external.zip", comp="zip", extracted=False, exts=(".png",),
label_kind="none", label_path=None, pii="low", dedup_group="tongren_pool", role="train",
note="209,091 (verified). 99.5% SAME PATIENTS as tongren_fundus but 0 same-file -> OK as extra TRAIN, NEVER as eval (leakage)."),
dict(key="tongren_95disease_fundus", modality="fundus_color", center="tongren",
src=f"{NFS_BACKUP}/tr/tr1695L2/tongren16G95DFundus", comp="none", extracted=True, exts=(".png",),
label_kind="folder", label_path=None, pii="low", dedup_group="tongren_pool", role="train",
note="264,412 (verified). 16 groups / ~95 disease subclasses (folder). GOLDMINE for downstream. dedup vs tongren_pool by 编号. SKIP the tr .7z (extracted copy already here). class=parent, group=grandparent."),
dict(key="eryuan_fundus", modality="fundus_color", center="eryuan",
src=f"{NFS_BACKUP}/data0410/eryuan.zip", comp="zip", extracted=False, exts=(".tif", ".png"),
label_kind="folder", label_path=None, pii="low", dedup_group="eryuan_pool", role="train",
note="19,599 (verified): 4 classes AMD/DR/Normal/RVO (NOT 17 as md said). SKIP eryuan_split (subset). dedup vs data0410_master."),
dict(key="dual_comorbidity_fundus", modality="fundus_color", center="data0410",
src=f"{NFS_BACKUP}/data0410/Dual_comornidity.tar.gz", comp="targz", extracted=False, exts=(".png",),
label_kind="folder", label_path=None, pii="low", dedup_group="data0410_pool", role="train",
note="~12k unique (24,120 entries = 6-class scheme + 4-class scheme of SAME pool). Keep ONE scheme in manifest. hypertension comorbidity classes."),
dict(key="hcw_fundus", modality="fundus_color", center="hcw",
src=f"{NFS_BACKUP}/data0410/fundus_hcw.zip", comp="zip", extracted=False, exts=(".tif", ".png"),
extract_glob="fundus/fundus_img/*", label_kind="xlsx", label_path=None, pii="low",
dedup_group="data0410_pool", role="train",
note="~15,503 imgs ONLY (extract_glob excludes 150G .pth + code!). dx-pairing xlsx keyed by image_name."),
dict(key="data0410_master_fundus", modality="fundus_color", center="data0410",
src=f"{NFS_BACKUP}/data0410/data.tar.gz", comp="targz", extracted=False, exts=(".png", ".jpg"),
label_kind="xlsx", label_path=None, pii="t1", dedup_group="data0410_pool", role="train",
note="104,505 (md-UNVERIFIED). master 二院 pool. reports_2020_2025_cleaned.xlsx has 姓名/PatientID/DOB (STRIP). ⚠ xlsx->image join key UNRESOLVED (datetime filenames vs patient key) -> label as none until join confirmed. dedup vs eryuan/hcw."),
dict(key="eyfrd6_fundus", modality="fundus_color", center="eryuan",
src=f"{DATASETS}/eyFRDCls", comp="none", extracted=True, exts=(".tif",),
label_kind="folder", label_path=None, pii="low", dedup_group="fundus_pool", role="train",
note="~645. 6 classes CSC/ERM/MH/RAO/RD/VKH (has train/val/test). tiny."),
dict(key="handan_fundus", modality="fundus_color", center="handan",
src=f"{NFS_BACKUP}/ffa/handan_ffa/only_image", comp="none", extracted=True, exts=(".png",),
label_kind="json", label_path=f"{NFS_BACKUP}/ffa/handan_ffa/data.json", pii="t1",
dedup_group="handan", role="external_test",
note="6,432 fundus = filenames ending _1/_2 ONLY (must filter by suffix at enumerate). HELD OUT (邯郸 external). data.json 印象 dx; strip 姓名/年龄/检查日期/ID号."),
# ===================== OCTA =====================
dict(key="octbuckets_octa", modality="octa", center="octbuckets",
src=f"{WORK}/Dataser/shards_oct", comp="none", extracted=True, exts=(".png",),
label_kind="json", label_path=None, pii="none", dedup_group="octa", role="train",
note="~34,519 WebDataset (de-id product; eye/scan_mode/frame). USE THIS, skip octBuckets.zip (raw, has name-in-filename). Is OCTA (Angio/en-face), NOT plain OCT."),
# ===================== FFA (fluorescein angiography) -- NEW modality =====================
dict(key="handan_ffa", modality="ffa", center="handan",
src=f"{NFS_BACKUP}/ffa/handan_ffa/only_image", comp="none", extracted=True, exts=(".png",),
label_kind="json", label_path=f"{NFS_BACKUP}/ffa/handan_ffa/data.json", pii="t1",
dedup_group="handan", role="external_test",
note="23,212 FFA = filenames _3 and higher suffix (filter by suffix). HELD OUT (邯郸 external). 3,226 study impressions; strip PII."),
dict(key="chengdu_ffa", modality="ffa", center="chengdu",
src=f"{NFS_BACKUP}/ffa/chengdu_ffa/jpg", comp="none", extracted=True, exts=(".png",),
label_kind="jsonl", label_path=f"{NFS_BACKUP}/ffa/chengdu_ffa/visionoph4.jsonl", pii="low",
dedup_group="chengdu_ffa", role="external_test",
note="4,938 PNG (dir misnamed 'jpg', holds .png). HELD OUT (成都 FFA external). visionoph4.jsonl is a JSON ARRAY: scan_id/structured dx codes; normalize windows backslash paths."),
dict(key="yinhai_ffa", modality="ffa", center="yinhai",
src=f"{NFS_BACKUP}/ffa/yinhai_ffa/jpg", comp="none", extracted=True, exts=(".bmp",),
label_kind="jsonl", label_path=f"{NFS_BACKUP}/ffa/yinhai_ffa/output2.jsonl", pii="t1",
dedup_group="yinhai_ffa", role="train",
note="1,058 BMP (dir misnamed 'jpg', holds .bmp). output2.jsonl 拟诊报告; strip 姓名+P-ID+签名."),
dict(key="eryuan_ffa", modality="ffa", center="eryuan",
src=f"{NFS_BACKUP}/ffa/Final_eryuan_FFA/FFA", comp="none", extracted=True, exts=(".tif",),
label_kind="none", label_path=None, pii="low", dedup_group="eryuan_ffa", role="train",
note="18,543 tif (verified). SKIP the redundant 72.5G Final_eryuan_FFA.zip. no labels."),
# ===================== B-scan ocular ultrasound -- NEW modality =====================
dict(key="yinhai_bscan", modality="bscan_us", center="yinhai",
src=f"{NFS_BACKUP}/pretrainNewDS/BUltrasound/YinhaiBscan", comp="none", extracted=True, exts=(".png",),
label_kind="json", label_path=None, pii="low", dedup_group="yinhai_bscan", role="train",
note="71,289 (verified). images in image/ subdir. Use RAW json (超声所见 findings); cleanedv3 nulls findings. no name/dob."),
dict(key="xiangya_bscan", modality="bscan_us", center="xiangya",
src=f"{NFS_BACKUP}/pretrainNewDS/BUltrasound/XiangyaBscan", comp="none", extracted=True, exts=(".bmp",),
label_kind="json", label_path=None, pii="t1", dedup_group="xiangya_bscan", role="train",
note="33,740 (verified) bmp in image/. cleanedv3.json 4,939 records: findings + name/dob/examdate (STRIP)."),
dict(key="chengdu_bscan", modality="bscan_us", center="chengdu",
src=f"{NFS_BACKUP}/pretrainNewDS/BUltrasound/chengdu_Bscan", comp="none", extracted=True, exts=(".jpg",),
label_kind="none", label_path=None, pii="none", dedup_group="chengdu_bscan", role="train",
note="8,726 (verified) jpg flat. no labels."),
# ===================== UBM (ultrasound biomicroscopy) -- NEW modality =====================
dict(key="chengdu_shiyi_ubm", modality="ubm", center="chengdu",
src=f"{NFS_BACKUP}/pretrainNewDS/ubm/ChengduShiyiUBM", comp="none", extracted=True, exts=(".png",),
label_kind="json", label_path=None, pii="low", dedup_group="chengdu_ubm", role="train",
note="236,028 (verified) png in image/. Use cleanedv3 json (clinical report; raw json has corrupted blobs/false-PII)."),
dict(key="yinhai_ubm", modality="ubm", center="yinhai",
src=f"{NFS_BACKUP}/pretrainNewDS/ubm/YinhaiUBM", comp="none", extracted=True, exts=(".png",),
label_kind="json", label_path=None, pii="low", dedup_group="yinhai_ubm", role="train",
note="83,750 (verified). cleanedv3 clinical text."),
dict(key="eryuan_ubm", modality="ubm", center="eryuan",
src=f"{NFS_BACKUP}/pretrainNewDS/ubm/Final_eryuan_ubm", comp="none", extracted=True, exts=(".tif",),
label_kind="none", label_path=None, pii="low", dedup_group="eryuan_ubm", role="train",
note="134,350 (verified) tif. truly no labels. SKIP the 2 redundant UBM .rar packs. ms-timestamp in filename (quasi-id)."),
# ===================== UWF (ultra-widefield) -- NEW modality, single center =====================
dict(key="yinhai_uwf", modality="uwf", center="yinhai",
src=f"{NFS_BACKUP}/pretrainNewDS/uwf/yinhai_uwf", comp="rar5", extracted=False, exts=(".jpg",),
label_kind="none", label_path=None, pii="low", dedup_group="yinhai_uwf", role="train",
note="11,113 (md-UNVERIFIED). 3 RAR5 multipart sets (Secondary_1/_2/_3). extract first volume of each set with unrar. SINGLE CENTER -> no external val possible (paper limitation)."),
]
# Archives explicitly NOT ingested (dups / products-superseded / code). Documented for transparency; never deleted.
SKIP = {
"rawFundus_predicted": "dup of fq_rawfundus (quality-resorted)",
"testFundus_predicted": "dup of fq_testfundus",
"eryuan_split.tar.gz": "subset of eryuan_fundus",
"handan_ffa2": "strict subset of handan (0 unique files)",
"Final_eryuan_FFA.zip": "redundant archive of eryuan_ffa extracted dir",
"2-UBM-SW3200L-去噪声处理.rar / 3-UBM-SW3200L2-dataset.rar": "redundant with eryuan_ubm",
"同仁/fundus.zip": "superseded by tongren_fundus shards (de-id)",
"octBuckets.zip": "superseded by octbuckets_octa shards (de-id)",
"tr/*.7z": "extracted copy tr1695L2 already present",
"BioCliFM.tar.gz": "code, not data",
"fundus_hcw .pth/code": "150G checkpoints+code; only images extracted via extract_glob",
}
INCLUDE = COHORTS
def by_role(role): return [c for c in COHORTS if c["role"] == role]
def to_extract(): return [c for c in COHORTS if not c.get("extracted")]
def modalities(): return sorted({c["modality"] for c in COHORTS})