Skip to content

Commit

Permalink
Plot start and end of transects in different colours
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchharley committed Jan 27, 2022
1 parent cd1a6bd commit 62e74a2
Show file tree
Hide file tree
Showing 15 changed files with 205 additions and 724 deletions.
58 changes: 58 additions & 0 deletions CSPgetParticipationStatistics.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
function out = CSPgetParticipationStatistics(site,startdate,enddate)

%Find path of DB file
CSPloadPaths
dbfile = fullfile([DB_path filesep 'CoastSnapDB.xlsx']);
[data,txt] = xlsread(dbfile,'database');
siteDB = CSPreadSiteDB(site); %Read metadata

%Read image times - make sure Excel format is as below
if isempty(strfind(txt{2,3},'PM'))||isempty(strfind(txt{2,3},'AM')) %if using AM/PM
imtimes = datenum(char(txt{2:end,3}),'dd/mm/yyyy HH:MM:SS AM');
else
imtimes = datenum(char(txt{2:end,3}),'dd/mm/yyyy HH:MM:SS'); %if using 24 hour clock
end

%Convert to GMT time
imtimesGMT = imtimes;
Idefault= find(strcmp(txt(2:end,4),siteDB.timezone.name)); %e.g. AEDT = Australian Eastern Daylight Time
imtimesGMT(Idefault) = imtimesGMT(Idefault)-siteDB.timezone.gmt_offset/24; %Subtract the offset in hours to convert to gmt time
Ialternative = find(strcmp(txt(2:end,4),siteDB.timezone.alternative.name)); %e.g. AEDT = Australian Eastern Daylight Time
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);

subtypes = {'Email','Facebook','Instagram','Twitter','App','Internal'};
dd = startdate:enddate;
M = NaN(length(dd),length(subtypes)); %Matrix of number of submissions for each type
for i = 1:length(dd)
J1 = find(floor(imtimesLocal)==dd(i)&strcmp(txt(2:end,1),site)&strcmp(txt(2:end,6),subtypes{1}));
J2 = find(floor(imtimesLocal)==dd(i)&strcmp(txt(2:end,1),site)&strcmp(txt(2:end,6),subtypes{2}));
J3 = find(floor(imtimesLocal)==dd(i)&strcmp(txt(2:end,1),site)&strcmp(txt(2:end,6),subtypes{3}));
J4 = find(floor(imtimesLocal)==dd(i)&strcmp(txt(2:end,1),site)&strcmp(txt(2:end,6),subtypes{4}));
J5=find(floor(apptimes)==dd(i));
J6 = find(floor(imtimesLocal)==dd(i)&strcmp(txt(2:end,1),site)&strcmp(txt(2:end,6),subtypes{6}));
M(i,1) = length(J1);
M(i,2) = length(J2);
M(i,3) = length(J3);
M(i,4) = length(J4);
M(i,5) = length(J5);
M(i,6) = length(J6);
end

out.dates = dd;
out.subtypes = subtypes;
out.stats_matrix = M;
2 changes: 1 addition & 1 deletion CSPloadPaths.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
%Mitch Harley, June 2018

%Load various paths
base_path = 'C:\Users\z2273773\Google Drive\CoastSnap\';
base_path = 'C:\Users\z2273773\OneDrive - UNSW (1)\CoastSnap\';
%base_path = 'D:\Google Drive\CoastSnap';
DB_path = fullfile(base_path,'Database'); %Path where database is located
image_path = fullfile(base_path,'Images'); %Path where all images are stored
Expand Down
2 changes: 2 additions & 0 deletions CSPmakeDayTimex.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ function CSPmakeDayTimex(site,matlabday1,matlabday2)
matlabtimes_vec = datevec(matlabtimes);
I = find(ismember(matlabtimes_vec(:,4),[7:18])); %Only use images between 8am and 6pm
matlabtimes = matlabtimes(I);
filenames = filenames(I);
filepaths = filepaths(I);
matlabdays = matlabday1:matlabday2;

