Merge from DG (#76)

* Work on bug fixes in CTD classifier

* couple of final neatenings up of CTD

* DWV Import

Fixed DWV importer so that a binary file is still created if a DWV file
doesn't exist. this is totally normal in quiet conditions, so the
correct thing to do is to generate a binary file with no data so that
effort is correctly recorded.
This commit is contained in:
Douglas Gillespie 2022-10-18 17:04:16 +01:00 committed by GitHub
parent e4faed5cfc
commit 63cc66a4b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 93 additions and 31 deletions

View File

@ -9,13 +9,17 @@ public class DWVConvertInformation {
private STGroupInfo fileGroup; private STGroupInfo fileGroup;
private int nDWV; private int nDWV;
private int nDone; private int nDWVDone;
private int nFileDone;
private int nFile;
public DWVConvertInformation(STGroupInfo fileGroup, int nDWV, int nDone) { public DWVConvertInformation(STGroupInfo fileGroup, int nFile, int nFileDone, int nDWV, int nDWVDone) {
this.fileGroup = fileGroup; this.fileGroup = fileGroup;
this.nFile = nFile;
this.nFileDone = nFileDone;
this.nDWV = nDWV; this.nDWV = nDWV;
this.nDone = nDone; this.nDWVDone = nDWVDone;
} }
@ -36,10 +40,26 @@ public class DWVConvertInformation {
/** /**
* @return the nDone * @return the nDWVDone
*/ */
public int getnDone() { public int getnDWVDone() {
return nDone; return nDWVDone;
}
/**
* @return the nFileDone
*/
public int getnFileDone() {
return nFileDone;
}
/**
* @return the nFile
*/
public int getnFile() {
return nFile;
} }
} }

View File

@ -81,8 +81,10 @@ public class DWVConverter {
binarySource.setBinaryStorageStream(outputStream); binarySource.setBinaryStorageStream(outputStream);
binaryStream = clickBinaryDataSource.getBinaryStorageStream(); binaryStream = clickBinaryDataSource.getBinaryStorageStream();
int iFile = 0;
int nFile = fileGroups.size();
for (STGroupInfo fileGroup:fileGroups) { for (STGroupInfo fileGroup:fileGroups) {
processFiles(fileGroup); processFiles(fileGroup, nFile, ++iFile);
if (keepRunning == false) { if (keepRunning == false) {
break; break;
} }
@ -94,16 +96,30 @@ public class DWVConverter {
return null; return null;
} }
private void processFiles(STGroupInfo fileGroup) { private void processFiles(STGroupInfo fileGroup, int nFile, int iFile) {
this.publish(new DWVConvertInformation(fileGroup, 0, 0)); this.publish(new DWVConvertInformation(fileGroup, nFile, iFile, 0, 0));
if (fileGroup.hasDWV() == false) return; if (fileGroup.hasDWV() == false) {
/*
* Don't do this. In quiet conditions there will be a BCL file with a start and stop time
* but if there were no detections there will be no dwv file. We should make the pgdf file
* in any case so that there is a full PAMGuard record of effort.
* In other circumstances dwv files don't actually have data, in which case there may still be
* a null file, which is not so good. Will have to think about how to report this - perhaps in
* this case it's better not to make a pgdf file to show a genuine gap in the data.
*/
// return;
}
BCLReader bclReader = new BCLReader(fileGroup.getBclFile()); BCLReader bclReader = new BCLReader(fileGroup.getBclFile());
boolean ok = bclReader.open(); boolean ok = bclReader.open();
if (ok == false) return; if (ok == false) return;
DWVReader dwvReader = new DWVReader(fileGroup.getDwvFile(), fileGroup.getDwvInfo()); int nDWV = 0;
dwvReader.openDWV(); DWVReader dwvReader = null;
int nDWV = dwvReader.getNumDWV(); if (fileGroup.hasDWV()) {
int repStep = Math.max(1, nDWV/100); dwvReader = new DWVReader(fileGroup.getDwvFile(), fileGroup.getDwvInfo());
dwvReader.openDWV();
nDWV = dwvReader.getNumDWV();
}
int repStep = Math.max(10, nDWV/100);
int nRead = 0; int nRead = 0;
while (true) { while (true) {
BCLLine bclLine = bclReader.nextBCLLine(); BCLLine bclLine = bclReader.nextBCLLine();
@ -127,7 +143,7 @@ public class DWVConverter {
dataLine(fileGroup, bclLine, dwvReader); dataLine(fileGroup, bclLine, dwvReader);
nRead++; nRead++;
if (nRead%repStep == 0) { if (nRead%repStep == 0) {
this.publish(new DWVConvertInformation(fileGroup, nDWV, nRead)); this.publish(new DWVConvertInformation(fileGroup, nFile, iFile, nDWV, nRead));
} }
break; break;
@ -140,10 +156,14 @@ public class DWVConverter {
// e.printStackTrace(); // e.printStackTrace();
// } // }
} }
this.publish(new DWVConvertInformation(fileGroup, nFile, iFile, nDWV, nDWV));
} }
private void dataLine(STGroupInfo fileGroup, BCLLine bclLine, DWVReader dwvReader) { private void dataLine(STGroupInfo fileGroup, BCLLine bclLine, DWVReader dwvReader) {
double[] dwvData = dwvReader.readNextClick(null); double[] dwvData = null;
if (dwvReader != null) {
dwvData = dwvReader.readNextClick(null);
}
if (dwvData == null) { if (dwvData == null) {
return; // can happen if file didn't flush correclty and some dwv is missing. return; // can happen if file didn't flush correclty and some dwv is missing.
} }
@ -185,21 +205,37 @@ public class DWVConverter {
} }
if (bclLine.getState() == 1) { if (bclLine.getState() == 1) {
long dwvFileStart = fileGroup.getDwvInfo().getTimeInfo().samplingStartTimeUTC;
long wavFileStart = fileGroup.getWavInfo().getTimeInfo().samplingStartTimeUTC;
fileStartMicroseconds = bclLine.getMicroSeconds(); fileStartMicroseconds = bclLine.getMicroSeconds();
Debug.out.printf("DWV start %s wav start %s bcl start %s\n", PamCalendar.formatDBDateTime(dwvFileStart), long wavFileStart = fileGroup.getWavInfo().getTimeInfo().samplingStartTimeUTC;
PamCalendar.formatDBDateTime(wavFileStart), PamCalendar.formatDBDateTime(bclLine.getMilliseconds())); try {
if (fileGroup.getDwvInfo() != null) {
long dwvFileStart = fileGroup.getDwvInfo().getTimeInfo().samplingStartTimeUTC;
Debug.out.printf("DWV start %s wav start %s bcl start %s\n", PamCalendar.formatDBDateTime(dwvFileStart),
PamCalendar.formatDBDateTime(wavFileStart), PamCalendar.formatDBDateTime(bclLine.getMilliseconds()));
}
else {
Debug.out.printf("No DWV File !!! wav start %s bcl start %s\n",
PamCalendar.formatDBDateTime(wavFileStart), PamCalendar.formatDBDateTime(bclLine.getMilliseconds()));
}
}
catch (Exception e) {
System.out.println(e.getMessage());
}
binaryStream.openOutputFiles(bclLine.getMilliseconds()); binaryStream.openOutputFiles(bclLine.getMilliseconds());
binaryStream.writeHeader(bclLine.getMilliseconds(), System.currentTimeMillis()); binaryStream.writeHeader(bclLine.getMilliseconds(), System.currentTimeMillis());
binaryStream.writeModuleHeader(); binaryStream.writeModuleHeader();
onEffort = true; onEffort = true;
} }
if (bclLine.getState() == 0) { if (bclLine.getState() == 0) {
long dwvFileStop = fileGroup.getDwvInfo().getTimeInfo().samplingStopTimeUTC; try {
long wavFileStop = fileGroup.getWavInfo().getTimeInfo().samplingStopTimeUTC; long dwvFileStop = fileGroup.getDwvInfo().getTimeInfo().samplingStopTimeUTC;
Debug.out.printf("DWV stop %s wav stop %s E stop %s\n", PamCalendar.formatDBDateTime(dwvFileStop), long wavFileStop = fileGroup.getWavInfo().getTimeInfo().samplingStopTimeUTC;
PamCalendar.formatDBDateTime(wavFileStop), PamCalendar.formatDBDateTime(bclLine.getMilliseconds())); Debug.out.printf("DWV stop %s wav stop %s E stop %s\n", PamCalendar.formatDBDateTime(dwvFileStop),
PamCalendar.formatDBDateTime(wavFileStop), PamCalendar.formatDBDateTime(bclLine.getMilliseconds()));
}
catch (Exception e) {
System.out.println(e.getMessage());
}
binaryStream.writeModuleFooter(); binaryStream.writeModuleFooter();
binaryStream.writeFooter(bclLine.getMilliseconds(), System.currentTimeMillis(), BinaryFooter.END_UNKNOWN); binaryStream.writeFooter(bclLine.getMilliseconds(), System.currentTimeMillis(), BinaryFooter.END_UNKNOWN);
binaryStream.closeFile(); binaryStream.closeFile();

View File

@ -56,7 +56,7 @@ public class ImportBCLDialog extends PamDialog {
private JTextField customDateTimeFormat; private JTextField customDateTimeFormat;
private JLabel fileCountInfo; private JLabel fileCountInfo;
private JLabel thisFileInfo; private JLabel thisFileInfo;
private JProgressBar allProgress; private JProgressBar oneFileProgress, totalProgress;
private JComboBox<String> detectorName; private JComboBox<String> detectorName;
private int nSoundTraps; private int nSoundTraps;
private Hashtable<String, String> uniqueDevices = new Hashtable<>(); private Hashtable<String, String> uniqueDevices = new Hashtable<>();
@ -162,8 +162,10 @@ public class ImportBCLDialog extends PamDialog {
thisFileInfo = new JLabel(" - "); thisFileInfo = new JLabel(" - ");
progressPanel.add(thisFileInfo); progressPanel.add(thisFileInfo);
allProgress = new JProgressBar(); totalProgress = new JProgressBar();
progressPanel.add(allProgress); progressPanel.add(totalProgress);
oneFileProgress = new JProgressBar();
progressPanel.add(oneFileProgress);
startButton = new JButton("Start"); startButton = new JButton("Start");
getButtonPanel().add(startButton, 0); getButtonPanel().add(startButton, 0);
@ -388,10 +390,14 @@ public class ImportBCLDialog extends PamDialog {
thisFileInfo.setText("NO DWV records"); thisFileInfo.setText("NO DWV records");
return; return;
} }
int prog = dwvConvertInformation.getnDone() * 100 / dwvConvertInformation.getnDWV(); int prog = dwvConvertInformation.getnDWVDone() * 100 / dwvConvertInformation.getnDWV();
allProgress.setValue(prog); oneFileProgress.setValue(prog);
thisFileInfo.setText(String.format("Repacked %d of %d clicks", dwvConvertInformation.getnDone(), thisFileInfo.setText(String.format("Repacked %d of %d clicks in file %d of %d",
dwvConvertInformation.getnDWV())); dwvConvertInformation.getnDWVDone(), dwvConvertInformation.getnDWV(),
dwvConvertInformation.getnFileDone(), dwvConvertInformation.getnFile()));
prog = dwvConvertInformation.getnFileDone() * 100 / dwvConvertInformation.getnFile();
totalProgress.setValue(prog);
} }
@Override @Override