From 01d12ad505624b829093c67507dc0168b5631d47 Mon Sep 17 00:00:00 2001 From: markmikkelsen Date: Tue, 14 Mar 2023 14:47:24 -0400 Subject: [PATCH] Further cosmetic changes --- GannetLoad.m | 12 ++++++------ PhilipsDataRead_7T.m | 23 +++++++++++++---------- PhilipsRawRead.m | 32 +++++++++++++++++--------------- SiemensDICOMRead.m | 2 +- SiemensRead.m | 38 ++++++++++++++++++++------------------ 5 files changed, 57 insertions(+), 50 deletions(-) diff --git a/GannetLoad.m b/GannetLoad.m index 6331e91..467d6a2 100644 --- a/GannetLoad.m +++ b/GannetLoad.m @@ -328,19 +328,19 @@ % calculate the SENSE reconstruction matrix here if MRS_struct.p.PRIAM MRS_struct = senseRecon(MRS_struct); - PRIAMData = zeros(length(MRS_struct.p.vox),MRS_struct.p.Navg,MRS_struct.p.npoints); - PRIAMWaterData = zeros(length(MRS_struct.p.vox),MRS_struct.p.Nwateravg,MRS_struct.p.npoints); - for kk = 1:MRS_struct.p.Navg + PRIAMData = zeros(length(MRS_struct.p.vox), MRS_struct.p.Navg(ii), MRS_struct.p.npoints(ii)); + PRIAMWaterData = zeros(length(MRS_struct.p.vox), MRS_struct.p.Nwateravg(ii), MRS_struct.p.npoints(ii)); + for kk = 1:MRS_struct.p.Navg(ii) PRIAMData(:,kk,:) = MRS_struct.p.SENSE.U * squeeze(MRS_struct.fids.data(:,kk,:)); % Phase by multiplying with normalized complex conjugate of first point conj_norm = conj(PRIAMData(:,kk,1)) ./ abs(conj(PRIAMData(:,kk,1))); - PRIAMData(:,kk,:) = PRIAMData(:,kk,:) .* repmat(conj_norm, [1 1 MRS_struct.p.npoints]); + PRIAMData(:,kk,:) = PRIAMData(:,kk,:) .* repmat(conj_norm, [1 1 MRS_struct.p.npoints(ii)]); end - for kk = 1:MRS_struct.p.Nwateravg + for kk = 1:MRS_struct.p.Nwateravg(ii) PRIAMWaterData(:,kk,:) = MRS_struct.p.SENSE.U * squeeze(MRS_struct.fids.data_water(:,kk,:)); % Phase by multiplying with normalized complex conjugate of first point conj_norm = conj(PRIAMWaterData(:,kk,1)) ./ abs(conj(PRIAMWaterData(:,kk,1))); - PRIAMWaterData(:,kk,:) = PRIAMWaterData(:,kk,:) .* repmat(conj_norm, [1 1 MRS_struct.p.npoints]); + PRIAMWaterData(:,kk,:) = PRIAMWaterData(:,kk,:) .* repmat(conj_norm, [1 1 MRS_struct.p.npoints(ii)]); end end diff --git a/PhilipsDataRead_7T.m b/PhilipsDataRead_7T.m index e3f9363..a6a5e82 100644 --- a/PhilipsDataRead_7T.m +++ b/PhilipsDataRead_7T.m @@ -12,6 +12,9 @@ % the waterdata is before loading in the GABAdata. %% Read in water data -- MGSaleh 2017 + +ii = MRS_struct.ii; + if nargin > 2 % work out data header name sparname = [fname_water(1:(end-4)) 'list']; @@ -19,12 +22,12 @@ %ADH - decide if there is water data as ref data included in the data and %if so, set a flag to pull it out properly... sparidx=find(ismember(sparheader, 'F-resolution')==1); -MRS_struct.p.npoints_water = str2double(sparheader{sparidx+2}); +MRS_struct.p.npoints_water(ii) = str2double(sparheader{sparidx+2}); sparidx=find(ismember(sparheader, 'number_of_extra_attribute_1_values')==1); -MRS_struct.p.nrows_water = str2double(sparheader{sparidx+2}); +MRS_struct.p.nrows_water(ii) = str2double(sparheader{sparidx+2}); sparidx=find(ismember(sparheader, 'number_of_signal_averages')==1); -MRS_struct.p.NSA_water(MRS_struct.ii) = str2double(sparheader{sparidx+2}); -MRS_struct.p.Navg_water(MRS_struct.ii) = MRS_struct.p.NSA_water(MRS_struct.ii)*MRS_struct.p.nrows_water; +MRS_struct.p.NSA_water(ii) = str2double(sparheader{sparidx+2}); +MRS_struct.p.Navg_water(ii) = MRS_struct.p.NSA_water(ii)*MRS_struct.p.nrows_water; %Need to determine the offset of the data - i.e. how many channels are %there... sparidx=find(ismember(sparheader, 'NOI')==1); @@ -32,10 +35,10 @@ sparidx=find(ismember(sparheader, 'STD')==1); MRS_struct.p.ptr_offset_water=str2double(sparheader{sparidx(3)+20}); -MRS_struct.p.Navg_water(MRS_struct.ii) = MRS_struct.p.Navg_water(MRS_struct.ii)*MRS_struct.p.coil_channels; % MGSaleh +MRS_struct.p.Navg_water(ii) = MRS_struct.p.Navg_water(ii)*MRS_struct.p.coil_channels; % MGSaleh %Need to skip rows associated with the ' % [ %real/imag FID points random total_FIDS/dynamic scans dynamic scans] -MRS_struct.fids.data_water = readraw_Gannet(fname_water, 'float', [2 MRS_struct.p.npoints_water 1 MRS_struct.p.Navg_water(MRS_struct.ii)/MRS_struct.p.nrows_water MRS_struct.p.nrows_water], 'l',MRS_struct.p.ptr_offset_water); +MRS_struct.fids.data_water = readraw_Gannet(fname_water, 'float', [2 MRS_struct.p.npoints_water 1 MRS_struct.p.Navg_water(ii)/MRS_struct.p.nrows_water MRS_struct.p.nrows_water], 'l',MRS_struct.p.ptr_offset_water); % Make data complex. MRS_struct.fids.data_water = squeeze(complex(MRS_struct.fids.data_water(1,:,:,:,:), MRS_struct.fids.data_water(2,:,:,:,:))); FullData_water = MRS_struct.fids.data_water; @@ -71,15 +74,15 @@ sparidx=find(ismember(sparheader, 'number_of_extra_attribute_1_values')==1); %Dynamic scans MRS_struct.p.nrows = str2double(sparheader{sparidx+2}); sparidx=find(ismember(sparheader, 'number_of_signal_averages')==1); -MRS_struct.p.Navg(MRS_struct.ii) = str2double(sparheader{sparidx+2}); +MRS_struct.p.Navg(ii) = str2double(sparheader{sparidx+2}); %Need to determine the offset of the data - i.e. how many channels are there... sparidx=find(ismember(sparheader, 'NOI')==1); MRS_struct.p.coil_channels=size(sparidx,1)-2; sparidx=find(ismember(sparheader, 'STD')==1); MRS_struct.p.ptr_offset=str2double(sparheader{sparidx(3)+20}); -MRS_struct.p.Navg_all_chann(MRS_struct.ii) = MRS_struct.p.Navg(MRS_struct.ii)*MRS_struct.p.nrows*MRS_struct.p.coil_channels; % MGSaleh +MRS_struct.p.Navg_all_chann(ii) = MRS_struct.p.Navg(ii)*MRS_struct.p.nrows*MRS_struct.p.coil_channels; % MGSaleh %Need to skip rows associated with the [real/imag FID points random total_FIDS/dynamic_scans dynamic scans ] -MRS_struct.fids.data = readraw_Gannet(fname, 'float', [ 2 MRS_struct.p.npoints 1 MRS_struct.p.Navg_all_chann(MRS_struct.ii)/MRS_struct.p.nrows MRS_struct.p.nrows], 'l',MRS_struct.p.ptr_offset); +MRS_struct.fids.data = readraw_Gannet(fname, 'float', [ 2 MRS_struct.p.npoints 1 MRS_struct.p.Navg_all_chann(ii)/MRS_struct.p.nrows MRS_struct.p.nrows], 'l',MRS_struct.p.ptr_offset); % Make data complex. MRS_struct.fids.data = squeeze(complex(MRS_struct.fids.data(1,:,:,:,:), MRS_struct.fids.data(2,:,:,:,:))); % [ FID points coil NSA dynamic scans ] @@ -109,7 +112,7 @@ end disp('water suppressed data ... done') %I moved it to the end of the function -- MGSaleh 05252018 -MRS_struct.p.Navg(MRS_struct.ii) = MRS_struct.p.Navg(MRS_struct.ii)*MRS_struct.p.nrows; +MRS_struct.p.Navg(ii) = MRS_struct.p.Navg(ii)*MRS_struct.p.nrows; end diff --git a/PhilipsRawRead.m b/PhilipsRawRead.m index 0e64fd6..5a2714f 100644 --- a/PhilipsRawRead.m +++ b/PhilipsRawRead.m @@ -24,6 +24,8 @@ % function MRS_struct = PhilipsRawRead(MRS_struct, rawfile, recon_voxel, editing) +ii = MRS_struct.ii; + % Clear previous instances signalunf = []; @@ -845,7 +847,7 @@ %% store images if save_images - if ~(exist([rawpath filesep 'images'])==7) + if ~exist([rawpath filesep 'images'],'dir') mkdir([rawpath filesep 'images']); end @@ -896,21 +898,21 @@ clear a; % Save all relevant data/information to MRS_struct % GO 11/01/2016 -MRS_struct.p.NVoxels=size(signalunf,1); -MRS_struct.p.npoints = npoints; % GO 11/01/2016 -MRS_struct.p.nrows = size(signalunf,4); % GO 11/01/2016 -MRS_struct.p.ncoils = ncoils; % GO 11/01/2016 -MRS_struct.p.Navg = size(signalunf,4); % GO 11/01/2016 -MRS_struct.p.Nwateravg = nwaterfiles; % GO 11/01/2016 -MRS_struct.p.voxsize = [mrs_voxelsize(1) mrs_voxelsize(2) mrs_voxelsize(3)]; %AP, RL, FH - preliminary, TEST! % GO 11/01/2016 -MRS_struct.p.voxoff = [mrs_offset(1) mrs_offset(2) mrs_offset(3)]; %AP, RL, FH - preliminary, TEST! % GO 11/01/2016 -MRS_struct.p.voxang = vox_ang; % voxel angulation (1 dimension only so far) % GO 11/01/2016 -MRS_struct.p.TR = get_sin_TR([rawpath filesep MRSfile(1:end-4) '.sin']);% GO 11/01/2016 -MRS_struct.p.TE = get_sin_TE([rawpath filesep MRSfile(1:end-4) '.sin']);% GO 11/01/2016 -MRS_struct.p.LarmorFreq = 127; % Need to get that from somewhere! GO 11/01/2016 -MRS_struct.p.sw = 2e3; % Need to parse that from somewhere! GO 11/01/2016 +MRS_struct.p.NVoxels = size(signalunf,1); +MRS_struct.p.npoints(ii) = npoints; % GO 11/01/2016 +MRS_struct.p.nrows(ii) = size(signalunf,4); % GO 11/01/2016 +MRS_struct.p.ncoils = ncoils; % GO 11/01/2016 +MRS_struct.p.Navg(ii) = size(signalunf,4); % GO 11/01/2016 +MRS_struct.p.Nwateravg(ii) = nwaterfiles; % GO 11/01/2016 +MRS_struct.p.voxdim(ii,:) = [mrs_voxelsize(1) mrs_voxelsize(2) mrs_voxelsize(3)]; %AP, RL, FH - preliminary, TEST! % GO 11/01/2016 +MRS_struct.p.voxoff(ii,:) = [mrs_offset(1) mrs_offset(2) mrs_offset(3)]; %AP, RL, FH - preliminary, TEST! % GO 11/01/2016 +MRS_struct.p.voxang(ii,:) = vox_ang; % voxel angulation (1 dimension only so far) % GO 11/01/2016 +MRS_struct.p.TR(ii) = get_sin_TR([rawpath filesep MRSfile(1:end-4) '.sin']);% GO 11/01/2016 +MRS_struct.p.TE(ii) = get_sin_TE([rawpath filesep MRSfile(1:end-4) '.sin']);% GO 11/01/2016 +MRS_struct.p.LarmorFreq(ii) = 127; % Need to get that from somewhere! GO 11/01/2016 +MRS_struct.p.sw(ii) = 2e3; % Need to parse that from somewhere! GO 11/01/2016 MRS_struct.multivoxel.sensitivities = sensitivities; % GO 11/01/2016 -MRS_struct.multivoxel.voxsep = vox_sep; % voxel separation (1 dimension only so far) % GO 11/01/2016 +MRS_struct.multivoxel.voxsep = vox_sep; % voxel separation (1 dimension only so far) % GO 11/01/2016 % save all unfolded signals to MRS_struct MRS_struct.multivoxel.allsignals = signalunf; % GO 11/01/2016 diff --git a/SiemensDICOMRead.m b/SiemensDICOMRead.m index 117642d..0a53b80 100644 --- a/SiemensDICOMRead.m +++ b/SiemensDICOMRead.m @@ -90,7 +90,7 @@ %%% DATA LOADING %%% % Preallocate array in which the FIDs are to be extracted. -MRS_struct.fids.data = zeros(MRS_struct.p.npoints(ii),length(ima_file_names)); +MRS_struct.fids.data = zeros(MRS_struct.p.npoints(ii), length(ima_file_names)); % Collect all FIDs and sort them into MRS_struct for kk = 1:length(ima_file_names) diff --git a/SiemensRead.m b/SiemensRead.m index c9a9c88..d32ee5e 100644 --- a/SiemensRead.m +++ b/SiemensRead.m @@ -1,5 +1,7 @@ function MRS_struct = SiemensRead(MRS_struct, off_filename, on_filename, water_filename) +ii = MRS_struct.ii; + % First load in the OFF data rda_filename = off_filename; fid = fopen(rda_filename); @@ -83,30 +85,30 @@ %%RE 110726 Take the used bits of the header info if isfield(rda,'VOIRotationInPlane') - MRS_struct.p.VoI_InPlaneRot(MRS_struct.ii) = rda.VOIRotationInPlane; + MRS_struct.p.VoI_InPlaneRot(ii) = rda.VOIRotationInPlane; else - MRS_struct.p.VoI_InPlaneRot(MRS_struct.ii) = 0; + MRS_struct.p.VoI_InPlaneRot(ii) = 0; end -MRS_struct.p.voxdim(MRS_struct.ii,1) = rda.FoVHeight; -MRS_struct.p.voxdim(MRS_struct.ii,2) = rda.FoVWidth; -MRS_struct.p.voxdim(MRS_struct.ii,3) = rda.SliceThickness; -MRS_struct.p.voxoff(MRS_struct.ii,1) = rda.PositionVector(1); -MRS_struct.p.voxoff(MRS_struct.ii,2) = rda.PositionVector(2); -MRS_struct.p.voxoff(MRS_struct.ii,3) = rda.PositionVector(3); +MRS_struct.p.voxdim(ii,1) = rda.FoVHeight; +MRS_struct.p.voxdim(ii,2) = rda.FoVWidth; +MRS_struct.p.voxdim(ii,3) = rda.SliceThickness; +MRS_struct.p.voxoff(ii,1) = rda.PositionVector(1); +MRS_struct.p.voxoff(ii,2) = rda.PositionVector(2); +MRS_struct.p.voxoff(ii,3) = rda.PositionVector(3); if isfield(rda,'MRFrequency') - MRS_struct.p.LarmorFreq(MRS_struct.ii) = rda.MRFrequency; + MRS_struct.p.LarmorFreq(ii) = rda.MRFrequency; end if isfield(rda,'VectorSize') - MRS_struct.p.npoints(MRS_struct.ii) = rda.VectorSize; + MRS_struct.p.npoints(ii) = rda.VectorSize; end if isfield(rda,'DwellTime') - MRS_struct.p.sw(MRS_struct.ii) = 1/rda.DwellTime*1E6; + MRS_struct.p.sw(ii) = 1/rda.DwellTime*1E6; end if isfield(rda,'TR') - MRS_struct.p.TR(MRS_struct.ii) = rda.TR; + MRS_struct.p.TR(ii) = rda.TR; end if isfield(rda,'TE') - MRS_struct.p.TE(MRS_struct.ii) = rda.TE; + MRS_struct.p.TE(ii) = rda.TE; end % @@ -214,9 +216,9 @@ end %%RE 110726 Take the used bits of the header info -MRS_struct.p.LarmorFreq(MRS_struct.ii) = rda.MRFrequency; -MRS_struct.p.npoints(MRS_struct.ii) = rda.VectorSize; -MRS_struct.p.Navg(MRS_struct.ii) = rda.NumberOfAverages; +MRS_struct.p.LarmorFreq(ii) = rda.MRFrequency; +MRS_struct.p.npoints(ii) = rda.VectorSize; +MRS_struct.p.Navg(ii) = rda.NumberOfAverages; % So now we should have got to the point after the header text % % Siemens documentation suggests that the data should be in a double complex format (8bytes for real, and 8 for imaginary?) @@ -322,8 +324,8 @@ end %%RE 110726 Take the used bits of the header info - MRS_struct.p.LarmorFreq(MRS_struct.ii) = rda.MRFrequency; - MRS_struct.p.npoints(MRS_struct.ii) = rda.VectorSize; + MRS_struct.p.LarmorFreq(ii) = rda.MRFrequency; + MRS_struct.p.npoints(ii) = rda.VectorSize; % % So now we should have got to the point after the header text %