Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Camille Pagniello committed Aug 28, 2023
1 parent 35b9fc2 commit 1324612
Show file tree
Hide file tree
Showing 5 changed files with 857 additions and 759 deletions.
105 changes: 85 additions & 20 deletions code/matlab/sub_functions/figures/figure_S1.m
Original file line number Diff line number Diff line change
@@ -1,33 +1,98 @@
%% figure_S1
% Sub-function of Irish_Tuna.m; calculate residency of each tag in each
% region
%% figure_1a.m
% Sub-function of Irish_Tuna.m; plots SSM tracks of all tags colored by
% year.

%% Run Table S2
%% Create figure and axes for bathymetry.

run table_S2
figure('Position',[476 334 716 532]);

%% Mean % of Deployment Days
%% Set projection of map.

b = bar(mean((table2array(tbl_S2(:,2:7))./sum(table2array(tbl_S2(:,2:7)),2))*100),'FaceColor','flat');
b.CData = cmap_r;
LATLIMS = [20 70]; LONLIMS = [-80 40];
m_proj('miller','lon',LONLIMS,'lat',LATLIMS);

%% Plot bathymetry.

[cs,ch] = m_etopo2('contourf',-8000:500:0,'edgecolor','none');

h1 = m_contfbar([.3 .7],.05,cs,ch,'endpiece','no','FontSize',16);
xlabel(h1,'Bottom Depth (m)');

colormap(m_colmap('blue'));

hold on

%% Plot land.

m_gshhs_i('patch',[.7 .7 .7]);

hold on

errorbar(1:6,mean((table2array(tbl_S2(:,2:7))./sum(table2array(tbl_S2(:,2:7)),2))*100),[],std((table2array(tbl_S2(:,2:7))./sum(table2array(tbl_S2(:,2:7)),2))*100),'LineStyle','none','Color','k');
%% Plot SSM positions of tuna colored by year.

% Set colormap of year.
cmap1 = hot(length(unique(year(META.Date)))+1);
cmap2 = autumn(length(unique(year(META.Date))));
cmap = [cmap1(1:3,:); cmap2(4:end,:)];

% Get years.
yyyy = unique(year(META.Date));

% Plot each year.
for i = 1:length(yyyy)
m(i) = m_plot(META.Longitude(yyyy(i) == year(META.Date)),...
META.Latitude(yyyy(i) == year(META.Date)),...
'ko','MarkerFaceColor',cmap(i,:),'MarkerSize',3,'MarkerEdgeColor','k');
hold on
end
clear i

%% Plot ICCAT regions.

m_line([-45 -45],[20 70],'linewi',2,'color','k','linestyle','--')

%% Plot ocean regions.

m_line(regions.NB.bndry(1,:),regions.NB.bndry(2,:),'linewi',2,'color','k');
%m_text(-53,51.5,'Newfoundland Basin','FontWeight','bold');

m_line(regions.CI.bndry(1,:),regions.CI.bndry(2,:),'linewi',2,'color','k');
%m_text(-20.5,61.2,'Coastal Ireland','FontWeight','bold');

m_line(regions.Biscay.bndry(1,:),regions.Biscay.bndry(2,:),'linewi',2,'color','k');
%m_text(-2,51,'Bay of Biscay','FontWeight','bold');

m_line(regions.WEB.bndry(1,:),regions.WEB.bndry(2,:),'linewi',2,'color','k');
%m_text(-2,51,'West European Basin','FontWeight','bold');

m_line(regions.Med.bndry(1,:),regions.Med.bndry(2,:),'linewi',2,'color','k');
%m_text(-4.5,32,'Mediterranean','FontWeight','bold');

%% Create figure border.

m_grid('linewi',2,'tickdir','in','linest','none','fontsize',24);

%% Add north arrow and scale bar.

m_northarrow(-75,65,4,'type',2,'linewi',2);
m_ruler([.78 .98],.1,2,'fontsize',16,'ticklength',0.01);

%% Add Legend

set(gca,'FontSize',20);
set(gca,'XTickLabel',{'CI','BoB','WEB','NB','Med','Outside'})
set(gca,"XTickLabelRotation",0);
[~,icon] = legend(m,{num2str(yyyy)},'FontSize',14);
icons = findobj(icon, 'type', 'line');
set(icons,'MarkerSize',12);
clear yyyy
clear icon*

ylabel('Mean % of Deployment Days','FontSize',22);
xlabel('Hotspot','FontSize',22);
%% Save figure.

grid on
grid minor
cd([fdir 'figures']);
exportgraphics(gcf,'figure_1a.png','Resolution',300);

