function output = bulk_velocity(pat, spill, notplot)
    if spill
        fs = load(strjoin(['/Volumes/home/test/calib/' pat '/clean/tracks/z001_t001.mat'], "")).tracks;
    else
        fs = load(strjoin(['/Volumes/home/test/calib/' pat '/tracks/z001_t001.mat'], "")).tracks;
    end
    U = [fs.u];
    X = [fs.x];
    
    lowest = cast(min(X(1,:)), "int16");
    highest = cast(max(X(1,:)), "int16");
    
    
    totals = zeros((highest - lowest), 1);
    
    for i = lowest: highest-2
        slice = (i-0.5 < X(1,:) & X(1,:) < i+0.5);
        totals(i - lowest + 1) = mean(sum(U(:,slice)));
    end
    totals = totals(1:size(totals, 1)-1);
    if nargin == 2
        plot(totals, "o")
        ylim([min(0, min(totals)), max(totals)+20])
        ylabel("bulk velocity in slice $mm s^{-1}$", "Interpreter", "latex")
        xlabel("slice position $mm$", "Interpreter", "latex")
    end
    
    output = nanmean(totals);
end