Skip to content

Commit

Permalink
added telemetry to matlab converters
Browse files Browse the repository at this point in the history
  • Loading branch information
bendhouseart committed Aug 2, 2024
1 parent b3bf9af commit 8550942
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
10 changes: 5 additions & 5 deletions matlab/dcm2niix4pet.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,24 @@ function dcm2niix4pet(FolderList,MetaList,varargin)
end

if ~ispc % overwrite if not windowns (as it should be in the computer path)
dcm2niixpath = '/usr/local/bin/dcm2niix';
dcm2niixpath = 'dcm2niix';
end

% we rely on more recent version of dcm2niix, certain pet fields are unavailable in the sidecar jsons for versions
% before v1.0.20220720

minimum_version = 'v1.0.20220720';
minimum_version_date = datetime(minimum_version(6:end), 'InputFormat', 'yyyyMMdd');
%version_cmd = ['dcm2niix', ' -v']; % TODO fix this as it's not detecting dcm2niix running matlab on osx as of matlab v2023b.
version_cmd = ['/usr/local/bin/dcm2niix', ' -v'];
version_cmd = ['dcm2niix', ' -v'];

[status, version_output_string] = system(version_cmd);
version = regexp(version_output_string, 'v[0-9].[0-9].{8}[0-9]', 'match'); % TODO this returns an array with two of the same versions
version = regexp(version_output_string, 'v[0-9].[0-9].{8}[0-9]', 'match');


% initalize telemetry data fror later uploading

Check failure on line 71 in matlab/dcm2niix4pet.m

View workflow job for this annotation

GitHub Actions / Check for spelling errors

initalize ==> initialize
telemetry_data = {};
dcm2niix_data = {};
dcm2niix_data.version = version;
dcm2niix_data.version = version(1);
dcm2niix_data.returncode = 0;
telemetry_data.dcm2niix = dcm2niix_data;
telemetry_data.description = "Matlab_dcm2niix4pet.m"
Expand Down
25 changes: 20 additions & 5 deletions matlab/ecat2nii.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
parts = strsplit(ecat_save_steps_dir, filesep);
ecat_save_steps_dir = strjoin([parts(1:end-2), 'ecat_testing', 'steps'], filesep);

%% initialize telemetry variable for reporting
telemetry_data = {};
telemetry_data.description = "Matlab_ecat2nii";

%% check inputs
% ------------

Expand Down Expand Up @@ -131,14 +135,18 @@
%% Read and write data
% --------------------
for j=1:length(FileListIn)

try
fprintf('Conversion of file: %s\n',FileListIn{j});

% quickly ensure we have the TimeZero - key to all analyzes!
info = MetaList{1};
if ~isfield(info,'TimeZero')
error('Metadata TimeZero is missing - set to ScanStart or empty to use the scanning time as injection time')
error_text = 'Metadata TimeZero is missing - set to ScanStart or empty to use the scanning time as injection time';
telemetry_data.returncode = 1;
telemetry_data.error = error_text;
telemetry(telemetry_data, FileListIn{j})
error(error_text)
end

% Read ECAT file headers
Expand Down Expand Up @@ -180,6 +188,9 @@
end
end

% capture ecat version
telemetry_data.InputType = append("ECAT", string(mh.sw_version));

% save debugging steps 6 and 7
if (ecat_save_steps == '1')
first_middle_last_frames_to_text_cell(data,ecat_save_steps_dir, '6_ecat2nii_matlab');
Expand All @@ -206,8 +217,6 @@
fclose(fid);
end



% save debugging step 8 - rescale to 16 bits
if (ecat_save_steps == '1')
first_middle_last_frames_to_text(img_temp,ecat_save_steps_dir, '8_rescale_to_16_ecat2nii_matlab');
Expand Down Expand Up @@ -489,8 +498,14 @@
% FileListOut{j} = [filenameout '_pet.nii'];
% niftiwrite(img_temp,FileListOut{j},info,'Endian','little','Compressed',false);
% end

telemetry_data.returncode = 0;
telemetry(telemetry_data, FileListIn{j});

catch conversionerr
telemetry_data.returncode = 1;
telemetry_data.error = conversionerr.message;
telemetry(telemetry_data, FileListIn{j});
FileListOut{j} = sprintf('%s failed to convert:%s',FileListIn{j},conversionerr.message, conversionerr.stack.line);
end

Expand Down

0 comments on commit 8550942

Please sign in to comment.