From 60435e567a9e38a7c47c2f0df21f3147e15d5e74 Mon Sep 17 00:00:00 2001 From: Brian S Miller <93690136+BrianSMiller@users.noreply.github.com> Date: Fri, 8 Sep 2023 21:54:40 +1000 Subject: [PATCH] Fixes issues #111 and fixes #112 (DIFAR module crashes and ability to use Deep Learning Detections in DIFAR module) (#110) * Bugfix for OverlayMarks Check for a null pointer exception in OverlayMarks that was causing a crash on startup. * Bugfix for null pointer in symbol manager Fix a bug that I found where the DIFAR module was crashing the symbol manager. Seems that this was due to this subclass of clip generator having a null value for it's uniqueName. I've fixed by checking for null values and assigning a generic symbol when null. * DeepLearning detections canGenerateClips=true Set flag in DeepLearning detector so that detections are considered 'clips' by Pamguard. This allows them to be processed automatically in the DIFAR Localisation module (and maybe others). * DIFAR: bugfix frequency limits for auto-detections Fix a bug in DIFAR module where the frequency limits of automated detections were not being set properly by the DIFAR module. * DeepLearning - Bugfix to detection duration Fix bug in deep learning detector where duration (in samples) was being set to number of samples in a hop instead of the number of samples in a segment. --- .../overlaymark/OverlayMarkProviders.java | 2 +- src/PamView/symbol/PamSymbolManager.java | 2 +- .../dataSelector/DataSelectorSettings.java | 2 ++ src/difar/DifarProcess.java | 14 +++++++++++--- .../dlClassification/DLClassifyProcess.java | 5 +++-- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/PamView/paneloverlay/overlaymark/OverlayMarkProviders.java b/src/PamView/paneloverlay/overlaymark/OverlayMarkProviders.java index a9d4611e..5bcc67ee 100644 --- a/src/PamView/paneloverlay/overlaymark/OverlayMarkProviders.java +++ b/src/PamView/paneloverlay/overlaymark/OverlayMarkProviders.java @@ -49,7 +49,7 @@ public class OverlayMarkProviders { continue; } String existingName = marker.getMarkerName(); - if (existingName.equals(nameToAdd)) { + if (existingName!=null && existingName.equals(nameToAdd)) { markProviders.remove(i); break; } diff --git a/src/PamView/symbol/PamSymbolManager.java b/src/PamView/symbol/PamSymbolManager.java index 96d74f46..440f3111 100644 --- a/src/PamView/symbol/PamSymbolManager.java +++ b/src/PamView/symbol/PamSymbolManager.java @@ -125,7 +125,7 @@ abstract public class PamSymbolManager implements Pa * This doesn't work since different displays will still need different options based on * their projector - so it can work, but need to set the projector. */ - if (managedSymbolData.useGeneric) { + if (managedSymbolData.useGeneric || displayName==null) { displayName = GENERICNAME; } diff --git a/src/PamguardMVC/dataSelector/DataSelectorSettings.java b/src/PamguardMVC/dataSelector/DataSelectorSettings.java index 7d593f4d..f29c8103 100644 --- a/src/PamguardMVC/dataSelector/DataSelectorSettings.java +++ b/src/PamguardMVC/dataSelector/DataSelectorSettings.java @@ -23,7 +23,9 @@ public class DataSelectorSettings implements Serializable, ManagedParameters { if (selectorParams == null) { selectorParams = new Hashtable<>(); } + if (name != null) { selectorParams.put(name, params); + } } /** diff --git a/src/difar/DifarProcess.java b/src/difar/DifarProcess.java index 694c4529..644da952 100644 --- a/src/difar/DifarProcess.java +++ b/src/difar/DifarProcess.java @@ -316,11 +316,19 @@ public class DifarProcess extends PamProcess { sP = difarControl.getDifarParameters().findSpeciesParams(difarDataUnit); } difarDataUnit.setDisplaySampleRate(sP.sampleRate); - if (!sP.useMarkedBandsForSpectrogramClips){ - double[] frequency = {sP.processFreqMin, sP.processFreqMax}; - difarDataUnit.setFrequency(frequency); + if (difarDataUnit.triggerName.equals(difarControl.getUnitName())) { // User detection + if (!sP.useMarkedBandsForSpectrogramClips ){ + double[] frequency = {sP.processFreqMin, sP.processFreqMax}; + difarDataUnit.setFrequency(frequency); + } + } else { //Check whether to override auto detection freq limits with DIFAR limits + if (!sP.useDetectionLimitsForTriggeredDetections ){ // Auto-detection + double[] frequency = {sP.processFreqMin, sP.processFreqMax}; + difarDataUnit.setFrequency(frequency); + } } + demuxDataUnit(difarDataUnit, demuxWorker, startTime); calculateDifarGram(difarDataUnit, demuxWorker, startTime); diff --git a/src/rawDeepLearningClassifier/dlClassification/DLClassifyProcess.java b/src/rawDeepLearningClassifier/dlClassification/DLClassifyProcess.java index 930377b1..aebed235 100644 --- a/src/rawDeepLearningClassifier/dlClassification/DLClassifyProcess.java +++ b/src/rawDeepLearningClassifier/dlClassification/DLClassifyProcess.java @@ -107,7 +107,8 @@ public class DLClassifyProcess extends PamInstantProcess { addOutputDataBlock(dlDetectionDataBlock); dlDetectionDataBlock.setNaturalLifetimeMillis(600*1000); //keep this data for a while. dlDetectionDataBlock.addDataAnnotationType(dlAnnotationType); - + //ClipGeneration allows processing of detections by DIFAR module (and possibly others) + dlDetectionDataBlock.setCanClipGenerate(true); //add custom graphics PamDetectionOverlayGraphics overlayGraphics = new DLGraphics(dlModelResultDataBlock); overlayGraphics.setDetectionData(true); @@ -483,7 +484,7 @@ public class DLClassifyProcess extends PamInstantProcess { DataUnitBaseData basicData = groupDataBuffer.get(0).getBasicData().clone(); basicData.setMillisecondDuration(1000.*rawdata[0].length/this.sampleRate); - basicData.setSampleDuration((long) (groupDataBuffer.size()*dlControl.getDLParams().sampleHop)); + basicData.setSampleDuration((long) (groupDataBuffer.size()*dlControl.getDLParams().rawSampleSize)); // System.out.println("Model result: " + modelResult.size()); DLDetection dlDetection = new DLDetection(basicData, rawdata);