Commit fe6deb0e authored by Thomas Rogers Shaw's avatar Thomas Rogers Shaw
Browse files

Merge branch 'fixup-time-edge-unif' into 'main'

Fix time_edge_correction_unif ...

See merge request !21
parents 103a4247 021be50e
......@@ -19,6 +19,9 @@ function [out, params] = spacetime_resolution(varargin)
% than nm.
% 'Bootstrap' (default: false): Generate a bootstrapped confidence interval by resampling the
% data. This is off by default because it takes a considerable amount of time.
% 'TEdgeMethod', 'actual' or 'unif' (default: 'actual'):
% 'actual': use density correction in the time edge correction.
% 'unif': assume uniform rate of localizations/frame
% Copyright (C) 2021 Thomas Shaw, and Sarah Veatch
% This file is part of SMLM SPACETIME RESOLUTION
......@@ -288,6 +291,7 @@ p.addParameter('NTauBin', 10, @(x) isnumeric(x) && isscalar(x))
p.addParameter('TauEdges', [], @(x) isnumeric(x) && issorted(x))
p.addParameter('SigmaStartpoint', 10, @(x) isnumeric(x) && isscalar(x))
p.addParameter('Bootstrap', false)
p.addParameter('TEdgeMethod', 'actual');
%TODO: add more
p.parse(args{:});
......
function taufactor = time_edge_correction_unif(tau_edges, timewin)
% TIME_EDGE_CORRECTION_UNIF temporal edge correction assuming uniform rate
% Copyright (C) 2021 Thomas Shaw, and Sarah Veatch
% This file is part of SMLM SPACETIME RESOLUTION
% SMLM SPACETIME RESOLUTION is free software: you can redistribute it and/or modify
......@@ -11,24 +14,14 @@
% You should have received a copy of the GNU General Public License
% along with SMLM SPACETIME RESOLUTION. If not, see <https://www.gnu.org/licenses/>
function taufactor = time_edge_correction_unif(tau, timewin)
tmax = numel(timevec);
timediffs = zeros(tmax*(tmax-1)/2, 1);
count = 1;
for i = 1:tmax-1
for j = i:tmax
timediffs(count) = timevec(j) - timevec(i);
count = count + 1;
end
end
dt = tau(2)-tau(1);
[~, ~, bin] = histcounts(timediffs, [tau]);% tau(end)+2*dt]);
inds = bin>0 & bin <= tau(end)/dt + 1;
exptauperbin = accumarray(bin(inds), 1, [ntout,1]);
taufactor = exptauperbin/numel(timevec);
taufactor = taufactor';
tau = tau_edges(2:end) - diff(tau_edges)/2;
if ~timewin_isvalid(timewin)
error('time_edge_correction: invalid time window provided');
end
T = timewin_duration(timewin);
overlap = arrayfun(@(t) timewin_overlap(timewin, timewin + t), tau);
taufactor = overlap/T;
end
\ No newline at end of file
function overlap = timewin_overlap(tw1, tw2)
i = 1;
j = 1;
sum = 0;
% jump to sane start point
if tw1(i,2) <= tw2(j,1) % this section of tw1 entirely precedes this part of tw2
i = find(tw1(i:end,2) > tw2(j,1), 1); % find first section of 1 where there is overlap
elseif tw1(i,1) >= tw2(j,2)
j = find(tw1(1,2) > tw2(:,1), 1); % find first section of 2 where there is overlap
end
while i <= size(tw1, 1) && j <= size(tw2,1)
sum = sum + max(0, min(tw1(i,2),tw2(j,2)) - max(tw1(i,1),tw2(j,1)));
if tw1(i,2) <= tw2(j,2) % done with tw1(i,:)
i = i+1;
elseif tw2(j,2) <= tw1(i,2) % done with tw2(j,:)
j = j+1;
end
end
overlap = sum;
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment