Skip to content

Commit

Permalink
Made some improvements to make trend plot
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchharley committed Jun 17, 2022
1 parent 98f6c2a commit fb1552e
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 66 deletions.
2 changes: 2 additions & 0 deletions CSPgetImageList.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
%mat files
folders = dir(fullfile(image_path,site,type));
epochtimes = [];
%filenames = [];
%filepaths = [];
p = 1;
for i = 1:length(folders)
if folders(i).isdir&&length(folders(i).name)==4 %folder is most likely a year here if it has length 4
Expand Down
32 changes: 19 additions & 13 deletions CSPgetParticipationStatistics.m
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
function out = CSPgetParticipationStatistics(site,startdate,enddate)
function out = CSPgetParticipationStatistics(site,startdate,enddate,rootID)

%Find path of DB file
CSPloadPaths
dbfile = fullfile([DB_path filesep 'CoastSnapDB.xlsx']);
exportfile = fullfile([DB_path filesep 'spotteron_export.xlsx']); %File exported from spotteron db, converted to Excel first
[data,txt] = xlsread(dbfile,'database');
siteDB = CSPreadSiteDB(site); %Read metadata

Expand All @@ -21,19 +22,24 @@
imtimesGMT(Ialternative) = imtimesGMT(Ialternative)-siteDB.timezone.alternative.gmt_offset/24; %Subtract the offset in hours to convert to default
imtimesLocal = imtimesGMT+siteDB.timezone.gmt_offset/24;

% %Get images coming from App not listed in DB
% [epochtimes,filenames,~,~] = CSPgetImageList(site,'Processed');
% I = NaN(length(epochtimes),1);
% for i = 1:length(epochtimes)
% Iapp = strfind(filenames(i).name,'+'); %If taken by app, filename has a + in it instead of AEST
% if isempty(Iapp)
% I(i) = 0;
% else
% I(i) = 1;
% end
% end
% Iapp = find(I==1);
% apptimes = CSPepoch2LocalMatlab(epochtimes(Iapp),siteDB.timezone.gmt_offset);

%Get images coming from App not listed in DB
[epochtimes,filenames,~,~] = CSPgetImageList(site,'Processed');
I = NaN(length(epochtimes),1);
for i = 1:length(epochtimes)
Iapp = strfind(filenames(i).name,'+'); %If taken by app, filename has a + in it instead of AEST
if isempty(Iapp)
I(i) = 0;
else
I(i) = 1;
end
end
Iapp = find(I==1);
apptimes = CSPepoch2LocalMatlab(epochtimes(Iapp),siteDB.timezone.gmt_offset);
[data1,txt1] = xlsread(exportfile);
Iroot = find(data1(:,2)==rootID); %RootID is 2nd column in export file
apptimes=datenum(char(txt1{Iroot+1,12}),'dd/mm/yyyy HH:MM:SS AM');

subtypes = {'Email','Facebook','Instagram','Twitter','App','Internal'};
dd = startdate:enddate;
Expand Down
32 changes: 19 additions & 13 deletions CSPplotParticipationStatistics.m
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
function CSPplotParticipationStatistics(site,startdate,enddate)
function CSPplotParticipationStatistics(site,startdate,enddate,rootID)

%Find path of DB file
CSPloadPaths
dbfile = fullfile([DB_path filesep 'CoastSnapDB.xlsx']);
exportfile = fullfile([DB_path filesep 'spotteron_export.xlsx']); %File exported from spotteron db, converted to Excel first
[data,txt] = xlsread(dbfile,'database');
siteDB = CSPreadSiteDB(site); %Read metadata

Expand All @@ -21,19 +22,24 @@ function CSPplotParticipationStatistics(site,startdate,enddate)
imtimesGMT(Ialternative) = imtimesGMT(Ialternative)-siteDB.timezone.alternative.gmt_offset/24; %Subtract the offset in hours to convert to default
imtimesLocal = imtimesGMT+siteDB.timezone.gmt_offset/24;

% %Get images coming from App not listed in DB
% [epochtimes,filenames,~,~] = CSPgetImageList(site,'Processed');
% I = NaN(length(epochtimes),1);
% for i = 1:length(epochtimes)
% Iapp = strfind(filenames(i).name,'+'); %If taken by app, filename has a + in it instead of AEST
% if isempty(Iapp)
% I(i) = 0;
% else
% I(i) = 1;
% end
% end
% Iapp = find(I==1);
% apptimes = CSPepoch2LocalMatlab(epochtimes(Iapp),siteDB.timezone.gmt_offset);
%Get images coming from App not listed in DB
[epochtimes,filenames,~,~] = CSPgetImageList(site,'Processed');
I = NaN(length(epochtimes),1);
for i = 1:length(epochtimes)
Iapp = strfind(filenames(i).name,'+'); %If taken by app, filename has a + in it instead of AEST
if isempty(Iapp)
I(i) = 0;
else
I(i) = 1;
end
end
Iapp = find(I==1);
apptimes = CSPepoch2LocalMatlab(epochtimes(Iapp),siteDB.timezone.gmt_offset);

[data1,txt1] = xlsread(exportfile);
Iroot = find(data1(:,2)==rootID); %RootID is 2nd column in export file
apptimes=datenum(char(txt1{Iroot+1,12}),'dd/mm/yyyy HH:MM:SS AM');

dd = startdate:enddate;
for i = 1:length(dd)
Expand Down
2 changes: 2 additions & 0 deletions GUI/CSPGmakeBeachWidthAnimation.m
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ function CSPGmakeBeachWidthAnimation(handles)
plot(dates,f(dates),'color','k','linewidth',1)
xlim([min(dates) max(dates)])
datetick('x','keeplimits')
set(gca,'ygrid','on')
set(gca,'xgrid','on')
ylabel('Beach width (m)','fontsize',11)
YL = ylim;
XL = xlim;
Expand Down
8 changes: 7 additions & 1 deletion GUI/CSPGmakeShorelineChangePlot.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ function CSPGmakeShorelineChangePlot(handles)
slfile = strrep(navfiles(Icommon(Iprev)).name,'snap','shoreline');
slfile = strrep(slfile,'timex','shoreline');
slfile = strrep(slfile,'.jpg','.mat');
load(fullfile(sldir,slfile));
if exist(fullfile(sldir,slfile)) %Catch in case shoreline was mapped on registered image
load(fullfile(sldir,slfile));
else
slfile = strrep(slfile,'.mat','_registered.mat');
load(fullfile(sldir,slfile));
end
%load(fullfile(sldir,slfile));
UV = findUVnDOF(metadata.geom.betas,sl.xyz,metadata.geom);
UV = reshape(UV,length(sl.xyz),2);
plot(UV(:,1),UV(:,2),'linewidth',1.5,'color',colors(1,:))
Expand Down
103 changes: 64 additions & 39 deletions GUI/CSPGmakeTrendPlot.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function CSPGmakeTrendPlot(handles)
trendinterval = str2num(get(handles.trendinterval,'String')); %In days (usually 6 weeks)
trendinterval_seconds = trendinterval*3600*24;
slope = data.siteDB.sl_settings.beach_slope;
sl_cutoff = 8;

%Get shoreline list for site
[slepochs,slfiles,slpaths,sltide] = CSPgetShorelineList(data.site);
Expand Down Expand Up @@ -45,14 +46,6 @@ function CSPGmakeTrendPlot(handles)
imtimes = cell(length(Icommon),1);
p =NaN(length(Icommon),length(transect_nos)); %beach width matrix to calculate alongshore-average beach width based on defined transects

%If more than 8 shorelines, plot shorelines differently
if length(Icommon)>8
colors = ones(length(Icommon),3)*0; %Make all colours black
colors2 = distinguishable_colors(4)
colors(1,:) = colors2(1,:);
colors(end,:) = colors2(end,:);
end

