clear all
clc
%% Instructions

% Set working directory to location of HERO WEC full deployment data file.
% Input visualization start and end times in UTC 24 hour date string
% format. Run this script to plot all HERO WEC data collected during the
% selected timespan. The HERO WEC 2024 hydraulic configuration deployment
% started at 14-Mar-2024 13:30:00 UTC and ended at 19-Mar-2024 08:29:59
% UTC when the hydraulic hose was cut as a result of abrasion against the
% winch line. A table of important timestamps can be found in the
% acompanying data descriptions document.
%% Visualization Settings

% Enter start and end times in UTC date string format for plots here
Visualization.Start = '14-Mar-2024 13:30:00';   
Visualization.End = '19-Mar-2024 09:30:00';  

% Convert inputs to datetime format
Visualization.Start = datetime(Visualization.Start,TimeZone = 'UTC');
Visualization.End = datetime(Visualization.End,TimeZone = 'UTC');
%% Import Data

load('2024_NREL_HERO_WEC_Hydraulic_Deploy_VAP_10Hz.mat');
%% WEC Plotting

figure; plot(Datetime,LC_MOOR_1001)
xlabel('Time [ns]')
ylabel('Tension [lbf]')
title('Anchor Line Loading')
xlim([Visualization.Start Visualization.End])

figure; plot(Datetime,vap_POS_OS_1001_UW)
xlabel('Time [ns]')
ylabel('Position [degrees]')
title('Encoder Position')
xlim([Visualization.Start Visualization.End])

figure; plot(Datetime,calc_POS_OS_1001_UW_V)
xlabel('Time (UTC)')
ylabel('Velocity [rpm]')
title('Encoder Velocity')
xlim([Visualization.Start Visualization.End])

figure; plot(Datetime,calc_Winch_V)
xlabel('Time (UTC)')
ylabel('Velocity [rpm]')
title('Winch Velocity')
xlim([Visualization.Start Visualization.End])

figure; plot(Datetime,calc_Gearbox_V)
xlabel('Time (UTC)')
ylabel('Velocity [rpm]')
title('Gearbox Velocity')
xlim([Visualization.Start Visualization.End])

figure; plot(Datetime,PRESS_OS_2002)
xlabel('Time [ns]')
ylabel('Pressure [psi]')
title('Air Spring Pressure')
xlim([Visualization.Start Visualization.End])

figure; plot(Datetime,calc_P_abs)
xlabel('Time (UTC)')
ylabel('Power [kW]')
title('Absorbed Power')
xlim([Visualization.Start Visualization.End])

figure; plot(Datetime,FLOW_OS_1001)
xlabel('Time [ns]')
ylabel('Flow Rate [gpm]')
title('Pump Output Flow')
xlim([Visualization.Start Visualization.End])

figure; plot(Datetime,PRESS_OS_1001)
xlabel('Time [ns]')
ylabel('Pressure [psi]')
title('Pump Output Pressure')
xlim([Visualization.Start Visualization.End])

figure; plot(Datetime,calc_P_Hydraulic_1)
xlabel('Time (UTC)')
ylabel('Power [kW]')
title('Hydraulic Power at Pump Outlet')
xlim([Visualization.Start Visualization.End])
%% RO Plotting

figure; plot(Datetime,FLOW_ON_1001)
xlabel('Time (UTC)')
ylabel('Flow Rate [gpm]')
title('RO System Feed Flow')
xlim([Visualization.Start Visualization.End])

figure; plot(Datetime,PRESS_ON_1001)
xlabel('Time (UTC)')
ylabel('Pressure [psi]')
title('RO System Feed Pressure')
xlim([Visualization.Start Visualization.End])

figure; plot(Datetime,FLOW_ON_1002)
xlabel('Time (UTC)')
ylabel('Flow Rate [gpm]')
title('Clark Pump Feed Flow')
xlim([Visualization.Start Visualization.End])