for i = 1:length(matlabdays)
Expand Down
3 changes: 2 additions & 1 deletion CSPplotParticipationStatistics.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function CSPplotParticipationStatistics(site,startdate,enddate)
if length(h1)>=8
h1(8).FontSize = 10;
end
h = legend(subtypes,'Location','southoutside')%,'Orientation','horizontal');
h = legend(subtypes,'Location','southoutside');%,'Orientation','horizontal');
h.FontSize = 10;
title(h,'Submission type');
%title('Image submission type')
Expand All @@ -100,3 +100,4 @@ function CSPplotParticipationStatistics(site,startdate,enddate)
disp(['Average number of submissions per week is ' num2str(7*cN(end)/((1+(enddate-startdate))),'%0.1f')])



2 changes: 1 addition & 1 deletion CSPprocessEZDetach.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
CSPloadPaths

%Set timezone
timezone = 'AEST';
timezone = 'AEDT';


%Read files in directory
Expand Down
2 changes: 1 addition & 1 deletion CSPsetPaths.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
%Add relevant paths to Matlab
github_path = 'C:\Users\z2273773\OneDrive - UNSW\RESEARCH2\GitHub'; %Path where CIRN toolboxes (Coastsnap and Shoreline Mapping) are located
addpath(genpath(github_path))
addpath(genpath(github_path))
5 changes: 3 additions & 2 deletions CSPtagRegisteredImages.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%Insert site-specific data here
site = 'blacksmiths'
photoshoptemp_dir = 'C:\Users\z2273773\Desktop\blacksmiths\registered2294'; %Name of directory where you have saved your registered images from photoshop
photoshoptemp_dir = 'C:\Users\z2273773\Desktop\manly\New folder'; %Name of directory where you have saved your registered images from photoshop


%Now do processing
Expand All @@ -23,7 +23,8 @@
YL = ylim;
matlablocal = CSPepoch2LocalMatlab(str2num(out.epochtime),siteDB.timezone.gmt_offset);
tidelevel = CSPgetTideLevel(str2num(out.epochtime),site);
txt = ['Date: ' datestr(matlablocal,'yyyy/mm/dd') ' Time: ' datestr(matlablocal,'HH:MM') ' Contributor: ' out.user ' Tide level: ' num2str(tidelevel,'%0.2f') 'm AHD'];
user = strrep(out.user,'_','');
txt = ['Date: ' datestr(matlablocal,'yyyy/mm/dd') ' Time: ' datestr(matlablocal,'HH:MM') ' Contributor: ' user ' Tide level: ' num2str(tidelevel,'%0.2f') 'm AHD'];
h=text(XL(1)+0.02*diff(XL),YL(1)+0.02*diff(YL),txt,'color',0.2*[1 1 1]);
h.HorizontalAlignment = 'left';
h.FontSize = 12;
Expand Down
11 changes: 6 additions & 5 deletions CSPtagRegisteredImagesNoTide.m
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
%Insert site-specific data here
site = 'fourmile'
photoshoptemp_dir = 'C:\Users\z2273773\Desktop\fourmile\Registered'; %Name of directory where you have saved your registered images from photoshop

site = 'turimetta'
photoshoptemp_dir = 'C:\Users\z2273773\OneDrive - UNSW\RESEARCH2\GitHub\coastsnap\sites\DIYstation\Working\Registered'; %Name of directory where you have saved your registered images from photoshop
gmt_offset = 10;

%Now do processing
files = dir([photoshoptemp_dir filesep '*.jpg']);
siteDB = CSPreadSiteDB(site);
%siteDB = CSPreadSiteDB(site);
for i = 1:length(files)
i
fname = files(i).name(7:end-4) %Assumes that your exported files have the default 6-char identifyer from Photoshop
%fname = files(i).name;
%out = CSreadImageData(files(i).name)

