Calculations/Data-Analyzer/extractQuantities.m

119 lines
3.2 KiB
Matlab

%% Parameters
% === Define folders and settings ===
% === Define folders and settings ===
baseFolder = '//DyLabNAS/Data/TwoDGas/2025/04/';
dates = ["01", "02"]; % Example: three folders
runs = {
["0059", "0060", "0061"],
["0007", "0008", "0009", "0010", "0011"]
};
options.scan_parameter = 'rot_mag_fin_pol_angle';
options.scan_groups = 0:10:50;
options.cam = 5;
% Image cropping and alignment
options.angle = 0;
options.center = [1285, 2100];
options.span = [200, 200];
options.fraction = [0.1, 0.1];
% Imaging and calibration parameters
options.pixel_size = 5.86e-6; % in meters
options.magnification = 23.94;
options.removeFringes = false;
options.ImagingMode = 'HighIntensity';
options.PulseDuration = 5e-6;
% Fourier analysis: Radial
options.theta_min = deg2rad(0);
options.theta_max = deg2rad(180);
options.N_radial_bins = 500;
options.Radial_Sigma = 2;
options.Radial_WindowSize = 5; % Must be odd
% Fourier analysis: Angular
options.r_min = 10;
options.r_max = 20;
options.k_min = 1.2; % in μm⁻¹
options.k_max = 2.2; % in μm⁻¹
options.N_angular_bins = 180;
options.Angular_Threshold = 75;
options.Angular_Sigma = 2;
options.Angular_WindowSize = 5;
% Optional visualization / zooming
options.zoom_size = 50;
% Optional flags or settings struct
options.skipUnshuffling = false;
options.skipPreprocessing = true;
options.skipMasking = true;
options.skipIntensityThresholding = true;
options.skipBinarization = true;
% === Loop through folders and collect results ===
results_all = [];
assert(length(dates) == length(runs), ...
'Each entry in `dates` must correspond to a cell in `runs`.');
for i = 1:length(dates)
currentDate = dates(i);
currentRuns = runs{i};
for j = 1:length(currentRuns)
runID = currentRuns(j);
folderPath = fullfile(baseFolder, currentDate, runID);
if ~endsWith(folderPath, filesep)
options.folderPath = [char(folderPath) filesep];
else
options.folderPath = char(folderPath);
end
try
% Unpack options struct into name-value pairs
args = [fieldnames(options), struct2cell(options)]';
args = args(:)';
results = analyzeFolder(args{:});
results_all = [results_all; results];
catch ME
warning("Error processing %s/%s: %s", currentDate, runID, ME.message);
end
end
end
%% Plotting heatmap of mean_max_g2_values
N_x = length(options.scan_groups);
N_y = length(results_all) / N_x;
% Preallocate
g2_matrix = zeros(N_y, N_x);
angle_matrix = zeros(N_y, N_x);
for i = 1:length(results_all)
row = ceil(i / N_x); % outer parameter (e.g., date)
col = mod(i-1, N_x) + 1; % inner scan parameter
g2_matrix(row, col) = results_all(i).mean_max_g2_values(col);
angle_matrix(row, col) = results_all(i).mean_max_g2_angle(col);
end
% Plot heatmap
figure;
imagesc(options.scan_groups, 1:N_y, g2_matrix);
xlabel('Scan Parameter (e.g. Angle)');
ylabel('Scan Set Index');
title('Mean g_2 Value Heatmap');
colorbar;