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
26 stars 20 forks source link

[BUG] pypet2bids collects additional values from spreadsheet that DNE; csv #227

Closed bendhouseart closed 11 months ago

bendhouseart commented 1 year ago

Describe the bug Given the attached spreadsheet as input to the -m flag, pet2bids raises a flatten series error, it seems to collect two values from the csv where there should only be on, n/a in this example. However, it's returning a series containing [0, 'n/a'] which is believed to create this error, see:

Traceback (most recent call last):
  File "/usr/local/bin/dcm2niix4pet", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.8/dist-packages/pypet2bids/dcm2niix4pet.py", line 1354, in main
    converter = Dcm2niix4PET(
  File "/usr/local/lib/python3.8/dist-packages/pypet2bids/dcm2niix4pet.py", line 471, in __init__
    helper_functions.single_spreadsheet_reader(
  File "/usr/local/lib/python3.8/dist-packages/pypet2bids/helper_functions.py", line 155, in single_spreadsheet_reader
    metadata[field] = flatten_series(series)
  File "/usr/local/lib/python3.8/dist-packages/pypet2bids/helper_functions.py", line 103, in flatten_series
    raise Exception(f"Invalid Series: {series}")
Exception: Invalid Series: 0   NaN
Name: SpecificRadioactivity, dtype: float64

pet_metadata.csv

Expected behaviour Reading in the attached spreadsheet should yield a specific radioactivity of n/a.

Desktop (please complete the following information):

dlevitas commented 1 year ago

This might partially be because having a value of n/a in Excel (for "SpecificRadioactivity" and "SpecificRadioactivityUnits" metadata fields) get interpreted as NaN by python. Explicitly making n/a a string value (i.e. "n/a") resolves this issue but triggers a new error message:

File "/usr/local/lib/python3.8/dist-packages/pypet2bids/dcm2niix4pet.py", line 991, in check_meta_radio_inputs
    tmp = ((InjectedRadioactivity * (10 ** 6) / SpecificRadioactivity) * (10 ** 6))
TypeError: unsupported operand type(s) for /: 'int' and 'str'

Which seems to be caused by an improper variable type for the "SpecificRadioactivity" and "SpecificRadioactivityUnits" metadata. Simply removing these two fields from the metadata files resolves all issues.

dlevitas commented 1 year ago

I may be mis-reading the BIDS-specification for PET data, but for these metadata fields, it appears that "n/a" is acceptable and even should be entered, assuming it isn't an FDG sequence.

bendhouseart commented 1 year ago

Yes, "n/a" is accepted as often the data simply isn't available. We'd rather people share what they have then give up entirely.

bendhouseart commented 11 months ago

@dlevitas closing this as I believe it was fixed some time ago, just not closed. Let me know if otherwise.