-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Plot start and end of transects in different colours
- Loading branch information
1 parent
cd1a6bd
commit 62e74a2
Showing
15 changed files
with
205 additions
and
724 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
CSPloadPaths | ||
|
||
%Set timezone | ||
timezone = 'AEST'; | ||
timezone = 'AEDT'; | ||
|
||
|
||
%Read files in directory | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.