Merge pull request #20 from PAMGuard/main

Get CTD bug fix
This commit is contained in:
Douglas Gillespie 2022-09-27 16:57:54 +01:00 committed by GitHub
commit 481315187f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 126 additions and 27 deletions

View File

@ -16,5 +16,6 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="lib" path="/X3/src/org"/>
<classpathentry kind="output" path="target/classes"/> <classpathentry kind="output" path="target/classes"/>
</classpath> </classpath>

View File

@ -45,6 +45,14 @@ public class PamAudioSystem {
} }
} }
else if (file != null && isSudFile(file)) {
try {
return new SudAudioFileReader().getAudioInputStream(file);
}
catch (UnsupportedAudioFileException e) {
}
}
try { try {
return AudioSystem.getAudioInputStream(file); return AudioSystem.getAudioInputStream(file);
} }
@ -77,4 +85,20 @@ public class PamAudioSystem {
return (end.equals(".flac")); return (end.equals(".flac"));
} }
/**
* Check whether a file is a .sud file. This is the file format used
* by SoundTraps which contains X3 compressed data.
* @param file - the file to check.
* @return true if a .sud file.
*/
private static boolean isSudFile(File file) {
String name = file.getName();
if (name.length() < 5) {
return false;
}
String end = name.substring(name.length()-5).toLowerCase();
return (end.equals(".sud"));
}
} }

View File

