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"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="/X3/src/org"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@ -778,7 +778,7 @@
<groupId>pamguard.org</groupId>
<artifactId>x3</artifactId>
<version>2.0.0</version>
</dependency>
</dependency>
<!-- https://mvnrepository.com/artifact/it.sauronsoftware/jave -->
<dependency>

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 {
return AudioSystem.getAudioInputStream(file);
}
@ -76,5 +84,21 @@ public class PamAudioSystem {
String end = name.substring(name.length()-5).toLowerCase();
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);
}
static AudioFormat.Encoding getEncoding(int formatCode) {
switch (formatCode) {
case 1:

View File

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

View File

@ -22,7 +22,8 @@ public class CTClassifierParams implements Cloneable, Serializable, ManagedParam
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 = "";
// /**
// * 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.
// 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;
/**
* A unique ID for the classifier that never changes. This is important for accessing data selectors.
*/
public String uniqueID = UUID.randomUUID().toString();
/**

View File

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

View File

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

View File

@ -20,6 +20,7 @@ public class Chi2ThresholdParams extends CTClassifierParams implements ManagedPa
public Chi2ThresholdParams(){
super();
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() {
classifiers = new ArrayList<CTClassifier>();
//System.out.println("------CREATE CLASSIFIERS: -------");
//do this so that is CLASSIFIER_TYPES changes order things still work.
for (int i=0; i<CLASSIFIER_TYPES.length; i++) {
@ -104,6 +104,7 @@ public class StandardClassifier implements CTClassifier {
*/
private void setClassifierParams() {
if (standardClssfrParams.ctClassifierParams ==null || standardClssfrParams.ctClassifierParams.length != classifiers.size()) {
standardClssfrParams.ctClassifierParams = new CTClassifierParams[classifiers.size()];
standardClssfrParams.enable = new boolean[classifiers.size()];
@ -119,6 +120,11 @@ public class StandardClassifier implements CTClassifier {
standardClssfrParams.ctClassifierParams[i] = classifiers.get(i).getParams();
}
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.
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
//know which classifier to create.
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;
// chi2ThresholdParams = new Chi2ThresholdParams();
// template = DefualtSpectrumTemplates.getTemplate(SpectrumTemplateType.BEAKED_WHALE);
//System.out.println("Template classifier params: " + this);
}

View File

@ -43,7 +43,7 @@ public class SimpleCTClassifierGraphics implements CTClassifierGraphics {
@Override
public CTClassifierParams getParams() {
Chi2ThresholdParams clssfrParams = simpleCTClassiferPane.getParams(simpleChi2Classifier.getParams()).clone();
Chi2ThresholdParams clssfrParams = simpleCTClassiferPane.getParams(simpleChi2Classifier.getParams()).clone();
if (clssfrParams==null) {
System.err.print("Simple Chi2 Classifier returned null params");
return null;

View File

@ -76,6 +76,8 @@ public class SimpleCTClassifierPane extends SettingsPane<Chi2ThresholdParams> {
*/
private ControlField<Double> minPercClicks;
private Chi2ThresholdParams currParams;
public SimpleCTClassifierPane(Chi2ThresholdClassifier simpleChi2Classifier) {
super(null);
this.simpleChi2Classifier=simpleChi2Classifier;
@ -214,6 +216,9 @@ public class SimpleCTClassifierPane extends SettingsPane<Chi2ThresholdParams> {
public Chi2ThresholdParams getParams(Chi2ThresholdParams currParams) {
//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();
//HACK - for some reason Integer spinner is returning a double
currParams.minClicks=minClicks.getSpinner().getValue().intValue();
@ -224,17 +229,25 @@ public class SimpleCTClassifierPane extends SettingsPane<Chi2ThresholdParams> {
simpleChi2Classifier.getDataSelector().getDialogPaneFX().getParams(true);
}
return currParams;
currParams.uniqueID = this.currParams.uniqueID;
return currParams=this.currParams;
}
@Override
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);
//HACK - for some reason Integer spinner is returning a double
minClicks.getSpinner().getValueFactory().setValue((double) input.minClicks);
minTime.getSpinner().getValueFactory().setValue(input.minTime);
minPercClicks.getSpinner().getValueFactory().setValue(input.minPercentage*100.);
}
@Override

View File

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

View File

@ -84,7 +84,15 @@ public class StandardClassifierPane extends SettingsPane<StandardClassifierPara
@Override
public void setParams(StandardClassifierParams input) {
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]);
enableSwitch[i].setSelected(input.enable[i]);
disableClassifierPane(i);
}

View File

@ -64,9 +64,7 @@ public class AmplitudeChi2AdvPane extends AdvMHTVarPane {
@Override
public AmplitudeChi2Params getParams(SimpleChi2VarParams currParams) {
System.out.println("Get params: AMPLITUDE");
AmplitudeChi2Params newParams = new AmplitudeChi2Params(super.getParams(currParams));
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.setSubArrayType(bearingAnnotation.getBearingLocalisation().getSubArrayType());
System.out.println("Loc content!: " + this.getLocContents().hasLocContent(LocContents.HAS_AMBIGUITY) + " angles: " + angles.length);
PamUtils.PamArrayUtils.printArray(angles);
//System.out.println("Loc content!: " + this.getLocContents().hasLocContent(LocContents.HAS_AMBIGUITY) + " angles: " + angles.length);
//PamUtils.PamArrayUtils.printArray(angles);
}
@Override

View File

@ -58,7 +58,7 @@ public abstract class DLTaskThread extends Thread {
for (int i =0; i<modelResult.size(); i++) {
// modelResult.get(i).setClassNameID(getClassNameIDs());
// 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 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

View File

@ -161,7 +161,7 @@ public class SoundSpotClassifier implements DLClassiferModel, PamSettings {
}
@Override
public void newResult(GenericPrediction soundSpotResult, GroupedRawData groupedRawData) {
public void newDLResult(GenericPrediction soundSpotResult, GroupedRawData groupedRawData) {
soundSpotResult.setClassNameID(getClassNameIDs());
soundSpotResult.setBinaryClassification(isBinaryResult(soundSpotResult));
newResult(soundSpotResult, groupedRawData);
@ -241,9 +241,10 @@ public class SoundSpotClassifier implements DLClassiferModel, PamSettings {
* @param modelResult - the model result;
* @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);
}
@Override

View File

@ -323,7 +323,7 @@ public class GenericDLClassifier implements DLClassiferModel, PamSettings {
}
@Override
public void newResult(GenericPrediction modelResult, GroupedRawData groupedRawData) {
public void newDLResult(GenericPrediction modelResult, GroupedRawData groupedRawData) {
modelResult.setClassNameID(getClassNameIDs(genericModelParams));
modelResult.setBinaryClassification(isBinaryResult(modelResult, genericModelParams));
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
* @return an array of class name IDs

View File

@ -169,13 +169,22 @@ public class KetosClassifier implements DLClassiferModel, PamSettings {
}
@Override
public void newResult(GenericPrediction soundSpotResult, GroupedRawData groupedRawData) {
public void newDLResult(GenericPrediction soundSpotResult, GroupedRawData groupedRawData) {
soundSpotResult.setClassNameID(GenericDLClassifier.getClassNameIDs(ketosDLParams));
soundSpotResult.setBinaryClassification(GenericDLClassifier.isBinaryResult(soundSpotResult, ketosDLParams));
newResult(soundSpotResult, groupedRawData);
}
}
/**
* 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