out = CSPparseFilename(fname)
out.user = strrep(out.user,'_','');
I = imread(fullfile(photoshoptemp_dir,files(i).name));
width = 20;
ax_height = width*size(I,1)/size(I,2);
Expand All @@ -21,7 +22,7 @@
axis off
XL = xlim;
YL = ylim;
matlablocal = CSPepoch2LocalMatlab(str2num(out.epochtime),siteDB.timezone.gmt_offset);
matlablocal = CSPepoch2LocalMatlab(str2num(out.epochtime),gmt_offset);
%tidelevel = CSPgetTideLevel(str2num(out.epochtime),site);
txt = ['Date: ' datestr(matlablocal,'yyyy/mm/dd') ' Time: ' datestr(matlablocal,'HH:MM') ' Contributor: ' out.user ];
h=text(XL(1)+0.02*diff(XL),YL(1)+0.02*diff(YL),txt,'color',0.2*[1 1 1]);
Expand Down
6 changes: 3 additions & 3 deletions GUI/CSPGmakeShorelineChangePlot.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function CSPGmakeShorelineChangePlot(handles)
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,'color',colors(1,:))
plot(UV(:,1),UV(:,2),'linewidth',1.5,'color',colors(1,:))
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)
Expand All @@ -81,7 +81,7 @@ function CSPGmakeShorelineChangePlot(handles)
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,'color',colors(2,:))
plot(UV(:,1),UV(:,2),'linewidth',1.5,'color',colors(2,:))
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)
Expand All @@ -105,7 +105,7 @@ function CSPGmakeShorelineChangePlot(handles)
p(2,:) = p(2,:)-bw_corr;

h = legend(imtimes,'location','NorthEast');
h.FontSize = 8;
h.FontSize = 10;


%Plot time-series below
Expand Down
87 changes: 87 additions & 0 deletions GUI/CSPGmakeTransectFiles.asv
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
function CSPGmakeTransectFiles(handles)

CSPloadPaths
%Get data from handles
data = get(handles.oblq_image,'UserData');
data_plan = get(handles.plan_image,'UserData');

%First, check if image has already been rectified
fileparts = CSPparseFilename(data.fname);
rect_path = strrep(data.pname,'Processed','Rectified');
rect_path = strrep(rect_path,'Registered','Rectified'); %For Registered images
rect_name = strrep(data.fname,'snap','plan'); %Rectified is called plan to keep with Argus conventions
rect_name = strrep(rect_name,'timex','plan'); %For timex images
if ~exist(fullfile(rect_path,rect_name),'file')
ButtonName = warndlg('Image has not been rectified. To make a transect file you need to first rectify an image','Image has not been rectified');
else
helpdlg('Welcome to the Transect File Creator. To start, click on the area in the rectified image on right that evenly spans the beach and water. This forms the region of interest where shorelines can be detected.','Transect File Editor')
%h = impoly(handles.plan_image,'closed',1);
%ROI = getPosition(h);
ROI = drawpolygon(handles.plan_image,'InteractionsAllowed','none'); %Use drawpolygon as it is cleaner. Might have some issues if people dont have certain toolboxes or matlab versions?
helpdlg('Now click on area that approximates the coastline, start with the area closest to the station and moving away to the farfield. This will be used to determine the orientation of the transects.')
%h = impoly(handles.plan_image,'closed',0);
%sl = getPosition(h);
sl = drawpolyline(handles.plan_image,'Color','Green');
marker_dist = 5; %Spacings of the transects. Set niminally to 5m but could
%x = sl(:,1)';
%y = sl(:,2)';
x = sl.Position(:,1)';
y = sl.Position(:,2)';
dist_from_start = cumsum( [0, sqrt((x(2:end)-x(1:end-1)).^2 + (y(2:end)-y(1:end-1)).^2)] );
marker_locs = 0 : marker_dist : dist_from_start(end); %replace with specific distances if desired
marker_indices = interp1( dist_from_start, 1 : length(dist_from_start), marker_locs);
marker_base_pos = floor(marker_indices);
weight_second = marker_indices - marker_base_pos;
marker_x = x(marker_base_pos) .* (1-weight_second) + x(marker_base_pos+1) .* weight_second;
marker_y = y(marker_base_pos) .* (1-weight_second) + y(marker_base_pos+1) .* weight_second;
m = (marker_y(2:end)-marker_y(1:end-1))./(marker_x(2:end)-marker_x(1:end-1));
marker_locs(end) = []; %Needed to get alongshore distances correct
d = -500:0.1:500;
X = NaN(length(d),length(m));
Y = X;
for i = 1:length(marker_x)-1
tangent = -(1/m(i));
r = sqrt(1+tangent^2);
xx = marker_x(i)+d./r;
yy = marker_y(i)+d.*(tangent/r);
X(:,i) = xx';
Y(:,i) = yy';
end
%I = find(~inpolygon(X,Y,ROI(:,1),ROI(:,2)));
I = find(~inpolygon(X,Y,ROI.Position(:,1),ROI.Position(:,2))); %For when using drawpolygon
X(I) = NaN;
Y(I) = NaN;
X2ends = NaN(2,length(m));
Y2ends = NaN(2,length(m));
Icut = [];
for i = 1:length(m)
I = find(~isnan(X(:,i)));
if ~isempty(I)
X2ends(1,i) = X(I(1),i);
X2ends(2,i) = X(I(end),i);
Y2ends(1,i) = Y(I(1),i);
Y2ends(2,i) = Y(I(end),i);
hold on
plot(X2ends(:,i),Y2ends(:,i),'r')
else
Icut = [Icut i];
end
end
marker_locs(Icut) = [];
I = find(isnan(X2ends(1,:)));
X2ends(:,I) = [];
Y2ends(:,I) = [];
marker_locs(I) = [];
SLtransects.x = X2ends;
SLtransects.y = Y2ends;
SLtransects.alongshore_distances = marker_locs;

