Noise logging

This commit is contained in:
Douglas Gillespie 2023-09-18 12:49:39 +01:00
parent 415ec87938
commit 5fe0927c10
10 changed files with 105 additions and 40 deletions

View File

@ -116,5 +116,27 @@ public class NoiseLogging extends SQLLogging {
}
}
}
private long lastTime;
@Override
protected PamDataUnit createDataUnit(SQLTypes sqlTypes, long timeMilliseconds, int databaseIndex) {
int chan = channelNumber.getIntegerValue();
int nBands = noiseDataBlock.getBandLoEdges().length;
int nMeasures = noiseDataBlock.getUsedMeasureNames().length;
if (nMeasures * nBands != bandItems.length) {
return null;
}
double[][] bandData = new double[nBands][nMeasures];
for (int iBand = 0, iCol = 0; iBand < nBands; iBand++) {
for (int iMeasure = 0; iMeasure < nMeasures; iMeasure++, iCol++) {
bandData[iBand][iMeasure] = bandItems[iCol].getDoubleValue();
}
}
NoiseDataUnit noiseDataUnit = new NoiseDataUnit(timeMilliseconds, 1<<chan, 0, 0);
noiseDataUnit.setNoiseBandData(bandData);
return noiseDataUnit;
}
}

View File

@ -17,6 +17,8 @@ import tethys.niluswraps.PDeployment;
import tethys.output.StreamExportParams;
import tethys.output.TethysExportParams;
import tethys.pamdata.AutoTethysProvider;
import tethys.swing.export.ExportWizardCard;
import tethys.swing.export.GranularityCard;
public class TethysNoiseDataProvider extends AutoTethysProvider {
@ -39,7 +41,7 @@ public class TethysNoiseDataProvider extends AutoTethysProvider {
Detection detection = super.createDetection(dataUnit, tethysExportParams, streamExportParams);
NoiseDataUnit noiseDataUnit = (NoiseDataUnit) dataUnit;
/*
* Now all the noise measurements, noting thre may be several types.
* Now all the noise measurements, noting there may be several types.
*/
int statTypes = noiseDataBlock.getStatisticTypes();
int nTypes = PamUtils.getNumChannels(statTypes);
@ -92,4 +94,12 @@ public class TethysNoiseDataProvider extends AutoTethysProvider {
}
}
@Override
public boolean wantExportDialogCard(ExportWizardCard wizPanel) {
if (wizPanel.getClass() == GranularityCard.class) {
return false;
}
return super.wantExportDialogCard(wizPanel);
}
}

View File

