nimh-dsst / dsst-defacing-pipeline

Defacing algorithm to improve and evaluate accuracy for large datasets.
2 stars 2 forks source link

Blows up with `KeyError: 'ses-02'` whenever that subject does not have T1w in any other session but one #42

Open yarikoptic opened 5 months ago

yarikoptic commented 5 months ago

Not yet sure if it is related to

since no details on error was provided there. Invocation based on a container from

for a sample participant, with mount points only under current PWD (for proper isolation etc)

yoh@typhon:/mnt/DATA/data/yoh/1076_spacetop$ mkdir -p derivatives scratch
yoh@typhon:/mnt/DATA/data/yoh/1076_spacetop$ singularity run -B $PWD:$PWD:ro -B $PWD/derivatives:$PWD/derivatives:rw -B $PWD/scratch:$PWD/scratch:rw --scratch $PWD/scratch --pwd $PWD --net --network none ../dsst-defacing-pipeline/dsst-defacing-pipeline-test.sing -p 0001 -- . derivatives/dss-defacing-1 

and leading to

====================
Dataset Summary
====================
Total number of sessions with 'anat' directory in the dataset: 115
Sessions with 'anat' directory with at least one T1w scan: 115

Please find the mapping file in JSON format at /mnt/DATA/data/yoh/1076_spacetop/derivatives/dss-defacing-1/primary_to_others_mapping.json
and other helpful logs at /mnt/DATA/data/yoh/1076_spacetop/derivatives/dss-defacing-1/logs

Defacing in Serial, one at a time
Running @afni_refacer_run on sub-0001_ses-01_acq-MPRAGEXp3X08mm_T1w.nii.gz
Find command logs at /mnt/DATA/data/yoh/1076_spacetop/derivatives/dss-defacing-1/bids_defaced/sub-0001/ses-01/anat/defacing_pipeline.log
@afni_refacer_run command completed on sub-0001_ses-01_acq-MPRAGEXp3X08mm_T1w.nii.gz

Reorganizing ses-01 with defaced images into BIDS tree...

[]
Preparing for QC by visual inspection...

Traceback (most recent call last):
  File "/opt/dsst-defacing-pipeline/run.py", line 192, in <module>
    main()
  File "/opt/dsst-defacing-pipeline/run.py", line 132, in main
    missing_refacer_out = deface.deface_primary_scan(
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/dsst-defacing-pipeline/deface.py", line 218, in deface_primary_scan
    primary_t1 = mapping_dict[subj_id][sess_id]['primary_t1']
                 ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
KeyError: 'ses-02'

and the reason is that anatomical T1 is present only in session 1:

yoh@typhon:/mnt/DATA/data/yoh/1076_spacetop$ ls -l sub-0001/ses-*/anat
total 60
-rw-r--r-- 1 yoh yoh 56954 May 21 10:35 sub-0001_ses-01_acq-MPRAGEXp3X08mm_T1w.json
lrwxrwxrwx 1 yoh yoh   145 May 21 10:35 sub-0001_ses-01_acq-MPRAGEXp3X08mm_T1w.nii.gz -> ../../../.git/annex/objects/QZ/PK/MD5E-s19195514--f8c60f8bdbba3d715a0e23accb7255cd.nii.gz/MD5E-s19195514--f8c60f8bdbba3d715a0e23accb7255cd.nii.gz

yoh@typhon:/mnt/DATA/data/yoh/1076_spacetop$ ls -ld sub-0001/ses-*/anat
drwxr-xr-x 1 yoh yoh 176 May 21 10:35 sub-0001/ses-01/anat

how to mitigate?