%10th November 2021, Louise Wilson %Model boat source level. %Calculate SL at each source position on each transect. %Collate data for all transects at each speed and calculate median SL. load('ArrayData_11Aug2021_GoatIsland_Koura_+-2_5secs.mat'); %% Organise data into transects %Cut into different transects/speeds according to times in %'TransectData_11Aug2021_GoatIsland_Koura_positionsOnly.csv'. %10 knots times.t1.start=datetime(2021,08,11,09,58,25); times.t1.end=datetime(2021,08,11,10,01,00); times.t2.start=datetime(2021,8,11,10,02,20); times.t2.end=datetime(2021,8,11,10,04,05); times.t3.start=datetime(2021,8,11,10,06,20); times.t3.end=datetime(2021,8,11,10,09,00); times.t4.start=datetime(2021,8,11,10,10,00); times.t4.end=datetime(2021,8,11,10,12,45); %20 knots times.t5.start=datetime(2021,8,11,10,16,35); times.t5.end=datetime(2021,8,11,10,17,45); times.t6.start=datetime(2021,8,11,10,18,50); times.t6.end=datetime(2021,8,11,10,20,0); times.t7.start=datetime(2021,8,11,10,20,50); times.t7.end=datetime(2021,8,11,10,22,10); times.t8.start=datetime(2021,8,11,10,23,0); times.t8.end=datetime(2021,8,11,10,24,20); transects={'t1','t2','t3','t4','t5','t6','t7','t8'}; %date format is mixed up in table (month and day wrong way round) fmt = times.t1.start.Format; [year, mon, day] = ymd(gps.DateTime); gps.DateTime = datetime(year, day, mon, 'Format', fmt) + timeofday(gps.DateTime); %Group data into transects for i=1:length(transects) %for each transect start=times.(transects{i}).start; %get start and end time last=times.(transects{i}).end; for ii=1:height(gps); disp(gps.DateTime(ii)); %display vessel position time %if vessel position time occurs during particular transect working on if (gps.DateTime(ii)>=start)&&(gps.DateTime(ii)<=last) %append it to specific part of structure times.(transects{i}).data(ii,:)=gps(ii,:); else %do nothing end end times.(transects{i}).data=rmmissing(times.(transects{i}).data); %remove empty rows end transects=times; clearvars -except transects gps OUT_F %% Calculate distances between array and boat hydroLat=-36.266833; %hydrophone position hydroLon=174.790417; HydroDepth = 0.0085; %depth of hydrophone (km) SourceDepth = 0.0012 ; %depth of source (km) transect_nums=fields(transects); for i=1:length(transect_nums) %for each transect transect_on=transect_nums{i}; for ii = 1:height(transects.(transect_on).data); dist=deg2km(distance(transects.(transect_on).data.LAT(ii),transects.(transect_on).data.LONGITUDE(ii),hydroLat,hydroLon)); A = dist; B = HydroDepth - SourceDepth; %calculate diff. b/w source + receiver depths C = sqrt(A^2+B^2); %slope distance transects.(transect_on).data.slopeDist(ii) = C*1000; %metres transects.(transect_on).data.horizDist(ii) = A*1000; %metres end transects.(transect_on).data.Transect(:)=i; %column for transect num end clearvars -except transects gps OUT_F %% Concatenate data for each transect in order to append PL data correctly data=[transects.t1.data; transects.t2.data; transects.t3.data;transects.t4.data; transects.t5.data;transects.t6.data;transects.t7.data;transects.t8.data;]; %read PL data boat_PL=readtable('Test_11Aug21_15C_sand1__all_Rec_TOBTL_.xls'); boat_PL = removevars(boat_PL, {'CentralFreq_Hz__','Var4','Var5','Var6','Var7','Var8'}); %When using +/- X seconds data, we need to remove positions/rows in boat_PL %that aren't being used because that position occurred at a time when data %spanned two acoustic files (junction of 5min/5min). %Load boat source positions recorded on gps logger and correct datetime %format... pos_table=readtable('/Users/louisewilson/Documents/Manuscript data/Listening space paper (chapter 4)/TransectData_11Aug2021_GoatIsland_Koura_positionsOnly.csv'); fmt = data.DateTime.Format; %fix wonky datetime variable (M and d mixed up) [year, mon, day] = ymd(pos_table.DateTime); pos_table.DateTime = datetime(year, day, mon, 'Format', fmt); pos_table.DateTime=pos_table.DateTime+pos_table.LOCALTIME; boat_PL=[boat_PL pos_table]; %add lat/lon/datetime info to PL table %find rows which aren't in 'data' (should be 3 missing if using +/- 2.5 secs %or 2 extra if using +1 sec) [lia,loc]=ismember(boat_PL.DateTime,data.DateTime) %Positions @ 10:03:00, 10:08:00 & 10:23:00 removed. %**These positions also need to be removed from OUT_F. %remove rows missing from data from boat_PL boat_PL=boat_PL(lia,:); boat_PL = removevars(boat_PL, {'LOCALDATE','LOCALTIME','LATITUDE','N_S','LONGITUDE','E_W','ALTITUDE','SPEED_km_hr_','DateTime','LAT','utmX','utmY','wavFileName','wavDateTime','tlo','thi','Direction','Speed_knots_'}); %now we can join the PL data with the acoustic data data=[data boat_PL]; %We can see that it is joined correctly because the horizontal range %between the two datasets is the same for each row. %% Remove source positions where cut-off frequency > 80 Hz %(calculated in points2depths.m) clearvars -except OUT_F data all_OUT_F=struct2cell(OUT_F); %concatenate data tables all_OUT_F=vertcat(all_OUT_F{:}); pos_times=unique(all_OUT_F.boat_time); %Only use positions in 'data' than occur in OUT_F. (OUT_F having been %processed in points2depths.m to remove positions where cut-off frequency %is too high.) [lia,loc]=ismember(data.LOCALTIME,pos_times); data(~lia,:)=[]; %There should be 21 source positions removed. %(One of them (B164) is removed in previous step as occurred at end of a %recording) %So, now we have 158 data source positions in 'data' that will be used to %calculate the SL. %% Look at SL of boat for each boat position clearvars -except data OUT_F PL_frequencies={'x25_1','x31_6','x39_8','x50_1','x63_1','x79_4','x100_0',... 'x125_9','x158_5','x199_5','x251_2','x316_2','x398_1','x501_2',... 'x631_0','x794_3','x1000_0','x1258_9','x1584_9','x1995_3','x2511_9'}; RL_frequencies={'25.1188643150958','31.6227766016838','39.8107170553497',... '50.1187233627272','63.0957344480194','79.4328234724282','100.000000000000',... '125.892541179417','158.489319246111','199.526231496888','251.188643150958',... '316.227766016838','398.107170553498','501.187233627273','630.957344480194',... '794.328234724282','1000.00000000000','1258.92541179417','1584.89319246112',... '1995.26231496888','2511.88643150958'}; freq_labels=[PL_frequencies; RL_frequencies]; for i=1:8 %for each transect transect_on=i; S=data.Transect==transect_on; transect_data=data(S,:); %data for transect working on S=transect_data.Range_m_<50; %remove positions <50m away from array transect_data=transect_data(~S,:); columns=transect_data.Properties.VariableNames; %table columns %subplot(2,2,1) for ii = 1:length(freq_labels) %for centre frequency from 25 - 2511 Hz %figure(2) %scatter(hydroLon,hydroLat,300,'x','r') %hold on transect=strcat('transect',num2str(transect_on)); %create output centre_freq=num2str(transect_data.TOL_posMean{1,1}(1,ii)); centre_freq=strsplit(centre_freq,'.');centre_freq=centre_freq{1}; freq=strcat('freq_',num2str(centre_freq)); SLdat.(transect).(freq).SL=[]; %find PL data for frequency working on columns=transect_data.Properties.VariableNames; %table columns PLfreq_on=freq_labels{1,ii}; [lia,loc]=ismember(PLfreq_on,columns); PLfreq_col=loc; %column relevant to TOL working on for iii=1:height(transect_data) %for each boat position %find RL data for frequency working on RLfreq_on=round(str2num(freq_labels{2,ii}),4); idx=RLfreq_on==round(transect_data.TOL_posMean{iii,1}(1,:),4); [row,RLcol]=find(idx,1); RL=transect_data.TOL_posMean{iii,1}(2,RLcol); %get RL for freq PL=transect_data{iii,PLfreq_col}; %get PL for freq SL=RL+PL; %calc SL (may be NaN if no PL for that freq/position) SLdat.(transect).(freq).SL(iii)=SL; % %plot % scatter(transect_data.LONGITUDE(iii),transect_data.LAT(iii),[],SL,'filled'); %plot transect data % colorbar % colormap jet % hold on % % plot_title=strcat('transect ',num2str(transect_on)); % title(plot_title) %add plot title to subplot out(iii)=SL; %store SL for calculating median later end %Once all SL values plotted, add text for median value out=rmmissing(out); median_SL=string(median(out)); out=rmmissing(out); median_SL=string(median(out)); % text(174.786,-36.2615,strcat('median = ',median_SL),'Color','red') end end %% Get median source levels for particular speed working on %These values are then used to calculate received levels in LSR_boatRange.m %and LSR_map.m. clearvars -except OUT_F SLdat transect_nums=fields(SLdat); freqs=fields(SLdat.transect1); for z=1:length(freqs) %for each frequency freq_on=freqs{z}; %10 knots transects outSL.(freq_on)=[]; for zz=1:4 %for transects 1-4 @ 10 knots transect_on=transect_nums{zz}; dat=SLdat.(transect_on).(freq_on).SL; %SL for each boat position outSL.(freq_on)=[outSL.(freq_on) dat]; end outMedian.knots10.(freq_on)=median(rmmissing(outSL.(freq_on))); %median across all transects %20 knots transects outSL.(freq_on)=[]; for zzz=5:8 %for transects 5-8 @ 20 knots transect_on=transect_nums{zzz}; dat=SLdat.(transect_on).(freq_on).SL; %SL for each boat position outSL.(freq_on)=[outSL.(freq_on) dat]; end outMedian.knots20.(freq_on)=median(rmmissing(outSL.(freq_on))); %median across all transects end %Source levels are stored in output structure outMedian. %These values are used in LSR_boatRange.m and LSR_map.m to calculate %received levels. save('outMedianSL.mat','outMedian');