Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions 2-Channel Codes/channel_calibration.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,21 @@
% load calibration data and store in conglomorate array
for i = 1:numel(files)
load(files(i).name)
<<<<<<< HEAD
xf = [xf; cdata.red.ncoords(:,1)];
yf = [yf; cdata.red.ncoords(:,2)];
N = [N; cdata.red.ncoords(:,3)];
xf = [xf; cdata.orange.ncoords(:,1)];
yf = [yf; cdata.orange.ncoords(:,2)];
N = [N; cdata.orange.ncoords(:,3)];
fnum = [fnum; cdata.red.framenumber + max([max(fnum),0])];
fnum = [fnum; cdata.orange.framenumber + max([max(fnum),0])];
=======
xf = [xf; fits(:,1)];
yf = [yf; fits(:,2)];
N = [N; fits(:,3)];
fnum = [fnum; framenumber + max([max(fnum),0])];
>>>>>>> master
end

% display calibration parameters of splitting channels via horizontal
Expand Down
Binary file modified 2-Channel Codes/two_channel_drift_with_ruler.mlx
Binary file not shown.
4 changes: 4 additions & 0 deletions 2-Channel Codes/xy_feature.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
x = x(:);
y=y(:);
% vector = [x.^3, x.^2.*y, x.*y.^2, x.^2, y.^2, x.*y,x, y, x*0+1];
<<<<<<< HEAD
% vector = [x.^2, y.^2, x.*y,x, y, x*0+1];
=======
vector = [x.^2, y.^2, x.*y,x, y, x*0+1];
>>>>>>> master
vector = [x.^3, y.^3, x.^2.*y, x.*y.^2, x.^2, y.^2, x.*y,x, y, x*0+1];

66 changes: 46 additions & 20 deletions 3D-Localization/total_calibration.m
Original file line number Diff line number Diff line change
Expand Up @@ -284,18 +284,18 @@
end

% Find plane of least confusion
ds = ssx - ssy; % Subtract sigma-y from sigma-x
ds = ssy - ssx; % Subtract sigma-y from sigma-x
tds = uitab(tg3,'Title','DS curve');
ax = axes(tds);
plot(ax,abs(ds))
xlabel(ax,'Index')
ylabel(ax,'Difference between average sx and sy')
tdx = input('Choose an Index to grab minimum of the DS curve');
ind = find(abs(ds(tdx:end)) == min(abs(ds(tdx:end)))); % Find minimum of absolute value
ind = find(abs(ds(tdx:tdx + 30)) == min(abs(ds(tdx:tdx + 30)))); % Find minimum of absolute value
z0s = zus - zus(ind(1)+tdx); % Call the found index the 0 point

% Data Representation of Sigma and Z space
t3 = uitab(tg,'Title','Sigmas');
t3 = uitab(tg,'Title','Sigmas2');
ax = axes(t3);
plot(ax,z0(indy)-zus(ind(1)+tdx),sx(indy),'.') % Plot Toleranced Sigma-x data
hold on
Expand All @@ -304,13 +304,17 @@
plot(ax,z0s,ssy) % Plot average sigma-y

% Determining Z parameters
ind = abs(z0s) < 1.2; % Limit height over which to fit sigmas
ind = abs(z0s) < 0.5; % Limit height over which to fit sigmas
% z_net = train_neural_z(z0s(indy),ims(:,indy));
z_cal = get_z_params(z0s(ind),ssx(ind),ssy(ind)); % Fit sigma curves to data and return result

z_cal = get_z_params(z0s(ind),ssx(ind),ssy(ind));
% Fit sigma curves to data and return result
% Redfeining z_call and
% Display results of Z-calibration
yx = z_cal_fit(z0s(ind),z_cal(1:5)); % Determine ideal fitted Sig-x Values
yy = z_cal_fit(z0s(ind),z_cal(6:end)); % Determine ideal fitted Sig-y values
yy = z_cal_fit(z0s(ind),z_cal(6:end));


% Determine ideal fitted Sig-y values
% Overlay result on scattered / average sig-x plot
plot(ax,z0s(ind),yx,'gx')
plot(ax,z0s(ind),yy,'gx')
Expand All @@ -321,7 +325,7 @@
% It's known that in astigmatism there may be a slight slant that
% exists over the Z direction, in this section we'll address that

zf_um = getdz(sx,sy,z_cal); % Get Z-values
zf_um = getdz(sx,sy,z_cal,2); % Get Z-values
upz = 0.5;
dnz = -0.5;
indy = indy & zf_um <upz & zf_um > dnz; % Limit view to fitted region listed above
Expand All @@ -341,17 +345,22 @@

