Detections Document ready to go

This commit is contained in:
Douglas Gillespie 2023-03-15 18:13:11 +00:00
parent f97247f148
commit 4876899b54
5 changed files with 93 additions and 51 deletions

View File

@ -67,8 +67,8 @@ public class DeploymentHandler {
* Realistically, this list is always 0,1,2,etc or it goes horribly wrong ! * Realistically, this list is always 0,1,2,etc or it goes horribly wrong !
*/ */
// so write functions here to get information from the daqParams. // so write functions here to get information from the daqParams.
System.out.printf("Sample regime: %s input with rate %3.1fHz, %d channels, gain %3.1fdB, ADCp-p %3.1fV\n", daqParams.getDaqSystemType(), // System.out.printf("Sample regime: %s input with rate %3.1fHz, %d channels, gain %3.1fdB, ADCp-p %3.1fV\n", daqParams.getDaqSystemType(),
daqParams.getSampleRate(), daqParams.getNChannels(), daqParams.preamplifier.getGain(), daqParams.voltsPeak2Peak); // daqParams.getSampleRate(), daqParams.getNChannels(), daqParams.preamplifier.getGain(), daqParams.voltsPeak2Peak);
/** /**
* then there is the actual sampling. This is a bit harder to find. I thought it would be in the data map * then there is the actual sampling. This is a bit harder to find. I thought it would be in the data map
* but the datamap is a simple count of what's in the databasase which is not quite what we want. * but the datamap is a simple count of what's in the databasase which is not quite what we want.
@ -207,8 +207,8 @@ public class DeploymentHandler {
* Realistically, this list is always 0,1,2,etc or it goes horribly wrong ! * Realistically, this list is always 0,1,2,etc or it goes horribly wrong !
*/ */
// so write functions here to get information from the daqParams. // so write functions here to get information from the daqParams.
System.out.printf("Sample regime: %s input with rate %3.1fHz, %d channels, gain %3.1fdB, ADCp-p %3.1fV\n", daqParams.getDaqSystemType(), // System.out.printf("Sample regime: %s input with rate %3.1fHz, %d channels, gain %3.1fdB, ADCp-p %3.1fV\n", daqParams.getDaqSystemType(),
daqParams.getSampleRate(), daqParams.getNChannels(), daqParams.preamplifier.getGain(), daqParams.voltsPeak2Peak); // daqParams.getSampleRate(), daqParams.getNChannels(), daqParams.preamplifier.getGain(), daqParams.voltsPeak2Peak);
/** /**
* then there is the actual sampling. This is a bit harder to find. I thought it would be in the data map * then there is the actual sampling. This is a bit harder to find. I thought it would be in the data map
* but the datamap is a simple count of what's in the databasase which is not quite what we want. * but the datamap is a simple count of what's in the databasase which is not quite what we want.
@ -242,8 +242,8 @@ public class DeploymentHandler {
} }
} }
System.out.printf("Input map of sound data indicates data from %s to %s with %d starts and %d stops over %d files\n", // System.out.printf("Input map of sound data indicates data from %s to %s with %d starts and %d stops over %d files\n",
PamCalendar.formatDateTime(dataStart), PamCalendar.formatDateTime(dataEnd), nStart, nStop, nFile+1); // PamCalendar.formatDateTime(dataStart), PamCalendar.formatDateTime(dataEnd), nStart, nStop, nFile+1);
} }

View File

@ -3,11 +3,7 @@ package tethys.detection;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.w3c.dom.Document; import PamUtils.PamCalendar;
import PamController.PamControlledUnit;
import PamController.PamSettings;
import PamController.settings.output.xml.PamguardXMLWriter;
import PamguardMVC.PamDataBlock; import PamguardMVC.PamDataBlock;
import PamguardMVC.PamDataUnit; import PamguardMVC.PamDataUnit;
import PamguardMVC.dataSelector.DataSelector; import PamguardMVC.dataSelector.DataSelector;
@ -15,8 +11,10 @@ import dataMap.OfflineDataMap;
import dataMap.OfflineDataMapPoint; import dataMap.OfflineDataMapPoint;
import nilus.DataSourceType; import nilus.DataSourceType;
import nilus.Deployment; import nilus.Deployment;
import nilus.Detection;
import nilus.DetectionEffort; import nilus.DetectionEffort;
import nilus.DetectionEffortKind; import nilus.DetectionEffortKind;
import nilus.DetectionGroup;
import nilus.Detections; import nilus.Detections;
import tethys.TethysControl; import tethys.TethysControl;
import tethys.TethysTimeFuncs; import tethys.TethysTimeFuncs;
@ -24,7 +22,6 @@ import tethys.detection.DetectionGranularity.GRANULARITY;
import tethys.output.StreamExportParams; import tethys.output.StreamExportParams;
import tethys.output.TethysExportParams; import tethys.output.TethysExportParams;
import tethys.pamdata.TethysDataProvider; import tethys.pamdata.TethysDataProvider;
import tethys.pamdata.TethysSchema;
public class DetectionsHandler { public class DetectionsHandler {
@ -58,35 +55,9 @@ public class DetectionsHandler {
return exportByTimeChunk(aDataBlock, deployment, granularity.granularityIntervalSeconds, tethysExportParams, streamExportParams); return exportByTimeChunk(aDataBlock, deployment, granularity.granularityIntervalSeconds, tethysExportParams, streamExportParams);
default: default:
break; break;
} }
/**
* This will probably need to be passed additional parameters and may also want
* to return something other than void in order to build a bigger Tethys
* document.
*/
/*
* first we'll probably want a reference to the module containing the data. in
* principle this can't get null, since the datablock was found be searching in
* the other direction.
*/
PamControlledUnit pamControlledUnit = aDataBlock.getParentProcess().getPamControlledUnit();
TethysDataProvider dataProvider = aDataBlock.getTethysDataProvider(); return false;
Detections detections = new Detections();
detections.setId(deployment.getId());
detections.setDescription(dataProvider.getDescription(deployment, tethysExportParams));
DataSourceType dataSource = new DataSourceType();
dataSource.setDeploymentId(deployment.getId());
// dataSource.setEnsembleId(""); ToDo
detections.setDataSource(dataSource);
detections.setAlgorithm(dataProvider.getAlgorithm());
detections.setUserId("Unknown user");
detections.setEffort(getDetectorEffort(deployment));
return true;
} }
@ -168,13 +139,34 @@ public class DetectionsHandler {
/* /*
* Here, make Detection object and add the DetectionEffort data. * Here, make Detection object and add the DetectionEffort data.
*/ */
TethysDataProvider dataProvider = dataBlock.getTethysDataProvider();
Detections detections = new Detections();
detections.setId(deployment.getId());
detections.setDescription(dataProvider.getDescription(deployment, tethysExportParams));
DataSourceType dataSource = new DataSourceType();
dataSource.setDeploymentId(deployment.getId());
// dataSource.setEnsembleId(""); ToDo
detections.setDataSource(dataSource);
detections.setAlgorithm(dataProvider.getAlgorithm());
detections.setUserId("Unknown user");
detections.setEffort(getDetectorEffort(deployment, startTimeMillis, endTimeMillis));
DetectionGroup detectionGroup = new DetectionGroup();
detections.setOnEffort(detectionGroup);
List<Detection> detectionList = detectionGroup.getDetection();
for (int i = 0; i < data.size(); i++) { for (int i = 0; i < data.size(); i++) {
PamDataUnit dataUnit = data.get(i); PamDataUnit dataUnit = data.get(i);
// add many Detecion objects Detection detection = dataProvider.createDetection(dataUnit, tethysExportParams, streamExportParams);
if (detection != null) {
detectionList.add(detection);
}
} }
System.out.printf("Exporting %d %s detections for time period %s to %s\n", detectionList.size(), dataBlock.getDataName(),
// write to database detections.getEffort().getStart().toString(), detections.getEffort().getEnd().toString());
/*
* We should now have a fully populated Detections object, so write it to the database
* using functions in DBXMLConnect
*/
tethysControl.getDbxmlConnect(); // call whatever you need to call in here to write the Detections.
return true; return true;
@ -187,10 +179,10 @@ public class DetectionsHandler {
// return false; // return false;
// } // }
private DetectionEffort getDetectorEffort(Deployment deployment) { private DetectionEffort getDetectorEffort(Deployment deployment, long effortStart, long effortEnd) {
DetectionEffort effort = new DetectionEffort(); DetectionEffort effort = new DetectionEffort();
effort.setStart(deployment.getDeploymentDetails().getAudioTimeStamp()); effort.setStart(TethysTimeFuncs.xmlGregCalFromMillis(effortStart));
effort.setEnd(deployment.getRecoveryDetails().getAudioTimeStamp()); effort.setEnd(TethysTimeFuncs.xmlGregCalFromMillis(effortEnd));
// effort.set // no setter for DetectionEffortKind // effort.set // no setter for DetectionEffortKind
List<DetectionEffortKind> effortKinds = effort.getKind(); List<DetectionEffortKind> effortKinds = effort.getKind();
return effort; return effort;

View File

@ -216,7 +216,7 @@ public class TethysExporter {
Deployment deployment = deploymentHandler.createDeploymentDocument(i++, drd); Deployment deployment = deploymentHandler.createDeploymentDocument(i++, drd);
// System.out.println(deployment.toString()); // System.out.println(deployment.toString());
deploymentDocs.add(deployment1); deploymentDocs.add(deployment);
} }
@ -311,9 +311,9 @@ public class TethysExporter {
for (int iPhone = 0; iPhone < hydrophones.size(); iPhone++) { for (int iPhone = 0; iPhone < hydrophones.size(); iPhone++) {
Hydrophone aPhone = hydrophones.get(iPhone); Hydrophone aPhone = hydrophones.get(iPhone);
double totalCal = -daqProcess.rawAmplitude2dB(1, iPhone, false); double totalCal = -daqProcess.rawAmplitude2dB(1, iPhone, false);
System.out.printf( // System.out.printf(
"hydrophone %d has sensitivity %3.1fdB + gain %3.1fdB. Total calibration is %3.1fdB re1U/uPa\n", // "hydrophone %d has sensitivity %3.1fdB + gain %3.1fdB. Total calibration is %3.1fdB re1U/uPa\n",
iPhone, aPhone.getSensitivity(), aPhone.getPreampGain(), totalCal); // iPhone, aPhone.getSensitivity(), aPhone.getPreampGain(), totalCal);
} }
} }

View File

@ -1,5 +1,6 @@
package tethys.pamdata; package tethys.pamdata;
import java.math.BigInteger;
import java.util.List; import java.util.List;
import org.w3c.dom.Document; import org.w3c.dom.Document;
@ -21,6 +22,10 @@ import nilus.AlgorithmType;
import nilus.AlgorithmType.Parameters; import nilus.AlgorithmType.Parameters;
import nilus.Deployment; import nilus.Deployment;
import nilus.DescriptionType; import nilus.DescriptionType;
import nilus.Detection;
import nilus.SpeciesIDType;
import tethys.TethysTimeFuncs;
import tethys.output.StreamExportParams;
import tethys.output.TethysExportParams; import tethys.output.TethysExportParams;
/** /**
@ -104,7 +109,7 @@ public class AutoTethysProvider implements TethysDataProvider {
NodeList childs = settingsEl.getChildNodes(); NodeList childs = settingsEl.getChildNodes();
for (int i = 0; i < childs.getLength(); i++) { for (int i = 0; i < childs.getLength(); i++) {
Node el = childs.item(i); Node el = childs.item(i);
System.out.println(el.getNodeName()); // System.out.println(el.getNodeName());
if (el instanceof Element) { if (el instanceof Element) {
paramList.add((Element) el); paramList.add((Element) el);
} }
@ -165,4 +170,25 @@ public class AutoTethysProvider implements TethysDataProvider {
return pamControlledUnit.getUnitType(); return pamControlledUnit.getUnitType();
} }
@Override
public Detection createDetection(PamDataUnit dataUnit, TethysExportParams tethysExportParams,
StreamExportParams streamExportParams) {
Detection detection = new Detection();
detection.setStart(TethysTimeFuncs.xmlGregCalFromMillis(dataUnit.getTimeMilliseconds()));
detection.setEnd(TethysTimeFuncs.xmlGregCalFromMillis(dataUnit.getEndTimeInMilliseconds()));
detection.setSpeciesId(getSpeciesIdType());
/*
* NOTE: I use channel bitmaps throughout since detections are often made on multiple channels.
*/
detection.setChannel(BigInteger.valueOf(dataUnit.getChannelBitmap()));
return detection;
}
private SpeciesIDType getSpeciesIdType() {
SpeciesIDType species = new SpeciesIDType();
// species.s
return species;
}
} }

