openneuropet / PET2BIDS

PET2BIDS helps you convert your PET data into BIDS! raw PET scanner files (e.g. ecat, dicom) and additional side files like .e.g excel sheets -- paper @JOSS https://doi.org/10.21105/joss.06067
https://pet2bids.readthedocs.io
MIT License
25 stars 20 forks source link

AttributeError: 'DummyFile' object has no attribute 'flush' #267

Closed dlevitas closed 7 months ago

dlevitas commented 7 months ago

Describe the bug The following error occurs [in python] when attempting to use is_pet.pet_folder() on a folder containing DICOM-to-NIfTI transformed PET data:

To Reproduce

  1. code/command used (copy/paste what you did)
    from pathlib import Path
    is_pet.pet_folder(Path(path/to/PET_NIFTI/folder))
  2. error happening? (copy/paste the error)
    Traceback (most recent call last):
    File "./find_petdir.py", line 25, in <module>
    print([str(folder) for folder in is_pet.pet_folder(Path(root).resolve())])
    File "/usr/local/lib/python3.8/dist-packages/pypet2bids/is_pet.py", line 158, in pet_folder
    files = read_files_in_parallel(all_files, pet_file, n_jobs=1, return_only_path=True)
    File "/usr/local/lib/python3.8/dist-packages/pypet2bids/is_pet.py", line 61, in read_files_in_parallel
    results = Parallel(n_jobs=n_jobs)(delayed(function)(file_path, **kwargs) for file_path in file_paths)
    File "/usr/local/lib/python3.8/dist-packages/joblib/parallel.py", line 1863, in __call__
    return output if self.return_generator else list(output)
    File "/usr/local/lib/python3.8/dist-packages/joblib/parallel.py", line 1792, in _get_sequential_output
    res = func(*args, **kwargs)
    File "/usr/local/lib/python3.8/dist-packages/pypet2bids/is_pet.py", line 126, in pet_file
    read_file = spread_sheet_check_for_pet(file_path)
    File "/usr/local/lib/python3.8/dist-packages/pypet2bids/is_pet.py", line 26, in spread_sheet_check_for_pet
    data = helper_functions.open_meta_data(sourcefile)
    File "/usr/local/lib/python3.8/dist-packages/pypet2bids/helper_functions.py", line 406, in open_meta_data
    metadata_dataframe = use_me_to_read(metadata_path, sep=separator)
    TypeError: 'NoneType' object is not callable
    Exception ignored in: <pypet2bids.is_pet.DummyFile object at 0x7ff53daedf70>
    AttributeError: 'DummyFile' object has no attribute 'flush'

Expected behaviour I was anticipating ispet to return the folder path. At the very least, this seems a bit restrictive, as using ispet on the individual PET NIfTI file itself doesn't produce an error, it simply returns nothing. Perhaps this is the expected behavior, but it would be nice if ispet could determine that the file is indeed PET, simply transformed to the NIfTi format.

Desktop (please complete the following information):

bendhouseart commented 7 months ago

Seems to error out when tsv files are present.