@ -27,7 +27,6 @@ import PamController.PamControlledUnit;
import PamController.PamController;
import PamUtils.LatLong;
import PamUtils.PamUtils;
import PamView.dialog.warn.WarnOnce;
import PamguardMVC.PamDataBlock;
import PamguardMVC.PamRawDataBlock;
import binaryFileStorage.BinaryStore;
@ -87,10 +86,17 @@ public class DeploymentHandler implements TethysStateObserver {
private ArrayList<PDeployment> projectDeployments;
private Helper nilusHelper;
public DeploymentHandler(TethysControl tethysControl) {
super();
this.tethysControl = tethysControl;
tethysControl.addStateObserver(this);
tethysControl.addStateObserver(this);
try {
nilusHelper = new Helper();
} catch (JAXBException e) {
e.printStackTrace();
}
}
@Override
@ -973,12 +979,7 @@ public class DeploymentHandler implements TethysStateObserver {
ArrayList<Hydrophone> phones = array.getHydrophoneArray();
int iPhone = 0;
long timeMillis = TethysTimeFuncs.millisFromGregorianXML(deployment.getDeploymentDetails().getAudioTimeStamp());
Helper nilusHelper = null;
try {
nilusHelper = new Helper();
} catch (JAXBException e) {
e.printStackTrace();
}
for (Hydrophone aPhone : phones) {
PamVector hydLocs = array.getAbsHydrophoneVector(iPhone, timeMillis);
Audio audio = new Audio();

View File

@ -9,6 +9,7 @@ public class DetectionExportProgress {
public static final int STATE_CANCELED = 2;
public static final int STATE_COMPLETE = 3;
public static final int STATE_WRITING = 4;
public static final int STATE_COUNTING = 5;
public PDeployment currentDeployment;
public Detections currentDetections;
public long lastUnitTime;

View File

@ -8,6 +8,7 @@ import javax.swing.SwingWorker;
import PamController.PamControlledUnit;
import PamController.PamguardVersionInfo;
import PamModel.PamPluginInterface;
import PamUtils.PamCalendar;
import PamView.dialog.warn.WarnOnce;
import PamguardMVC.PamDataBlock;
import PamguardMVC.PamDataUnit;
@ -371,7 +372,6 @@ public class DetectionsHandler {
* and export the content of each separately.
*/
TethysExportParams exportParams = tethysControl.getTethysExportParams();
DBXMLConnect dbxmlConnect = tethysControl.getDbxmlConnect();
DeploymentHandler depHandler = tethysControl.getDeploymentHandler();
ArrayList<PDeployment> deployments = depHandler.getMatchedDeployments();
// Detections currentDetections = null;
@ -386,7 +386,7 @@ public class DetectionsHandler {
for (PDeployment deployment : deployments) {
int documentCount = 0;
prog = new DetectionExportProgress(deployment, null,
lastUnitTime, totalCount, exportCount, skipCount, DetectionExportProgress.STATE_GATHERING);
lastUnitTime, totalCount, exportCount, skipCount, DetectionExportProgress.STATE_COUNTING);
exportObserver.update(prog);
granularityHandler.prepare(deployment.getAudioStart());
// export everything in that deployment.
@ -407,6 +407,8 @@ public class DetectionsHandler {
}
dataBlock.loadViewerData(mapPoint.getStartTime(), mapPoint.getEndTime(), null);
ArrayList<PamDataUnit> dataCopy = dataBlock.getDataCopy(deployment.getAudioStart(), deployment.getAudioEnd(), true, dataSelector);
// System.out.printf("%d loaded from %s to %s %d kept\n", dataBlock.getUnitsCount(), PamCalendar.formatDateTime(mapPoint.getStartTime()),
// PamCalendar.formatDateTime(mapPoint.getEndTime()), dataCopy.size());
skipCount += dataBlock.getUnitsCount() - dataCopy.size();
for (PamDataUnit dataUnit : dataCopy) {
/*
@ -425,7 +427,7 @@ public class DetectionsHandler {
}
prog = new DetectionExportProgress(deployment, null,
lastUnitTime, totalCount, exportCount, skipCount, DetectionExportProgress.STATE_GATHERING);
lastUnitTime, totalCount, exportCount, skipCount, DetectionExportProgress.STATE_COUNTING);
exportObserver.update(prog);
// if (documentCount > 500000 && mapPoint != dataMap.getLastMapPoint()) {
@ -450,9 +452,9 @@ public class DetectionsHandler {
}
prog = new DetectionExportProgress(null, null,
lastUnitTime, totalCount, exportCount, skipCount, DetectionExportProgress.STATE_COMPLETE);
exportObserver.update(prog);
// prog = new DetectionExportProgress(null, null,
// lastUnitTime, totalCount, exportCount, skipCount, DetectionExportProgress.STATE_GATHERING);
// exportObserver.update(prog);
return exportCount;
}/**
* Export detections in all deployments for this PAMGuard dataset.

View File

@ -44,6 +44,7 @@ import tethys.species.DataBlockSpeciesManager;
import tethys.species.DataBlockSpeciesMap;
import tethys.species.ITISTypes;
import tethys.species.SpeciesMapItem;
import tethys.swing.export.ExportWizardCard;
import whistleClassifier.WhistleContour;
import javax.xml.bind.JAXBException;
@ -72,25 +73,31 @@ abstract public class AutoTethysProvider implements TethysDataProvider {
private PamProcess pamProcess;
private PamControlledUnit pamControlledUnit;
private TethysControl tethysControl;
private Helper helper;
public AutoTethysProvider(TethysControl tethysControl, PamDataBlock pamDataBlock) {
this.tethysControl = tethysControl;
this.pamDataBlock = pamDataBlock;
pamProcess = pamDataBlock.getParentProcess();
pamControlledUnit = pamProcess.getPamControlledUnit();
}
@Override
public TethysSchema getSchema() {
SQLLogging logging = pamDataBlock.getLogging();
if (logging == null) {
return null;
try {
helper = new Helper();
} catch (JAXBException e) {
e.printStackTrace();
}
DBSchemaWriter schemaWriter = new DBSchemaWriter();
Document doc = schemaWriter.generateDatabaseSchema(pamDataBlock, logging, logging.getTableDefinition());
TethysSchema schema = new TethysSchema(doc);
return schema;
}
//
// @Override
// public TethysSchema getSchema() {
// SQLLogging logging = pamDataBlock.getLogging();
// if (logging == null) {
// return null;
// }
// DBSchemaWriter schemaWriter = new DBSchemaWriter();
// Document doc = schemaWriter.generateDatabaseSchema(pamDataBlock, logging, logging.getTableDefinition());
// TethysSchema schema = new TethysSchema(doc);
// return schema;
// }
// @Override
// public TethysDataPoint getDataPoint(PamDataUnit pamDataUnit) {
@ -369,10 +376,8 @@ abstract public class AutoTethysProvider implements TethysDataProvider {
userDefined = new UserDefined();
parameters.setUserDefined(userDefined);
}
Helper helper;
Element el = null;
try {
helper = new Helper();
el = helper.AddAnyElement(userDefined.getAny(), parameterName, parameterValue);
} catch (JAXBException e) {
e.printStackTrace();
@ -401,8 +406,8 @@ abstract public class AutoTethysProvider implements TethysDataProvider {
List<Double> offsetS = tonal.getOffsetS();
List<Double> hz = tonal.getHz();
for (int i = 0; i < tMillis.length; i++) {
offsetS.add((double) (tMillis[i]-tMillis[0]) / 1000.);
hz.add(fHz[i]);
offsetS.add(roundSignificantFigures((double) (tMillis[i]-tMillis[0]) / 1000., 4));
hz.add(roundSignificantFigures(fHz[i], 4));
}
detParams.setTonal(tonal);
return true;
@ -417,8 +422,8 @@ abstract public class AutoTethysProvider implements TethysDataProvider {
List<Double> offsetS = tonal.getOffsetS();
List<Double> hz = tonal.getHz();
for (int i = 0; i < t.length; i++) {
offsetS.add(t[i]-t[0]);
hz.add(f[i]);
offsetS.add(roundSignificantFigures(t[i]-t[0],4));
hz.add(roundSignificantFigures(f[i],4));
}
detParams.setTonal(tonal);
return true;
@ -553,5 +558,10 @@ abstract public class AutoTethysProvider implements TethysDataProvider {
return sign*(double) longVal/scale;
}
@Override
public boolean wantExportDialogCard(ExportWizardCard wizPanel) {
return true;
}
}

View File

@ -13,6 +13,7 @@ import nilus.GranularityEnumType;
import tethys.niluswraps.PDeployment;
import tethys.output.StreamExportParams;
import tethys.output.TethysExportParams;
import tethys.swing.export.ExportWizardCard;
/**
* Any PAMGuard data stream which can provide Detection data to PAMGuard will
@ -24,13 +25,13 @@ import tethys.output.TethysExportParams;
*/
public interface TethysDataProvider {
/**
* This gets the Tethys schema for this type of data in whatever
* form we decide it's best stored in, an XML string, or what ?
* @return
*/
public TethysSchema getSchema();
// /**
// * This gets the Tethys schema for this type of data in whatever
// * form we decide it's best stored in, an XML string, or what ?
// * @return
// */
// public TethysSchema getSchema();
//
/**
* This will convert a data unit for this provider into whatever format we need the
@ -110,6 +111,14 @@ public interface TethysDataProvider {
* @param exportParams
*/
public void getEffortKinds(PDeployment pDeployment, List<DetectionEffortKind> effortKinds, StreamExportParams exportParams);
/**
* See if a particular card should be used in the export wizard. This may
* not be the best way of doing this, but will do for now.
* @param wizPanel
* @return
*/
public boolean wantExportDialogCard(ExportWizardCard wizPanel);
}

View File

@ -18,6 +18,7 @@ import PamView.dialog.PamDialog;
import PamguardMVC.PamDataBlock;
import tethys.TethysControl;
import tethys.output.StreamExportParams;
import tethys.pamdata.TethysDataProvider;
public class DetectionsExportWizard extends PamDialog {
@ -32,6 +33,7 @@ public class DetectionsExportWizard extends PamDialog {
private ArrayList<ExportWizardCard> wizardCards = new ArrayList();
private AlgorithmCard algorithmCard;
private ExportWorkerCard exportWorkerCard;
private TethysDataProvider tethysDataProvider;
private DetectionsExportWizard(Window parentFrame, TethysControl tethysControl, PamDataBlock dataBlock) {
super(parentFrame, "Detections Export", false);
@ -41,6 +43,7 @@ public class DetectionsExportWizard extends PamDialog {
if (streamExportParams == null) {
streamExportParams = new StreamExportParams(tethysControl, dataBlock, false);
}
tethysDataProvider = dataBlock.getTethysDataProvider(tethysControl);
cardLayout = new CardLayout();
JPanel mainPanel = new JPanel(new BorderLayout());
@ -73,8 +76,10 @@ public class DetectionsExportWizard extends PamDialog {
}
private void addCard(ExportWizardCard wizPanel) {
if (tethysDataProvider.wantExportDialogCard(wizPanel)) {
cardPanel.add(wizPanel, wizPanel.getTitle());
wizardCards.add(wizPanel);
}
}
public static void showDilaog(Window parentFrame, TethysControl tethysControl, PamDataBlock dataBlock) {

View File

@ -12,7 +12,9 @@ import tethys.output.StreamExportParams;
* @author dg50
*
*/
abstract class ExportWizardCard extends JPanel {
abstract public class ExportWizardCard extends JPanel {
private static final long serialVersionUID = 1L;
private String title;
private PamDataBlock dataBlock;

View File

@ -144,6 +144,9 @@ public class ExportWorkerCard extends ExportWizardCard implements DetectionExpor
case DetectionExportProgress.STATE_GATHERING:
progressText.setText("Running export");
break;
case DetectionExportProgress.STATE_COUNTING:
progressText.setText("Counting data");
break;
case DetectionExportProgress.STATE_CANCELED:
progressText.setText("Export cancelled");
break;