figure; plot(Datetime,PRESS_ON_1002)
xlabel('Time (UTC)')
ylabel('Pressure [psi]')
title('Clark Pump Feed Pressure')
xlim([Visualization.Start Visualization.End])

figure; plot(Datetime,calc_Acc_Flow)
xlabel('Time (UTC)')
ylabel('Flow Rate [gpm]')
title('Accumulator Flow Rate')
xlim([Visualization.Start Visualization.End])

figure; plot(Datetime,FLOW_ON_1003)
xlabel('Time (UTC)')
ylabel('Flow Rate [gpm]')
title('Brine Discharge')
xlim([Visualization.Start Visualization.End])

figure; plot(Datetime,FLOW_ON_1004)
xlabel('Time (UTC)')
ylabel('Flow Rate [gpm]')
title('Permeate Production')
xlim([Visualization.Start Visualization.End])

figure; plot(Datetime,FLOW_ON_1004)
hold on
xlabel('Time (UTC)')
ylabel('Flow Rate [gpm]')
yyaxis right
plot(Datetime,PRESS_ON_1002)
ylabel('Pressure [psi]')
title('Permeate Production and Clark Pump Pressure')
xlim([Visualization.Start Visualization.End])
hold off

figure; plot(Datetime,FLOW_ON_1001,Datetime,FLOW_ON_1002,Datetime,FLOW_ON_1003,Datetime,FLOW_ON_1004)
xlabel('Time (UTC)')
ylabel('Flow Rate [gpm]')
legend('FLOW-ON-1001','FLOW-ON-1002','FLOW-ON-1003','FLOW-ON-1004')
title('Hydraulic System Flow Rates')
xlim([Visualization.Start Visualization.End])

figure; plot(Datetime,PRESS_ON_1001,Datetime,PRESS_ON_1002)
xlabel('Time (UTC)')
ylabel('Pressure [psi]')
title('RO System Pressures')
legend('PRESS-ON-1001','PRESS-ON-1002')
xlim([Visualization.Start Visualization.End])

figure; plot(Datetime,calc_Filter_DP)
xlabel('Time (UTC)')
ylabel('Pressure Differential [psi]')
title('Pressure Drop Across RO Prefilters')
xlim([Visualization.Start Visualization.End])

figure; plot(Datetime,CND_ON_1001)
xlabel('Time (UTC)')
ylabel('Conductivity [uS]')
title('Seawater Conductivity')
xlim([Visualization.Start Visualization.End])

figure; plot(Datetime,CND_ON_1002)
xlabel('Time (UTC)')
ylabel('Conductivity [uS]')
title('Permeate Conductivity')
xlim([Visualization.Start Visualization.End])

figure; plot(Datetime,calc_Recovery_Ratio,'.')
xlabel('Time (UTC)')
ylabel('Recovery Ratio [-]')
title('RO System Recovery Ratio')
ylim([0 1])
xlim([Visualization.Start Visualization.End])

figure; plot(Datetime,calc_P_Hydraulic_2)
xlabel('Time (UTC)')
ylabel('Power [kW]')
title('Hydraulic Power at RO Inlet')
xlim([Visualization.Start Visualization.End])

figure; plot(Datetime,calc_P_Hydraulic_3)
xlabel('Time (UTC)')
ylabel('Power [kW]')
title('Hydraulic Power at Clark Pump Inlet')
xlim([Visualization.Start Visualization.End])

figure; plot(Datetime,calc_P_abs,Datetime,calc_P_Hydraulic_1,Datetime,calc_P_Hydraulic_2,Datetime,calc_P_Hydraulic_3)
xlabel('Time (UTC)')
ylabel('Power [kW]')
title('WEC Power Mapping')
legend('Absorbed Power','Hydraulic Power 1','Hydraulic Power 2','Hydraulic Power 3')
xlim([Visualization.Start Visualization.End])