Command line error: "saveNII", "savePDF" creates errors

When I edit job file to enable “saveNII” or “savePDF” I get errors when running at the command line.

OSPREY:
Timestamp February 03, 2023 13:06:13 Osprey 2.4.0

MATLAB:
R2021a Update 7 (9.10.0.2015706) 64-bit (glnxa64)

JOBFILE:
{
“seqType”: “HERCULES”,
“editTarget”: [“GABA”,“GSH”],
“dataScenario”: “invivo”,
“MM3coModel”: “3to2MM”,
“FWHMMM3co”: “^N”,
“SpecReg”: “RobSpecReg”,
“SubSpecAlignment”: “L2Norm”,
“UnstableWater”: “0”,
“saveLCM”: “1”,
“savejMRUI”: “1”,
“saveVendor”: “1”,
“saveNII”: “1”,
“savePDF”: “1”,
“method”: “Osprey”,
“ECCmetab”: “1”,
“ECCmm”: “1”,
“includeMetabs”: [“default”],
“style”: “Separate”,
“lolim_range”: “0.5”,
“uplim_range”: “4.0”,
“lolim_rangew”: “2.0”,
“uplim_rangew”: “7.4”,
“bLineKnotSpace”: “0.4”,
“fitMM”: “1”,
“files”: [“/na/homes/jling/studies/laptop20/mrs.analysis/rawdata/sub-01/ses-01/mrs/sub-01_HERC_3CM.dat”],
“files_nii”: [“/na/homes/jling/studies/laptop20/mrs.analysis/rawdata/sub-01/ses-01/anat/sub-01_T1w.nii.gz”],
“file_stat”: [“”],
“outputFolder”: [“/na/homes/jling/studies/laptop20/mrs.analysis/derivatives/sub-01/ses-01/mrs/json_gen_herc”]
}

COMMAND LINE:

Both these command line options fail:

MRSCont = RunOspreyJob(jobFilePath);

or

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% run job with individual stages
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
MRSCont = OspreyJob(jobFilePath, 0, ‘11’);
MRSCont = OspreyLoad(MRSCont);
MRSCont = OspreyProcess(MRSCont);
MRSCont = OspreyFit(MRSCont);
MRSCont = OspreyCoreg(MRSCont);
MRSCont = OspreySeg(MRSCont);
MRSCont = OspreyQuantify(MRSCont);
MRSCont = OspreyOverview(MRSCont);

Error if flag “savePDF” is true:

Printing of uicontrols is not supported on this platform.

Error in print (line 67)
pj = validate( pj );

Error in saveas (line 181)
print( h, name, [‘-d’ dev{i}] )

Error in osp_plotModule (line 967)
saveas(out,fullfile(outputFolder,outputFile),‘pdf’);

Error in osp_plotAllPDF (line 37)
osp_plotModule(MRSCont, ‘OspreyLoad’, kk,[1 1], ‘metabolites’);

Error in OspreyLoad (line 396)
osp_plotAllPDF(MRSCont, ‘OspreyLoad’)

Error in run_osprey_proc (line 33)
MRSCont = OspreyLoad(MRSCont);

Error if flag “saveNII” is true:

Elapsed time 25.926129 seconds
Unrecognized field name “nii_mrs”.

Error in io_writeniimrs (line 155)
nii.hdr = in.nii_mrs.hdr;

Error in osp_saveNII (line 87)
RF = outputFunction(op_takesubspec(MRSCont.processed.metab{kk},1),outfileA);

Error in OspreyProcess (line 803)
[MRSCont] = osp_saveNII(MRSCont);

Error in run_osprey_proc (line 36)
MRSCont = OspreyProcess(MRSCont);

Hi @jling,

Thanks for reaching out.

saveNII is currently only working if your input data is nii-mrs as well. We will address this in a future release or you could also convert your data to nii-mrs first to resolve this issue.

The print issue seems to be related to your OS. We don’t usually use linux for the development or testing. I am going to ping (@alex) because he might have experienced this before.

@alex Did you ever experience similar issues with the pdf export?

Best,
Helge

Best,
Helge

Thanks.

Good to know as we exclusively use linux.

Alex, yes if “savePDF” is enabled i get errors from that module.

What is “nii-mrs”? Is that a NIFTI/JSON pair created from the Siemens dat file?

Note: I have ~16 versions of Matlab back to 2015 if there is a version know to work better.

I think, it is really not a problem of Matlab but linux not being able to create the pdfs. Are you running Osprey in batch mode on linux? This could explain your problem (Error when saving figure with linux command line - MATLAB Answers - MATLAB Central)

nii-mrs describes the NIfTI-MRs data format which is an extension of the nifit format to MRS. YOu can find a tool to convert data to nii-mrs here (GitHub - wtclarke/spec2nii: Multi-format in vivo MR spectroscopy conversion to NIFTI) and the paper here ( * 10.1002/mrm.29418).

Hi @Helge, @jling,

Yes, this is a documented limitation of the saveas function operating in batch/headless mode.

To print or save the figure, hide the uicontrols by setting their Visible properties to 'off' , or use the '-noui' option with the print function.

At the bottom of osp_plotModule.m, I use this pattern instead of the simple saveas:

if osp_platform('desktop')
  saveas(out,fullfile(outputFolder,outputFile),'pdf');
else
 print('-noui',out,fullfile(outputFolder,outputFile),'-dpdf')
end

The resultant PDF is not exactly beautiful (some of the font scalings etc are suboptimal), but it’s good enough for inspection. It’s probably possible to tune the resolution etc to get nicer results.

1 Like

Thank you. We will get this setup.

Alex,

I added your suggestion to my code. It threw the error: “Warning: The figure is too large for the page and will be cut off” so i changed the print statement to this:
print(‘-noui’, out, fullfile(outputFolder,outputFile), ‘-dpdf’, ‘-bestfit’)

It works great. Thanks.

3 Likes