muschellij2/fslr

Error in fslsmooth: "Cannot open the connection"

Closed this issue · 7 comments

I am trying to use the fslsmooth function on a NIFTI object. It is returning the following error:

Error in gzfile(paste(filename, "nii.gz", sep = "."), "wb", compression = compression) :
cannot open the connection

I am having a difficult time understanding what is causing this error, or how to fix it. I have verified that the input objects are valid NIFTI objects. Here is a screenshot that shows the summary of each NIFTI object as well as the syntax of the fslsmooth function call.

screenshot

Any idea where to look as to how to resolve this? This same code chunk has previously worked for me on the same NIFTI files, so I'm at a bit of a loss as to why suddenly it is unable to execute.

Can you provide a MCWE: https://stackoverflow.com/help/mcve - either uploading the images or the output.

Can you also run traceback()?

Can you provide a MCWE: https://stackoverflow.com/help/mcve - either uploading the images or the output.

I unfortunately cannot upload the images themselves. What output specifically would be helpful? I don't know exactly what you mean by "output" in this case.

Can you also run traceback()?

Yes, here is the traceback:

traceback()
12: gzfile(paste(filename, "nii.gz", sep = "."), "wb", compression = compression)
11: .writeNIfTI(nim, filename, onefile, gzipped, verbose, warn, compression)
10: .local(nim, ...)
9: oro.nifti::writeNIfTI(nim, nii.stub(filename), compression = compression,
...)
8: oro.nifti::writeNIfTI(nim, nii.stub(filename), compression = compression,
...)
7: withCallingHandlers(expr, warning = function(w) invokeRestart("muffleWarning"))
6: suppressWarnings({
x = oro.nifti::writeNIfTI(nim, nii.stub(filename), compression = compression,
...)
})
5: writenii(nim, filename = f, onefile = TRUE, gzipped = gzipped,
warn = warn)
4: tempimg(file, ...)
3: checkimg(file, ...)
2: checkimg(file, ...)
1: fslsmooth(whole_brain_nifti, sigma = 1.25, mask = voxel_selection,
retimg = TRUE, smooth_mask = TRUE)

I think the problem is that you're using mask = subject_dataframe$voxel_selection, which is likely a vector. Can you print

class(subject_dataframe$voxel_selection)
subject_dataframe$voxel_selection

If that doesn't work I can't really help without you sharing the inputs to the function.

It's an object of class nifti. The details for it are in the screenshot (the print out under "voxel_selection" before the fslsmooth call).

I have fslr version 2.21.0.9000. In case it's relevant, oro.nifti is at version 0.9.7 and neurobase is at version 1.27.1.

Unfortunately, I can't share these inputs, I'm fairly certain it would violate my data sharing agreement. The object I used in the call that caused this original error is a NIFTI object generated by fitting some models to the original NIFTI data. However, when I tested using fslsmooth on the original data (in case there was something odd about the model predictions specifically), I got the same error. I am currently trying the function on some other NIFTI data, for which it worked in the past, to see what happens.

Any idea what type of problem with the NIFTI object I should be looking for, e.g. NA values or values outside of a certain range?

Note, in the printout, you print voxel_selection, but pass subject_dataframe$voxel_selection. So please print that out.

Without a reproducible example, I'm going to close this issue.

They are the same object. I apologize for the mix-up, there. The error persists regardless.

For the record, I spent some time today going through the source code line by line for each function to track down the source of the problem. It turns out the issue was arising from the "filename" input to the neurobase::writenii function within the neurobase::tempimg function call. By default, the tempimg function creates the filename using the base function tempfile(). However, the protections/permissions on the cluster I am using to run my analyses are such that tempfile() was creating an inaccessible file path, thus the "cannot open the connection" error.

So the solution to this on my end seems to be writing a duplicate tempimg function that generates the filename in a different way, since I can't figure out a way to pass options top-down to override this.