%Save transect file?
button = questdlg('Do you want to save this transect file?','Save transect file?','Yes','No','No');
switch button
case 'Yes'
savefname = inputdlg('Please write filename of transect file','Transect file name');
save([transect_dir filesep savefname{1} '.mat'],'SLtransects')
disp('Transect file has been saved! Please make sure you update the database accordingly')
end
end
2 changes: 2 additions & 0 deletions GUI/CSPGmakeTransectFiles.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ function CSPGmakeTransectFiles(handles)
X2ends(:,I) = [];
Y2ends(:,I) = [];
marker_locs(I) = [];
plot(X2ends(1,:),Y2ends(1,:),'ro')
plot(X2ends(2,:),Y2ends(2,:),'bo')
SLtransects.x = X2ends;
SLtransects.y = Y2ends;
SLtransects.alongshore_distances = marker_locs;
Expand Down
2 changes: 1 addition & 1 deletion GUI/CSPGmakeTrendPlot.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ 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));
else
elseif
slfile = strrep(slfile,'.mat','_registered.mat');
load(fullfile(sldir,slfile));
end
Expand Down
72 changes: 37 additions & 35 deletions GUI/CSPGmapShoreline.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function CSPGmapShoreline(handles)
disp('Shoreline chosen to not be mapped')
case 'Yes'
go = 1;
end
end
end

if go ==1
Expand All @@ -31,8 +31,8 @@ function CSPGmapShoreline(handles)

%Remove any existing shorelines plotted on the figure
if exist('data_plan.sl_handle_plan')

delete(data_plan.sl_handle_oblq);
delete(data_plan.sl_handle_oblq);
end

