Skip to content

FixClustGUIAxes #148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Functions/Call Classification/CreateClusteringData.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
freqRange = [];
xFreq = [];
xTime = [];
FreqScale = [];
TimeScale = [];
stats.Power = [];

% Select the files
Expand Down Expand Up @@ -94,7 +96,7 @@
waitbar(i/height(Calls),h, sprintf('Loading File %u of %u', Calls.audiodata_index(i), length(fileName)));

% Change the audio file if needed
if Calls.audiodata_index(i) ~= currentAudioFile;
if Calls.audiodata_index(i) ~= currentAudioFile
audioReader.audiodata = audiodata{Calls.audiodata_index(i)};
currentAudioFile = Calls.audiodata_index(i);
perFileCallID = 0;
Expand Down Expand Up @@ -137,13 +139,16 @@
{perFileCallID} % Call ID in file
{stats.Power}
{box(4)}
{FreqScale}
{TimeScale}
{Calls.CallID(i)}
]'];

clustAssign = [clustAssign; Calls.Type(i)];
end


ClusteringData = cell2table(ClusteringData, 'VariableNames', {'Spectrogram', 'MinFreq', 'Duration', 'xFreq', 'xTime', 'Filename', 'callID', 'Power', 'Bandwidth'});
ClusteringData = cell2table(ClusteringData(:,1:12), 'VariableNames', {'Spectrogram', 'MinFreq', 'Duration', 'xFreq', 'xTime', 'Filename', 'callID', 'Power', 'Bandwidth','FreqScale','TimeScale','UserID'});

close(h)

Expand Down
9 changes: 7 additions & 2 deletions Functions/Call Classification/UpdateCluster.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@ function UpdateCluster(ClusteringData, clustAssign, clusterName, rejected)
% Find the index of the clustering data that belongs to the file
cluster_idx = find(file_idx == i);

% Find the index of the calls in the file that correspond the the clustering data
call_idx = [ClusteringData{cluster_idx, 7}];
if ismember('UserID',obj.ClusteringData.Properties.VariableNames)
% Find the index of the calls in the file that correspond the the clustering data
[~,call_idx] = ismember(ClusteringData{cluster_idx, 'UserID'},Calls.CallID);
else
warning('This will not assign clusters correctly if rejected Calls were not removed from your detections file.')
[~,call_idx] = ismember(ClusteringData{cluster_idx, 'callID'},Calls.CallID);
end

% Update call type with cluster names
Calls.Type(call_idx) = clustAssign(cluster_idx);
Expand Down
31 changes: 21 additions & 10 deletions Functions/Call Classification/clusteringGUI.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,14 @@
obj.ClusteringData = ClusteringData;
obj.rejected = zeros(1,length(obj.clustAssign));

obj.minfreq = prctile(ClusteringData.MinFreq, 5);
obj.maxfreq = prctile(ClusteringData.MinFreq + ClusteringData.Bandwidth, 95);
% obj.minfreq = prctile(ClusteringData.MinFreq, 5);
% obj.maxfreq = prctile(ClusteringData.MinFreq + ClusteringData.Bandwidth, 95);
%This is going to be scaled from 0 to the Nyquist, not the
%boxed call
obj.minfreq = 0;
%Assumes all calls in ClusteringData were recorded at the same
%SR
obj.maxfreq = size(ClusteringData.Spectrogram{1},1)*ClusteringData.FreqScale(1);
obj.ColorData = jet(256); % Color by mean frequency
% obj.ColorData = HSLuv_to_RGB(256, 'H', [270 0], 'S', 100, 'L', 75, 'type', 'HSL'); % Make a color map for each category
obj.ColorData = reshape(obj.ColorData,size(obj.ColorData,1),1,size(obj.ColorData,2));
Expand Down Expand Up @@ -220,8 +226,8 @@ function render_GUI(obj)
% Resize the image while maintaining the aspect ratio by
% padding with zeros
im_size = size(ClusteringData.Spectrogram{clustIndex(callID)}) ;
new_size = floor(im_size .* min(obj.thumbnail_size ./ im_size));
im = double(imresize(ClusteringData.Spectrogram{clustIndex(callID)}, new_size));
new_size = obj.thumbnail_size;
im = double(imresize(ClusteringData.Spectrogram{clustIndex(callID)}, obj.thumbnail_size));
pad = (obj.thumbnail_size - size(im)) / 2;
im = padarray(im, floor(pad), 'pre');
im = padarray(im, ceil(pad), 'post');
Expand All @@ -231,9 +237,12 @@ function render_GUI(obj)
rel_x = [rel_size(2), 1-rel_size(2)];
rel_y = [rel_size(1), 1-rel_size(1)];

