Added scripts to analyse simulation data, now possible to extract spectral contrast, weight and autocorrelation.
This commit is contained in:
parent
63904f2a95
commit
047a1b2d85
554
Data-Analyzer/analyzePhaseTransitionSimulation.m
Normal file
554
Data-Analyzer/analyzePhaseTransitionSimulation.m
Normal file
@ -0,0 +1,554 @@
|
||||
%% Extract Images
|
||||
|
||||
baseDir = 'D:/Results - Numerics/Data_Full3D/PhaseTransition/DTS/';
|
||||
JobNumber = 0;
|
||||
runFolder = sprintf('Run_%03d', JobNumber);
|
||||
movieFileName = 'DropletsToStripes.mp4'; % Output file name
|
||||
datafileName = './DropletsToStripes.mat';
|
||||
reverseOrder = false; % Set this to true to reverse the theta ordering
|
||||
|
||||
TitleString = 'Change across transition: Droplets To Stripes';
|
||||
|
||||
%%
|
||||
baseDir = 'D:/Results - Numerics/Data_Full3D/PhaseTransition/STD/';
|
||||
JobNumber = 0;
|
||||
runFolder = sprintf('Run_%03d', JobNumber);
|
||||
movieFileName = 'StripesToDroplets.mp4'; % Output file name
|
||||
datafileName = './StripesToDroplets.mat';
|
||||
reverseOrder = true; % Set this to true to reverse the theta ordering
|
||||
|
||||
|
||||
TitleString = 'Change across transition: Stripes To Droplets';
|
||||
|
||||
%%
|
||||
folderList = dir(baseDir);
|
||||
isValid = [folderList.isdir] & ~ismember({folderList.name}, {'.', '..'});
|
||||
folderNames = {folderList(isValid).name};
|
||||
nimgs = numel(folderNames);
|
||||
|
||||
% Extract theta values from folder names
|
||||
PolarAngleVals = zeros(1, nimgs);
|
||||
for k = 1:nimgs
|
||||
tokens = regexp(folderNames{k}, 'theta_(\d{3})', 'tokens');
|
||||
if isempty(tokens)
|
||||
warning('No theta found in folder name: %s', folderNames{k});
|
||||
PolarAngleVals(k) = NaN;
|
||||
else
|
||||
PolarAngleVals(k) = str2double(tokens{1}{1});
|
||||
end
|
||||
end
|
||||
|
||||
% Choose sort direction
|
||||
sortDirection = 'ascend';
|
||||
if reverseOrder
|
||||
sortDirection = 'descend';
|
||||
end
|
||||
|
||||
% Sort folderNames based on polar angle
|
||||
[~, sortIdx] = sort(PolarAngleVals, sortDirection);
|
||||
folderNames = folderNames(sortIdx);
|
||||
PolarAngleVals = PolarAngleVals(sortIdx); % Optional: if you still want sorted list
|
||||
|
||||
imgs = cell(1, nimgs);
|
||||
alphas = zeros(1, nimgs);
|
||||
|
||||
for k = 1:nimgs
|
||||
folderName = folderNames{k};
|
||||
SaveDirectory = fullfile(baseDir, folderName, runFolder);
|
||||
|
||||
% Extract alpha (theta) again from folder name
|
||||
tokens = regexp(folderName, 'theta_(\d{3})', 'tokens');
|
||||
alpha_val = str2double(tokens{1}{1});
|
||||
alphas(k) = alpha_val;
|
||||
|
||||
matPath = fullfile(SaveDirectory, 'psi_gs.mat');
|
||||
if ~isfile(matPath)
|
||||
warning('Missing psi_gs.mat in %s', SaveDirectory);
|
||||
continue;
|
||||
end
|
||||
|
||||
try
|
||||
Data = load(matPath, 'psi', 'Params', 'Transf', 'Observ');
|
||||
catch ME
|
||||
warning('Failed to load %s: %s', matPath, ME.message);
|
||||
continue;
|
||||
end
|
||||
|
||||
Params = Data.Params;
|
||||
Transf = Data.Transf;
|
||||
Observ = Data.Observ;
|
||||
|
||||
psi = Data.psi;
|
||||
if isgpuarray(psi)
|
||||
psi = gather(psi);
|
||||
end
|
||||
if isgpuarray(Observ.residual)
|
||||
Observ.residual = gather(Observ.residual);
|
||||
end
|
||||
|
||||
% Axes and projection
|
||||
x = Transf.x * Params.l0 * 1e6;
|
||||
y = Transf.y * Params.l0 * 1e6;
|
||||
z = Transf.z * Params.l0 * 1e6;
|
||||
dx = x(2)-x(1); dy = y(2)-y(1); dz = z(2)-z(1);
|
||||
|
||||
% Calculate frequency increment (frequency axes)
|
||||
Nx = length(x); % grid size along X
|
||||
Ny = length(y); % grid size along Y
|
||||
dx = mean(diff(x)); % real space increment in the X direction (in micrometers)
|
||||
dy = mean(diff(y)); % real space increment in the Y direction (in micrometers)
|
||||
dvx = 1 / (Nx * dx); % reciprocal space increment in the X direction (in micrometers^-1)
|
||||
dvy = 1 / (Ny * dy); % reciprocal space increment in the Y direction (in micrometers^-1)
|
||||
|
||||
% Create the frequency axes
|
||||
vx = (-Nx/2:Nx/2-1) * dvx; % Frequency axis in X (micrometers^-1)
|
||||
vy = (-Ny/2:Ny/2-1) * dvy; % Frequency axis in Y (micrometers^-1)
|
||||
|
||||
% Calculate maximum frequencies
|
||||
% kx_max = pi / dx;
|
||||
% ky_max = pi / dy;
|
||||
|
||||
% Generate reciprocal axes
|
||||
% kx = linspace(-kx_max, kx_max * (Nx-2)/Nx, Nx);
|
||||
% ky = linspace(-ky_max, ky_max * (Ny-2)/Ny, Ny);
|
||||
|
||||
% Create the Wavenumber axes
|
||||
kx = 2*pi*vx; % Wavenumber axis in X
|
||||
ky = 2*pi*vy; % Wavenumber axis in Y
|
||||
|
||||
n = abs(psi).^2;
|
||||
nxy = squeeze(trapz(n * dz, 3));
|
||||
|
||||
imgs{k} = nxy;
|
||||
end
|
||||
|
||||
%% Analyze Images
|
||||
|
||||
|
||||
makeMovie = true; % Set to false to disable movie creation
|
||||
font = 'Bahnschrift';
|
||||
|
||||
skipPreprocessing = true;
|
||||
skipMasking = true;
|
||||
skipIntensityThresholding = true;
|
||||
skipBinarization = true;
|
||||
|
||||
% Run Fourier analysis over images
|
||||
|
||||
fft_imgs = cell(1, nimgs);
|
||||
spectral_contrast = zeros(1, nimgs);
|
||||
spectral_weight = zeros(1, nimgs);
|
||||
g2_all = cell(1, nimgs);
|
||||
theta_values_all = cell(1, nimgs);
|
||||
|
||||
N_bins = 180;
|
||||
Threshold = 25;
|
||||
Sigma = 2;
|
||||
|
||||
if makeMovie
|
||||
% Create VideoWriter object for movie
|
||||
videoFile = VideoWriter(movieFileName, 'MPEG-4');
|
||||
videoFile.Quality = 100; % Set quality to maximum (0–100)
|
||||
videoFile.FrameRate = 2; % Set the frame rate (frames per second)
|
||||
open(videoFile); % Open the video file to write
|
||||
end
|
||||
|
||||
% Display the cropped image
|
||||
for k = 1:nimgs
|
||||
IMG = imgs{k};
|
||||
[IMGFFT, IMGPR] = computeFourierTransform(IMG, skipPreprocessing, skipMasking, skipIntensityThresholding, skipBinarization);
|
||||
[theta_vals, S_theta] = computeNormalizedAngularSpectralDistribution(IMGFFT, 10, 35, N_bins, Threshold, Sigma);
|
||||
|
||||
g2 = zeros(1, N_bins); % Preallocate
|
||||
|
||||
for dtheta = 0:N_bins-1
|
||||
profile = S_theta;
|
||||
profile_shifted = circshift(profile, -dtheta, 2);
|
||||
|
||||
num = mean(profile .* profile_shifted);
|
||||
denom = mean(profile)^2;
|
||||
|
||||
g2(dtheta+1) = num / denom - 1;
|
||||
end
|
||||
|
||||
g2_all{k} = g2;
|
||||
theta_values_all{k} = theta_vals;
|
||||
|
||||
figure(1);
|
||||
clf
|
||||
set(gcf,'Position',[500 100 1000 800])
|
||||
t = tiledlayout(2, 2, 'TileSpacing', 'compact', 'Padding', 'compact'); % 1x4 grid
|
||||
|
||||
y_min = min(y);
|
||||
y_max = max(y);
|
||||
x_min = min(x);
|
||||
x_max = max(x);
|
||||
|
||||
% Display the cropped OD image
|
||||
ax1 = nexttile;
|
||||
imagesc(x, y, IMG')
|
||||
% Define normalized positions (relative to axis limits)
|
||||
x_offset = 0.025; % 5% offset from the edges
|
||||
y_offset = 0.025; % 5% offset from the edges
|
||||
% Top-right corner (normalized axis coordinates)
|
||||
hText = text(1 - x_offset, 1 - y_offset, ['Angle = ', num2str(alphas(k), '%.1f')], ...
|
||||
'Color', 'white', 'FontWeight', 'bold', 'Interpreter', 'tex', 'FontSize', 20, 'Units', 'normalized', 'HorizontalAlignment', 'right', 'VerticalAlignment', 'top');
|
||||
axis square;
|
||||
hcb = colorbar;
|
||||
colormap(ax1, 'jet');
|
||||
set(gca, 'FontSize', 14); % For tick labels only
|
||||
hL = ylabel(hcb, 'Optical Density');
|
||||
set(hL,'Rotation',-90);
|
||||
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
|
||||
hXLabel = xlabel('x (pixels)', 'Interpreter', 'tex');
|
||||
hYLabel = ylabel('y (pixels)', 'Interpreter', 'tex');
|
||||
hTitle = title('Density', 'Interpreter', 'tex');
|
||||
set([hXLabel, hYLabel, hL, hText], 'FontName', font)
|
||||
set([hXLabel, hYLabel, hL], 'FontSize', 14)
|
||||
set(hTitle, 'FontName', font, 'FontSize', 16, 'FontWeight', 'bold'); % Set font and size for title
|
||||
|
||||
% Plot the power spectrum
|
||||
ax2 = nexttile;
|
||||
[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);
|
||||
imagesc(log(1 + abs(fft_imgs{k}).^2));
|
||||
% Define normalized positions (relative to axis limits)
|
||||
x_offset = 0.025; % 5% offset from the edges
|
||||
y_offset = 0.025; % 5% offset from the edges
|
||||
axis square;
|
||||
hcb = colorbar;
|
||||
colormap(ax2, 'jet');
|
||||
set(gca, 'FontSize', 14); % For tick labels only
|
||||
set(gca,'YDir','normal')
|
||||
hXLabel = xlabel('k_x', 'Interpreter', 'tex');
|
||||
hYLabel = ylabel('k_y', 'Interpreter', 'tex');
|
||||
hTitle = title('Power Spectrum - S(k_x,k_y)', 'Interpreter', 'tex');
|
||||
set([hXLabel, hYLabel, hText], 'FontName', font)
|
||||
set([hXLabel, hYLabel], 'FontSize', 14)
|
||||
set(hTitle, 'FontName', font, 'FontSize', 16, 'FontWeight', 'bold'); % Set font and size for title
|
||||
|
||||
% Plot the angular distribution
|
||||
nexttile
|
||||
spectral_contrast(k) = computeSpectralContrast(fft_imgs{k}, 10, 25, Threshold);
|
||||
[theta_vals, S_theta] = computeNormalizedAngularSpectralDistribution(fft_imgs{k}, 10, 25, N_bins, Threshold, Sigma);
|
||||
spectral_weight(k) = trapz(theta_vals, S_theta);
|
||||
plot(theta_vals/pi, S_theta,'Linewidth',2);
|
||||
axis square;
|
||||
set(gca, 'FontSize', 14); % For tick labels only
|
||||
hXLabel = xlabel('\theta/\pi [rad]', 'Interpreter', 'tex');
|
||||
hYLabel = ylabel('Normalized magnitude (a.u.)', 'Interpreter', 'tex');
|
||||
hTitle = title('Angular Spectral Distribution - S(\theta)', 'Interpreter', 'tex');
|
||||
set([hXLabel, hYLabel, hText], 'FontName', font)
|
||||
set([hXLabel, hYLabel], 'FontSize', 14)
|
||||
set(hTitle, 'FontName', font, 'FontSize', 16, 'FontWeight', 'bold'); % Set font and size for title
|
||||
grid on
|
||||
|
||||
nexttile
|
||||
plot(theta_vals/pi, g2, 'o-', 'LineWidth', 1.2, 'MarkerSize', 5);
|
||||
set(gca, 'FontSize', 14);
|
||||
ylim([-1.5 3.0]); % Set y-axis limits here
|
||||
hXLabel = xlabel('$\delta\theta / \pi$', 'Interpreter', 'latex');
|
||||
hYLabel = ylabel('$g^{(2)}(\delta\theta)$', 'Interpreter', 'latex');
|
||||
hTitle = title('Autocorrelation', 'Interpreter', 'tex');
|
||||
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;
|
||||
|
||||
if makeMovie
|
||||
frame = getframe(gcf);
|
||||
writeVideo(videoFile, frame);
|
||||
else
|
||||
pause(0.5); % Only pause when not recording
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if makeMovie
|
||||
close(videoFile);
|
||||
disp(['Movie saved to ', movieFileName]);
|
||||
end
|
||||
|
||||
%% Track across the transition
|
||||
|
||||
figure(2);
|
||||
set(gcf,'Position',[100 100 950 750])
|
||||
plot(alphas, spectral_contrast, 'o--', ...
|
||||
'LineWidth', 1.5, 'MarkerSize', 6);
|
||||
set(gca, 'FontSize', 14); % For tick labels only
|
||||
hXLabel = xlabel('\alpha (degrees)', 'Interpreter', 'tex');
|
||||
% hXLabel = xlabel('B_z (G)', 'Interpreter', 'tex');
|
||||
hYLabel = ylabel('Spectral Contrast', 'Interpreter', 'tex');
|
||||
hTitle = title(TitleString, 'Interpreter', 'tex');
|
||||
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
|
||||
|
||||
figure(3);
|
||||
set(gcf,'Position',[100 100 950 750])
|
||||
plot(alphas, spectral_weight, 'o--', ...
|
||||
'LineWidth', 1.5, 'MarkerSize', 6);
|
||||
set(gca, 'FontSize', 14); % For tick labels only
|
||||
hXLabel = xlabel('\alpha (degrees)', 'Interpreter', 'tex');
|
||||
% hXLabel = xlabel('B_z (G)', 'Interpreter', 'tex');
|
||||
hYLabel = ylabel('Spectral Weight', 'Interpreter', 'tex');
|
||||
hTitle = title(TitleString, 'Interpreter', 'tex');
|
||||
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
|
||||
|
||||
save(datafileName, 'alphas', 'spectral_contrast', 'spectral_weight');
|
||||
|
||||
figure(4);
|
||||
clf;
|
||||
set(gcf,'Position',[100 100 950 750])
|
||||
hold on;
|
||||
|
||||
% Reconstruct theta axis from any one of the stored values
|
||||
theta_vals = theta_values_all{1}; % assuming it's in radians
|
||||
|
||||
legend_entries = cell(nimgs, 1);
|
||||
|
||||
% Generate a colormap with enough unique colors
|
||||
cmap = sky(nimgs); % You can also try 'jet', 'turbo', 'hot', etc.
|
||||
|
||||
for i = 1:nimgs
|
||||
plot(theta_vals/pi, g2_all{i}, ...
|
||||
'o-', 'Color', cmap(i,:), 'LineWidth', 1.2, ...
|
||||
'MarkerSize', 5);
|
||||
legend_entries{i} = sprintf('$\\alpha = %g^\\circ$', alphas(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(TitleString, '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;
|
||||
|
||||
%% Track across the transition
|
||||
|
||||
set(0,'defaulttextInterpreter','latex')
|
||||
set(groot, 'defaultAxesTickLabelInterpreter','latex'); set(groot, 'defaultLegendInterpreter','latex');
|
||||
|
||||
format long
|
||||
|
||||
font = 'Bahnschrift';
|
||||
|
||||
% Load data
|
||||
Data = load('./DropletsToStripes.mat', 'alphas', 'spectral_contrast', 'spectral_weight');
|
||||
dts_alphas = Data.alphas;
|
||||
dts_sc = Data.spectral_contrast;
|
||||
dts_sw = Data.spectral_weight;
|
||||
|
||||
Data = load('./StripesToDroplets.mat', 'alphas', 'spectral_contrast', 'spectral_weight');
|
||||
std_alphas = Data.alphas;
|
||||
std_sc = Data.spectral_contrast;
|
||||
std_sw = Data.spectral_weight;
|
||||
|
||||
% Normalize dts data
|
||||
dts_min = min(dts_sw);
|
||||
dts_max = max(dts_sw);
|
||||
dts_range = dts_max - dts_min;
|
||||
dts_sf_norm = (dts_sw - dts_min) / dts_range;
|
||||
|
||||
% Normalize std data
|
||||
std_min = min(std_sw);
|
||||
std_max = max(std_sw);
|
||||
std_range = std_max - std_min;
|
||||
std_sf_norm = (std_sw - std_min) / std_range;
|
||||
|
||||
figure(5);
|
||||
set(gcf,'Position',[100 100 950 750])
|
||||
plot(dts_alphas, dts_sc, 'o--', 'LineWidth', 1.5, 'MarkerSize', 6, 'DisplayName' , 'Droplets to Stripes');
|
||||
hold on
|
||||
plot(std_alphas, std_sc, 'o--', 'LineWidth', 1.5, 'MarkerSize', 6, 'DisplayName' , 'Stripes to Droplets');
|
||||
set(gca, 'FontSize', 14); % For tick labels only
|
||||
hXLabel = xlabel('\alpha (degrees)', 'Interpreter', 'tex');
|
||||
hYLabel = ylabel('Spectral Contrast', 'Interpreter', 'tex');
|
||||
hTitle = title('Change across transition', '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
|
||||
|
||||
figure(6);
|
||||
set(gcf,'Position',[100 100 950 750])
|
||||
plot(dts_alphas, dts_sw, 'o--', 'LineWidth', 1.5, 'MarkerSize', 6, 'DisplayName' , 'Droplets to Stripes');
|
||||
hold on
|
||||
plot(std_alphas, std_sw, 'o--', 'LineWidth', 1.5, 'MarkerSize', 6, '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('Change across transition', '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
|
||||
|
||||
%%
|
||||
function [IMGFFT, IMGPR] = computeFourierTransform(I, skipPreprocessing, skipMasking, skipIntensityThresholding, skipBinarization)
|
||||
% computeFourierSpectrum - Computes the 2D Fourier power spectrum
|
||||
% of binarized and enhanced lattice image features, with optional central mask.
|
||||
%
|
||||
% Inputs:
|
||||
% I - Grayscale or RGB image matrix
|
||||
%
|
||||
% Output:
|
||||
% F_mag - 2D Fourier power spectrum (shifted)
|
||||
|
||||
if ~skipPreprocessing
|
||||
% Preprocessing: Denoise
|
||||
filtered = imgaussfilt(I, 10);
|
||||
IMGPR = I - filtered; % adjust sigma as needed
|
||||
else
|
||||
IMGPR = I;
|
||||
end
|
||||
|
||||
if ~skipMasking
|
||||
[rows, cols] = size(IMGPR);
|
||||
[X, Y] = meshgrid(1:cols, 1:rows);
|
||||
% Elliptical mask parameters
|
||||
cx = cols / 2;
|
||||
cy = rows / 2;
|
||||
|
||||
% Shifted coordinates
|
||||
x = X - cx;
|
||||
y = Y - cy;
|
||||
|
||||
% Ellipse semi-axes
|
||||
rx = 0.4 * cols;
|
||||
ry = 0.2 * rows;
|
||||
|
||||
% Rotation angle in degrees -> radians
|
||||
theta_deg = 30; % Adjust as needed
|
||||
theta = deg2rad(theta_deg);
|
||||
|
||||
% Rotated ellipse equation
|
||||
cos_t = cos(theta);
|
||||
sin_t = sin(theta);
|
||||
|
||||
x_rot = (x * cos_t + y * sin_t);
|
||||
y_rot = (-x * sin_t + y * cos_t);
|
||||
|
||||
ellipseMask = (x_rot.^2) / rx^2 + (y_rot.^2) / ry^2 <= 1;
|
||||
|
||||
% Apply cutout mask
|
||||
IMGPR = IMGPR .* ellipseMask;
|
||||
end
|
||||
|
||||
if ~skipIntensityThresholding
|
||||
% Apply global intensity threshold mask
|
||||
intensity_thresh = 0.20;
|
||||
intensity_mask = IMGPR > intensity_thresh;
|
||||
IMGPR = IMGPR .* intensity_mask;
|
||||
end
|
||||
|
||||
if ~skipBinarization
|
||||
% Adaptive binarization and cleanup
|
||||
IMGPR = imbinarize(IMGPR, 'adaptive', 'Sensitivity', 0.0);
|
||||
IMGPR = imdilate(IMGPR, strel('disk', 2));
|
||||
IMGPR = imerode(IMGPR, strel('disk', 1));
|
||||
IMGPR = imfill(IMGPR, 'holes');
|
||||
F = fft2(double(IMGPR)); % Compute 2D Fourier Transform
|
||||
IMGFFT = abs(fftshift(F))'; % Shift zero frequency to center
|
||||
else
|
||||
F = fft2(double(IMGPR)); % Compute 2D Fourier Transform
|
||||
IMGFFT = abs(fftshift(F))'; % Shift zero frequency to center
|
||||
end
|
||||
end
|
||||
|
||||
function [theta_vals, S_theta] = computeNormalizedAngularSpectralDistribution(IMGFFT, r_min, r_max, num_bins, threshold, sigma)
|
||||
% Apply threshold to isolate strong peaks
|
||||
IMGFFT(IMGFFT < threshold) = 0;
|
||||
|
||||
% Prepare polar coordinates
|
||||
[ny, nx] = size(IMGFFT);
|
||||
[X, Y] = meshgrid(1:nx, 1:ny);
|
||||
cx = ceil(nx/2);
|
||||
cy = ceil(ny/2);
|
||||
R = sqrt((X - cx).^2 + (Y - cy).^2);
|
||||
Theta = atan2(Y - cy, X - cx); % range [-pi, pi]
|
||||
|
||||
% Choose radial band
|
||||
radial_mask = (R >= r_min) & (R <= r_max);
|
||||
|
||||
% Initialize the angular structure factor array
|
||||
S_theta = zeros(1, num_bins); % Pre-allocate for 180 angle bins
|
||||
% Define the angle values for the x-axis
|
||||
theta_vals = linspace(0, pi, num_bins);
|
||||
|
||||
% Loop through each angle bin
|
||||
for i = 1:num_bins
|
||||
angle_start = (i-1) * pi / num_bins;
|
||||
angle_end = i * pi / num_bins;
|
||||
|
||||
% Define a mask for the given angle range
|
||||
angle_mask = (Theta >= angle_start & Theta < angle_end);
|
||||
|
||||
bin_mask = radial_mask & angle_mask;
|
||||
|
||||
% Extract the Fourier components for the given angle
|
||||
fft_angle = IMGFFT .* bin_mask;
|
||||
|
||||
% Integrate the Fourier components over the radius at the angle
|
||||
S_theta(i) = sum(sum(abs(fft_angle).^2)); % sum of squared magnitudes
|
||||
end
|
||||
|
||||
% Create a 1D Gaussian kernel
|
||||
half_width = ceil(3 * sigma);
|
||||
x = -half_width:half_width;
|
||||
gauss_kernel = exp(-x.^2 / (2 * sigma^2));
|
||||
gauss_kernel = gauss_kernel / sum(gauss_kernel); % normalize
|
||||
|
||||
% Apply convolution (circular padding to preserve periodicity)
|
||||
S_theta = conv([S_theta(end-half_width+1:end), S_theta, S_theta(1:half_width)], gauss_kernel, 'same');
|
||||
S_theta = S_theta(half_width+1:end-half_width); % crop back to original size
|
||||
|
||||
% Normalize to 1
|
||||
S_theta = S_theta / max(S_theta);
|
||||
end
|
||||
|
||||
function contrast = computeSpectralContrast(IMGFFT, r_min, r_max, threshold)
|
||||
% Apply threshold to isolate strong peaks
|
||||
IMGFFT(IMGFFT < threshold) = 0;
|
||||
|
||||
% Prepare polar coordinates
|
||||
[ny, nx] = size(IMGFFT);
|
||||
[X, Y] = meshgrid(1:nx, 1:ny);
|
||||
cx = ceil(nx/2);
|
||||
cy = ceil(ny/2);
|
||||
R = sqrt((X - cx).^2 + (Y - cy).^2);
|
||||
|
||||
% Ring region (annulus) mask
|
||||
ring_mask = (R >= r_min) & (R <= r_max);
|
||||
|
||||
% Squared magnitude in the ring
|
||||
ring_power = abs(IMGFFT).^2 .* ring_mask;
|
||||
|
||||
% Maximum power in the ring
|
||||
ring_max = max(ring_power(:));
|
||||
|
||||
% Power at the DC component
|
||||
dc_power = abs(IMGFFT(cy, cx))^2;
|
||||
|
||||
% Avoid division by zero
|
||||
if dc_power == 0
|
||||
contrast = Inf; % or NaN or 0, depending on how you want to handle this
|
||||
else
|
||||
contrast = ring_max / dc_power;
|
||||
end
|
||||
end
|
@ -8,42 +8,63 @@ format long
|
||||
font = 'Bahnschrift';
|
||||
|
||||
% Load data
|
||||
Data = load('C:/Users/Karthik/Documents/GitRepositories/Calculations/Data-Analyzer/B2.45G/DropletsToStripes.mat', 'unique_scan_parameter_values', 'mean_sf', 'stderr_sf');
|
||||
Data = load('D:/Results - Experiment/B2.45G/DropletsToStripes.mat', 'unique_scan_parameter_values', 'mean_sc', 'stderr_sc', 'mean_sw', 'stderr_sw');
|
||||
|
||||
dts_scan_parameter_values = Data.unique_scan_parameter_values;
|
||||
dts_mean_sf = Data.mean_sf;
|
||||
dts_stderr_sf = Data.stderr_sf;
|
||||
dts_mean_sc = Data.mean_sc;
|
||||
dts_stderr_sc = Data.stderr_sc;
|
||||
dts_mean_sw = Data.mean_sw;
|
||||
dts_stderr_sw = Data.stderr_sw;
|
||||
|
||||
Data = load('C:/Users/Karthik/Documents/GitRepositories/Calculations/Data-Analyzer/B2.45G/StripesToDroplets.mat', 'unique_scan_parameter_values', 'mean_sf', 'stderr_sf');
|
||||
Data = load('D:/Results - Experiment/B2.45G/StripesToDroplets.mat', 'unique_scan_parameter_values', 'mean_sc', 'stderr_sc', 'mean_sw', 'stderr_sw');
|
||||
|
||||
std_scan_parameter_values = Data.unique_scan_parameter_values;
|
||||
std_mean_sf = Data.mean_sf;
|
||||
std_stderr_sf = Data.stderr_sf;
|
||||
std_mean_sw = Data.mean_sw;
|
||||
std_stderr_sw = Data.stderr_sw;
|
||||
std_mean_sc = Data.mean_sc;
|
||||
std_stderr_sc = Data.stderr_sc;
|
||||
|
||||
% Normalize dts data
|
||||
dts_min = min(dts_mean_sf);
|
||||
dts_max = max(dts_mean_sf);
|
||||
dts_min = min(dts_mean_sw);
|
||||
dts_max = max(dts_mean_sw);
|
||||
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;
|
||||
dts_mean_sw_norm = (dts_mean_sw - dts_min) / dts_range;
|
||||
dts_stderr_sw_norm = dts_stderr_sw / dts_range;
|
||||
|
||||
% Normalize std data
|
||||
std_min = min(std_mean_sf);
|
||||
std_max = max(std_mean_sf);
|
||||
std_min = min(std_mean_sw);
|
||||
std_max = max(std_mean_sw);
|
||||
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;
|
||||
std_mean_sw_norm = (std_mean_sw - std_min) / std_range;
|
||||
std_stderr_sw_norm = std_stderr_sw / std_range;
|
||||
|
||||
figure(1);
|
||||
set(gcf,'Position',[100 100 950 750])
|
||||
errorbar(dts_scan_parameter_values, dts_mean_sf_norm, dts_stderr_sf_norm, 'o--', ...
|
||||
errorbar(dts_scan_parameter_values, dts_mean_sc, dts_stderr_sc, 'o--', ...
|
||||
'LineWidth', 1.5, 'MarkerSize', 6, 'CapSize', 5, 'DisplayName' , 'Droplets to Stripes');
|
||||
hold on
|
||||
errorbar(std_scan_parameter_values, std_mean_sf_norm, std_stderr_sf_norm, 'o--', ...
|
||||
errorbar(std_scan_parameter_values, std_mean_sc, std_stderr_sc, '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('Normalized Spectral Weight', 'Interpreter', 'tex');
|
||||
hYLabel = ylabel('Spectral Contrast', 'Interpreter', 'tex');
|
||||
hTitle = title('B = 2.45 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
|
||||
|
||||
figure(2);
|
||||
set(gcf,'Position',[100 100 950 750])
|
||||
errorbar(dts_scan_parameter_values, dts_mean_sw, dts_stderr_sw, 'o--', ...
|
||||
'LineWidth', 1.5, 'MarkerSize', 6, 'CapSize', 5, 'DisplayName' , 'Droplets to Stripes');
|
||||
hold on
|
||||
errorbar(std_scan_parameter_values, std_mean_sw, std_stderr_sw, '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.45 G', 'Interpreter', 'tex');
|
||||
legend
|
||||
set([hXLabel, hYLabel], 'FontName', font)
|
||||
|
@ -198,150 +198,6 @@ set([hXLabel, hYLabel], 'FontSize', 14)
|
||||
set(hTitle, 'FontName', font, 'FontSize', 16, 'FontWeight', 'bold'); % Set font and size for title
|
||||
grid on;
|
||||
|
||||
%% Extract g2 from simulation data
|
||||
|
||||
Data = load('E:/Results - Numerics/Data_Full3D/PhaseDiagram/ImagTimePropagation/Theta0/HighN/aS_9.562000e+01_theta_000_phi_000_N_712500/Run_000/psi_gs.mat','psi','Params','Transf','Observ');
|
||||
|
||||
% Data = load('E:/Results - Numerics/Data_Full3D/PhaseDiagram/ImagTimePropagation/Theta40/HighN/aS_9.562000e+01_theta_040_phi_000_N_508333/Run_000/psi_gs.mat','psi','Params','Transf','Observ');
|
||||
|
||||
Params = Data.Params;
|
||||
Transf = Data.Transf;
|
||||
Observ = Data.Observ;
|
||||
|
||||
if isgpuarray(Data.psi)
|
||||
psi = gather(Data.psi);
|
||||
else
|
||||
psi = Data.psi;
|
||||
end
|
||||
if isgpuarray(Data.Observ.residual)
|
||||
Observ.residual = gather(Data.Observ.residual);
|
||||
else
|
||||
Observ.residual = Data.Observ.residual;
|
||||
end
|
||||
|
||||
% Axes scaling and coordinates in micrometers
|
||||
x = Transf.x * Params.l0 * 1e6;
|
||||
y = Transf.y * Params.l0 * 1e6;
|
||||
z = Transf.z * Params.l0 * 1e6;
|
||||
|
||||
dx = x(2)-x(1); dy = y(2)-y(1); dz = z(2)-z(1);
|
||||
|
||||
% Calculate frequency increment (frequency axes)
|
||||
Nx = length(x); % grid size along X
|
||||
Ny = length(y); % grid size along Y
|
||||
dx = mean(diff(x)); % real space increment in the X direction (in micrometers)
|
||||
dy = mean(diff(y)); % real space increment in the Y direction (in micrometers)
|
||||
dvx = 1 / (Nx * dx); % reciprocal space increment in the X direction (in micrometers^-1)
|
||||
dvy = 1 / (Ny * dy); % reciprocal space increment in the Y direction (in micrometers^-1)
|
||||
|
||||
% Create the frequency axes
|
||||
vx = (-Nx/2:Nx/2-1) * dvx; % Frequency axis in X (micrometers^-1)
|
||||
vy = (-Ny/2:Ny/2-1) * dvy; % Frequency axis in Y (micrometers^-1)
|
||||
|
||||
% Calculate maximum frequencies
|
||||
% kx_max = pi / dx;
|
||||
% ky_max = pi / dy;
|
||||
|
||||
% Generate reciprocal axes
|
||||
% kx = linspace(-kx_max, kx_max * (Nx-2)/Nx, Nx);
|
||||
% ky = linspace(-ky_max, ky_max * (Ny-2)/Ny, Ny);
|
||||
|
||||
% Create the Wavenumber axes
|
||||
kx = 2*pi*vx; % Wavenumber axis in X
|
||||
ky = 2*pi*vy; % Wavenumber axis in Y
|
||||
|
||||
% Compute probability density |psi|^2
|
||||
n = abs(psi).^2;
|
||||
|
||||
nxz = squeeze(trapz(n*dy,2));
|
||||
nyz = squeeze(trapz(n*dx,1));
|
||||
nxy = squeeze(trapz(n*dz,3));
|
||||
|
||||
skipPreprocessing = true;
|
||||
skipMasking = true;
|
||||
skipIntensityThresholding = true;
|
||||
skipBinarization = true;
|
||||
|
||||
font = 'Bahnschrift';
|
||||
% Extract g2
|
||||
|
||||
N_bins = 90;
|
||||
Threshold = 75;
|
||||
Sigma = 2;
|
||||
|
||||
IMG = nxy;
|
||||
|
||||
[IMGFFT, IMGPR] = computeFourierTransform(IMG, skipPreprocessing, skipMasking, skipIntensityThresholding, skipBinarization);
|
||||
|
||||
[theta_vals, S_theta] = computeNormalizedAngularSpectralDistribution(IMGFFT, 10, 35, N_bins, Threshold, Sigma);
|
||||
|
||||
g2_all = zeros(1, N_bins); % Preallocate
|
||||
|
||||
for dtheta = 0:N_bins-1
|
||||
profile = S_theta;
|
||||
profile_shifted = circshift(profile, -dtheta, 2);
|
||||
|
||||
num = mean(profile .* profile_shifted);
|
||||
denom = mean(profile)^2;
|
||||
|
||||
g2_all(dtheta+1) = num / denom - 1;
|
||||
end
|
||||
|
||||
figure(2);
|
||||
clf
|
||||
set(gcf,'Position',[500 100 1000 800])
|
||||
t = tiledlayout(2, 2, 'TileSpacing', 'compact', 'Padding', 'compact'); % 1x4 grid
|
||||
|
||||
% Display the cropped OD image
|
||||
nexttile
|
||||
plotxy = pcolor(x,y,IMG');
|
||||
set(plotxy, 'EdgeColor', 'none');
|
||||
cbar1 = colorbar;
|
||||
cbar1.Label.Interpreter = 'latex';
|
||||
colormap(gca, Helper.Colormaps.plasma())
|
||||
xlabel('$x$ ($\mu$m)', 'Interpreter', 'latex', 'FontSize', 14)
|
||||
ylabel('$y$ ($\mu$m)', 'Interpreter', 'latex', 'FontSize', 14)
|
||||
title('$|\Psi(x,y)|^2$', 'Interpreter', 'latex', 'FontSize', 14)
|
||||
|
||||
% Plot the power spectrum
|
||||
nexttile;
|
||||
imagesc(kx, ky, log(1 + abs(IMGFFT).^2));
|
||||
axis square;
|
||||
hcb = colorbar;
|
||||
colormap(gca, Helper.Colormaps.plasma())
|
||||
set(gca, 'FontSize', 14); % For tick labels only
|
||||
set(gca,'YDir','normal')
|
||||
hXLabel = xlabel('k_x', 'Interpreter', 'tex');
|
||||
hYLabel = ylabel('k_y', 'Interpreter', 'tex');
|
||||
hTitle = title('Power Spectrum - S(k_x,k_y)', 'Interpreter', 'tex');
|
||||
set([hXLabel, hYLabel], 'FontName', font)
|
||||
set([hXLabel, hYLabel], 'FontSize', 14)
|
||||
set(hTitle, 'FontName', font, 'FontSize', 16, 'FontWeight', 'bold'); % Set font and size for title
|
||||
|
||||
% Plot the angular distribution
|
||||
nexttile
|
||||
plot(theta_vals/pi, S_theta,'Linewidth',2);
|
||||
set(gca, 'FontSize', 14); % For tick labels only
|
||||
hXLabel = xlabel('\theta/\pi [rad]', 'Interpreter', 'tex');
|
||||
hYLabel = ylabel('Normalized magnitude (a.u.)', 'Interpreter', 'tex');
|
||||
hTitle = title('Angular Spectral Distribution - S(\theta)', 'Interpreter', 'tex');
|
||||
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
|
||||
|
||||
nexttile
|
||||
plot(theta_vals/pi, g2_all, 'o-', 'LineWidth', 1.2, 'MarkerSize', 5);
|
||||
set(gca, 'FontSize', 14);
|
||||
ylim([-1.5 3.0]); % Set y-axis limits here
|
||||
hXLabel = xlabel('$\delta\theta / \pi$', 'Interpreter', 'latex');
|
||||
hYLabel = ylabel('$g^{(2)}(\delta\theta)$', 'Interpreter', 'latex');
|
||||
hTitle = title('Autocorrelation', 'Interpreter', 'tex');
|
||||
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
|
||||
|
@ -6,7 +6,7 @@ groupList = ["/images/MOT_3D_Camera/in_situ_absorption", "/images/ODT_1_Axi
|
||||
|
||||
folderPath = "D:/Data - Experiment/2025/05/22/";
|
||||
|
||||
run = '0078';
|
||||
run = '0079';
|
||||
|
||||
folderPath = strcat(folderPath, run);
|
||||
|
||||
@ -25,7 +25,9 @@ scan_parameter = 'rot_mag_fin_pol_angle';
|
||||
scan_parameter_text = 'Angle = ';
|
||||
% scan_parameter_text = 'BField = ';
|
||||
|
||||
font = 'Bahnschrift';
|
||||
savefodlerPath = 'D:/Results - Experiment/B2.45G/';
|
||||
savefileName = 'StripesToDroplets.mat';
|
||||
font = 'Bahnschrift';
|
||||
|
||||
skipPreprocessing = true;
|
||||
skipMasking = true;
|
||||
@ -96,6 +98,7 @@ end
|
||||
%% Run Fourier analysis over images
|
||||
|
||||
fft_imgs = cell(1, nimgs);
|
||||
spectral_contrast = zeros(1, nimgs);
|
||||
spectral_weight = zeros(1, nimgs);
|
||||
|
||||
N_bins = 180;
|
||||
@ -197,6 +200,7 @@ for k = 1:N_shots
|
||||
|
||||
% Plot the angular distribution
|
||||
nexttile
|
||||
spectral_contrast(k) = computeSpectralContrast(fft_imgs{k}, 10, 25, Threshold);
|
||||
[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);
|
||||
@ -220,25 +224,51 @@ end
|
||||
% Close the video file
|
||||
close(videoFile);
|
||||
|
||||
%% Track spectral weight across the transition
|
||||
%% Track across the transition
|
||||
|
||||
% Assuming scan_parameter_values and spectral_weight are column vectors (or row vectors of same length)
|
||||
[unique_scan_parameter_values, ~, idx] = unique(scan_parameter_values);
|
||||
|
||||
% Preallocate arrays
|
||||
mean_sf = zeros(size(unique_scan_parameter_values));
|
||||
stderr_sf = zeros(size(unique_scan_parameter_values));
|
||||
mean_sc = zeros(size(unique_scan_parameter_values));
|
||||
stderr_sc = zeros(size(unique_scan_parameter_values));
|
||||
|
||||
% Loop through each unique theta and compute mean and standard error
|
||||
for i = 1:length(unique_scan_parameter_values)
|
||||
group_vals = spectral_weight(idx == i);
|
||||
mean_sf(i) = mean(group_vals);
|
||||
stderr_sf(i) = std(group_vals) / sqrt(length(group_vals)); % standard error = std / sqrt(N)
|
||||
group_vals = spectral_contrast(idx == i);
|
||||
mean_sc(i) = mean(group_vals);
|
||||
stderr_sc(i) = std(group_vals) / sqrt(length(group_vals)); % standard error = std / sqrt(N)
|
||||
end
|
||||
|
||||
figure(2);
|
||||
set(gcf,'Position',[100 100 950 750])
|
||||
errorbar(unique_scan_parameter_values, mean_sf, stderr_sf, 'o--', ...
|
||||
errorbar(unique_scan_parameter_values, mean_sc, stderr_sc, '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');
|
||||
hYLabel = ylabel('Spectral Contrast', 'Interpreter', 'tex');
|
||||
hTitle = title('Change across transition', 'Interpreter', 'tex');
|
||||
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
|
||||
|
||||
|
||||
% Preallocate arrays
|
||||
mean_sw = zeros(size(unique_scan_parameter_values));
|
||||
stderr_sw = zeros(size(unique_scan_parameter_values));
|
||||
|
||||
% Loop through each unique theta and compute mean and standard error
|
||||
for i = 1:length(unique_scan_parameter_values)
|
||||
group_vals = spectral_weight(idx == i);
|
||||
mean_sw(i) = mean(group_vals);
|
||||
stderr_sw(i) = std(group_vals) / sqrt(length(group_vals)); % standard error = std / sqrt(N)
|
||||
end
|
||||
|
||||
figure(3);
|
||||
set(gcf,'Position',[100 100 950 750])
|
||||
errorbar(unique_scan_parameter_values, mean_sw, stderr_sw, 'o--', ...
|
||||
'LineWidth', 1.5, 'MarkerSize', 6, 'CapSize', 5);
|
||||
set(gca, 'FontSize', 14); % For tick labels only
|
||||
hXLabel = xlabel('\alpha (degrees)', 'Interpreter', 'tex');
|
||||
@ -250,6 +280,8 @@ set([hXLabel, hYLabel], 'FontSize', 14)
|
||||
set(hTitle, 'FontName', font, 'FontSize', 16, 'FontWeight', 'bold'); % Set font and size for title
|
||||
grid on
|
||||
|
||||
save([savefolderPath savefileName], 'unique_scan_parameter_values', 'mean_sc', 'stderr_sc', 'mean_sw', 'stderr_sw');
|
||||
|
||||
%% k-means Clustering
|
||||
|
||||
% Reshape to column vector
|
||||
@ -433,6 +465,37 @@ function [theta_vals, S_theta] = computeNormalizedAngularSpectralDistribution(IM
|
||||
S_theta = S_theta / max(S_theta);
|
||||
end
|
||||
|
||||
function contrast = computeSpectralContrast(IMGFFT, r_min, r_max, threshold)
|
||||
% Apply threshold to isolate strong peaks
|
||||
IMGFFT(IMGFFT < threshold) = 0;
|
||||
|
||||
% Prepare polar coordinates
|
||||
[ny, nx] = size(IMGFFT);
|
||||
[X, Y] = meshgrid(1:nx, 1:ny);
|
||||
cx = ceil(nx/2);
|
||||
cy = ceil(ny/2);
|
||||
R = sqrt((X - cx).^2 + (Y - cy).^2);
|
||||
|
||||
% Ring region (annulus) mask
|
||||
ring_mask = (R >= r_min) & (R <= r_max);
|
||||
|
||||
% Squared magnitude in the ring
|
||||
ring_power = abs(IMGFFT).^2 .* ring_mask;
|
||||
|
||||
% Maximum power in the ring
|
||||
ring_max = max(ring_power(:));
|
||||
|
||||
% Power at the DC component
|
||||
dc_power = abs(IMGFFT(cy, cx))^2;
|
||||
|
||||
% Avoid division by zero
|
||||
if dc_power == 0
|
||||
contrast = Inf; % or NaN or 0, depending on how you want to handle this
|
||||
else
|
||||
contrast = ring_max / dc_power;
|
||||
end
|
||||
end
|
||||
|
||||
function ret = getBkgOffsetFromCorners(img, x_fraction, y_fraction)
|
||||
% image must be a 2D numerical array
|
||||
[dim1, dim2] = size(img);
|
||||
|
164
Data-Analyzer/matchTFRadii.m
Normal file
164
Data-Analyzer/matchTFRadii.m
Normal file
@ -0,0 +1,164 @@
|
||||
% ----------------------------
|
||||
% Experimental data
|
||||
% ----------------------------
|
||||
PixelSize = 5.86; % microns
|
||||
|
||||
AtomNumbers = [9.14950197, 8.6845907 , 8.82521245, 8.5899089 , 8.21675841, ...
|
||||
8.96234044, 8.8636914 , 8.70332154, 8.82930706, 8.91869919, ...
|
||||
8.58553165, 8.73391981, 8.71943552, 8.11717678, 8.59490351, ...
|
||||
8.57514491, 8.81628891, 8.37211343, 8.76077699, 8.71297796, ...
|
||||
9.17634469, 8.81424285, 8.61176745, 8.40555897, 8.97137861, ...
|
||||
8.88393124, 8.66625724, 8.30688943, 9.02338201, 8.57729816, ...
|
||||
8.50333458, 8.67617084, 8.8936879 , 9.02031475, 8.98459233, ...
|
||||
8.76525048, 8.76801503, 8.58302559, 8.4617431 , 8.74479855, ...
|
||||
8.83882896, 8.69091377, 8.79282459, 8.51785483, 8.75629649, ...
|
||||
8.58994308, 8.36816564, 9.2429294 , 8.6583425 , 8.55827961];
|
||||
|
||||
EstimatedAtomNumber = mean(AtomNumbers) * 1E4;
|
||||
|
||||
TF_Radii_X_pixels = [48.44308968, 46.01326593, 46.45950681, 46.41644117, 45.56176919, ...
|
||||
46.60816438, 46.85307478, 47.61086543, 46.66687703, 46.17986721, ...
|
||||
46.67877165, 46.07789481, 46.42285497, 46.22167708, 45.95144492, ...
|
||||
47.05400117, 49.03005788, 45.84588659, 46.85742777, 45.9824117 , ...
|
||||
47.14731188, 47.4984484 , 45.9055646 , 47.31804553, 47.52321888, ...
|
||||
47.76823968, 46.459749 , 45.4498851 , 45.38339308, 46.68736642, ...
|
||||
45.76607233, 48.1796053 , 46.94291541, 47.54092708, 48.26130406, ...
|
||||
47.44092616, 48.73463214, 46.39356452, 48.74120217, 45.57014182, ...
|
||||
47.56467835, 46.62867035, 46.62322802, 46.03032919, 44.78559832, ...
|
||||
46.31282562, 46.83537518, 47.68015029, 47.71093571, 47.34079816];
|
||||
|
||||
TF_Radii_Y_pixels = [113.52610841, 113.68862761, 112.84031747, 114.22062324, ...
|
||||
112.45378285, 114.53863928, 111.39181472, 112.67024271, ...
|
||||
113.65387448, 113.57576769, 110.22576589, 110.45091803, ...
|
||||
109.97966067, 112.84785553, 109.3836049 , 111.22290862, ...
|
||||
111.17028727, 110.71088554, 111.72973603, 112.39623635, ...
|
||||
113.18160954, 112.00016346, 109.66542778, 111.98705097, ...
|
||||
112.35983901, 110.21703075, 112.14565939, 111.2029942 , ...
|
||||
110.74296 , 112.56607054, 112.58015318, 111.93031032, ...
|
||||
111.59774288, 112.30723266, 112.79543793, 111.08288891, ...
|
||||
113.85269603, 111.77349741, 113.58639434, 111.28694353, ...
|
||||
112.1993445 , 111.72215918, 111.93271101, 112.17593036, ...
|
||||
110.82246602, 113.61806907, 114.13693144, 114.27245731, ...
|
||||
114.24223538, 112.61704196];
|
||||
|
||||
% ----------------------------
|
||||
% Load simulation data for fitting
|
||||
% ----------------------------
|
||||
% baseDir = 'D:\Results - Numerics\Data_Full3D\PhaseDiagram\TFRadii\LowN';
|
||||
baseDir = 'C:\Users\Karthik\Documents\GitRepositories\Calculations\Estimations\ThomasFermiRadius';
|
||||
refData = load(fullfile(baseDir, 'TFFermi_Theta0.mat'));
|
||||
|
||||
% ----------------------------
|
||||
% Find simulation values at the estimated atom number
|
||||
% ----------------------------
|
||||
[~, idxClosest] = min(abs(refData.NUM_ATOMS_LIST - EstimatedAtomNumber));
|
||||
|
||||
if ndims(refData.TF_Radii) > 2
|
||||
TF_Radii = squeeze(refData.TF_Radii);
|
||||
TF_X_target = TF_Radii(idxClosest, 1);
|
||||
TF_Y_target = TF_Radii(idxClosest, 2);
|
||||
else
|
||||
TF_X_target = refData.TF_Radii(idxClosest, 1);
|
||||
TF_Y_target = refData.TF_Radii(idxClosest, 2);
|
||||
end
|
||||
|
||||
fprintf('Target radii from simulation at N = %.0f:\n', refData.NUM_ATOMS_LIST(idxClosest));
|
||||
fprintf('TF_X_target = %.2f µm\n', TF_X_target);
|
||||
fprintf('TF_Y_target = %.2f µm\n', TF_Y_target);
|
||||
|
||||
% ----------------------------
|
||||
% Find optimal magnification
|
||||
% ----------------------------
|
||||
errorFunc = @(mag) ...
|
||||
(mean(TF_Radii_X_pixels)*PixelSize/mag - TF_X_target)^2 + ...
|
||||
(mean(TF_Radii_Y_pixels)*PixelSize/mag - TF_Y_target)^2;
|
||||
|
||||
Magnification = fminbnd(errorFunc, 10, 50);
|
||||
fprintf('Best-fit magnification: %.4f\n', Magnification);
|
||||
|
||||
% ----------------------------
|
||||
% Convert to real space and get stats
|
||||
% ----------------------------
|
||||
TF_Radii_X_Real = TF_Radii_X_pixels * PixelSize / Magnification;
|
||||
TF_Radii_Y_Real = TF_Radii_Y_pixels * PixelSize / Magnification;
|
||||
|
||||
Avg_X = mean(TF_Radii_X_Real);
|
||||
Avg_Y = mean(TF_Radii_Y_Real);
|
||||
Std_X = std(TF_Radii_X_Real);
|
||||
Std_Y = std(TF_Radii_Y_Real);
|
||||
|
||||
fprintf('TF Radius X = %.2f ± %.2f µm\n', Avg_X, Std_X);
|
||||
fprintf('TF Radius Y = %.2f ± %.2f µm\n', Avg_Y, Std_Y);
|
||||
|
||||
% ----------------------------
|
||||
% Plotting
|
||||
% ----------------------------
|
||||
fileList = {'TFFermi_Theta0.mat'};
|
||||
thetaLabels = {'\theta = 0^\circ', '\theta = 20^\circ', '\theta = 40^\circ'};
|
||||
|
||||
fig = figure(1); clf;
|
||||
set(gcf,'Position', [100, 100, 1200, 500])
|
||||
t = tiledlayout(1, 2, 'TileSpacing', 'compact', 'Padding', 'compact');
|
||||
colors = lines(length(fileList));
|
||||
legendEntries = cell(1, length(fileList));
|
||||
|
||||
for j = 1:length(fileList)
|
||||
data = load(fullfile(baseDir, fileList{j}));
|
||||
|
||||
aS = data.SCATTERING_LENGTH_RANGE;
|
||||
NUM_ATOMS_LIST = data.NUM_ATOMS_LIST;
|
||||
if ndims(data.TF_Radii) > 2
|
||||
TF_Radii = squeeze(data.TF_Radii);
|
||||
else
|
||||
TF_Radii = data.TF_Radii;
|
||||
end
|
||||
|
||||
legendEntries{j} = sprintf('%s, a_s = %.2f a_0', thetaLabels{j}, aS);
|
||||
|
||||
% Rx
|
||||
nexttile(1);
|
||||
plot(NUM_ATOMS_LIST, TF_Radii(:,1), '-', ...
|
||||
'Color', colors(j,:), 'LineWidth', 1.5, ...
|
||||
'DisplayName', legendEntries{j}); hold on;
|
||||
|
||||
% Ry
|
||||
nexttile(2);
|
||||
plot(NUM_ATOMS_LIST, TF_Radii(:,2), '-', ...
|
||||
'Color', colors(j,:), 'LineWidth', 1.5, ...
|
||||
'DisplayName', legendEntries{j}); hold on;
|
||||
end
|
||||
|
||||
% ----------------------------
|
||||
% Add experimental point w/ error bars and annotation
|
||||
% ----------------------------
|
||||
% TF Radius X
|
||||
nexttile(1);
|
||||
errorbar(EstimatedAtomNumber, Avg_X, Std_X, ...
|
||||
'd', 'MarkerSize', 8, 'MarkerFaceColor', [0.2 0.2 0.8], ...
|
||||
'MarkerEdgeColor', 'k', 'Color', 'k', 'LineWidth', 1.2, ...
|
||||
'DisplayName', '\theta = 0^\circ, Experimental Value');
|
||||
|
||||
% TF Radius Y
|
||||
nexttile(2);
|
||||
errorbar(EstimatedAtomNumber, Avg_Y, Std_Y, ...
|
||||
'd', 'MarkerSize', 8, 'MarkerFaceColor', [0.2 0.2 0.8], ...
|
||||
'MarkerEdgeColor', 'k', 'Color', 'k', 'LineWidth', 1.2, ...
|
||||
'DisplayName', '\theta = 0^\circ, Experimental Value');
|
||||
|
||||
% ----------------------------
|
||||
% Finalize
|
||||
% ----------------------------
|
||||
nexttile(1);
|
||||
xlabel('Number of Atoms', 'FontSize', 16);
|
||||
ylabel('TF Radius - X ($\mu$m)', 'Interpreter', 'latex', 'FontSize', 16);
|
||||
legend('FontSize', 12, 'Interpreter', 'tex', 'Location', 'bestoutside');
|
||||
axis square; grid on;
|
||||
|
||||
nexttile(2);
|
||||
xlabel('Number of Atoms', 'FontSize', 16);
|
||||
ylabel('TF Radius - Y ($\mu$m)', 'Interpreter', 'latex', 'FontSize', 16);
|
||||
legend('FontSize', 12, 'Interpreter', 'tex', 'Location', 'bestoutside');
|
||||
axis square; grid on;
|
||||
|
||||
sgtitle('[ \omega_x, \omega_y, \omega_z ] = 2 \pi \times [ 50, 20, 150 ] Hz', ...
|
||||
'Interpreter', 'tex', 'FontSize', 18);
|
@ -573,9 +573,14 @@ JobNumber = 0;
|
||||
Plotter.visualizeGSWavefunction(SaveDirectory, JobNumber)
|
||||
|
||||
%%
|
||||
SaveDirectory = 'D:/Results - Numerics/Data_Full3D/PhaseDiagram/ImagTimePropagation/Theta0/HighN/aS_9.562000e+01_theta_000_phi_000_N_712500';
|
||||
SaveDirectory = 'D:/Results - Numerics/Data_Full3D/PhaseDiagram/ImagTimePropagation/Theta0/HighN/aS_9.562000e+01_theta_000_phi_000_N_1733333';
|
||||
JobNumber = 0;
|
||||
Plotter.visualizeGSWavefunction(SaveDirectory, JobNumber)
|
||||
%%
|
||||
SaveDirectory = 'D:/Results - Numerics/Data_Full3D/PhaseTransition/STD/aS_9.562000e+01_theta_025_phi_000_N_500000';
|
||||
JobNumber = 0;
|
||||
Plotter.visualizeGSWavefunction(SaveDirectory, JobNumber)
|
||||
|
||||
|
||||
%% Identify and count droplets
|
||||
Radius = 2; % The radius within which peaks will be considered duplicates
|
||||
@ -591,7 +596,7 @@ PeakThreshold = 3E3;
|
||||
SaveDirectory = 'D:/Results - Numerics/Data_Full3D/PhaseDiagram/ImagTimePropagation/Theta0/HighN/aS_9.562000e+01_theta_000_phi_000_N_712500';
|
||||
JobNumber = 0;
|
||||
SuppressPlotFlag = false;
|
||||
AveragePCD = Scripts.extractAveragePeakColumnDensity(SaveDirectory, JobNumber, Radius, PeakThreshold, SuppressPlotFlag);
|
||||
AveragePCD = Scripts.extractAveragePeakColumnDensity(SaveDirectory, JobNumber, Radius, PeakThreshold, SuppressPlotFlag);
|
||||
|
||||
%% Extract average unit cell density - Droplets
|
||||
Radius = 2; % The radius within which peaks will be considered duplicates
|
||||
@ -604,7 +609,7 @@ UCD = Scripts.extractAverageUnitCellDensity(SaveDirectory, J
|
||||
%% Extract average unit cell density - Stripes
|
||||
Radius = 2; % The radius within which peaks will be considered duplicates
|
||||
PeakThreshold = 3E3;
|
||||
SaveDirectory = 'D:/Results - Numerics/Data_Full3D/PhaseDiagram/ImagTimePropagation/Theta0/HighN/aS_9.562000e+01_theta_000_phi_000_N_1529167';
|
||||
SaveDirectory = 'D:/Results - Numerics/Data_Full3D/PhaseDiagram/ImagTimePropagation/Theta0/HighN/aS_9.562000e+01_theta_000_phi_000_N_1325000';
|
||||
JobNumber = 0;
|
||||
SuppressPlotFlag = false;
|
||||
UCD = Scripts.extractAverageUnitCellDensity(SaveDirectory, JobNumber, Radius, PeakThreshold, SuppressPlotFlag);
|
||||
@ -766,10 +771,10 @@ xlabel(inset_ax, 'N', 'FontSize', 9);
|
||||
ylabel(inset_ax, 'CD', 'FontSize', 9);
|
||||
|
||||
%% Plot average unit cell density
|
||||
Radius = 2;
|
||||
PeakThreshold = 3E3;
|
||||
JobNumber = 0;
|
||||
SuppressPlotFlag = true; % Suppress plots during batch processing
|
||||
Radius = 2;
|
||||
PeakThreshold = 3E3;
|
||||
JobNumber = 0;
|
||||
SuppressPlotFlag = true; % Suppress plots during batch processing
|
||||
TitleString = "[ \omega_x, \omega_y, \omega_z ] = 2 \pi \times [ 50, 20, 150 ] Hz; \theta = 0^\circ";
|
||||
|
||||
|
||||
@ -777,7 +782,7 @@ SCATTERING_LENGTH_RANGE = [95.62];
|
||||
|
||||
NUM_ATOMS_LIST = [712500 916667 1120833 1325000 1529167 1733333 1937500 2141667 2345833 2550000 2754167 2958333 3162500 3366667 3570833];
|
||||
|
||||
UCD_values = zeros(length(SCATTERING_LENGTH_RANGE), length(NUM_ATOMS_LIST));
|
||||
UCD_values = zeros(length(SCATTERING_LENGTH_RANGE), length(NUM_ATOMS_LIST));
|
||||
|
||||
% Prepare figure
|
||||
figure(1);
|
||||
@ -824,6 +829,32 @@ legend(arrayfun(@(aS) sprintf('a_s = %.2f a_0', aS), SCATTERING_LENGTH_RANGE, ..
|
||||
set(gca, 'FontSize', 14);
|
||||
grid on;
|
||||
|
||||
% Physical constants
|
||||
PlanckConstant = 6.62607015E-34;
|
||||
PlanckConstantReduced = 6.62607015E-34/(2*pi);
|
||||
AtomicMassUnit = 1.660539066E-27;
|
||||
BohrMagneton = 9.274009994E-24;
|
||||
|
||||
% Dy specific constants
|
||||
Dy164Mass = 163.929174751*AtomicMassUnit;
|
||||
Dy164IsotopicAbundance = 0.2826;
|
||||
DyMagneticMoment = 9.93*BohrMagneton;
|
||||
|
||||
add = VacuumPermeability*DyMagneticMoment^2*Dy164Mass/(12*pi*PlanckConstantReduced^2); % Dipole length
|
||||
nadd2s = 0.01:0.01:0.25;
|
||||
ppmum = nadd2s.*(1E12*add^2)^-1;
|
||||
%
|
||||
figure(2);
|
||||
clf;
|
||||
set(gcf,'Position', [100, 100, 850, 700]);
|
||||
hold on
|
||||
plot(nadd2s, ppmum, 'o-', 'LineWidth', 1.5)
|
||||
xlabel('na_{dd}^2', 'Interpreter', 'tex', 'FontSize', 16);
|
||||
ylabel('Unit Cell Density (UCD) [$\mu m^{-2}$]', 'Interpreter', 'latex', 'FontSize', 16);
|
||||
title("[ \omega_x, \omega_y, \omega_z ] = 2 \pi \times [ 0, 0, 72.4 ] Hz; \theta = 0^\circ", 'Interpreter', 'tex', 'FontSize', 18);
|
||||
set(gca, 'FontSize', 14);
|
||||
grid on;
|
||||
|
||||
%% Plot TF radii of unmodulated states
|
||||
% Parameters
|
||||
JobNumber = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user