%{
Title: plotTEAMER_Uncertainty_postAccessReport.m
Written by: Courtney Beringer
Date: October 31st, 2024

Summary:
This script loads and plots the processed uncertainty data from TEAMER RFTS 7 testing in
October 2023 at the O.H. Hinsdale Wave Research Laboratory. 

%}

%% Clear it out
clear
close all
clc

%% Load the data and set the trial to analyze the data from
load("LUPA Wave Data Uncertainty Struct.mat")

% Row of the data struct to analyze. There are 40 trials total.
% i = 1 was used for the TEAMER post access report
i = 1;

%% Plot wave height and period uncertainties across all the trials

figure
scatter([dataMega.Hreq_m],[dataMega.uA_H_percent],[],[dataMega.Treq_s])
ylabel('Wave Height Uncertainty (%)')
xlabel('Requested Wave Height (m)')
c = colorbar();
colormap('winter')
c.Ticks = linspace(1.75,2.35,2);
c.Label.String = 'Requested Wave Period (s)';
xlim([0 0.20])
title('Regular Wave Height Uncertainty')

figure
scatter([dataMega.Treq_s],[dataMega.uA_T_percent],[],[dataMega.Hreq_m])
ylabel('Wave Period Uncertainty (%)')
xlabel('Requested Wave Period (s)')
c = colorbar();
colormap('jet')
c.Ticks = linspace(0.05,0.15,3);
c.Label.String = 'Requested Wave Height (m)';
xlim([1.5 2.75])
title('Regular Wave Period Uncertainty')


%% Plot successive wave heights for a single trial
figure
hold on
plot(dataMega(i).dataProc.HallPAreflect_m,'ro')
plot(dataMega(i).dataProc.HallPAinitial_m,'bo')
yline(dataMega(i).dataProc.meanHPAreflect_m,'--r')
yline(dataMega(i).dataProc.meanHPAinitial_m,'--b')
xlabel('Successive Wave Heights')
ylabel('Wave Height (m)')
legend('With reflection','Without reflection','Location','eastoutside')
title("Wave Heights, T="+num2str(dataMega(i).Treq_s)+"s, H="+num2str(dataMega(i).Hreq_m)+"m")
hold off

%% Plot Uncertainties - Wave Height for a single trial
figure;
bar([dataMega(i).dataProc.uAHPAinitial_m dataMega(i).dataProc.uAHPAreflect_m])
text(1,dataMega(i).dataProc.uAHPAinitial_m/2,strcat(num2str(round(dataMega(i).dataProc.uAHPAinitial_percent,2)),'%'),'Color','white')
text(2,dataMega(i).dataProc.uAHPAreflect_m/2,strcat(num2str(round(dataMega(i).dataProc.uAHPAreflect_percent,2)),'%'),'Color','white')
xlabel("No reflection       Reflection")
ylabel("Type A Uncertainty (m)")
title("Wave Height Uncertainty, T="+num2str(dataMega(i).Treq_s)+"s, H="+num2str(dataMega(i).Hreq_m)+"m")

%% Plot phase separated wave elevation with reflection for a single trial

wgFinalReflection = reshape(dataMega(i).dataProc.waveCyclesPAreflect.eta_m,1,[]);
timePA = repmat(dataMega(i).dataProc.waveCyclesPAreflect.t_s,length(wgFinalReflection)/175,1);
time = 0:0.01:(length(wgFinalReflection)-1)*0.01;

figure
hold on
scatter(dataMega(i).dataProc.etaPAreflect(:,1),dataMega(i).dataProc.etaPAreflect(:,2),'.k')
scatter(timePA ,wgFinalReflection,[],time,'.')
c = colorbar();
c.Label.String = 'Time (s)';
xlabel('Time (s)')
ylabel('Eta (m)')
title("All Wave Cycles, T="+num2str(dataMega(i).Treq_s)+"s, H="+num2str(dataMega(i).Hreq_m)+"m")
scatter(dataMega(i).dataProc.etaPAreflect(:,1),dataMega(i).dataProc.etaPAreflect(:,2),'.k')
legend('Phase Averaged','Location','best')
hold off