ImageFileError: Cannot work out file type of ".nii" - filenames

When I try to load my .NII file as a 4D Niimg-like object (I've tried both nilearn and nibabel),
I get the below error
Error: ImageFileError: Cannot work out file type of
"/Users/audreyphan/Documents/Spring2020/DESPO/res4d/1/res4d_anat.nii"
Here is my code:
ds_name = '/Users/audreyphan/Documents/Spring2020/DESPO/res4d/1/res4d_anat.nii'
block = nib.load(ds_name) #Nibabel
block = image.load_img(ds_name) #Nilearn
Both attempts result in the same error.
I'm not sure what's causing this error to occur?
Thanks!

It looks like the libraries are not able to extract the file type from your file.
So first of all we have to be sure that the file is not corrupt. Therefore, can you load the data correctly with a tool such as ITK-SNAP (http://www.itksnap.org)?
If yes, you can try to define the file type by your own in the nibabel package by using the specific loader function. E.g. you can try each one of the following loader functions:
img_nifti1 = nib.Nifti1Image.from_filename(file)
img_nifti2 = nib.Nifti2Image.from_filename(file)

Oddly enough, this error also occurs when the access permissions are not set appropriately for the file you are trying to load. Try using chmod to change those access permissions appropriately and then loading the *.nii file.

Related

Using Leigh version of S3Wrapper.cfc Can't get past Init

I am new to S3 and need to use it for image storage. I found a half dozen versions of an s2wrapper for cf but it appears that the only one set of for v4 is one modified by Leigh
https://gist.github.com/Leigh-/26993ed79c956c9309a9dfe40f1fce29
Dropped in the com directory and created a "test" page that contains the following code:
s3 = createObject('component','com.S3Wrapper').init(application.s3.AccessKeyId,application.s3.SecretAccessKey);
but got the following error :
So I changed the line 37 from
variables.Sv4Util = createObject('component', 'Sv4').init(arguments.S3AccessKey, arguments.S3SecretAccessKey);
to
variables.Sv4Util = createObject('component', 'Sv4Util').init(arguments.S3AccessKey, arguments.S3SecretAccessKey);
Now I am getting:
I feel like going through Leigh code and start changing things is a bad idea since I have lurked here for year an know Leigh's code is solid.
Does any know if there are any examples on how to use this anywhere? If not what I am doing wrong. If it makes a difference I am using Lucee 5 and not Adobe's CF engine.
UPDATE :
I followed Leigh's directions and the error is now gone. I am addedsome more code to my test page which now looks like this :
<cfscript>
s3 = createObject('component','com.S3v4').init(application.s3.AccessKeyId,application.s3.SecretAccessKey);
bucket = "imgbkt.domain.com";
obj = "fake.ping";
region = "s3-us-west-1"
test = s3.getObject(bucket,obj,region);
writeDump(test);
test2 = s3.getObjectLink(bucket,obj,region);
writeDump(test2);
writeDump(s3);
</cfscript>
Regardless of what I put in for bucket, obj or region I get :
JIC I did go to AWS and get new keys:
Leigh if you are still around or anyone how has used one of the s3Wrappers any suggestions or guidance?
UPDATE #2:
Even after Alex's help I am not able to get this to work. The Link I receive from getObjectLink is not valid and getObject never does download an object. I thought I would try the putObject method
test3 = s3.putObject(bucketName=bucket,regionName=region,keyName="favicon.ico");
writeDump(test3);
to see if there is any additional information, I received this :
I did find this article https://shlomoswidler.com/2009/08/amazon-s3-gotcha-using-virtual-host.html but it is pretty old and since S3 specifically suggests using dots in bucketnames I don't that it is relevant any longer. There is obviously something I am doing wrong but I have spent hours trying to resolve this and I can't seem to figure out what it might be.
I will give you a rundown of what the code does:
getObjectLink returns a HTTP URL for the file fake.ping that is found looking in the bucket imgbkt.domain.com of region s3-us-west-1. This link is temporary and expires after 60 seconds by default.
getObject invokes getObjectLink and immediately requests the URL using HTTP GET. The response is then saved to the directory of the S3v4.cfc with the filename fake.ping by default. Finally the function returns the full path of the downloaded file: E:\wwwDevRoot\taa\fake.ping
To save the file in a different location, you would invoke:
downloadPath = 'E:\';
test = s3.getObject(bucket,obj,region,downloadPath);
writeDump(test);
The HTTP request is synchronous, meaning the file will be downloaded completely when the functions returns the filepath.
If you want to access the actual content of the file, you can do this:
test = s3.getObject(bucket,obj,region);
contentAsString = fileRead(test); // returns the file content as string
// or
contentAsBinary = fileReadBinary(test); // returns the content as binary (byte array)
writeDump(contentAsString);
writeDump(contentAsBinary);
(You might want to stream the content if the file is large since fileRead/fileReadBinary reads the whole file into buffer. Use fileOpen to stream the content.
Does that help you?

Powershell v2 - The correct way to load an assembly as part of a module

I have a Powershell (v2.0) script that I am working on.
One of the first things it does is loads a Module (runMySQLQuery.psm1) which includes (amongst other bits) a function to connect to a MySQL Database.
Import-Module runMySQLQuery.psm1
However, this requires that an assembly MySQL.Data.DLL is loaded in order for this to work.
If I place the line:
[void][system.reflection.Assembly]::LoadFrom("C:\PowerShell\modules\runMySQLQuery\MySql.Data.dll")
at the top of my script (separate to the Import-Module entry), then the whole thing works fine.
But I want to be able to load this assembly at the same time as the module, so that I don't have to worry about forgetting to including the assembly each time I use this module.
I tried placing it at the top of the .psm1 file, but that didn't work.
I then added it to my manifest file as:
RequiredAssemblies = #("C:\PowerShell\modules\runMySQLQuery\MySql.Data.dll")
This also didn't work.
Am I missing something here, is there a proper way to include assemblies as part of a module?
n.b. the error I get when it hasn't loaded properly is:
You cannot call a method on a null-valued expression
Can you just try to assign a varialbe a the beginig of you module :
$dumy = [system.reflection.Assembly]::LoadFrom("C:\PowerShell\modules\runMySQLQuery\MySql.Data.dll")

Pig latin load from S3 (folder expansion)

I am trying to use load with data source as S3 bucket.
load s3n://hourly-logprocessing/{2013090100,2013100501}/??????_0.gz' using some loader()
does not work.
load s3n://hourly-logprocessing/{201309????}/??????_0.gz using some loader()
does not work.
I get this exception.
Caused by: java.lang.IllegalArgumentException: Can not create a Path
from an empty string
at org.apache.hadoop.fs.Path.checkPathArg(Path.java:91)
at org.apache.hadoop.fs.Path.(Path.java:99)
at org.apache.hadoop.fs.Path.(Path.java:58)
at org.apache.hadoop.fs.s3native.NativeS3FileSystem.listStatus(NativeS3FileSystem.java:498)
at org.apache.hadoop.fs.FileSystem.listStatus(FileSystem.java:1341)
at org.apache.hadoop.fs.FileSystem.listStatus(FileSystem.java:1418)
at org.apache.hadoop.fs.FileSystem.globPathsLevel(FileSystem.java:1602)
at org.apache.hadoop.fs.FileSystem.globStatusInternal(FileSystem.java:1539)
It only works when i use a single folder.
load s3n://some-folder/2013090100/??????_0.gz
How does pig expand. Any help would be appreciated.
First of all, I didn't try your examples, o lazy me, but this works for my 'load' statements:
's3n://SOME_BUCKET/20[0-9][0-9]-[0-9][0-9]-[0-9][0-9]-23-*.mystuff_v14*'
don't forget single quotes after the load command (which is missing in your examples)

an error 3013 thrown when writing a file Adobe AIR

I'm trying to write/create a JSON file from a AIR app, I'm trying not so show a 'Save as' dialogue box.
Here's the code I'm using:
var fileDetails:Object = CreativeMakerJSX.getFileDetails();
var fileName:String = String(fileDetails.data.filename);
var path:String = String(fileDetails.data.path);
var f:File = File.userDirectory.resolvePath( path );
var stream:FileStream = new FileStream();
stream.open(f, FileMode.WRITE );
stream.writeUTFBytes( jsonToExport );
stream.close();
The problem I'm having is that I get a 'Error 3013. File or directory in use'. The directory/path is gathered from a Creative Suite Extension I'm building, this path is the same as the FLA being developed in CS that the Extension is being used with.
So I'm not sure if the problem is that there are already files in the directory I'm writing the JSON file to?
Do I need to add a timer in order to close the stream after a slight delay, giving some time to writing the file?
Can you set up some trace() commands? I would need to know what the values of the String variables are, and the f.url.
Can you read from the file that you are trying to write to, or does nothing work?
Where is CreativeMakerJSX.getFileDetails() coming from? Is it giving you data about a file that is in use?
And from Googling around, this seems like it may be a bug. Try setting up a listener for when you are finished, if you have had the file open previously.
I re-wrote how the file was written, no longer running into this issue.

wxBitmap::LoadFile fails in Windows

I am trying to load an Image file of type .xpm into the wxBitmap Object using LoadFile method. The following call fails
wxBitmap aBitmap;
aBitmap.LoadFile(strIconPath,wxBITMAP_TYPE_XPM);
with the error
No image handler for type wxBITMAP_TYPE_XPM defined.
Whereas, if I load it by including the xpm file and using it as shown below, it works.
#include "Icon.xpm"
wxBitmap aBitmap;
aBitmap.CopyFromIcon(wxIcon(Icon_xpm));
What is the problem with the first implementation?
If you only want to use XPM files then wxImage::AddHandler(new wxXPMHandler); should fix it, otherwise wxInitAllImageHandlers(); is easier for multiple image types. Both of these need to be called before you try to load the file.
Try adding ::wxInitAllImageHandlers(); before the LoadFile call or changing the image type specified in the LoadFile call to wxBITMAP_TYPE_ANY.