PeerHerholz / BIDSonym

a BIDS app for pseudo-anonymization of neuroimaging data
https://peerherholz.github.io/BIDSonym/
BSD 3-Clause "New" or "Revised" License
51 stars 14 forks source link

crash in report_wf.plt_defaced when subjects have differing number of sessions #69

Open BarnardVisionLab opened 1 year ago

BarnardVisionLab commented 1 year ago

Describe the bug

Hello, in running BIDSonym for the first time, we found a bug that we think is caused by having subjects with differing numbers of sessions.

In our dataset, one subject had 3 sessions and the rest had 2. When we first ran BIDSonym, it crashed in plt_defaced. That happened when trying to run it on just 1 subject or on the whole dataset directory.

The text output to the terminal describing the error is below. But I was able to get past it by simply moving out of the data set the one subject that has 3 sessions. So it seems like the code first determines the number of sessions per subject, assuming they are all the same (the max). The code generating the report and images for each subject tries to loop through all the sessions, and crashes if one file can't be found. Ideally it would check how many sessions each individual subject has.

In any case, thanks for making a great tool! Very useful.

Here is the terminal output, starting with the first mention of a warning:

230206-16:49:41,117 nipype.workflow WARNING: [Node] Error on "report_wf.plt_defaced" (/tmp/tmpf3cku5x4/report_wf/plt_defaced) 230206-16:49:41,125 nipype.workflow ERROR: Node plt_defaced failed to run on host 30f06d8dbdb0. 230206-16:49:41,126 nipype.workflow ERROR: Saving crash info to /tmp/crash-20230206-164941-root-plt_defaced-5925e894-9235-4be7-a066-691072b2d10f.pklz Traceback (most recent call last): File "/opt/miniconda-latest/envs/bidsonym/lib/python3.6/site-packages/nipype/pipeline/plugins/linear.py", line 46, in run node.run(updatehash=updatehash) File "/opt/miniconda-latest/envs/bidsonym/lib/python3.6/site-packages/nipype/pipeline/engine/nodes.py", line 516, in run result = self._run_interface(execute=True) File "/opt/miniconda-latest/envs/bidsonym/lib/python3.6/site-packages/nipype/pipeline/engine/nodes.py", line 635, in _run_interface return self._run_command(execute) File "/opt/miniconda-latest/envs/bidsonym/lib/python3.6/site-packages/nipype/pipeline/engine/nodes.py", line 741, in _run_command result = self._interface.run(cwd=outdir) File "/opt/miniconda-latest/envs/bidsonym/lib/python3.6/site-packages/nipype/interfaces/base/core.py", line 434, in run runtime = self._run_interface(runtime) File "/opt/miniconda-latest/envs/bidsonym/lib/python3.6/site-packages/nipype/interfaces/utility/wrappers.py", line 142, in _run_interface out = function_handle(**args) File "", line 70, in plot_defaced UnboundLocalError: local variable 't1w' referenced before assignment

230206-16:49:41,137 nipype.workflow INFO:


230206-16:49:41,137 nipype.workflow ERROR: could not run node: report_wf.plt_defaced 230206-16:49:41,137 nipype.workflow INFO: crashfile: /tmp/crash-20230206-164941-root-plt_defaced-5925e894-9235-4be7-a066-691072b2d10f.pklz 230206-16:49:41,137 nipype.workflow INFO:


Traceback (most recent call last): File "/opt/miniconda-latest/envs/bidsonym/bin/bidsonym", line 33, in sys.exit(load_entry_point('bidsonym', 'console_scripts', 'bidsonym')()) File "/home/bm/bidsonym/run_deeid.py", line 180, in run_deeid create_graphics(args.bids_dir, subject_label, session=session, t2w=None) File "/home/bm/bidsonym/reports.py", line 184, in create_graphics report_wf.run() File "/opt/miniconda-latest/envs/bidsonym/lib/python3.6/site-packages/nipype/pipeline/engine/workflows.py", line 632, in run runner.run(execgraph, updatehash=updatehash, config=self.config) File "/opt/miniconda-latest/envs/bidsonym/lib/python3.6/site-packages/nipype/pipeline/plugins/linear.py", line 70, in run report_nodes_not_run(notrun) File "/opt/miniconda-latest/envs/bidsonym/lib/python3.6/site-packages/nipype/pipeline/plugins/tools.py", line 98, in report_nodes_not_run ("Workflow did not execute cleanly. " "Check log for details") RuntimeError: Workflow did not execute cleanly. Check log for details

To Reproduce We tried running this command:

docker run -it --rm -v {directory_name}/:/bids_dataset -v /home/alwhite/engram/tmp/:/tmp peerherholz/bidsonym /bids_dataset group --deid pydeface --brainextraction bet --bet_frac 0.5 --skip_bids_validation

where {directory_name} is the full address of the BIDS directory.

Expected behavior We expected the software to continue through all subjects in the directory.

OS/environment (please provide precise information on your OS/environment): We are running this code in Linux Ubuntu 20.04.3 LTS, Docker version 20.10.12.

Additional context Add any other context about the problem here.

raphaelchristin commented 11 months ago

I am still getting that error, was there any fix that was found??

yarikoptic commented 2 months ago

confirming still seeing this one with the flagman version

Traceback:
        Traceback (most recent call last):
          File "/opt/miniconda-latest/lib/python3.11/site-packages/nipype/interfaces/base/core.py", line 398, in run
            runtime = self._run_interface(runtime)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
          File "/opt/miniconda-latest/lib/python3.11/site-packages/nipype/interfaces/utility/wrappers.py", line 142, in _run_interface
            out = function_handle(**args)
                  ^^^^^^^^^^^^^^^^^^^^^^^
          File "<string>", line 70, in plot_defaced
        UnboundLocalError: cannot access local variable 't1w' where it is not associated with a value
bash-5.2$ bidsonym --version
BIDS-App version 0+unknown

well, it is from

bash-5.2$ git -C /opt/bidsonym-src/ -c safe.directory=* describe
v0.0.6-17-g8417c18

although not sure if issue exactly the same since for those 2 subjects I invoked for there is identical number of sessions:

bash-5.2$ ls -l sub-000{1,2}/
sub-0001/:
total 0
drwxr-xr-x 1 47521 47522 132 Jun  9 16:39 ses-01
drwxr-xr-x 1 47521 47522 118 Jun  9 16:39 ses-02
drwxr-xr-x 1 47521 47522 118 Jun  9 16:39 ses-03
drwxr-xr-x 1 47521 47522 118 Jun  9 16:39 ses-04

sub-0002/:
total 0
drwxr-xr-x 1 47521 47522 132 Jun  9 16:39 ses-01
drwxr-xr-x 1 47521 47522 118 Jun  9 16:39 ses-02
drwxr-xr-x 1 47521 47522 118 Jun  9 16:39 ses-03
drwxr-xr-x 1 47521 47522 118 Jun  9 16:39 ses-04