Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cubids-group filepath referenced before assignment in get_param_groups_from_key_group #207

Closed
ericearl opened this issue May 13, 2022 · 3 comments

Comments

@ericearl
Copy link

A very "vanilla" call to cubids-group with a dataset and a prefix leads to:

100%|███████████████████████████████████████████████████████████████████████████████████████████████| 125/125 [00:00<00:00, 292.04it/s]
Traceback (most recent call last):
  File "/home/earlea/.local/bin/cubids-group", line 8, in <module>
    sys.exit(cubids_group())
  File "/home/earlea/.local/lib/python3.8/site-packages/cubids/cli.py", line 272, in cubids_group
    bod.get_CSVs(str(opts.output_prefix),)
  File "/home/earlea/.local/lib/python3.8/site-packages/cubids/cubids.py", line 941, in get_CSVs
    big_df, summary = self.get_param_groups_dataframes()
  File "/home/earlea/.local/lib/python3.8/site-packages/cubids/cubids.py", line 783, in get_param_groups_dataframes
    self.get_param_groups_from_key_group(key_group)
  File "/home/earlea/.local/lib/python3.8/site-packages/cubids/cubids.py", line 759, in get_param_groups_from_key_group
    if mod in filepath:
UnboundLocalError: local variable 'filepath' referenced before assignment

It looks like filepath is only defined on line 749 as a variable in a for loop:

for filepath in matching_files:

I think this means that if the iterable of matching_files is empty, then filepath would not be defined. Since matching_files comes from:

matching_files = self.layout.get(return_type="file", scope="self", regex_search=True, **key_entities)

Do you think I might be missing some certainly expected files or metadata?

@ericearl
Copy link
Author

If it helps, I added a print('matching_files length', len(matching_files)) to get_param_groups_from_key_group and a print(key_groups) to get_param_groups_dataframes. This is what I got:

100%|███████████████████████████████████████████████████████████████████████████████████████████████| 125/125 [00:00<00:00, 296.66it/s]
['acquisition-2d_datatype-anat_reconstruction-scic_suffix-FLAIR', 'acquisition-2d_datatype-anat_suffix-FLAIR', 'acquisition-3d_datatype-anat_reconstruction-scic_suffix-FLAIR', 'acquisition-3d_datatype-anat_suffix-FLAIR', 'acquisition-cube_datatype-anat_reconstruction-scic_suffix-T2w', 'acquisition-cube_datatype-anat_suffix-T2w', 'acquisition-dwi_datatype-fmap_fmap-fieldmap_suffix-fieldmap', 'acquisition-dwi_datatype-fmap_suffix-magnitude', 'acquisition-fspgr_datatype-anat_reconstruction-scic_run-1_suffix-T1w', 'acquisition-fspgr_datatype-anat_reconstruction-scic_run-2_suffix-T1w', 'acquisition-fspgr_datatype-anat_reconstruction-scic_suffix-T1w', 'acquisition-highreshippo_datatype-anat_suffix-T1w', 'acquisition-mprage_datatype-anat_reconstruction-scic_suffix-T1w', 'acquisition-mprage_datatype-anat_suffix-T1w', 'acquisition-resting_datatype-fmap_fmap-fieldmap_suffix-fieldmap', 'acquisition-resting_datatype-fmap_suffix-magnitude', 'datatype-anat_reconstruction-scic_suffix-T2starw', 'datatype-dwi_direction-flipped_suffix-dwi', 'datatype-dwi_direction-unflipped_suffix-dwi', 'datatype-dwi_suffix-dwi', 'datatype-func_direction-reverse_suffix-bold_task-rest', 'datatype-func_run-1_suffix-bold_task-rest', 'datatype-func_run-2_suffix-bold_task-rest', 'datatype-func_suffix-bold_task-rest', 'datatype-perf_suffix-asl']
matching_files length 146
matching_files length 151
matching_files length 25
matching_files length 50
matching_files length 89
matching_files length 242
matching_files length 66
matching_files length 66
matching_files length 1
matching_files length 1
matching_files length 63
matching_files length 0
Traceback (most recent call last):
  File "/home/earlea/.local/bin/cubids-group", line 8, in <module>
    sys.exit(cubids_group())
  File "/home/earlea/.local/lib/python3.8/site-packages/cubids/cli.py", line 272, in cubids_group
    bod.get_CSVs(str(opts.output_prefix),)
  File "/home/earlea/.local/lib/python3.8/site-packages/cubids/cubids.py", line 943, in get_CSVs
    big_df, summary = self.get_param_groups_dataframes()
  File "/home/earlea/.local/lib/python3.8/site-packages/cubids/cubids.py", line 785, in get_param_groups_dataframes
    self.get_param_groups_from_key_group(key_group)
  File "/home/earlea/.local/lib/python3.8/site-packages/cubids/cubids.py", line 760, in get_param_groups_from_key_group
    if mod in filepath:
UnboundLocalError: local variable 'filepath' referenced before assignment

So I think this means my key_group known as "acquisition-highreshippo_datatype-anat_suffix-T1w" is finding nothing with self.layout.get.

@ericearl
Copy link
Author

For what it's worth, I found data in the sourcedata/ folder organized much like the BIDS root folder. So while I had no results with an ls of sub-*/ses-*/anat/*highreshippo*, I did have ls results among sourcedata/sub-*/ses-*/anat/*highreshippo*.

I do still think cubids-group should fail or raise an exception more gracefully in a case like this though.

@scovitz
Copy link
Collaborator

scovitz commented Feb 15, 2023

Flagging this again. Yes our error messages need to be more robust/descriptive, which is flagged in #253, so I'm closing this one.

@scovitz scovitz closed this as completed Feb 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants