function [rafosLimits, temperatureLimits] = getTemperatureLimits(pWorkspace, pIncludeDeleted)
%GETTOALIMITS Finds the maximum and minimum of toa data.
%   If pIncludeDeleted equals to true, all values that are either selected or
%   manually deleted are used for estimation.

if nargin == 1
    pIncludeDeleted = false;
end

if pIncludeDeleted
    selection = pWorkspace.statusTemperature ~= 2;
else
    selection = true(size(pWorkspace.statusTemperature));
end

nanFilter = ~isnan(pWorkspace.rafosDate) & ~isnan(pWorkspace.temperature);

selection = selection & nanFilter;

temperatureLimits = [min(pWorkspace.temperature(selection)), max(pWorkspace.temperature(selection))];
rafosLimits = [min(pWorkspace.rafosDate(selection)), max(pWorkspace.rafosDate(selection))];

end

