Skip to content

error writing .txt to /ecat_testing/steps folder #329

@fishpm

Description

@fishpm

Describe the bug

If pet image created by ecat2nii requires rescaling, then ecat2nii.m tries to write scaling info to a .txt file saved to a folder (ecat_save_steps_dir) that is .../PET2BIDS/ecat_testing/steps, which does not exist in current PET2BIDS structure. Seems to me there are at least two straight-forward solutions: 1) write .txt file to .../PET2BIDS/matlab/ecat_testing, which does exist in current PET2BIDS structure, or 2) mkdir(ecat_save_steps_dir) if it does not exist. I am uncertain whether one is preferred for reasons about which I am unaware.

l. 202 - 220 of ecat2nii.m:

% rescale to 16 bits
rg = max(img_temp(:))-min(img_temp(:));
if rg ~= 32767 % same as range(img_temp(:)) but no need of stats toolbox
MaxImg = max(img_temp(:));
img_temp = img_temp/MaxImg*32767;
Sca = MaxImg/32767;
MinImg = min(img_temp(:));
if (MinImg<-32768)
img_temp = img_temp/MinImg*(-32768);
Sca = Sca*MinImg/(-32768);
end
% save scaling factor to file located at ecat_save_steps_dir/8.5_sca_matlab.txt
fid = fopen([ecat_save_steps_dir filesep '8.5_sca_matlab.txt'],'w');
fprintf(fid,'Scaling factor: %10e\n',Sca);
x = mh.ecat_calibration_factor * Sca;
fprintf(fid,'Scaling factor * ECAT Cal Factor: %10.10f\n',x);
fclose(fid);
end

To Reproduce
code: ecat2nii(filename{1},metadata);
error: Invalid file identifier. Use fopen to generate a valid file identifier.

Desktop (please complete the following information):

  • OS: Linux
  • matlab r2023a

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions