91 lines
3.7 KiB
Matlab
91 lines
3.7 KiB
Matlab
function [full_od_imgs, full_bkg_imgs, raw_scan_parameter_values, raw_file_list] = processRawData(options)
|
|
%% Reads HDF5 files, computes OD images
|
|
%
|
|
% Inputs: options.folderPath, options.cam, options.angle, ImagingMode, PulseDuration, scan_parameter, etc.
|
|
%
|
|
% Returns the OD images and scan parameters immediately in memory.
|
|
% This function does NOT do cropping or fringe removal.
|
|
|
|
fprintf('\nProcessing raw data files at %s ...\n', options.folderPath);
|
|
|
|
% ===== Group paths in HDF5 files =====
|
|
groupList = ["/images/MOT_3D_Camera/in_situ_absorption", ...
|
|
"/images/ODT_1_Axis_Camera/in_situ_absorption", ...
|
|
"/images/ODT_2_Axis_Camera/in_situ_absorption", ...
|
|
"/images/Horizontal_Axis_Camera/in_situ_absorption", ...
|
|
"/images/Vertical_Axis_Camera/in_situ_absorption"];
|
|
|
|
% ===== Find files =====
|
|
files = dir(fullfile(options.folderPath, '*.h5'));
|
|
nFiles = length(files);
|
|
if nFiles == 0
|
|
error('\nNo HDF5 files found in %s', options.folderPath);
|
|
end
|
|
|
|
% Determine image size from first file
|
|
testFile = fullfile(files(1).folder, files(1).name);
|
|
atm_test = double(imrotate(h5read(testFile, append(groupList(options.cam), "/atoms")), options.angle));
|
|
[ny, nx] = size(atm_test);
|
|
|
|
% --- Preallocate in-memory arrays ---
|
|
full_od_imgs = nan(ny, nx, nFiles, 'single');
|
|
full_bkg_imgs = nan(ny, nx, nFiles, 'single');
|
|
raw_scan_parameter_values = zeros(1, nFiles);
|
|
|
|
% --- Progress bar ---
|
|
if isfield(options, 'showProgressBar') && options.showProgressBar
|
|
pb = Helper.ProgressBar();
|
|
pb.run('Computing OD images | Progress: ');
|
|
end
|
|
|
|
raw_file_list = strings(1, nFiles); % store full file paths
|
|
|
|
% ===== Loop over files =====
|
|
for k = 1:nFiles
|
|
fullFileName = fullfile(files(k).folder, files(k).name);
|
|
raw_file_list(k) = fullFileName; % track original file
|
|
|
|
if ~isfield(options, 'showProgressBar') || ~options.showProgressBar
|
|
fprintf('Now reading %s\n', fullFileName);
|
|
end
|
|
|
|
try
|
|
atm_img = double(imrotate(h5read(fullFileName, append(groupList(options.cam), "/atoms")), options.angle));
|
|
bkg_img = double(imrotate(h5read(fullFileName, append(groupList(options.cam), "/background")), options.angle));
|
|
dark_img = double(imrotate(h5read(fullFileName, append(groupList(options.cam), "/dark")), options.angle));
|
|
od_img = Helper.calculateODImage(atm_img, bkg_img, dark_img, options.ImagingMode, options.PulseDuration);
|
|
full_od_imgs(:, :, k) = single(od_img);
|
|
full_bkg_imgs(:, :, k) = single(bkg_img);
|
|
catch
|
|
warning('Missing data in %s, storing NaNs.', fullFileName);
|
|
full_od_imgs(:, :, k) = nan(ny, nx, 1, 'single');
|
|
full_bkg_imgs(:, :, k) = nan(ny, nx, 1, 'single');
|
|
continue;
|
|
end
|
|
|
|
% Extract scan parameter
|
|
info = h5info(fullFileName, '/globals');
|
|
for i = 1:length(info.Attributes)
|
|
if strcmp(info.Attributes(i).Name, options.scan_parameter)
|
|
if strcmp(options.scan_parameter, 'ps_rot_mag_fin_pol_angle')
|
|
raw_scan_parameter_values(k) = 180 - info.Attributes(i).Value;
|
|
else
|
|
raw_scan_parameter_values(k) = info.Attributes(i).Value;
|
|
end
|
|
end
|
|
end
|
|
|
|
% Update progress bar
|
|
if isfield(options, 'showProgressBar') && options.showProgressBar
|
|
progressPercent = round(k / nFiles * 100);
|
|
pb.run(progressPercent);
|
|
end
|
|
end
|
|
|
|
% Finish progress bar
|
|
if isfield(options, 'showProgressBar') && options.showProgressBar
|
|
pb.run(' Done!');
|
|
end
|
|
|
|
end
|