abids_tool.py doesn't recognize json file

AFNI version info (afni -ver): Precompiled binary linux_xorg7_64: Oct 19 2020 (Version AFNI_20.3.01 'Vespasian')

I'm attempting to add slice timing information from a json file to a nifti header using abids_tool.py. I get a message that says my json file "is not a valid json file!!" I've converted with from dicom with dcm2niix both with and without the -b y options. Is there a quick fix for this? I can upload the json if that will help.

Sure, you can send me the JSON; I just pinged you via email for sharing. Can you please copy+past the command you are trying to run?

I will note that probably updating your AFNI codebase would make sense; we are coming up on the 4 year birthday of that version, which is quiiiite old. It is possible that program fixes in the meantime would sort the issue, but I will see.

Also, what Linux OS and version are you using? I think there is probably a better binary version available than xorg7, which we might not update anymore, actually.

--pt

abids_tool.py -input sub-s4033-ABCD_fMRI_rest.nii -add_slice_times

The OS appears to be a version of Red Hat.
uname -a says it's this:

x86_64 x86_64 x86_64 GNU/Linux

I'm working on a server that's administered by others. I requested an AFNI version update last December. I'll try again.

I've uploaded the json file to the BOX folder.

Thanks, I've got it.

Firstly, you should load the JSON, not the NIFTI, so (edit: PT is mistaken about this point for this program, as he notes below; the NIFTI indeed should be loaded in with "-input .." here; this is noted below; the real error for this file is correctly diagnosed here, though, that one value appears to need to be wrapped in quotes):

abids_tool.py -input sub-s4033-ABCD_fMRI_rest.json -add_slice_times

Then, I got errors, too, reading it in:

Error: sub-s4033-ABCD_fMRI_rest.json does not exist or is not loadable!!

So, I tried reading it with the straightup Python "json" module:

python
Python 3.12.4 | packaged by Anaconda, Inc. | (main, Jun 18 2024, 10:14:12) [Clang 14.0.6 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import json
>>> x = json.load(open('sub-s4033-ABCD_fMRI_rest.json'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/taylorpa3/miniconda3/envs/py3_afni_tiny/lib/python3.12/json/__init__.py", line 293, in load
    return loads(fp.read(),
           ^^^^^^^^^^^^^^^^
  File "/Users/taylorpa3/miniconda3/envs/py3_afni_tiny/lib/python3.12/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/taylorpa3/miniconda3/envs/py3_afni_tiny/lib/python3.12/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/taylorpa3/miniconda3/envs/py3_afni_tiny/lib/python3.12/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
               ^^^^^^^^^^^^^^^^^^^^^^
json.decoder.JSONDecodeError: Expecting ',' delimiter: line 5 column 29 (char 159)

That line 5 looks like:

	"AcquisitionDateTime": 2022-04-08T16:58:17.937500,

If I copied the file and edited that line's value to look like a string:

	"AcquisitionDateTime": "2022-04-08T16:58:17.937500",

... then that resolved the error there, and I could use the abids*py tools on it.

I am not sure why dcm2niix converted it that way. It may be a version thing there, too? I can only speculate.

--pt

If putting that field on line 5 in quotes is all you did, that didn't solve the problem for me. I tried using a newer version of dcm2niix and the json file looks different and doesn't have that line 5 any more, but I still got the same error message. I'm guessing my version of AFNI is the problem. I'll try to get that udated.

I put the new version of the json file in the Box folder, assuming it successfully overwrote the other one.

Hi-

OK, there are a couple things here. I misunderstood how this abids_tool.py works. You are correct that that program should read in the NIFTI format dataset, and the JSON should just be accompanying it (the program will internally find the parter JSON based on filename).

I have edited the program to be more clear about what is happening when reading in, so future generations will have less confusion. So:

  • in the first case here, there was an error with the JSON itself, I believe, and the value of one of the entries needed to be wrapped in quotes;
  • in the second case, the error was caused by me (!), incorrectly stating that the JSON should be read in (that is only for other abids*py programs, with which I had been more familiar).

Therefore, for the second file, can you try:

abids_tool.py -input DSET_NIFTI ...

and see if that reads in that JSON fine?

Sorry for confusing things here.

--pt

That worked! Thanks for the help.