% Overlay stage v fit curves
zc = z0;
for i = 1:numel(psfs)
id = psf == i & abs(zf_um) < 1; % ident by psf and position
figure
for i = 4:numel(psfs)
id = psf == i & abs(z0 - 0.88) < 0.22; % ident by psf and position
zs = z0(id); % subset of stage positions
zfs = zf_um(id); % subset of fitted positions
plot(zs,zfs,'.')
a = polyfit(zfs,zs,1); % linear fit to obtain x-intercept of stage
zc(id) = zc(id) - a(2); % adjust stage position to 'center' by subtracting x-interecept of all psfs
hold on
end


% plot(ax,z0(indy),zf_um(indy),'.')
% a = polyfit(z0(indy),zf_um(indy),1); % The slope of this distribution gives us the 'correction' for absolute Z

%purge clumped psfs for orange

% grab subsets
dist = 0.5;
Expand All @@ -360,6 +369,11 @@
yfs = yf(indy);
zfs = zf_um(indy)/q;
pfs = psf(indy);
done_id = psf <4;
xfs(done_id) = [];
yfs(done_id) = [];
zfs(done_id) = [];
pfs(done_id) = [];
zs = (min(zfs*q):0.040:max(zfs*q))/q; % zfs is in pixels, are values are in pixels right now
for i = 1:numel(zs)-1 % Attempt to grab the magnification curve of stage versus fit
id = zf_um >= zs(i)*q & zf_um < zs(i+1)*q;
Expand All @@ -369,7 +383,15 @@
z0m(i) = mean(zc(id2));
zfm(i) = mean(zf_um(id2));
end
a = polyfit(z0m,zfm,1);
id = zf_um < 0.18;
z0m = zc(id);
% a = polyfit(z0m,zfm,1);
ind = psf >3 & abs(z0 - 0.88) < 0.22;
plot(z0(ind),zf_um(ind),'.')
a_actual = polyfit(z0(ind),zf_um(ind),1);
hold on
plot(z0(ind),z0(ind)*a_actual(1) + a_actual(2),'r')

clear zfm
plot(ax,zc(indy),zf_um(indy),'.');
hold on
Expand All @@ -384,11 +406,14 @@
xt = [];
yt = [];
zt = [];
for i = 1:max(pfs)
ind = pfs == i;
xt = [xt;xfs(ind)-mean(xfs(ind))];
yt = [yt;yfs(ind)-mean(yfs(ind))];
zt = [zt;zfs(ind)];
for i = 4:max(psf)
ind = psf == i;
try
xt = [xt;xfs(ind)-mean(xfs(ind))];
yt = [yt;yfs(ind)-mean(yfs(ind))];
zt = [zt;zfs(ind)];
catch
end
end
% indy = indy & xfc.^0.5*q < 0.005 & yfc.^0.5*q < 0.005;
% indy = indy & abs(xf) < 0.5 & abs(yf) < 0.5;
Expand All @@ -398,12 +423,12 @@
zsel = [];
for i = 1:numel(zs) - 1 % Loop over a variety of height windows for averaging of points
ind1 = zt >= zs(i) & zt <=zs(i+1); % grab all points within height window
ind1 = ind1 & (xt.^2+yt.^2).^0.5 < 0.5; % grab all points who lie within a half pixel radius of center (at this point all scans have a 0 mean in XY)
ind1 = ind1 & ((xt - mean(xt(ind1))).^2+(yt - mean(yt(ind1))).^2).^0.5 < 0.5; % grab all points who lie within a half pixel radius of center (at this point all scans have a 0 mean in XY)
% Subsets
xts = xt(ind1);
yts = yt(ind1);
zts = zt(ind1);
rts = (xts.^2+yts.^2).^0.5; % convert subsetted xy to R
rts = ((xts-mean(xts)).^2+(yts-mean(yts)).^2).^0.5; % convert subsetted xy to R
mr = mean(rts); % grab mean of R
str = std(rts); % grab stdev of R
% my = mean(yts);
Expand All @@ -419,7 +444,7 @@
zfm(i) = mean(zts(ind2));
end

splz = (-1:0.001:1)/q;
splz = (-0.5:0.001:0.5)/q;
xtilt = gausssmooth(xfm,5,10);
ytilt = gausssmooth(yfm,5,10);
splx = spline(zs(1:end-1) + mean(diff(zs))/2,xtilt,splz);
Expand All @@ -442,6 +467,7 @@
zf = zf_um/q;
xc = spline(zs(1:end-1) + mean(diff(zs))/2,xtilt,zf);
yc = spline(zs(1:end-1) + mean(diff(zs))/2,ytilt,zf);
% new drift correction attempt

xf_c = xf - xc;
yf_c = yf - yc;
Expand All @@ -464,4 +490,4 @@

%% Calibration Handling
disp(['Distance between Minima is ', num2str(1000*(cal.z_cal(2)-cal.z_cal(7))),'nm']);
save('z_calib.mat','cal')
save('z_calib_orange.mat','cal')
Loading