Arrays have incompatible sizes for this operation

Continuing the discussion from Error using OspreyProcess with job file, but not GUI - Error in osp_WriteBIDsTable: this time I have a new error.

When I run my MRS analysis (either command line or with GUI) when I get to fitting stage I get the following error:

Arrays have incompatible sizes for this operation.

Error in fit_OspreyParamsToModel (line 161)
completeFit = A * ampl + baseline;

Error in osp_fit_Quality (line 140)
                                [ModelOutput] = fit_OspreyParamsToModel(inputData, inputSettings, fitParams);

Error in OspreyFit (line 147)
    [MRSCont] = osp_fit_Quality(MRSCont);

Error in RunOspreyJob (line 34)
    MRSCont = OspreyFit(MRSCont);

I have run the file with ‘Pause on errors’ selected in MatLab and here is a screenshot:

I have attached the job file as well.
ACC_all.m (13.6 KB)

Any ideas why I am getting the incompatible array sizes and what I can do to solve this?

I initially thought this might be caused by one of the participants having a weird preprocessing output

but the problem didn’t go away even if I excluded this data before fitting.

Actually, when I deleted the entire folder where MRS dicom data for participant 207 MRI2 was located and re-run the script from the beginning then everything was working again.

It must be something with the preprocessing step for that scan (since the raw scan looks fine, it’s the ‘aligned and averaged’ window where the graph appears weird) and it’s not enough that I exlclude the data in the Osprey GUI container. Ideally I would like to not exclude this data, as it appears fine. Any advice?

  1. Can you post a screenshot of a dataset that doesn’t have the ‘weird’ aligned and averaged output?
  2. Are you sure that you’re assigning the correct water reference scan for this particular dataset? Using the wrong water ref to do the eddy-current correction might throw everything off.
  3. This is Siemens data, yes? Acquired with the product sequence? What software version are you on? (You might try setting opts.ECC.raw to 0, although I think that at least older sequences have no way of applying eddy-current correction since they don’t have an integrated water ref scan built-in.
  4. Can you show a successful fit from one of your successful runs? I’m intrigued by your setting opts.fit.fitMM = 0; which is unusual to say the least - you should have MMs in your fit.
  5. What region is this from in the ACC, as in, how far frontal did you go for this? Data quality (linewidth) isn’t awful, but also not exquisite.

Hi,

  1. Here is a screenshot of another processed data with normal aligned and averaged graph:
    sub-210_ses-MRI1_voi-ACC_acq-pres_svs_Voxel_1_OspreyProcess_metab_A

  2. Pretty sure it’s correct. I have a script that orders the dicoms into correct folders and adjusts the filenames, and each pariticpant has one ref file per session (each participant has 2 sessions=a placebo and a drug scan), so I cannot think of where I could go wrong with chosing the water reference file.

  3. Yes, it’s siemens dicom, each participant has: a water reference file, a noECC metabolite file, and ECC metabolite file. I don’t use the last one since I do ECC in Osprey. If I set opts.ECC.raw = 0 then I wouldn’t be doing eddy-current correction, right? I guess I could use the ECC files that we get from the scanner software but I’d prefer to use the not-ECC and do ECC in Osprey.

  4. Here is a successful fit:
    sub-102_ses-MRI1_voi-ACC_acq-pres_svs_OspreyFit_metab_A_basis_1
    I re-run it with opts.fit.fitMM = 1 and still got the same output.

  5. This region of ACC is in our scanning manual:

  6. Also, I want to take back what I said in my last comment. Deleting participant 207 ses-MRI2 did not help, as now fitting is done up until participant 109 MRI1. I do get the metabolite fit output for 109 MRI1 but not for 109 MRI1 ref. I get a similar error, though at a later stage than before because half of the fitting is done, but not after participant 109.

Error I get after fitting
Arrays have incompatible sizes for this operation.

Error in fit_waterOspreyParamsToModel (line 80)
residual    = data - completeFit;

Error in osp_plotFit (line 293)
            [ModelOutput] = fit_waterOspreyParamsToModel(inputData, inputSettings, fitParams);

Error in osp_plotModule (line 757)
            temp = osp_plotFit(MRSCont, kk, which,[1 subspectrum basis],which);

Error in osp_plotAllPDF (line 76)
                                osp_plotModule(MRSCont, 'OspreyFit', kk,[bb ss], Names{mm});

Error in OspreyFit (line 228)
    osp_plotAllPDF(MRSCont, 'OspreyFit');

Error in osp_onFit (line 60)
    MRSCont = OspreyFit(MRSCont);

Related documentation
 
Error while evaluating UIControl Callback.

So I am still not able to progress beyond fitting.

Hi @juliam98,

From the posts, it seems that the ppm range is not correctly identified for the metabolite fit (sub 207) and for the water fit (sub 109) during the plotting. I am not sure why this is happening. The fitting itself seemed to have worked fine. You can set the savePDF flag in the jobfile to 0. Then it might be easier to take a look at all subjects after the fitting.

Could you share one subject who is fine and the two other subjects who are failing the metabolite and water scan, respectively?

And lastly about the opts.ECC.raw flag. If you want to do ECC in Osprey you have to set it to 1
and parse the water reference and noECC metabolites.

Helge

Hi,

I used the GUI to create a new job just for participant 109 and left all the default settings - I only provided the file paths, and weirdly it all worked fine.

Here's what the fitted water reference file for sub-109_ses-MRI1 looks like:

I have attached a zipped folder with 207,109, and 223 - the last one works fine. I did not include the ECC files, as I’m not using them (since I’m doing ECC in Osprey) - so only noECC and ref files for each participant are in the folder.

And lastly about the opts.ECC.raw flag. If you want to do ECC in Osprey you have to set it to 1 and parse the water reference and noECC metabolites.

Okay great, this is what I have been doing.

mrs_files.zip (200.7 KB)

Hi @Helge ,

I have set the opts.savePDF=0 like you recommended and this time it did not stop at fitting, but run until the quantification and gave me a similar error about arrays having incompatible sizes.

The error I got this time:
Quantifying dataset  23 out of  23 total datasets...

... done.
 Elapsed time 0.183011 seconds
Timestamp August 14, 2024 16:31:03 Osprey 2.6.5  OspreyOverview

Gathering spectra from subspectrum 2 out of 2 total subspectra...
... done.
Gathering fit models from fit 2 out of 2 total fits...Arrays have incompatible sizes for this operation.

Error in fit_waterOspreyParamsToModel (line 80)
residual    = data - completeFit;

Error in OspreyOverview (line 223)
                                [ModelOutput] = fit_waterOspreyParamsToModel(inputData, inputSettings, fitParams);

Error in RunOspreyJob (line 57)
    MRSCont = OspreyOverview(MRSCont);

Related documentation

I had a look at the Quantify Results folder and most .tsv files look normal except A_TissCorrWaterScaled.tsv and A_CSFWaterScaled_Voxel_1_Basis_1.tsv where two rows have Inf as their values. Also the TissueFractions.tsv file has values fGM=0, fWM=0, fCSF=1, for these two participants (I attached the zipped files). The first of those two is sub-207_MRI2 about which I commented above because their 'aligned and averaged` image didn’t look right. The other is sub-223_MRI1, which I just added to the dataset.

Quantify_output.zip (12.1 KB)

Setting opts.savePDF=0 gave me a lot less errors. Yesterday I tried re-running the job file and excluding any participant & session that gave me an error during fitting then re-running again, and I ended up removing about 6 sessions before I gave up with that method.

Do you know if that might be a segmentation issue because of the script/options in the job file, or is it likely to be a problem with the data?