cd([fdir 'figures'])
exportgraphics(gcf,'figure_S1.png','Resolution',300);
%% Clear

close gcf
clear ax* c* h* m M *LIMS
clear ans

clear b
close gcf
228 changes: 21 additions & 207 deletions code/matlab/sub_functions/figures/figure_S2.m
Original file line number Diff line number Diff line change
@@ -1,219 +1,33 @@
%% figure_S2.m
% Sub-function of Irish_Tuna.m; plot time at temperature
%% figure_S1
% Sub-function of Irish_Tuna.m; calculate residency of each tag in each
% region

%% Define temperature bins.
%% Run Table S2

bins.temp = [0,5,10,12,14,16,18,20,22,24,26,28,45]; % last bin is > 28 deg C
run table_S2

%% Load *TimeAtTemp.csv files.
%% Mean % of Deployment Days

cd([fdir 'data/time_at_temp'])
files = dir('*TimeAtTemp.csv');
b = bar(mean((table2array(tbl_S2(:,2:7))./sum(table2array(tbl_S2(:,2:7)),2))*100),'FaceColor','flat');
b.CData = cmap_r;

new = table();
TAT = table();
for i = 1:length(files)
new = readtable(files(i).name);
new.toppID = str2double(files(i).name(1:7)).*ones(height(new),1);
TAT = [TAT; new];
end
clear i
clear new
clear files
hold on

TAT(:,[1:2 15:16]) = [];
TAT.DateTime = datetime(TAT.year,TAT.month,TAT.day);
TAT(:,13:16) = [];
TAT = movevars(TAT, 'toppID', 'Before', 'Bin1');
TAT = movevars(TAT, 'DateTime', 'Before', 'Bin1');
errorbar(1:6,mean((table2array(tbl_S2(:,2:7))./sum(table2array(tbl_S2(:,2:7)),2))*100),[],std((table2array(tbl_S2(:,2:7))./sum(table2array(tbl_S2(:,2:7)),2))*100),'LineStyle','none','Color','k');

%% Load and bin WC *Series.csv files.
set(gca,'FontSize',20);
set(gca,'XTickLabel',{'CI','BoB','WEB','NB','Med','Outside'})
set(gca,"XTickLabelRotation",0);

cd([fdir 'data/time_at_depth/WC/series'])
files = dir('*Series.csv');
ylabel('Mean % of Deployment Days','FontSize',22);
xlabel('Hotspot','FontSize',22);

for i = 1:length(files)
tmp = readtable(files(i).name);
grid on
grid minor

dt = unique(tmp.Day);
dt = dt(dt <= max(META.Date(META.TOPPid == str2double(files(i).name(1:7)))));
for j = 1:length(dt)
TAT.toppID(end+1) = str2double(files(i).name(1:7));
TAT.DateTime(end) = dt(j);
TAT(end,3:end) = array2table(histcounts(tmp.Temperature(tmp.Day == dt(j)),'BinEdges',bins.temp)./sum(tmp.Day == dt(j)));
end
clear j
cd([fdir 'figures'])
exportgraphics(gcf,'figure_S1.png','Resolution',300);

clear dt
clear tmp
end
clear i
clear files
close gcf

%% Load and bin WC *Archive.csv files.

cd([fdir 'data/time_at_depth/WC/archive'])
files = dir('*Archive.csv');

for i = 1:length(files)
tmp = readtable(files(i).name);
tmp = tmp(:,[1 3]);
tmp.Properties.VariableNames = {'Time','Temperature'};
tmp.Day = datetime(year(tmp.Time),month(tmp.Time),day(tmp.Time));

dt = unique(tmp.Day);
dt = dt(dt <= max(META.Date(META.TOPPid == str2double(files(i).name(1:7)))));
for j = 1:length(dt)
TAT.toppID(end+1) = str2double(files(i).name(1:7));
TAT.DateTime(end) = dt(j);
TAT(end,3:end) = array2table(histcounts(tmp.Temperature(tmp.Day == dt(j)),'BinEdges',bins.temp)./sum(tmp.Day == dt(j)));
end
clear j

clear dt
clear tmp
end
clear i
clear files

%% Load and bin Lotek *_clean.csv files.

cd([fdir 'data/time_at_depth/Lotek'])
files = dir('*_clean.csv');

for i = 1:length(files)
tmp = readtable(files(i).name);
tmp = tmp(:,[1 5]);
tmp.Properties.VariableNames = {'Time','Temperature'};
tmp.Day = datetime(year(tmp.Time),month(tmp.Time),day(tmp.Time));

