AQC_dataset / create_acdc_json.py
maxmo2009's picture
Upload folder using huggingface_hub
ea4eb5a verified
#!/usr/bin/env python3
"""
Create JSON file for ACDC QC software with patient folder paths as keys
"""
import json
from pathlib import Path
def create_acdc_json():
# Base directory for ACDC data (output of rename_acdc_specific.py)
base_dir = Path("/mnt/storage/home/ym1413/QC_data_preprocessing/sabotaged_dataset")
# Create dictionary with patient folders as keys
acdc_data = {}
# Get all patient directories
patient_dirs = sorted([d for d in base_dir.iterdir() if d.is_dir() and d.name.startswith('patient')])
for patient_dir in patient_dirs:
# Remove base path /mnt/storage/home/ym1413 from the key
key = str(patient_dir).replace("/mnt/storage/home/ym1413", "")
# Extract patient ID from folder name
patient_id = patient_dir.name
# Create entry for this patient - just the key with empty dict for QC software to populate
acdc_data[key] = {}
# Save to JSON file
output_file = Path("/mnt/storage/home/ym1413/QC_data_preprocessing/acdc_qc_dataset.json")
with open(output_file, 'w') as f:
json.dump(acdc_data, f, indent=4, sort_keys=True)
print(f"Created JSON file with {len(acdc_data)} patient entries")
print(f"Output saved to: {output_file}")
# Show first few entries as preview
print("\nFirst 3 entries:")
for i, key in enumerate(list(acdc_data.keys())[:3]):
print(f"\nEntry {i+1}:")
print(f" Key: {key}")
if __name__ == "__main__":
create_acdc_json()