Skip to content

Q: Difficulty opening a file with .nii.gz extension #1075

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

Closed
effigies opened this issue Jan 25, 2022 · 8 comments
Closed

Q: Difficulty opening a file with .nii.gz extension #1075

effigies opened this issue Jan 25, 2022 · 8 comments

Comments

@effigies
Copy link
Member

Hello, I'm using nib.load(file_name) to access a ".nii.gz" file, and the function raise ImageFileError and I found that nib.filebasedimages.FileBasedImage.path_maybe_image('.nii') still gives me a (False, None). How can I solve the problem? Thanks

Originally posted by @lanranranM in #621 (comment)

@effigies
Copy link
Member Author

Hi @lanranranM, I created a new issue. Posting on closed issues is a good way to get buried. I'm not positive I got the title right.

In any event, can you run file on the file you have? For example:

$ file .nii.gz 
.nii.gz: gzip compressed data, max speed, original size modulo 2^32 1352

@lanranranM
Copy link

Hi @lanranranM, I created a new issue. Posting on closed issues is a good way to get buried. I'm not positive I got the title right.

In any event, can you run file on the file you have? For example:

$ file .nii.gz 
.nii.gz: gzip compressed data, max speed, original size modulo 2^32 1352

Thank you for opening a new Post! I run the command in powerShell and it gives me

.nii.gz; cannot open `.nii.gz' (No such file or directory)

For convenience, here is the screenshot for the files
image
Thank you so much!

@effigies
Copy link
Member Author

Ah, then I misunderstood your earlier post. Can you share the full filename of a file you would like to open, and the output of file run on that?

@lanranranM
Copy link

lanranranM commented Jan 26, 2022

Sure! The full file name is sub-S01_task-localizer_space-MNI152NLin2009cAsym_boldref.nii. with type extension .gz
After I run file on it, the terminal prompts up sub-S01_task-localizer_space-MNI152NLin2009cAsym_boldref.nii.gz; ASCII text, with no line terminators
So I'm really new to neuroimaging data processing and I'm loading the data from Brain_Data() methods. However, it raised the same errors because of the filename in posts #620 and #621. As you mentioned in that post, I switched to use nib.Nifti1Image.from_filename() and nib.load() to access data. Now the nib.Nifti1Image.from_filename() raises nibabel.wrapstruct.WrapStructError: Binary block is wrong size
btw I'm using windows. Thank you so much
.

Ah, then I misunderstood your earlier post. Can you share the full filename of a file you would like to open, and the output of file run on that?

@effigies
Copy link
Member Author

ASCII text, with no line terminators

I assume that file on Windows would recognize a .gz file. Might be worth opening the file and looking at what's inside. I would have a quick look with Notepad; if it looks like gibberish, then you can dump the binary data in hex format. See https://www.howtohaven.com/system/view-binary-file-on-windows.shtml.

Feel free to paste the output here.

@effigies effigies changed the title Q: How to open a file named ".nii.gz" Q: Difficulty opening a file with .nii.gz extension Jan 26, 2022
@lanranranM
Copy link

ASCII text, with no line terminators

I assume that file on Windows would recognize a .gz file. Might be worth opening the file and looking at what's inside. I would have a quick look with Notepad; if it looks like gibberish, then you can dump the binary data in hex format. See https://www.howtohaven.com/system/view-binary-file-on-windows.shtml.

Feel free to paste the output here.

Thanks! The .nii.gz file contains ../../../../.git/annex/objects/xV/xV/MD5E-s3337907--6fa57c6b825708ce4d2187a2d204805e.nii.gz/MD5E-s3337907--6fa57c6b825708ce4d2187a2d204805e.nii.gz
I tried to unzip it by 7-zip but it gives me "Cannot open file as archive" error.

I run format-hex on the file and it shows as
image

@effigies
Copy link
Member Author

Okay, this looks like a problem with using datalad or git-annex on Windows. In normal circumstances, that would be a symlink that would either resolve or not, but it appears to just be a text file here.

It looks like this might be a relevant question for https://github.com/ljchang/dartbrains or https://github.com/datalad/datalad/, but there's nothing to do on the nibabel end if the file contents are missing.

@yarikoptic
Copy link
Member

Oh, that is a gitlink file (since windows doesn't support symlinks), so you would need to datalad or git-annex get it to get it replaced with the actual data file.

@effigies effigies closed this as completed Feb 7, 2022
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