dt = unique(tmp.Day);
dt = dt(dt <= max(META.Date(META.TOPPid == str2double(files(i).name(1:7)))));
for j = 1:length(dt)
TAT.toppID(end+1) = str2double(files(i).name(1:7));
TAT.DateTime(end) = dt(j);
TAT(end,3:end) = array2table(histcounts(tmp.Temperature(tmp.Day == dt(j)),'BinEdges',bins.temp)./sum(tmp.Day == dt(j)));
end
clear j

clear dt
clear tmp
end
clear i
clear files

%% Identify tat Region, Season, Latitude and Longitude Based on Date

Season = zeros(height(TAT),1);
TAT = addvars(TAT,Season,'After','Bin12');
clear Season

Region = zeros(height(TAT),1);
TAT = addvars(TAT,Region,'After','Season');
clear Region

Latitude = zeros(height(TAT),1);
TAT = addvars(TAT,Latitude,'After','Region');
clear Latitude

Longitude = zeros(height(TAT),1);
TAT = addvars(TAT,Longitude,'After','Latitude');
clear Longitude

% Make dates same format dd-mm-yyyy.
tmp.tat.Date = datetime(year(TAT.DateTime),month(TAT.DateTime),day(TAT.DateTime));
tmp.META.Date = datetime(year(META.Date),month(META.Date),day(META.Date));

% Remove tat dates not in metatata.
TAT = TAT(ismember(tmp.tat.Date,tmp.META.Date),:);
tmp.tat.Date = tmp.tat.Date(ismember(tmp.tat.Date,tmp.META.Date),:);

for i = 1:height(META)
ind_time = find(tmp.tat.Date == tmp.META.Date(i));
ind_topp = find(TAT.toppID == META.TOPPid(i));

ind = intersect(ind_time,ind_topp);

TAT.Season(ind) = META.Season(i);
TAT.Region(ind) = META.Region(i);
TAT.Latitude(ind) = META.Latitude(i);
TAT.Longitude(ind) = META.Longitude(i);
end
clear i
clear ind*
clear tmp

%% Compute mean in each bin for each tag.

toppID = unique(TAT.toppID);

for i = 1:length(toppID)
cnt = 0;
for j = [2 3 4 1 5 0]
cnt = cnt + 1;
tat.stats.mean_per_tag(i,cnt,:) = mean(table2array(TAT(TAT.toppID == toppID(i) & TAT.Region == j, 3:14)).*100,'omitnan');
end
end
clear i
clear j
clear cnt

%% Plot tat

cnt = 0;
for i = [2 3 4 1 5 0] % each hotspot and outside hotspots

figure();

cnt = cnt + 1;

tat.stats.median_of_all_tags(cnt,:) = median(tat.stats.mean_per_tag(:,cnt,:),'omitnan');
tat.stats.mad_of_all_tags(cnt,:) = mad(tat.stats.mean_per_tag(:,cnt,:),1);

b = barh(tat.stats.median_of_all_tags(cnt,:));
b.EdgeColor = 'k';
b.FaceColor = cmap_r(cnt,:);
b.LineWidth = 1;

hold on

er = errorbar(tat.stats.median_of_all_tags(cnt,:),1:1:12,[],tat.stats.mad_of_all_tags(cnt,:),'horizontal');
er.Color = [0 0 0];
er.LineStyle = 'none';
er.LineWidth = 1;

set(gca,'ydir','normal','FontSize',16,'linewidth',2,'tickdir','out');
xlabel('Median % Time at Temperature','FontSize',20); ylabel('Temperature (^oC)','FontSize',20);
xlim([0 80]); set(gca,'XTick',0:5:80);
set(gca,'XTickLabel',{'0','','10','','20','','30','','40','','50','','60','','70','','80'});
set(gca,'XTickLabelRotation',0);
ylim([0 13]);
set(gca,'YTickLabels',{'0-5'; '5-10'; '10-12'; '12-14'; '14-16'; '16-18'; '18-20'; '20-22'; ...
'22-24'; '24-26'; '26-28'; '> 28'});
axis square
grid on

if i == 1
rg = 'd';
elseif i == 2
rg = 'a';
elseif i == 3
rg = 'b';
elseif i == 4
rg = 'c';
elseif i == 5
rg = 'e';
elseif i == 0
rg = 'f';
end

cd([fdir 'figures']);
exportgraphics(gcf,['figure_S2_' rg '.png'],'Resolution',300);

% close all

end
clear i
clear b
clear er
clear eg
clear b
Loading

0 comments on commit 1324612

Please sign in to comment.