Closed pauldmccarthy closed 7 months ago
Attention: Patch coverage is 86.66667%
with 2 lines
in your changes are missing coverage. Please review.
Project coverage is 92.26%. Comparing base (
27c2427
) to head (5bcf012
). Report is 6 commits behind head on master.
Files | Patch % | Lines |
---|---|---|
nibabel/gifti/parse_gifti_fast.py | 86.66% | 1 Missing and 1 partial :warning: |
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
We need to consider the ArrayIndexingOrder
. MATLAB seems likely to ravel from column-major, while numpy will default to row-major. We do consider it below:
I think if we uniformize the dtype at the top of the function, then we can safely get rid of the byteswap at the end and reuse the existing reshape.
byteorder = gifti_endian_codes.npcode[darray.endian]
dtype = data_type_codes.type[darray.datatype].newbyteorder(endian)
I'm also noticing that the memmap
created here does not respect index order:
So perhaps we want to go ahead and determine the shape and order at the top as well:
shape = tuple(darray.dims)
order = array_index_order_codes.npcode[darray.ind_ord]
Then we can use these consistently.
As to shape, I think we probably want to respect the actual shape as specified in the XML, not squeeze. We should update tests if this is not the case currently.
Applied and tested my suggestions in https://github.com/pauldmccarthy/nibabel/pull/1
@effigies Thanks! You evidently also noticed that the row/column ordering was not being applied as well :+1:
Hi @effigies I hope you're well!
I had a report from a FSLeyes user who has used a MATLAB GIfTI library to generate some
.gii
files that were failing to load in FSLeyes. The GIfTI files that this library generates are ASCII-encoded, but without any newlines to separate elements along the first dimension, e.g.. instead of the conventional:these files instead contain
Once again, the GIfTI specification is light on details as to the expected format of ASCII-encoded data arrays - all it says is (from Section 2.3.4.5 Encoding):
But every ASCII-encoded GIfTI file I've encountered has contained newlines to separate elements along the first dimension.
In any case, when using nibabel to load such a file (e.g. the
ascii_flat_data.gii
test file in this PR), the loaded data arrays are one dimensional, e.g.:It turns out that, for non-ASCII-encoded data arrays, the
nibabel.gifit.parse_gifti_fast.read_data_block
function will ensure that the loaded array has the shape specified in theDataArray
attributes. But this is not the case for ASCII-encoded arrays.This PR contains a small patch which ensures that ASCII-encoded arrays are reshaped to the expected dimensionality.
There is a slight complexity in that one of the existing unit tests is expecting the result to be 1D when loading a file that contains an array of shape
(1, 3)
.I added the
.squeeze()
call in to preserve this behaviour, but I'm not sure whether a better option is to always return the shape specified in theDataArray
attributes. I'm not sure how widely used ASCII-encoded GIFTIs, so am unsure of the potential impact of such a change. It's obviously unlikely that one would encounter aPOINTSET
orTRIANGLE
array with a dimension of length 1, but it could occur withSHAPE
orTIMESERIES
arrays.