% addpath(genpath('W:\Cassini\Titan\valerio\Anthony_backscatter'));
% addpath(genpath('W:\Anthony\Plains Backscatter'));

% site_names = {'Site1NNN','Site3N', 'Site5N', 'Site6', 'Site7N', 'Site8', 'Site9', 'Site9a', 'Site10', 'Site12', 'Site13', 'Site16', 'Site17'};
 
site_names = {'SiteA','SiteB', 'SiteC', 'SiteD', 'SiteE', 'SiteF', 'SiteG', 'SiteH', 'SiteI', 'SiteJ', 'SiteK', 'SiteL', 'SiteM'};



s = [];
for i = 1:numel(site_names)
    s = [s; load([site_names{i} '.mat'], "alt_inc", "alt_sigma0", "inc", "sigma0")];
end

% s = [];
% for i = 1:numel(site_names)
%     % Load the data from the file
%     new_site = load([site_names{i} '.mat'], "alt_inc", "alt_sigma0", "inc", "sigma0");
% 
%     % Calculate the mean of each variable
%     mean_data = struct();
%     field_names = fieldnames(new_site);
%     for j = 1:numel(field_names)
%         if isempty(new_site.(field_names{j}))
%              mean_data.(field_names{j}) = [];
%         else
%             mean_data.(field_names{j}) = mean(new_site.(field_names{j}), 'omitnan');
%         end
%     end
% 
%     % Add the mean values to the struct array
%     s = [s; mean_data];
% end

data = [];
data.alt.sigma0 = [];
data.alt.inc = [];

data.noalt.sigma0 = [];
data.noalt.inc = [];


for idx = 1:numel(s)


    data.alt.sigma0 = vertcat(data.alt.sigma0, [reshape(s(idx).sigma0,[],1); s(idx).alt_sigma0]);
    data.alt.inc = vertcat(data.alt.inc, deg2rad([reshape(s(idx).inc,[], 1); s(idx).alt_inc]));

    
    data.noalt.sigma0 = vertcat(data.noalt.sigma0,reshape(s(idx).sigma0,[],1));
    data.noalt.inc = vertcat(data.noalt.inc, deg2rad(reshape(s(idx).inc,[], 1)));

end


noise_ind = data.noalt.inc < deg2rad(2) | data.noalt.inc > deg2rad(25);
data.noalt.sigma0(noise_ind) = [];
data.noalt.inc(noise_ind) = [];

%% Fit

fits = fitBackscatter(data, 1); %Toggle 1 for all fits, 0 for only two_layer

%% Define Colors For Figures
blue = [57 106 177]./255;
red = [204 37 41]./255;
black = [83 81 84]./255;
green = [62 150 81]./255;
brown = [146 36 40]./255;
purple = [107 76 154]./255;
cl_colors = {blue, red, green, black, ...
    brown, purple};
cl_str_clr_names = ["blue", "red", "black", "green", "brown", "purple"];
pretty_colors = [blue;red;green;black;brown;purple];
clear blue red black green brown purple

%%
plotBlackPoints

%% Create "All Points" Figure with Distingushable Colors
figure;
plotColorPoints