% Apply color to the greyscale images
freqRange = [ClusteringData.MinFreq(clustIndex(callID)),...
ClusteringData.MinFreq(clustIndex(callID)) + ClusteringData.Bandwidth(clustIndex(callID))];
% % Apply color to the greyscale images
%this type of color scaling isn't applicable as is because
%all call images have the same frequency span
% freqRange = [ClusteringData.MinFreq(clustIndex(callID)),...
% ClusteringData.MinFreq(clustIndex(callID)) + ClusteringData.Bandwidth(clustIndex(callID))];
freqRange = [obj.minfreq, obj.maxfreq];
% Account for any padding on the y axis
freqRange = freqRange + range(freqRange) .* rel_y(1) .* [-1, 1];

Expand All @@ -249,14 +258,16 @@ function render_GUI(obj)
x_lim = xlim(axis_handles);
x_span = x_lim(2) - x_lim(1);
xtick_positions = linspace(x_span*rel_x(1)+x_lim(1), x_span*rel_x(2)+x_lim(1),4);
x_ticks = linspace(0,obj.ClusteringData.Duration(i),4);
%x_ticks = linspace(0,obj.ClusteringData.Duration(i),4);
x_ticks = linspace(0,size(obj.ClusteringData.Spectrogram{i},2)*obj.ClusteringData.TimeScale(i),4);
x_ticks = arrayfun(@(x) sprintf('%.3f',x),x_ticks(2:end),'UniformOutput',false);

y_lim = ylim(axis_handles);
y_span = y_lim(2) - y_lim(1);
ytick_positions = linspace(y_span*rel_y(1)+y_lim(1), y_span*rel_y(2)+y_lim(1),3);
ytick_positions = linspace(y_span*rel_y(1)+y_lim(1), y_span*rel_y(2)+y_lim(1),4);

y_ticks = linspace(obj.ClusteringData.MinFreq(i),obj.ClusteringData.MinFreq(i)+obj.ClusteringData.Bandwidth(i),3);
%y_ticks = linspace(obj.ClusteringData.MinFreq(i),obj.ClusteringData.MinFreq(i)+obj.ClusteringData.Bandwidth(i),3);
y_ticks = linspace(obj.minfreq,obj.maxfreq,4);
y_ticks = arrayfun(@(x) sprintf('%.1f',x),y_ticks(1:end),'UniformOutput',false);
y_ticks = flip(y_ticks);

Expand Down
3 changes: 2 additions & 1 deletion Functions/CreateFocusSpectrogram.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
s = handles.data.page_spect.s(:,handles.data.page_spect.t > call.Box(1) & handles.data.page_spect.t < sum(call.Box([1,3])));
ti = handles.data.page_spect.t( handles.data.page_spect.t > call.Box(1) & handles.data.page_spect.t < sum(call.Box([1,3])));
fr = handles.data.page_spect.f;

p = (1/(rate*(hamming(nfft)'*hamming(nfft))))*abs(s).^2;
p(2:end-1,:) = p(2:end-1,:).*2;
end

%% Get the part of the spectrogram within the box
Expand Down
2 changes: 1 addition & 1 deletion Functions/Network Training/TrainSqueakDetector.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
[detector,info] = trainYOLOv2ObjectDetector(TrainingTables,lgraph,options);
elseif nargin == 2
[detector,info] = trainYOLOv2ObjectDetector(TrainingTables,layers,options);
else
else
error('This should not happen');
end
end
Expand Down
7 changes: 7 additions & 0 deletions Functions/loadCallfile.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
error('This doesn''t appear to be a detection file!')
end

if ~any(strcmp('CallID', Calls.Properties.VariableNames)) || length(unique(Calls.CallID)) ~= height(Calls)
if length(unique(Calls.CallID)) ~= height(Calls)
warning('CallID not unique - replacing with 1:height(Calls)')
end
Calls.CallID = categorical(1:height(Calls))';
end

if isfield(data, 'audiodata')
audiodata = data.audiodata;
end
Expand Down