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

syntax problem in JSON siedecar when FrameDuration have only 1 element #616

Closed
benoitberanger opened this issue Jul 12, 2022 · 10 comments
Closed

Comments

@benoitberanger
Copy link

Describe the bug

On a DWI dataset, the JSON sidecar FrameDuration have only 1 element, but is written as an array, and the line is finished by a comma :

                105,
                108,
                114,
                117,
                120,
                129     ],
        "FrameDuration": [
                1200,
        ],
        "SliceThickness": 2,
        "SpacingBetweenSlices": 2,
        "SAR": 0.171903,
        "EchoTime": 0.095,
        "SpoilingState": true,
        "FlipAngle": 90,
        "PartialFourier": 0.875,
        "BaseResolution": 116,

This syntax in not JSON compatible.

To reproduce

Version number : 20211220
Commit number : 002ebcd
Command : dcm2niix -o /mnt/data/benoit/project/ADNI/nifti_20211220 -ba n /mnt/data/benoit/project/ADNI/dicom

Expected behavior

I would expect a JSON standard syntax :

                105,
                108,
                114,
                117,
                120,
                129     ],
        "FrameDuration": 1200,
        "SliceThickness": 2,
        "SpacingBetweenSlices": 2,
        "SAR": 0.171903,
        "EchoTime": 0.095,
        "SpoilingState": true,
        "FlipAngle": 90,
        "PartialFourier": 0.875,
        "BaseResolution": 116,

Output log

see above

Version

Please report the complete version string:

Chris Rorden's dcm2niiX version v1.0.20211220  GCC7.5.0 x86-64 (64-bit Linux)
v1.0.20211220
@benoitberanger
Copy link
Author

From reading the code, it comes from these lines :

