bids-standard / bids-validator

Validator for the Brain Imaging Data Structure
https://bids-standard.github.io/bids-validator/
MIT License
181 stars 109 forks source link

NIfTI/JSON metadata consistency checks #752

Open effigies opened 5 years ago

effigies commented 5 years ago

Based on a discussion in: https://github.com/bids-standard/bids-specification/issues/138

The JSON metadata fields PhaseEncodingDirection, SliceEncodingDirection have corresponding values in the NIfTI header field dim_info:

JSON NIfTI
"PhaseEncodingDirection": "i[-]" (dim_info >> 2) & 0x03 == 1
"PhaseEncodingDirection": "j[-]" (dim_info >> 2) & 0x03 == 2
"PhaseEncodingDirection": "k[-]" (dim_info >> 2) & 0x03 == 3
"SliceEncodingDirection": "i[-]" (dim_info >> 4) & 0x03 == 1
"SliceEncodingDirection": "j[-]" (dim_info >> 4) & 0x03 == 2
"SliceEncodingDirection": "k[-]" (dim_info >> 4) & 0x03 == 3

Additionally, SliceTiming can be consistent or inconsistent with the following fields:

    slice_duration = If this is positive, AND if slice_dim is nonzero,
                     indicates the amount of time used to acquire 1 slice.
                     slice_duration*dim[slice_dim] can be less than pixdim[4]
                     with a clustered acquisition method, for example.

    slice_code = If this is nonzero, AND if slice_dim is nonzero, AND
                 if slice_duration is positive, indicates the timing
                 pattern of the slice acquisition.  The following codes
                 are defined:
                   NIFTI_SLICE_SEQ_INC  == sequential increasing
                   NIFTI_SLICE_SEQ_DEC  == sequential decreasing
                   NIFTI_SLICE_ALT_INC  == alternating increasing
                   NIFTI_SLICE_ALT_DEC  == alternating decreasing
                   NIFTI_SLICE_ALT_INC2 == alternating increasing #2
                   NIFTI_SLICE_ALT_DEC2 == alternating decreasing #2
  { slice_start } = Indicates the start and end of the slice acquisition
  { slice_end   } = pattern, when slice_code is nonzero.  These values
                    are present to allow for the possible addition of
                    "padded" slices at either end of the volume, which
                    don't fit into the slice timing pattern.  If there
                    are no padding slices, then slice_start=0 and
                    slice_end=dim[slice_dim]-1 are the correct values.
                    For these values to be meaningful, slice_start must
                    be non-negative and slice_end must be greater than
                    slice_start.  Otherwise, they should be ignored.
effigies commented 5 years ago

Guess I forgot to finish this up, and the "Edit" button isn't working for me right now.

It would be good to validate consistency at least insofar as the NIfTI metadata should not directly contradict the JSON metadata. In many cases, the NIfTI header will have \x00 bytes in these fields, so that should probably not fail the check. Additionally, some values permissible in the JSON metadata may not be representable in NIfTI (e.g., the polarity of the phase encoding direction is not specifiable in NIfTI), so we should be aware of that in any checks proposed.