%Plot shorelines
for i = 1:length(Icommon)
imdata = CSPparseFilename(navfiles(Icommon(i)).name);
Expand All @@ -63,17 +56,21 @@ function CSPGmakeTrendPlot(handles)
slfile = strrep(slfile,'.jpg','.mat');
if exist(fullfile(sldir,slfile)) %Catch in case shoreline was mapped on registered image
load(fullfile(sldir,slfile));
elseif
else
slfile = strrep(slfile,'.mat','_registered.mat');
load(fullfile(sldir,slfile));
end
UV = findUVnDOF(metadata.geom.betas,sl.xyz,metadata.geom);
UV = reshape(UV,length(sl.xyz),2);
plot(UV(:,1),UV(:,2),'linewidth',1,'color',colors(i,:))

if length(Icommon)<sl_cutoff %Only plot shorelines if < sl_cutoff
UV = findUVnDOF(metadata.geom.betas,sl.xyz,metadata.geom);
UV = reshape(UV,length(sl.xyz),2);
plot(UV(:,1),UV(:,2),'linewidth',1,'color',colors(i,:))
end

for j = 1:length(transect_nos)
[x_int,y_int] = polyxpoly(sl.xyz(:,1),sl.xyz(:,2),SLtransects.x(:,transect_nos(j)),SLtransects.y(:,transect_nos(j)));
if ~isempty(x_int)
p(i,j) = sqrt((x_int-SLtransects.x(1,transect_nos(j)))^2+(y_int-SLtransects.y(1,transect_nos(j)))^2);
p(i,j) = sqrt((x_int(1)-SLtransects.x(1,transect_nos(j)))^2+(y_int(1)-SLtransects.y(1,transect_nos(j)))^2);
else
disp(['Warning: shoreline does not intersect with transect number ' num2str(transect_nos(j)) ' for date ' imtimes{i}])
end
Expand All @@ -83,26 +80,67 @@ function CSPGmakeTrendPlot(handles)
bw_corr = (0-sl.xyz(1,3))/slope; %now project to MSL instead of tide level from first image. %Slope taken from characteristic beach slope in CoastSnapDB
p(i,:) = p(i,:)-bw_corr;
end
av_bw = nanmean(p');
[~,Imin] = min(av_bw);
[~,Imax] = max(av_bw);
Iall = [1 Imin Imax length(av_bw)];

if length(Icommon)<8
if length(Icommon)<sl_cutoff
h = legend(imtimes,'location','NorthEast');
h.FontSize = 8;
h.FontSize = 8;
else
for i = 1:length(Iall)
imdata = CSPparseFilename(navfiles(Icommon(Iall(i))).name);
%imtimes{i} = datestr(CSPepoch2LocalMatlab(str2num(imdata.epochtime),data.siteDB.timezone.gmt_offset),'dd/mm/yyyy');
sldir = fullfile(shoreline_path,imdata.site,imdata.year);
slfile = strrep(navfiles(Icommon(Iall(i))).name,'snap','shoreline');
slfile = strrep(slfile,'timex','shoreline');
slfile = strrep(slfile,'.jpg','.mat');
if exist(fullfile(sldir,slfile)) %Catch in case shoreline was mapped on registered image
load(fullfile(sldir,slfile));
else
slfile = strrep(slfile,'.mat','_registered.mat');
load(fullfile(sldir,slfile));
end
UV = findUVnDOF(metadata.geom.betas,sl.xyz,metadata.geom);
UV = reshape(UV,length(sl.xyz),2);
plot(UV(:,1),UV(:,2),'linewidth',1,'color',colors(i,:))
end
end

h = legend(['Initial width = ' num2str(av_bw(1),'%0.1f') ' m (' imtimes{1} ')'],['Min. width = ' num2str(av_bw(Imin),'%0.1f') ' m (' imtimes{Imin} ')'],['Max. width = ' num2str(av_bw(Imax),'%0.1f') ' m (' imtimes{Imax} ')'],['Latest width = ' num2str(av_bw(end),'%0.1f') ' m (' imtimes{end} ')']);


%Plot time-series below
ver_mar2 = [ver_mar(1)+ax_height+plot_gap plot_bot];
hor_mar2 = [1.5 width/2];
geomplot(1,1,1,1,width,ax_height2,hor_mar2,ver_mar2,mid_mar)
dates = datenum(imtimes,'dd/mm/yyyy');
av_bw = nanmean(p');
for i = 1:length(dates)
plot(dates(i),av_bw(i),'.','markersize',20,'color',colors(i,:))
hold on
if length(Icommon)<sl_cutoff
for i = 1:length(dates)
plot(dates(i),av_bw(i),'.','markersize',20,'color',colors(i,:))
hold on
end
else
plot(dates,av_bw,'.','color',0.7*[1 1 1],'markersize',15)
hold on
plot(dates(1),av_bw(1),'.','color',colors(1,:),'markersize',15)
plot(dates(Imin),av_bw(Imin),'.','color',colors(2,:),'markersize',15)
plot(dates(Imax),av_bw(Imax),'.','color',colors(3,:),'markersize',15)
plot(dates(end),av_bw(end),'.','color',colors(4,:),'markersize',15)
end
alpha = polyfit(dates,av_bw',1);
plot([min(dates)-5 max(dates)+5],polyval(alpha,[min(dates)-5 max(dates)+5]),'linewidth',2,'color',0.7*[1 1 1])
YL1 = interp1([0:5:400],[0:5:400],min(av_bw)-5,'nearest');
YL2 = interp1([0:5:400],[0:5:400],max(av_bw)+5,'nearest');
texttype = 'Beach width trend';
units = ' metres/year';
if alpha(1)>0
value = num2str(alpha(1)*365.25,'+%0.2f'); %Convert to metres/year
textcolor = 'g';
elseif alpha(1)<0
value = num2str(alpha(1)*365.25,'%0.2f'); %Convert to metres/year
textcolor = 'r';
end
plot([min(dates)-5 max(dates)+5],polyval(alpha,[min(dates)-5 max(dates)+5]),'linewidth',2,'color','k')
YL1 = interp1([-100:5:400],[-100:5:400],min(av_bw)-5,'nearest');
YL2 = interp1([-100:5:400],[-100:5:400],max(av_bw)+5,'nearest');
XL1 = min(dates)-7;
XL2 = max(dates)+7;
xlim([XL1 XL2])
Expand All @@ -121,22 +159,9 @@ function CSPGmakeTrendPlot(handles)
set(gca,'xgrid','on')
XL = xlim;
YL = ylim;
if alpha(1)>0
text(XL(2)+0.1*diff(XL),YL(1)+0.7*diff(YL),'Beach width trend','fontsize',20,'color','b','fontname','Berlin Sans FB');
if (XL2-XL1)<365.25
text(XL(2)+0.1*diff(XL),YL(1)+0.45*diff(YL),['+' num2str(alpha(1)*7,'%0.2f') ' metres/week'],'fontsize',20,'color','g','fontname','Berlin Sans FB')
else
text(XL(2)+0.1*diff(XL),YL(1)+0.45*diff(YL),['+' num2str(alpha(1)*365.25,'%0.2f') ' metres/year'],'fontsize',20,'color','g','fontname','Berlin Sans FB')
end
else
text(XL(2)+0.1*diff(XL),YL(1)+0.7*diff(YL),'Beach width trend','fontsize',20,'color','b','fontname','Berlin Sans FB');
if (XL2-XL1)<365.25
text(XL(2)+0.1*diff(XL),YL(1)+0.45*diff(YL),[num2str(alpha(1)*7,'%0.2f') ' metres/week'],'fontsize',20,'color','r','fontname','Berlin Sans FB')
else
text(XL(2)+0.1*diff(XL),YL(1)+0.45*diff(YL),[num2str(alpha(1)*365.25,'%0.2f') ' metres/year'],'fontsize',20,'color','r','fontname','Berlin Sans FB')
end
end

text(XL(2)+0.1*diff(XL),YL(1)+0.7*diff(YL),texttype,'fontsize',20,'color','b','fontname','Berlin Sans FB');
text(XL(2)+0.1*diff(XL),YL(1)+0.45*diff(YL),[value units],'fontsize',20,'color',textcolor,'fontname','Berlin Sans FB')

%Put coastsnap logo
Ics = imread('CoastSnap Logo Portrait.png');
ax_height3 = 0.7*ax_height2;
Expand Down

0 comments on commit fb1552e

Please sign in to comment.