if (dti4D->frameDuration[i] < 0)

	if (dti4D->frameDuration[0] >= 0.0) { //see BEP009 PET https://docs.google.com/document/d/1mqMLnxVdLwZjDd4ZiWFqjEAmOmfcModA_R535v3eQs0
		fprintf(fp, "\t\"FrameDuration\": [\n");
		for (int i = 0; i < h->dim[4]; i++) {
			if (i != 0)
				fprintf(fp, ",\n");
			if (dti4D->frameDuration[i] < 0)
				break;
			if ((isSameFloatGE(dti4D->frameDuration[i], 0.0)) && (d.TR > 0.0))
				fprintf(fp, "\t\t%g", d.TR / 1000.0); // from 0018,1242 ms -> sec
			else
				fprintf(fp, "\t\t%g", dti4D->frameDuration[i] / 1000.0); // from 0018,1242 ms -> sec
		}
		fprintf(fp, "\t],\n");

The comma is written, then the break happens.

@neurolabusc
Copy link
Collaborator

neurolabusc commented Jul 12, 2022

@benoitberanger can you confirm that the latest commit to the development branch resolves this issue. The BIDS tag FrameDuration will now only be populated for 4D datasets. Perhaps you can provide more details on the ADNI dataset that is eliciting this error, as a DWI DICOM dataset should not contain this tag.

@captainnova maybe you want to track down why an ADNI DWI MR reports the Actual Frame Duration from the Nuclear Medicine module. I added this in to support BIDS BEP009.

@captainnova
Copy link
Collaborator

@neurolabusc, we certainly would like to track this down, although since we only use product sequences it will probably be more a matter of data curation than being able to do much about improving DICOM compliance in already acquired scans. We also don't acquire the sort of b = 0 + 3 b = 1000 scans that "DWI" often means, but often additional series get uploaded from the site to LONI along with the standard ADNI protocol. Such series should be filtered out and not leave LONI, but mistakes happen.

@benoitberanger can you please share the participant ID, scan date, and series number of this series? If you got it from LONI I should already have the DICOM in our local filesystem. If instead it came from some other source, such as an "ADNI-like" study, that will be important to know.

Thanks,

Rob

@benoitberanger
Copy link
Author

@neurolabusc @captainnova here is the JSON content :

{
	"Modality": "MR",
	"MagneticFieldStrength": 3,
	"ImagingFrequency": 123.259,
	"Manufacturer": "Siemens",
	"ManufacturersModelName": "Verio",
	"InstitutionName": "(HS)",
	"DeviceSerialNumber": "45BRw1yUPwCA",
	"SeriesInstanceUID": "2.16.124.113543.6006.99.04340590288885489085",
	"StudyInstanceUID": "2.16.124.113543.6006.99.04326325390037115711",
	"PatientName": "014_S_6437",
	"PatientID": "014_S_6437",
	"PatientSex": "O",
	"PatientWeight": 106.028,
	"PatientPosition": "HFS",
	"SoftwareVersions": "syngo MR B19",
	"MRAcquisitionType": "2D",
	"SeriesDescription": "Axial DTI",
	"ProtocolName": "Axial DTI",
	"ScanningSequence": "EP",
	"SequenceVariant": "SK\\SP",
	"ScanOptions": "PFP\\FS",
	"SequenceName": "*ep_b0",
	"ImageType": ["ORIGINAL", "PRIMARY", "DIFFUSION", "NONE", "ND", "NORM", "MOSAIC"],
	"SeriesNumber": 11,
	"AcquisitionTime": "14:36:32.697500",
	"AcquisitionDateTime": "2020-10-06T14:36:32.697500",
	"AcquisitionNumber": 1,
	"FrameTimesStart": [
		0,
		3,
		6,
		12,
		15,
		21,
		24,
		27,
		30,
		39,
		42,
		45,
		48,
		54,
		57,
		60,
		66,
		69,
		78,
		81,
		84,
		87,
		96,
		99,
		102,
		105,
		108,
		114,
		117,
		120,
		129	],
	"FrameDuration": [
		1200,
	],
	"SliceThickness": 2,
	"SpacingBetweenSlices": 2,
	"SAR": 0.171903,
	"EchoTime": 0.095,
	"SpoilingState": true,
	"FlipAngle": 90,
	"PartialFourier": 0.875,
	"BaseResolution": 116,
	"ShimSetting": [
		-1045,
		14235,
		7858,
		139,
		151,
		-849,
		551,
		7	],
	"DiffusionScheme": "Monopolar",
	"TxRefAmp": 531.957,
	"PhaseResolution": 1,
	"VendorReportedEchoSpacing": 0.00078,
	"ReceiveCoilName": "HeadMatrix",
	"PulseSequenceDetails": "%SiemensSeq%\\ep2d_diff",
	"RefLinesPE": 40,
	"CoilCombinationMethod": "Adaptive Combine",
	"MatrixCoilMode": "GRAPPA",
	"PercentPhaseFOV": 100,
	"PercentSampling": 100,
	"PhaseEncodingSteps": 100,
	"AcquisitionMatrixPE": 116,
	"ReconMatrixPE": 116,
	"BandwidthPerPixelPhaseEncode": 22.104,
	"ParallelReductionFactorInPlane": 2,
	"EffectiveEchoSpacing": 0.000390006,
	"DerivedVendorReportedEchoSpacing": 0.000780012,
	"TotalReadoutTime": 0.0448507,
	"PixelBandwidth": 1486,
	"DwellTime": 2.9e-06,
	"PhaseEncodingDirection": "j-",
	"SliceTiming": [
		6.225,
		0,
		6.38,
		0.155,
		6.535,
		0.31,
		6.69,
		0.4675,
		6.8475,
		0.6225,
		7.0025,
		0.7775,
		7.1575,
		0.9325,
		7.3125,
		1.09,
		7.47,
		1.245,
		7.625,
		1.4,
		7.78,
		1.555,
		7.935,
		1.7125,
		8.0925,
		1.8675,
		8.2475,
		2.0225,
		8.4025,
		2.1775,
		8.5575,
		2.335,
		8.715,
		2.49,
		8.87,
		2.645,
		9.025,
		2.8,
		9.18,
		2.9575,
		9.3375,
		3.1125,
		9.4925,
		3.2675,
		9.6475,
		3.4225,
		9.8025,
		3.58,
		9.96,
		3.735,
		10.115,
		3.89,
		10.27,
		4.045,
		10.425,
		4.2025,
		10.5825,
		4.3575,
		10.7375,
		4.5125,
		10.8925,
		4.6675,
		11.0475,
		4.825,
		11.205,
		4.98,
		11.36,
		5.135,
		11.515,
		5.29,
		11.67,
		5.4475,
		11.8275,
		5.6025,
		11.9825,
		5.7575,
		12.1375,
		5.9125,
		12.2925,
		6.0675	],
	"ImageOrientationPatientDICOM": [
		1,
		0,
		0,
		0,
		1,
		0	],
	"InPlanePhaseEncodingDirectionDICOM": "COL",
	"ConversionSoftware": "dcm2niix",
	"ConversionSoftwareVersion": "v1.0.20211220"
}

@benoitberanger
Copy link
Author

@neurolabusc using this dev commit 63c76f2, here is the same JSON :

{
	"Modality": "MR",
	"MagneticFieldStrength": 3,
	"ImagingFrequency": 123.259,
	"Manufacturer": "Siemens",
	"ManufacturersModelName": "Verio",
	"InstitutionName": "(HS)",
	"DeviceSerialNumber": "45BRw1yUPwCA",
	"SeriesInstanceUID": "2.16.124.113543.6006.99.04340590288885489085",
	"StudyInstanceUID": "2.16.124.113543.6006.99.04326325390037115711",
	"PatientName": "014_S_6437",
	"PatientID": "014_S_6437",
	"PatientSex": "O",
	"PatientWeight": 106.028,
	"PatientPosition": "HFS",
	"SoftwareVersions": "syngo MR B19",
	"MRAcquisitionType": "2D",
	"SeriesDescription": "Axial DTI",
	"ProtocolName": "Axial DTI",
	"ScanningSequence": "EP",
	"SequenceVariant": "SK\\SP",
	"ScanOptions": "PFP\\FS",
	"SequenceName": "*ep_b0",
	"ImageType": ["ORIGINAL", "PRIMARY", "DIFFUSION", "NONE", "ND", "NORM", "MOSAIC"],
	"SeriesNumber": 11,
	"AcquisitionTime": "14:36:32.697500",
	"AcquisitionDateTime": "2020-10-06T14:36:32.697500",
	"AcquisitionNumber": 1,
	"FrameTimesStart": [
		0,
		3,
		6,
		12,
		15,
		21,
		24,
		27,
		30,
		39,
		42,
		45,
		48,
		54,
		57,
		60,
		66,
		69,
		78,
		81,
		84,
		87,
		96,
		99,
		102,
		105,
		108,
		114,
		117,
		120,
		129	],
	"FrameDuration": [
		1200,
	],
	"FrameReferenceTime": [
		0,
	],
	"SliceThickness": 2,
	"SpacingBetweenSlices": 2,
	"SAR": 0.171903,
	"EchoTime": 0.095,
	"SpoilingState": true,
	"FlipAngle": 90,
	"PartialFourier": 0.875,
	"BaseResolution": 116,
	"ShimSetting": [
		-1045,
		14235,
		7858,
		139,
		151,
		-849,
		551,
		7	],
	"DiffusionScheme": "Monopolar",
	"TxRefAmp": 531.957,
	"PhaseResolution": 1,
	"VendorReportedEchoSpacing": 0.00078,
	"ReceiveCoilName": "HeadMatrix",
	"PulseSequenceDetails": "%SiemensSeq%\\ep2d_diff",
	"RefLinesPE": 40,
	"CoilCombinationMethod": "Adaptive Combine",
	"MatrixCoilMode": "GRAPPA",
	"PercentPhaseFOV": 100,
	"PercentSampling": 100,
	"PhaseEncodingSteps": 100,
	"AcquisitionMatrixPE": 116,
	"ReconMatrixPE": 116,
	"BandwidthPerPixelPhaseEncode": 22.104,
	"ParallelReductionFactorInPlane": 2,
	"EffectiveEchoSpacing": 0.000390006,
	"DerivedVendorReportedEchoSpacing": 0.000780012,
	"TotalReadoutTime": 0.0448507,
	"PixelBandwidth": 1486,
	"DwellTime": 2.9e-06,
	"PhaseEncodingDirection": "j-",
	"SliceTiming": [
		6.225,
		0,
		6.38,
		0.155,
		6.535,
		0.31,
		6.69,
		0.4675,
		6.8475,
		0.6225,
		7.0025,
		0.7775,
		7.1575,
		0.9325,
		7.3125,
		1.09,
		7.47,
		1.245,
		7.625,
		1.4,
		7.78,
		1.555,
		7.935,
		1.7125,
		8.0925,
		1.8675,
		8.2475,
		2.0225,
		8.4025,
		2.1775,
		8.5575,
		2.335,
		8.715,
		2.49,
		8.87,
		2.645,
		9.025,
		2.8,
		9.18,
		2.9575,
		9.3375,
		3.1125,
		9.4925,
		3.2675,
		9.6475,
		3.4225,
		9.8025,
		3.58,
		9.96,
		3.735,
		10.115,
		3.89,
		10.27,
		4.045,
		10.425,
		4.2025,
		10.5825,
		4.3575,
		10.7375,
		4.5125,
		10.8925,
		4.6675,
		11.0475,
		4.825,
		11.205,
		4.98,
		11.36,
		5.135,
		11.515,
		5.29,
		11.67,
		5.4475,
		11.8275,
		5.6025,
		11.9825,
		5.7575,
		12.1375,
		5.9125,
		12.2925,
		6.0675	],
	"ImageOrientationPatientDICOM": [
		1,
		0,
		0,
		0,
		1,
		0	],
	"InPlanePhaseEncodingDirectionDICOM": "COL",
	"ConversionSoftware": "dcm2niix",
	"ConversionSoftwareVersion": "v1.0.20220606"
}

JSON syntax is not correct here :

	"FrameDuration": [
		1200,
	],
	"FrameReferenceTime": [
		0,
	],

@neurolabusc
Copy link
Collaborator

Can you share the DICOMs privately with me by sending a GoogleDrive or DropBox link to my institutional email? It would be nice to have a concrete example to understand what is happening.

@benoitberanger
Copy link
Author

I just shared the whole dataset I have.

Here is the complete command line I run after changing the commit (or try a modification in the source myself) :

benoit.beranger@icm-cenir-le33: /usr/local/dcm2niix $ rm -rf build; mkdir build; cd build; cmake ..; make -j 4; cd ..; rm -f /mnt/data/benoit/project/ADNI/nifti_20211220/*; dcm2niix -o /mnt/data/benoit/project/ADNI/nifti_20211220 -ba n /mnt/data/benoit/project/ADNI/dicom; vi /mnt/data/benoit/project/ADNI/nifti_20211220/dicom_Axial_DTI_20201006135507_11.json

dcm2niix binary file have a symlink in /usr/local/bin :

benoit.beranger@icm-cenir-le33: /usr/local/dcm2niix $ which dcm2niix
/usr/local/bin/dcm2niix
benoit.beranger@icm-cenir-le33: /usr/local/dcm2niix $ ll /usr/local/bin/dcm2niix
lrwxrwxrwx 1 root root 38 2021-11-22 14:05 /usr/local/bin/dcm2niix -> /usr/local/dcm2niix/build/bin/dcm2niix*
benoit.beranger@icm-cenir-le33: /usr/local/dcm2niix $ 

@neurolabusc
Copy link
Collaborator

@benoitberanger thanks for the example data. Can you retest the latest version.

@captainnova this turns out to be a problem of my BEP009 implementation. While dcm2niix worked well for single classic series, it could be tripped up when dealing with complicated series. In this case, the Axial_rsfMRI__Eyes_Open series from ADNI participant 016_S_6790 is incomplete, which caused issues handling the Axial_DTI series. The patch should allow dcm2niix to handle these situations gracefully. So the root cause is certainly with dcm2niix, but it might be nice to deal with the missing images from that participant.

@benoitberanger
Copy link
Author

With the new commit in the dev branch (3583fcc), the JSON syntax problem is resolved !
Thanks you !

@captainnova
Copy link
Collaborator

Hi, to follow up on the possible ADNI data curation issue, @benoitberanger, @neurolabusc, could you please specify the ADNI subject ID and scan date of the problem session? ADNI is longitudinal, and 016_S_6790 has had more than one scan date, none of which are 2020-10-06. There was one on 2020-10-21 where both the dMRI and fMRI failed our protocol checker and thus should not have been released from quarantine (but they were).

Meanwhile 014_S_6437 20201006 from the BIDS Benoit posted above appears to be normal.

Thanks

yarikoptic added a commit to neurodebian/dcm2niix that referenced this issue Apr 29, 2024
* tag 'v1.0.20220720': (65 commits)
  GE Direct field mapping (TE1/TE2) (rordenlab#617)
  GE Direct field mapping (TE1/TE2) (rordenlab#617)
  Issue 618 (rordenlab#618)
  Update notes
  Siemens XA30 ASL parameters and ImageTypeText 0021,1175
  Reset PET values for classic DICOMs (rordenlab#616)
  PostLabelDelay for XA30, FrameDuration is only for 4D datasets (rordenlab#616)
  shims are signed (rordenlab#608)
  AcquisitionVoxelSize before any interpolation or resampling within reconstruction or image processing
  Add AcquisitionVoxelSize tag for Siemens ASL (rordenlab#608)
  Store GE ShimSetting as array (rordenlab#608)
  GE sequence details (rordenlab#608)
  Philips slice timing notes
  Verbose scan options (issue 606)
  Change scanOptions
  scan options is long string, fix bvec rejection (rordenlab#606)
  Ignore non-spatial physio data (rordenlab#606)
  Flipping Y also flips sign of determinant
  Better Siemens XA support (rordenlab#606)
  Report DwellTime for Siemens XA (rordenlab#240)
  ...
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

3 participants