View File

@ -4,6 +4,8 @@ import PamguardMVC.PamDataUnit;
import nilus.AlgorithmType; import nilus.AlgorithmType;
import nilus.Deployment; import nilus.Deployment;
import nilus.DescriptionType; import nilus.DescriptionType;
import nilus.Detection;
import tethys.output.StreamExportParams;
import tethys.output.TethysExportParams; import tethys.output.TethysExportParams;
/** /**
@ -34,9 +36,31 @@ public interface TethysDataProvider {
public TethysDataPoint getDataPoint(PamDataUnit pamDataUnit); public TethysDataPoint getDataPoint(PamDataUnit pamDataUnit);
/**
* Get DescriptionType object to include in a Tethys Detections document.
* @param deployment
* @param tethysExportParams
* @return Tethys DescriptionType object, which contains infromation about detections
*/
public DescriptionType getDescription(Deployment deployment, TethysExportParams tethysExportParams); public DescriptionType getDescription(Deployment deployment, TethysExportParams tethysExportParams);
/**
* Get Algorithm information for a Tethys Detections document
* @return Algorithm information
*/
public AlgorithmType getAlgorithm(); public AlgorithmType getAlgorithm();
/**
* Create a Tethys Detection object from a PamDataUnit.<br>
* It's OK for this to return null if for some reason the unit shouldn't be stored.
* @param dataUnit PAMGuard data unit
* @param tethysExportParams
* @param streamExportParams
* @return Detection Tethys Detection object.
*/
public Detection createDetection(PamDataUnit dataUnit, TethysExportParams tethysExportParams,
StreamExportParams streamExportParams);
} }