%Load transect dir from DB
Expand All @@ -42,37 +42,39 @@ function CSPGmapShoreline(handles)
addpath('../Shoreline-Mapping-Toolbox') %Relevant file (mapShorelineCCD.m) found in shoreline mapping toolbox
type = 'CCD'; %Only consider CCD here
if strcmp(type,'CCD')
sl = mapShorelineCCD(data_plan.xgrid,data_plan.ygrid,data_plan.Iplan,SLtransects,0,0); %Turn edit and plot mode off in GUI
elseif strcmp(type,'HUE')
sl = mapShorelineHUE(data_plan.xgrid,data_plan.ygrid,data_plan.Iplan,SLtransects,0,0);
sl = mapShorelineCCD(data_plan.xgrid,data_plan.ygrid,data_plan.Iplan,SLtransects,0,0); %Turn edit and plot mode off in GUI
elseif strcmp(type,'HUE')
sl = mapShorelineHUE(data_plan.xgrid,data_plan.ygrid,data_plan.Iplan,SLtransects,0,0);
end

%Add eastings and northings
out.whenDone = matlab2Epoch(now-siteDB.timezone.gmt_offset/24); %Get time when done in epochtime (similar to argus)
out.xyz = [sl.x sl.y metadata.rectz*ones(size(sl.x))]; %Output as a Mx3 matrix to be the same as
out.UTM = [sl.x+siteDB.origin.eastings sl.y+siteDB.origin.northings metadata.rectz*ones(size(sl.x))];
out.UTMzone = siteDB.UTMzone;
UV = findUVnDOF(metadata.geom.betas,out.xyz,metadata.geom); %Its good practise to store the original Image UV data of the shoreline so you don't have to redo the geometry
out.UV = reshape(UV,length(out.xyz),2);
out.method = sl.method;
out.threshold = sl.threshold;
out.QA = 1; %Boolean to say whether data has been QA'd or not (for autoshoreline mapping)
sl = out;
data_plan.sl = sl;


%Plot data on both oblq and plan image
axes(handles.plan_image)
hold on
sl_handle_plan = plot(sl.xyz(:,1),sl.xyz(:,2),'y','linewidth',4);
data_plan.sl_handle_plan = sl_handle_plan;
axes(handles.oblq_image)
hold on
sl_handle_oblq = plot(sl.UV(:,1),sl.UV(:,2),'y','linewidth',4);
data.sl_handle_oblq = sl_handle_oblq;

%Update user data
set(handles.plan_image,'UserData',data_plan);
set(handles.oblq_image,'UserData',data);
end

if ~isempty(sl.x) %if you couldnt get a shoreline

%Add eastings and northings
out.whenDone = matlab2Epoch(now-siteDB.timezone.gmt_offset/24); %Get time when done in epochtime (similar to argus)
out.xyz = [sl.x sl.y metadata.rectz*ones(size(sl.x))]; %Output as a Mx3 matrix to be the same as
out.UTM = [sl.x+siteDB.origin.eastings sl.y+siteDB.origin.northings metadata.rectz*ones(size(sl.x))];
out.UTMzone = siteDB.UTMzone;
UV = findUVnDOF(metadata.geom.betas,out.xyz,metadata.geom); %Its good practise to store the original Image UV data of the shoreline so you don't have to redo the geometry
out.UV = reshape(UV,length(out.xyz),2);
out.method = sl.method;
out.threshold = sl.threshold;
out.QA = 1; %Boolean to say whether data has been QA'd or not (for autoshoreline mapping)
sl = out;
data_plan.sl = sl;


%Plot data on both oblq and plan image
axes(handles.plan_image)
hold on
sl_handle_plan = plot(sl.xyz(:,1),sl.xyz(:,2),'y','linewidth',4);
data_plan.sl_handle_plan = sl_handle_plan;
axes(handles.oblq_image)
hold on
sl_handle_oblq = plot(sl.UV(:,1),sl.UV(:,2),'y','linewidth',4);
data.sl_handle_oblq = sl_handle_oblq;

%Update user data
set(handles.plan_image,'UserData',data_plan);
set(handles.oblq_image,'UserData',data);
end
end
1 change: 1 addition & 0 deletions GUI/CSPGrectifyImage.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

function out = CSPGrectifyImage(handles)

data = get(handles.oblq_image,'UserData'); %Get data stored in the userdata in the oblq_image handles
Expand Down
Loading

0 comments on commit 62e74a2

Please sign in to comment.