abhogal-lab / seeVR

Toolbox for analyzing cerebrovascular imaging data based on BOLD MRI
GNU General Public License v3.0
12 stars 5 forks source link

lagCVR() index error #13

Closed dariusvalevicius closed 1 year ago

dariusvalevicius commented 1 year ago

Hello,

I'm encountering an index error in lagCVR() on line 176. The error is paired with an odd comment on that line, suggesting that there is a known problem, but the comment is from the initial commit 2 years ago.

The error log:

Creating optimized regressor Correlating TS voxelwise to probe 1 . . . Index in position 1 exceeds array bounds.

Error in lagCVR (line 176) [~,lags] = xcorr(newprobe,gm_voxel_ts_nonan(1,:),'coeff'); %%%%%% !!!!!!!!!!

The 'probe' input to lagCVR() is a 350x1 double, if that helps.

Best, Darius

dariusvalevicius commented 1 year ago

This is using seeVR version 1.55 and MATLAB 2021b.

abhogal-lab commented 1 year ago

Hi Darius,

Thanks for trying out my tools and letting me know about the potential bug. I think that comment is just an old artifact since this line is really only there to setup the vector containing the potential lag indices. I can't seem to reproduce the error using my data so I suspect it might have something to do with the function inputs.

Can you please try some things to help me figure out what might be the problem and/or help me to reproduce the error?:

1) please provide the function call with the sizes of the inputs (i.e. func data, masks etc.) 2) place a break point at line 176 and run the function to see what the size of the newprobe and gm_voxel_ts_nonan is? 3) download tutorial Demo #1 from www.seeVR.nl and see if that successfully runs? If yes, confirm that your inputs are matching those used in the tutorial.

Otherwise I'm happy to do a call to help figure out the problem using your data directly (a.bhogal@umcutrecht.nl).

Best, Alex

dariusvalevicius commented 1 year ago

Hi Alex, thanks so much for the prompt response!

Using breakpoints to test the inputs to xcorr, I seem to have isolated the problem. For some reason, the "cast" function (called inside of grabTimeseries()) in my MATLAB installation contains no code, only comments, and returns empty arrays, causing the gm_voxel_tx input(1,:) to throw an index error.

image

I guess I'll try a reinstall of MATLAB - super strange!

Best, Darius

abhogal-lab commented 1 year ago

Hi Darius,

I think sometimes Matlab has functions where they don't let you see the code. I added the cast function recently as a way to handle different data types (someone gave me data exported as int16.. ). For the Matlab-niftii saving functions it becomes important to take care of the datatype. One option you could try is to just remove this from your code. Take care though, that you will then have to ensure that the maps you save have the same datatype as the data you load in. Another option is to use the loadImageData function instead of the loadTimeseries function to handle data import. This uses the old niftii/analyze I/O instead of the native Matlab options.

I hope you get it working, otherwise let me know so that we can debug.

Best, Alex

dariusvalevicius commented 1 year ago

Hi Alex,

You're right, it wasn't a problem with the cast() function. I spent the rest of the afternoon debugging and finally found the actual problem, it was an issue with one of the options (spatialdim was set to 4) that caused the smthData() function to return a 4D array of only NANs, which was then passed to lagCVR().

The value of spatialdim was set by my colleague - I'll ask them how come this was the case. I looked in smthData() and I see that it only performs operations on 4D data for spatialdim values of 2 or 3, so it breaks on 4 (but the function completes/fails silently). Setting it to 2 allowed the program to complete.

Thanks for the help in this!

Darius

abhogal-lab commented 1 year ago

Thanks Darius,

Sounds like a bug to me! I'll be sure to implement some more checks.