Latest scripts - added g2 correlation analysis

This commit is contained in:
Karthik 2025-05-30 21:02:24 +02:00
parent d341782462
commit b31c0168ad
5 changed files with 163 additions and 94 deletions

1
.gitignore vendored
View File

@ -12,5 +12,6 @@ Time-Series-Analyzer/Time-Series-Data
*.json
*.txt
*.asv
*.fig
.ipynb_checkpoints/
.vscode/

View File

@ -5,69 +5,46 @@ set(groot, 'defaultAxesTickLabelInterpreter','latex'); set(groot, 'defaultLegend
format long
font = 'Bahnschrift';
% Load data
Data = load('C:/Users/Karthik/Documents/GitRepositories/Calculations/Data-Analyzer/B2.3G/WithoutProcessing/DropletsToStripes.mat', 'unique_theta', 'mean_sf', 'stderr_sf');
Data = load('C:/Users/Karthik/Documents/GitRepositories/Calculations/Data-Analyzer/B2.45G/DropletsToStripes.mat', 'unique_scan_parameter_values', 'mean_sf', 'stderr_sf');
down_scan_parameter_values = Data.unique_theta;
dts_mean_sf = Data.mean_sf;
down_stderr_sf = Data.stderr_sf;
dts_scan_parameter_values = Data.unique_scan_parameter_values;
dts_mean_sf = Data.mean_sf;
dts_stderr_sf = Data.stderr_sf;
Data = load('C:/Users/Karthik/Documents/GitRepositories/Calculations/Data-Analyzer/B2.3G/WithoutProcessing/StripesToDroplets.mat', 'unique_theta', 'mean_sf', 'stderr_sf');
Data = load('C:/Users/Karthik/Documents/GitRepositories/Calculations/Data-Analyzer/B2.45G/StripesToDroplets.mat', 'unique_scan_parameter_values', 'mean_sf', 'stderr_sf');
std_theta_values = Data.unique_theta;
std_mean_sf = Data.mean_sf;
std_stderr_sf = Data.stderr_sf;
std_scan_parameter_values = Data.unique_scan_parameter_values;
std_mean_sf = Data.mean_sf;
std_stderr_sf = Data.stderr_sf;
% Normalize dts data
dts_min = min(dts_mean_sf);
dts_max = max(dts_mean_sf);
dts_range = dts_max - dts_min;
dts_mean_sf_norm = (dts_mean_sf - dts_min) / dts_range;
dts_stderr_sf_norm = dts_stderr_sf / dts_range;
% Normalize std data
std_min = min(std_mean_sf);
std_max = max(std_mean_sf);
std_range = std_max - std_min;
std_mean_sf_norm = (std_mean_sf - std_min) / std_range;
std_stderr_sf_norm = std_stderr_sf / std_range;
figure(1);
set(gcf,'Position',[100 100 950 750])
errorbar(down_scan_parameter_values, dts_mean_sf, down_stderr_sf, 'o--', ...
errorbar(dts_scan_parameter_values, dts_mean_sf_norm, dts_stderr_sf_norm, 'o--', ...
'LineWidth', 1.5, 'MarkerSize', 6, 'CapSize', 5, 'DisplayName' , 'Droplets to Stripes');
hold on
errorbar(std_theta_values, std_mean_sf, std_stderr_sf, 'o--', ...
errorbar(std_scan_parameter_values, std_mean_sf_norm, std_stderr_sf_norm, 'o--', ...
'LineWidth', 1.5, 'MarkerSize', 6, 'CapSize', 5, 'DisplayName', 'Stripes to Droplets');
set(gca, 'FontSize', 14); % For tick labels only
hXLabel = xlabel('\alpha (degrees)', 'Interpreter', 'tex');
hYLabel = ylabel('Spectral Weight', 'Interpreter', 'tex');
hTitle = title('B = 2.3 G', 'Interpreter', 'tex');
legend
set([hXLabel, hYLabel], 'FontName', font)
set([hXLabel, hYLabel], 'FontSize', 14)
set(hTitle, 'FontName', font, 'FontSize', 16, 'FontWeight', 'bold'); % Set font and size for title
grid on
%%
%% Track spectral weight across the transition
set(0,'defaulttextInterpreter','latex')
set(groot, 'defaultAxesTickLabelInterpreter','latex'); set(groot, 'defaultLegendInterpreter','latex');
format long
% Load data
Data = load('C:/Users/Karthik/Documents/GitRepositories/Calculations/Data-Analyzer/RampDownSL.mat', 'unique_scan_parameter_values', 'mean_sf', 'stderr_sf');
down_scan_parameter_values = Data.unique_scan_parameter_values;
down_mean_sf = Data.mean_sf;
down_stderr_sf = Data.stderr_sf;
Data = load('C:/Users/Karthik/Documents/GitRepositories/Calculations/Data-Analyzer/RampUpSL.mat', 'unique_scan_parameter_values', 'mean_sf', 'stderr_sf');
up_scan_parameter_values = Data.unique_scan_parameter_values;
up_mean_sf = Data.mean_sf;
up_stderr_sf = Data.stderr_sf;
figure(1);
set(gcf,'Position',[100 100 950 750])
errorbar(down_scan_parameter_values, down_mean_sf, down_stderr_sf, 'o--', ...
'LineWidth', 1.5, 'MarkerSize', 6, 'CapSize', 5, 'DisplayName' , 'BEC to Droplets');
hold on
errorbar(up_scan_parameter_values, up_mean_sf, up_stderr_sf, 'o--', ...
'LineWidth', 1.5, 'MarkerSize', 6, 'CapSize', 5, 'DisplayName', 'Droplets to BEC');
set(gca, 'FontSize', 14); % For tick labels only
hXLabel = xlabel('B_z (G)', 'Interpreter', 'tex');
hYLabel = ylabel('Spectral Weight', 'Interpreter', 'tex');
hTitle = title('\alpha = 0', 'Interpreter', 'tex');
hYLabel = ylabel('Normalized Spectral Weight', 'Interpreter', 'tex');
hTitle = title('B = 2.45 G', 'Interpreter', 'tex');
legend
set([hXLabel, hYLabel], 'FontName', font)
set([hXLabel, hYLabel], 'FontSize', 14)

View File

@ -4,27 +4,26 @@ groupList = ["/images/MOT_3D_Camera/in_situ_absorption", "/images/ODT_1_Axi
"/images/ODT_2_Axis_Camera/in_situ_absorption", "/images/Horizontal_Axis_Camera/in_situ_absorption", ...
"/images/Vertical_Axis_Camera/in_situ_absorption"];
folderPath = "C:/Users/Karthik/Documents/GitRepositories/Calculations/Data-Analyzer/15042025/";
folderPath = "D:/Data - Experiment/2025/05/22/";
run = '0035';
run = '0078';
folderPath = strcat(folderPath, run);
cam = 5;
angle = 0;
center = [1300, 2108];
center = [1375, 2020];
span = [200, 200];
fraction = [0.1, 0.1];
pixel_size = 5.86e-6;
removeFringes = false;
% scan_parameter = 'rot_mag_fin_pol_angle';
scan_parameter = 'rot_mag_fin_pol_angle';
% scan_parameter = 'rot_mag_field';
scan_parameter = 'rot_mag_field_up';
% scan_parameter_text = 'Angle = ';
scan_parameter_text = 'BField = ';
scan_parameter_text = 'Angle = ';
% scan_parameter_text = 'BField = ';
font = 'Bahnschrift';
@ -47,9 +46,9 @@ for k = 1 : length(files)
fprintf(1, 'Now reading %s\n', fullFileName);
atm_img = im2double(imrotate(h5read(fullFileName, append(groupList(cam), "/atoms")), angle));
bkg_img = im2double(imrotate(h5read(fullFileName, append(groupList(cam), "/background")), angle));
dark_img = im2double(imrotate(h5read(fullFileName, append(groupList(cam), "/dark")), angle));
atm_img = double(imrotate(h5read(fullFileName, append(groupList(cam), "/atoms")), angle));
bkg_img = double(imrotate(h5read(fullFileName, append(groupList(cam), "/background")), angle));
dark_img = double(imrotate(h5read(fullFileName, append(groupList(cam), "/dark")), angle));
refimages(:,:,k) = subtractBackgroundOffset(cropODImage(bkg_img, center, span), fraction)';
absimages(:,:,k) = subtractBackgroundOffset(cropODImage(calculateODImage(atm_img, bkg_img, dark_img), center, span), fraction)';
@ -96,8 +95,13 @@ end
%% Run Fourier analysis over images
fft_imgs = cell(1, nimgs);
spectral_weight = zeros(1, nimgs);
fft_imgs = cell(1, nimgs);
spectral_weight = zeros(1, nimgs);
N_bins = 180;
Threshold = 75;
Sigma = 2;
N_shots = length(od_imgs);
% Create VideoWriter object for movie
videoFile = VideoWriter('Single_Shot_FFT.mp4', 'MPEG-4');
@ -106,8 +110,8 @@ videoFile.FrameRate = 2; % Set the frame rate (frames per second)
open(videoFile); % Open the video file to write
% Display the cropped image
for k = 1 : length(od_imgs)
IMG = od_imgs{k};
for k = 1:N_shots
IMG = od_imgs{k};
[IMGFFT, IMGPR] = computeFourierTransform(IMG, skipPreprocessing, skipMasking, skipIntensityThresholding, skipBinarization);
figure(1);
@ -193,7 +197,7 @@ for k = 1 : length(od_imgs)
% Plot the angular distribution
nexttile
[theta_vals, S_theta] = computeNormalizedAngularSpectralDistribution(fft_imgs{k}, 10, 20, 180, 75, 2);
[theta_vals, S_theta] = computeNormalizedAngularSpectralDistribution(fft_imgs{k}, 10, 20, N_bins, Threshold, Sigma);
spectral_weight(k) = trapz(theta_vals, S_theta);
plot(theta_vals/pi, S_theta,'Linewidth',2);
set(gca, 'FontSize', 14); % For tick labels only
@ -237,8 +241,8 @@ set(gcf,'Position',[100 100 950 750])
errorbar(unique_scan_parameter_values, mean_sf, stderr_sf, 'o--', ...
'LineWidth', 1.5, 'MarkerSize', 6, 'CapSize', 5);
set(gca, 'FontSize', 14); % For tick labels only
% hXLabel = xlabel('\alpha (degrees)', 'Interpreter', 'tex');
hXLabel = xlabel('B_z (G)', 'Interpreter', 'tex');
hXLabel = xlabel('\alpha (degrees)', 'Interpreter', 'tex');
% hXLabel = xlabel('B_z (G)', 'Interpreter', 'tex');
hYLabel = ylabel('Spectral Weight', 'Interpreter', 'tex');
hTitle = title('Change across transition', 'Interpreter', 'tex');
set([hXLabel, hYLabel], 'FontName', font)
@ -305,6 +309,112 @@ set(hTitle, 'FontName', font, 'FontSize', 16, 'FontWeight', 'bold'); % Set font
grid on;
hold off;
%% Extract g2
fft_imgs = cell(1, nimgs);
spectral_distribution = cell(1, nimgs);
theta_values = cell(1, nimgs);
N_bins = 32;
Threshold = 75;
Sigma = 2;
N_shots = length(od_imgs);
% Display the cropped image
for k = 1:N_shots
IMG = od_imgs{k};
[IMGFFT, IMGPR] = computeFourierTransform(IMG, skipPreprocessing, skipMasking, skipIntensityThresholding, skipBinarization);
% Calculate the x and y limits for the cropped image
y_min = center(1) - span(2) / 2;
y_max = center(1) + span(2) / 2;
x_min = center(2) - span(1) / 2;
x_max = center(2) + span(1) / 2;
% Generate x and y arrays representing the original coordinates for each pixel
x_range = linspace(x_min, x_max, span(1));
y_range = linspace(y_min, y_max, span(2));
[rows, cols] = size(IMGFFT);
zoom_size = 50; % Zoomed-in region around center
mid_x = floor(cols/2);
mid_y = floor(rows/2);
fft_imgs{k} = IMGFFT(mid_y-zoom_size:mid_y+zoom_size, mid_x-zoom_size:mid_x+zoom_size);
[theta_vals, S_theta] = computeNormalizedAngularSpectralDistribution(fft_imgs{k}, 10, 20, N_bins, Threshold, Sigma);
spectral_distribution{k} = S_theta;
theta_values{k} = theta_vals;
end
% Create matrix of shape (N_shots x N_bins)
delta_nkr_all = zeros(N_shots, N_bins);
for k = 1:N_shots
delta_nkr_all(k, :) = spectral_distribution{k};
end
% Grouping by scan parameter value (e.g., alpha)
[unique_scan_parameter_values, ~, idx] = unique(scan_parameter_values);
% Number of unique alpha values
N_alpha = length(unique_scan_parameter_values);
% Preallocate result arrays
g2_all = zeros(N_alpha, N_bins);
g2_error_all = zeros(N_alpha, N_bins);
for i = 1:N_alpha
group_idx = find(idx == i); % Indices of 20 shots for this alpha
group_data = delta_nkr_all(group_idx, :); % (20 x N_bins) array
for dtheta = 0:N_bins-1
temp = zeros(length(group_idx), 1);
for j = 1:length(group_idx)
profile = group_data(j, :);
profile_shifted = circshift(profile, -dtheta, 2);
num = mean(profile .* profile_shifted);
denom = mean(profile)^2;
temp(j) = num / denom - 1;
end
g2_all(i, dtheta+1) = mean(temp);
g2_error_all(i, dtheta+1) = std(temp) / sqrt(length(group_idx)); % Standard error
end
end
% Reconstruct theta axis from any one of the stored values
theta_vals = theta_values{1}; % assuming it's in radians
% Number of unique alpha values
nAlpha = size(g2_all, 1);
% Generate a colormap with enough unique colors
cmap = sky(nAlpha); % You can also try 'jet', 'turbo', 'hot', etc.
figure(4);
clf;
set(gcf,'Position',[100 100 950 750])
hold on;
legend_entries = cell(nAlpha, 1);
for i = 1:nAlpha
errorbar(theta_vals/pi, g2_all(i, :), g2_error_all(i, :), ...
'o-', 'Color', cmap(i,:), 'LineWidth', 1.2, ...
'MarkerSize', 5, 'CapSize', 3);
legend_entries{i} = sprintf('$\\alpha = %g^\\circ$', unique_scan_parameter_values(i));
end
ylim([-1.5 3.0]); % Set y-axis limits here
set(gca, 'FontSize', 14);
hXLabel = xlabel('$\delta\theta / \pi$', 'Interpreter', 'latex');
hYLabel = ylabel('$g^{(2)}(\delta\theta)$', 'Interpreter', 'latex');
hTitle = title('B = 2.45 G - Droplets to Stripes', 'Interpreter', 'tex');
legend(legend_entries, 'Interpreter', 'latex', 'Location', 'bestoutside');
set([hXLabel, hYLabel], 'FontName', font)
set([hXLabel, hYLabel], 'FontSize', 14)
set(hTitle, 'FontName', font, 'FontSize', 16, 'FontWeight', 'bold'); % Set font and size for title
grid on;
%% Helper Functions
function [IMGFFT, IMGPR] = computeFourierTransform(I, skipPreprocessing, skipMasking, skipIntensityThresholding, skipBinarization)
% computeFourierSpectrum - Computes the 2D Fourier power spectrum
@ -398,7 +508,7 @@ function [theta_vals, S_theta] = computeNormalizedAngularSpectralDistribution(IM
theta_vals = linspace(0, pi, num_bins);
% Loop through each angle bin
for i = 1:180
for i = 1:num_bins
angle_start = (i-1) * pi / num_bins;
angle_end = i * pi / num_bins;

View File

@ -1,8 +1,8 @@
%% Parameters
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"];
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"];
folderPath = "D:/Data - Experiment/2025/05/22/";
@ -14,31 +14,12 @@ cam = 5;
angle = 0;
center = [1375, 2020];
span = [150, 150];
span = [200, 200];
fraction = [0.1, 0.1];
pixel_size = 5.86e-6;
removeFringes = false;
%{
folderPath = "C:/Users/Karthik/Documents/GitRepositories/Calculations/Imaging-Response-Function-Extractor/";
run = '0096';
folderPath = strcat(folderPath, run);
cam = 5;
angle = 0;
center = [1137, 2023];
span = [500, 500];
fraction = [0.1, 0.1];
pixel_size = 5.86e-6;
removeFringes = false;
%}
%% Compute OD image, rotate and extract ROI for analysis
% Get a list of all files in the folder with the desired file name pattern.
@ -104,7 +85,7 @@ for k = 1 : length(od_imgs)
hL = ylabel(hcb, 'Optical Density', 'FontSize', 16);
set(hL,'Rotation',-90);
colormap jet;
set(gca,'CLim',[0 0.4]);
% set(gca,'CLim',[0 0.4]);
set(gca,'YDir','normal')
set(gca, 'YTick', linspace(y_min, y_max, 5)); % Define y ticks
set(gca, 'YTickLabel', flip(linspace(y_min, y_max, 5))); % Flip only the labels

View File

@ -700,7 +700,7 @@ for j = 1:length(SCATTERING_LENGTH_RANGE)
aS_string = sprintf('%.6e', aS);
% Construct base directory for this aS
baseDir = ['D:/Results - Numerics/Data_Full3D/PhaseDiagram/ImagTimePropagation/Theta0/HighN/aS_' ...
baseDir = ['D:/Results - Numerics/Data_Full3D/PhaseDiagram/ImagTimePropagation/Theta0/aS_' ...
aS_string '_theta_000_phi_000_N_'];
% Preallocate results for this curve