@ -0,0 +1,23 @@
package Acquisition.pamAudio;
import java.io.File;
import java.io.IOException;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.UnsupportedAudioFileException;
/**
* Audio file reader for a .sud file. .sud files are a file format used by SoundTraps which contain
* blocks of X3 compressed data.
* @author Jamie Macaulay
*
*/
public class SudAudioFileReader {
public AudioInputStream getAudioInputStream(File file) throws UnsupportedAudioFileException, IOException {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -79,6 +79,8 @@ public class WavFileInputStream extends AudioInputStream {
return new WavFileInputStream(wavHeader, inputStream, audioFormat, nFrames); return new WavFileInputStream(wavHeader, inputStream, audioFormat, nFrames);
} }
static AudioFormat.Encoding getEncoding(int formatCode) { static AudioFormat.Encoding getEncoding(int formatCode) {
switch (formatCode) { switch (formatCode) {
case 1: case 1:

View File

@ -15,6 +15,7 @@ public class PamAudioFileFilter extends PamFileFilter {
// addFileType(".AIFF"); // addFileType(".AIFF");
// addFileType(".FLAC"); // addFileType(".FLAC");
addFileType(".flac"); addFileType(".flac");
addFileType(".sud");
} }
} }

View File

@ -22,7 +22,8 @@ public class CTClassifierParams implements Cloneable, Serializable, ManagedParam
public CTClassifierParams() { public CTClassifierParams() {
// this.uniqueID = UUID.randomUUID().toString(); // see comment below //this.uniqueID = UUID.randomUUID().toString();
//System.out.println("Create classifier params: " + uniqueID);
} }
@ -32,13 +33,10 @@ public class CTClassifierParams implements Cloneable, Serializable, ManagedParam
public String classifierName = ""; public String classifierName = "";
// /** /**
// * A unique ID for the classifier that never changes. This is important for accessing data selectors. * A unique ID for the classifier that never changes. This is important for accessing data selectors.
// * GET RID OF THIS, Every time you make a new set of params you get a new ID and it then creates a new */
// * classifier selector with default settings, so the classifier selectors never work. public String uniqueID = UUID.randomUUID().toString();
// Classifier selectors need to be names on something that's not oging to change, so the module name and the classifier species ame.
// */
// public String uniqueID;
/** /**

View File

@ -17,6 +17,7 @@ public class BearingClassifierParams extends CTClassifierParams implements Manag
public BearingClassifierParams(){ public BearingClassifierParams(){
super(); super();
type = CTClassifierType.BEARINGCLASSIFIER; type = CTClassifierType.BEARINGCLASSIFIER;
//System.out.println("Bearing classifier params");
} }
/** /**

View File

@ -11,6 +11,8 @@ public class IDIClassifierParams extends CTClassifierParams implements Serializa
public IDIClassifierParams(){ public IDIClassifierParams(){
super(); super();
type = CTClassifierType.IDICLASSIFIER; type = CTClassifierType.IDICLASSIFIER;
//System.out.println("IDI classifier params: " + this);
} }
/** /**

View File

@ -44,7 +44,7 @@ public class Chi2ThresholdClassifier implements CTClassifier {
public Chi2ThresholdClassifier(ClickTrainControl clickTrainControl, int defaultSpeciesID) { public Chi2ThresholdClassifier(ClickTrainControl clickTrainControl, int defaultSpeciesID) {
this.clickTrainControl=clickTrainControl; this.clickTrainControl=clickTrainControl;
clssfrParams.speciesFlag=defaultSpeciesID; clssfrParams.speciesFlag=defaultSpeciesID;
createDataSelector(clickTrainControl.getParentDataBlock()); //createDataSelector(clickTrainControl.getParentDataBlock());
} }
@ -110,12 +110,15 @@ public class Chi2ThresholdClassifier implements CTClassifier {
} }
/** /**
* Get the data selector. * Get the data selector.
* @param source - the source data block * @param source - the source data block
* @return the data selector. * @return the data selector.
*/ */
public void createDataSelector(PamDataBlock<?> source) { public void createDataSelector(PamDataBlock<?> source) {
//System.out.println("Create data selector " +" " + clssfrParams.classifierName + " " + clssfrParams.speciesFlag + " " + clssfrParams.uniqueID );
if (dataSelector==null || dataSelector.getPamDataBlock()!=source) { if (dataSelector==null || dataSelector.getPamDataBlock()!=source) {
//create the data selector //create the data selector
//System.out.println("Data selector: " + dataSelector); //System.out.println("Data selector: " + dataSelector);
@ -123,7 +126,6 @@ public class Chi2ThresholdClassifier implements CTClassifier {
dataSelector=source.getDataSelectCreator().getDataSelector(clickTrainControl.getUnitName() + "_" + clssfrParams.classifierName dataSelector=source.getDataSelectCreator().getDataSelector(clickTrainControl.getUnitName() + "_" + clssfrParams.classifierName
+ "_X2_threshold_classifier", false, null); + "_X2_threshold_classifier", false, null);
//System.out.println("Data selector: " + dataSelector);
} }
else { else {
dataSelector=null; dataSelector=null;
@ -198,7 +200,6 @@ public class Chi2ThresholdClassifier implements CTClassifier {
@Override @Override
public void setParams(CTClassifierParams ctClassifierParams) { public void setParams(CTClassifierParams ctClassifierParams) {
// TODO Auto-generated method stub
this.clssfrParams=(Chi2ThresholdParams) ctClassifierParams; this.clssfrParams=(Chi2ThresholdParams) ctClassifierParams;
} }

View File

@ -20,6 +20,7 @@ public class Chi2ThresholdParams extends CTClassifierParams implements ManagedPa
public Chi2ThresholdParams(){ public Chi2ThresholdParams(){
super(); super();
super.type=CTClassifierType.CHI2THRESHOLD; super.type=CTClassifierType.CHI2THRESHOLD;
//System.out.println("Chi2thrwesh classifier params: " + this);
} }
/** /**

View File

@ -74,7 +74,7 @@ public class StandardClassifier implements CTClassifier {
private void createClassifiers() { private void createClassifiers() {
classifiers = new ArrayList<CTClassifier>(); classifiers = new ArrayList<CTClassifier>();
//System.out.println("------CREATE CLASSIFIERS: -------");
//do this so that is CLASSIFIER_TYPES changes order things still work. //do this so that is CLASSIFIER_TYPES changes order things still work.
for (int i=0; i<CLASSIFIER_TYPES.length; i++) { for (int i=0; i<CLASSIFIER_TYPES.length; i++) {
@ -104,6 +104,7 @@ public class StandardClassifier implements CTClassifier {
*/ */
private void setClassifierParams() { private void setClassifierParams() {
if (standardClssfrParams.ctClassifierParams ==null || standardClssfrParams.ctClassifierParams.length != classifiers.size()) { if (standardClssfrParams.ctClassifierParams ==null || standardClssfrParams.ctClassifierParams.length != classifiers.size()) {
standardClssfrParams.ctClassifierParams = new CTClassifierParams[classifiers.size()]; standardClssfrParams.ctClassifierParams = new CTClassifierParams[classifiers.size()];
standardClssfrParams.enable = new boolean[classifiers.size()]; standardClssfrParams.enable = new boolean[classifiers.size()];
@ -119,6 +120,11 @@ public class StandardClassifier implements CTClassifier {
standardClssfrParams.ctClassifierParams[i] = classifiers.get(i).getParams(); standardClssfrParams.ctClassifierParams[i] = classifiers.get(i).getParams();
} }
else { else {
//set the current species ID and name for convenience
standardClssfrParams.ctClassifierParams[i].classifierName=standardClssfrParams.classifierName;
standardClssfrParams.ctClassifierParams[i].speciesFlag=standardClssfrParams.speciesFlag;
//the standard classifier should have settings set. //the standard classifier should have settings set.
classifiers.get(i).setParams(standardClssfrParams.ctClassifierParams[i]); classifiers.get(i).setParams(standardClssfrParams.ctClassifierParams[i]);
} }

View File

@ -33,6 +33,7 @@ public class StandardClassifierParams extends CTClassifierParams {
///very important to set this or else the clasifier manager does not ///very important to set this or else the clasifier manager does not
//know which classifier to create. //know which classifier to create.
type = CTClassifierType.STANDARDCLASSIFIER; type = CTClassifierType.STANDARDCLASSIFIER;
//System.out.println("Standard classifier params: " + this);
} }

View File

@ -26,6 +26,7 @@ public class TemplateClassifierParams extends CTClassifierParams implements Mana
super.type=CTClassifierType.TEMPLATECLASSIFIER; super.type=CTClassifierType.TEMPLATECLASSIFIER;
// chi2ThresholdParams = new Chi2ThresholdParams(); // chi2ThresholdParams = new Chi2ThresholdParams();
// template = DefualtSpectrumTemplates.getTemplate(SpectrumTemplateType.BEAKED_WHALE); // template = DefualtSpectrumTemplates.getTemplate(SpectrumTemplateType.BEAKED_WHALE);
//System.out.println("Template classifier params: " + this);
} }

View File

@ -76,6 +76,8 @@ public class SimpleCTClassifierPane extends SettingsPane<Chi2ThresholdParams> {
*/ */
private ControlField<Double> minPercClicks; private ControlField<Double> minPercClicks;
private Chi2ThresholdParams currParams;
public SimpleCTClassifierPane(Chi2ThresholdClassifier simpleChi2Classifier) { public SimpleCTClassifierPane(Chi2ThresholdClassifier simpleChi2Classifier) {
super(null); super(null);
this.simpleChi2Classifier=simpleChi2Classifier; this.simpleChi2Classifier=simpleChi2Classifier;
@ -214,6 +216,9 @@ public class SimpleCTClassifierPane extends SettingsPane<Chi2ThresholdParams> {
public Chi2ThresholdParams getParams(Chi2ThresholdParams currParams) { public Chi2ThresholdParams getParams(Chi2ThresholdParams currParams) {
//System.out.println("Get PERC spinner value; " + minPercClicks.getSpinner().getValue()); //System.out.println("Get PERC spinner value; " + minPercClicks.getSpinner().getValue());
//System.out.println("Chi2 pane get params: " + this.currParams.speciesFlag + " " + this.currParams.uniqueID + " " + this.currParams);
currParams.chi2Threshold=chi2Threshold.getSpinner().getValue(); currParams.chi2Threshold=chi2Threshold.getSpinner().getValue();
//HACK - for some reason Integer spinner is returning a double //HACK - for some reason Integer spinner is returning a double
currParams.minClicks=minClicks.getSpinner().getValue().intValue(); currParams.minClicks=minClicks.getSpinner().getValue().intValue();
@ -224,17 +229,25 @@ public class SimpleCTClassifierPane extends SettingsPane<Chi2ThresholdParams> {
simpleChi2Classifier.getDataSelector().getDialogPaneFX().getParams(true); simpleChi2Classifier.getDataSelector().getDialogPaneFX().getParams(true);
} }
return currParams; currParams.uniqueID = this.currParams.uniqueID;
return currParams=this.currParams;
} }
@Override @Override
public void setParams(Chi2ThresholdParams input) { public void setParams(Chi2ThresholdParams input) {
this.currParams = input;
//System.out.println("Chi2 pane set params: " + this.currParams.speciesFlag + " " + currParams.uniqueID + " " + currParams);
chi2Threshold.getSpinner().getValueFactory().setValue(input.chi2Threshold); chi2Threshold.getSpinner().getValueFactory().setValue(input.chi2Threshold);
//HACK - for some reason Integer spinner is returning a double //HACK - for some reason Integer spinner is returning a double
minClicks.getSpinner().getValueFactory().setValue((double) input.minClicks); minClicks.getSpinner().getValueFactory().setValue((double) input.minClicks);
minTime.getSpinner().getValueFactory().setValue(input.minTime); minTime.getSpinner().getValueFactory().setValue(input.minTime);
minPercClicks.getSpinner().getValueFactory().setValue(input.minPercentage*100.); minPercClicks.getSpinner().getValueFactory().setValue(input.minPercentage*100.);
} }
@Override @Override

View File

@ -64,7 +64,6 @@ public class StandardClassifierGraphics implements CTClassifierGraphics {
@Override @Override
public void setParams(CTClassifierParams params) { public void setParams(CTClassifierParams params) {
standardClassifierPane.setParams((StandardClassifierParams) params); standardClassifierPane.setParams((StandardClassifierParams) params);
} }
} }

View File

@ -84,7 +84,15 @@ public class StandardClassifierPane extends SettingsPane<StandardClassifierPara
@Override @Override
public void setParams(StandardClassifierParams input) { public void setParams(StandardClassifierParams input) {
for (int i=0; i<standardClassifier.getClassifiers().size(); i++) { for (int i=0; i<standardClassifier.getClassifiers().size(); i++) {
standardClassifier.getClassifiers().get(i).setParams(input.ctClassifierParams[i]);
/**
* It is important to set this here because otherwise the params can be out of sync with the classifer class. Usually this
* is not an issue because they are set later, however, if there is a paramter that does not have a correpsonding UI control, then
* this may change back to default - thus we have to explicitlly set here. (Note this caused issues with the uniqueID data selector string)
*/
standardClassifier.getClassifiers().get(i).getCTClassifierGraphics().setParams(input.ctClassifierParams[i]); standardClassifier.getClassifiers().get(i).getCTClassifierGraphics().setParams(input.ctClassifierParams[i]);
enableSwitch[i].setSelected(input.enable[i]); enableSwitch[i].setSelected(input.enable[i]);
disableClassifierPane(i); disableClassifierPane(i);
} }

View File

@ -65,8 +65,6 @@ public class AmplitudeChi2AdvPane extends AdvMHTVarPane {
@Override @Override
public AmplitudeChi2Params getParams(SimpleChi2VarParams currParams) { public AmplitudeChi2Params getParams(SimpleChi2VarParams currParams) {
System.out.println("Get params: AMPLITUDE");
AmplitudeChi2Params newParams = new AmplitudeChi2Params(super.getParams(currParams)); AmplitudeChi2Params newParams = new AmplitudeChi2Params(super.getParams(currParams));
newParams.maxAmpJump = ampJumpSpinner.getValue(); newParams.maxAmpJump = ampJumpSpinner.getValue();

Binary file not shown.

View File

@ -27,8 +27,8 @@ public class DLLocalisation extends AbstractLocalisation {
this.angles = bearingAnnotation.getBearingLocalisation().getAngles(); this.angles = bearingAnnotation.getBearingLocalisation().getAngles();
this.setSubArrayType(bearingAnnotation.getBearingLocalisation().getSubArrayType()); this.setSubArrayType(bearingAnnotation.getBearingLocalisation().getSubArrayType());
System.out.println("Loc content!: " + this.getLocContents().hasLocContent(LocContents.HAS_AMBIGUITY) + " angles: " + angles.length); //System.out.println("Loc content!: " + this.getLocContents().hasLocContent(LocContents.HAS_AMBIGUITY) + " angles: " + angles.length);
PamUtils.PamArrayUtils.printArray(angles); //PamUtils.PamArrayUtils.printArray(angles);
} }
@Override @Override

View File

@ -58,7 +58,7 @@ public abstract class DLTaskThread extends Thread {
for (int i =0; i<modelResult.size(); i++) { for (int i =0; i<modelResult.size(); i++) {
// modelResult.get(i).setClassNameID(getClassNameIDs()); // modelResult.get(i).setClassNameID(getClassNameIDs());
// modelResult.get(i).setBinaryClassification(isBinaryResult(modelResult.get(i))); // modelResult.get(i).setBinaryClassification(isBinaryResult(modelResult.get(i)));
newResult(modelResult.get(i), groupedRawData.get(i)); newDLResult(modelResult.get(i), groupedRawData.get(i));
} }
} }
@ -79,7 +79,7 @@ public abstract class DLTaskThread extends Thread {
* @param soundSpotResult - the new result. * @param soundSpotResult - the new result.
* @param groupedRawData - the grouped data unit. * @param groupedRawData - the grouped data unit.
*/ */
public abstract void newResult(GenericPrediction soundSpotResult, GroupedRawData groupedRawData); public abstract void newDLResult(GenericPrediction soundSpotResult, GroupedRawData groupedRawData);
/** /**
* Get the grouped data queue * Get the grouped data queue

View File

@ -161,7 +161,7 @@ public class SoundSpotClassifier implements DLClassiferModel, PamSettings {
} }
@Override @Override
public void newResult(GenericPrediction soundSpotResult, GroupedRawData groupedRawData) { public void newDLResult(GenericPrediction soundSpotResult, GroupedRawData groupedRawData) {
soundSpotResult.setClassNameID(getClassNameIDs()); soundSpotResult.setClassNameID(getClassNameIDs());
soundSpotResult.setBinaryClassification(isBinaryResult(soundSpotResult)); soundSpotResult.setBinaryClassification(isBinaryResult(soundSpotResult));
newResult(soundSpotResult, groupedRawData); newResult(soundSpotResult, groupedRawData);
@ -241,11 +241,12 @@ public class SoundSpotClassifier implements DLClassiferModel, PamSettings {
* @param modelResult - the model result; * @param modelResult - the model result;
* @param groupedRawData - the grouped raw data. * @param groupedRawData - the grouped raw data.
*/ */
private void newResult(GenericPrediction modelResult, GroupedRawData groupedRawData) { protected void newResult(GenericPrediction modelResult, GroupedRawData groupedRawData) {
this.dlControl.getDLClassifyProcess().newModelResult(modelResult, groupedRawData); this.dlControl.getDLClassifyProcess().newModelResult(modelResult, groupedRawData);
} }
@Override @Override
public void prepModel() { public void prepModel() {
//System.out.println("PrepModel! !!!"); //System.out.println("PrepModel! !!!");

View File

@ -323,7 +323,7 @@ public class GenericDLClassifier implements DLClassiferModel, PamSettings {
} }
@Override @Override
public void newResult(GenericPrediction modelResult, GroupedRawData groupedRawData) { public void newDLResult(GenericPrediction modelResult, GroupedRawData groupedRawData) {
modelResult.setClassNameID(getClassNameIDs(genericModelParams)); modelResult.setClassNameID(getClassNameIDs(genericModelParams));
modelResult.setBinaryClassification(isBinaryResult(modelResult, genericModelParams)); modelResult.setBinaryClassification(isBinaryResult(modelResult, genericModelParams));
newResult(modelResult, groupedRawData); newResult(modelResult, groupedRawData);
@ -331,6 +331,15 @@ public class GenericDLClassifier implements DLClassiferModel, PamSettings {
} }
/**
* Send a new result form the thread queue to the process.
* @param modelResult - the model result;
* @param groupedRawData - the grouped raw data.
*/
protected void newResult(GenericPrediction modelResult, GroupedRawData groupedRawData) {
this.dlControl.getDLClassifyProcess().newModelResult(modelResult, groupedRawData);
}
/** /**
* Get the class name IDs * Get the class name IDs
* @return an array of class name IDs * @return an array of class name IDs

View File

@ -169,7 +169,7 @@ public class KetosClassifier implements DLClassiferModel, PamSettings {
} }
@Override @Override
public void newResult(GenericPrediction soundSpotResult, GroupedRawData groupedRawData) { public void newDLResult(GenericPrediction soundSpotResult, GroupedRawData groupedRawData) {
soundSpotResult.setClassNameID(GenericDLClassifier.getClassNameIDs(ketosDLParams)); soundSpotResult.setClassNameID(GenericDLClassifier.getClassNameIDs(ketosDLParams));
soundSpotResult.setBinaryClassification(GenericDLClassifier.isBinaryResult(soundSpotResult, ketosDLParams)); soundSpotResult.setBinaryClassification(GenericDLClassifier.isBinaryResult(soundSpotResult, ketosDLParams));
newResult(soundSpotResult, groupedRawData); newResult(soundSpotResult, groupedRawData);
@ -177,6 +177,15 @@ public class KetosClassifier implements DLClassiferModel, PamSettings {
} }
/**
* Send a new result form the thread queue to the process.
* @param modelResult - the model result;
* @param groupedRawData - the grouped raw data.
*/
protected void newResult(GenericPrediction modelResult, GroupedRawData groupedRawData) {
this.dlControl.getDLClassifyProcess().newModelResult(modelResult, groupedRawData);
}
@Override @Override
public void closeModel() { public void closeModel() {