📄 codamagnitudegenerator.java
字号:
return new CodaWaveformData(wave, pTime, sCodaStartTime);
}
// invoke in runnable thread:
public final void run() {
if (debug) System.out.println("*** Loading thread started *** ");
loadWaveformData(solCodaWaveformDataList);
loadingThread = null;
if (debug) System.out.println("*** Loading thread ended *** ");
}
// invoke in runnable thread:
protected final void loadWaveformData(CodaWaveformData codaWaveData) {
codaWaveData.selfLoadedWaveTimeSeries = false;
if (! codaWaveData.wave.hasTimeSeries()) { // load time series only if not preloaded
codaWaveData.selfLoadedWaveTimeSeries = codaWaveData.wave.loadTimeSeries();
if (! codaWaveData.selfLoadedWaveTimeSeries) {
if (debug) System.out.println("loadWaveformData wave timeseries not loaded:" + currentSolId);
codaWaveData.rejected = true;
}
}
}
// invoke in runnable thread:
protected final void loadWaveformData(List codaWaveData) {
int size = (codaWaveData == null) ? 0 : codaWaveData.size();
if (size < 1) return;
for (int idx = solWaveformLoadedIndex+1; idx < size; idx++) {
if (solWaveformLoadedIndex - solWaveformToProcessIndex > maxWaveformCacheSize) {
if (debug) System.out.println(" Max waveforms cached: " +maxWaveformCacheSize+ " loading thread stopping.");
break;
}
loadWaveformData((CodaWaveformData) codaWaveData.get(idx));
solWaveformLoadedIndex = idx;
Thread.currentThread().yield();
}
}
/*
Does not load the timeseries if Channel data out of range,
sets start preP to recover timeseries needed to calculate pre-event noise LTA and S wave coda.
Waveform objects must contain valid Channel data objects
*/
protected boolean calcChannelMag(CodaWaveformData codaWaveData) {
if (codaWaveData.rejected) return false;
Waveform wave = codaWaveData.wave;
boolean selfLoadedWaveTimeSeries = codaWaveData.selfLoadedWaveTimeSeries;
double waveStartTime = wave.getEpochStart();
double waveEndTime = wave.getEpochEnd();
/* patch here temporary for .001 jigger at end of data after collapse
WFSegment waveSegment = (WFSegment) wave.getSegmentList().get(wave.getSegmentList().size()-1);
waveEndTime = waveSegment.getEpochEnd();
*/
// end of patch aww 12/7/00
double preEventStartTime =
codaWaveData.pTime - codaGenerator.getNoiseBiasSamples()/wave.getSampleRate() - codaPrePTimeBiasOffsetSecs;
if (debug) {
System.out.println(
"calcChannelMag " + wave.getChannelObj().getChannelName().toDelimitedString('_') +
" prePStart:" + EpochTime.toNoZoneYYString(preEventStartTime) +
" waveStart:" + EpochTime.toNoZoneYYString(waveStartTime) +
" waveEnd:" + EpochTime.toNoZoneYYString(waveEndTime));
}
if (preEventStartTime < waveStartTime) preEventStartTime = waveStartTime;
if (! codaGenerator.isResetOnClipping()) {
double desiredWaveEndTime = codaWaveData.sCodaStartTime + codaGenerator.getMaxCodaDurationSecs();
if (debug) System.out.println(" desired waveEndTime:" + EpochTime.toNoZoneYYString(desiredWaveEndTime));
waveEndTime = Math.min(waveEndTime, desiredWaveEndTime);
}
if (waveEndTime < waveStartTime) {
if (debug) {
System.out.println(" wave number of segments: " + wave.getSegmentList().size());
System.out.println(" input waveform timeStart: " + EpochTime.toNoZoneYYString(wave.getEpochStart()) );
System.out.println(" input waveform timeEnd: " + EpochTime.toNoZoneYYString(wave.getEpochEnd()) );
}
System.out.println("CodaMagnitudeGenerator.calcChannelMag waveEndTime < waveStartTime "
+ getStnChlNameString(wave.getChannelObj()));
if (selfLoadedWaveTimeSeries) wave.unloadTimeSeries();
return false;
}
DateRange codaTimeSpan = new DateRange(preEventStartTime, waveEndTime);
if (debug) {
System.out.println(" codaTimeSpan: " + codaTimeSpan.toString());
if (wave.hasTimeTears()) System.out.println(" waveform has time tears");
}
WFSegment wfs = window(wave, codaTimeSpan); // aka WFSegment.collapse(Vector)
if (wfs == null) {
if (debug)
System.out.println("calcChannelMag requested Swave coda segment out of bounds: " +
wave.getChannelObj().getChannelName().toDelimitedString('_'));
if (selfLoadedWaveTimeSeries) wave.unloadTimeSeries();
return false;
}
// scan coda from startingIdx to end.
double wfSampleInterval = wfs.getSampleInterval();
int startingIdx = (int) Math.round((codaWaveData.sCodaStartTime - wfs.getEpochStart())/wfSampleInterval);
int wfSamplesExpected = wfs.samplesExpected;
if (startingIdx < 0 || startingIdx >= wfSamplesExpected) {
if (debug) System.out.println("calcChannelMag requested Swave coda startindex out of bounds");
if (selfLoadedWaveTimeSeries) wave.unloadTimeSeries();
return false;
}
// calculate the coda fit parameters for station channel
double smpSecsToAdd = codaWaveData.sCodaStartTime - codaWaveData.pTime; // S-P time to add to S-coda to get P-coda
boolean status = calcCoda(wfSampleInterval, smpSecsToAdd, wfs.getTimeSeries(), startingIdx,
wfSamplesExpected, wave.getChannelObj(), 0.);
if (logCodaCalc) logCodaResult(wave.getChannelObj());
if (selfLoadedWaveTimeSeries) wave.unloadTimeSeries();
calcCount++;
return status;
}
public final double getSummaryMagnitudeValue() {
return (summaryMag == null) ? -1. : summaryMag.value.doubleValue();
}
public final Magnitude getSummaryMagnitude() {
return summaryMag;
}
protected final WFSegment getWaveformSegment(Waveform wave, DateRange codaTimeSpan) {
List waveformSegments = (List) wave.getSegmentList();
if (waveformSegments == null) {
System.out.println("ERROR - waveform segments list NULL");
return null;
}
int size = waveformSegments.size(); // should be 1 if contiguous
if (debug) System.out.println(" getWaveformSegment total waveform segments: " + size);
for (int idx = 0; idx < size; idx++) {
WFSegment wfs = (WFSegment) waveformSegments.get(idx);
DateRange ts = new DateRange(wfs.getEpochStart(), wfs.getEpochEnd());
if (debug) {
System.out.println(" getWaveformSegment segment timespan: " + ts.toString());
}
// if (ts.contains(codaTimeSpan)) return wfs;
if (ts.contains(codaTimeSpan)) return new WFSegment(wfs);
}
// resultsMessage = "time tear in requested waveform window";
return null;
}
protected final WFSegment window(Waveform wave, DateRange codaTimeSpan) {
double windowStartTime = codaTimeSpan.getMinEpochSecs();
double windowEndTime = codaTimeSpan.getMaxEpochSecs();
if (windowStartTime >= windowEndTime) return null;
WFSegment wfs = getWaveformSegment(wave, codaTimeSpan);
if (wfs == null ) {
if (debug) System.out.println(" CodaMagnitudeGenerator.window coda time not contiguous; spans wave segments");
return null;
}
int wfSamplesExpected = wfs.samplesExpected;
int wfTimeSeriesSize = wfs.size();
double wfEndTime = wfs.getEpochEnd();
double wfStartTime = wfs.getEpochStart();
if (debug) {
System.out.println(" wfSamplesExpected: " + wfSamplesExpected + " size: " + wfTimeSeriesSize);
System.out.println(" wfStartTime: " + EpochTime.toNoZoneYYString(wfStartTime)
+ " wfEndTIme: " + EpochTime.toNoZoneYYString(wfEndTime));
System.out.println(" windowStartTime: " + EpochTime.toNoZoneYYString(windowStartTime)
+ " windowEndTime: " + EpochTime.toNoZoneYYString(windowEndTime));
}
if (wfTimeSeriesSize < 1 || windowStartTime > wfEndTime || windowEndTime < wfStartTime) return null;
if (windowStartTime < wfStartTime) windowStartTime = wfStartTime;
if (windowEndTime > wfEndTime) windowEndTime = wfEndTime;
double wfSampleInterval = wfs.getSampleInterval();
int sampleStartOffset = (int) Math.round((windowStartTime - wfStartTime )/wfSampleInterval);
int sampleCount = (int) Math.round((windowEndTime - windowStartTime)/wfSampleInterval) + 1; // include end of range sample
if ((sampleCount + sampleStartOffset) > wfTimeSeriesSize) {
sampleCount = wfTimeSeriesSize - sampleStartOffset;
}
//if (debug) System.out.println(" window wfs.ts.sampleCount: " + sampleCount);
float[] sample = new float[sampleCount];
float[] wfsTimeSeries = wfs.getTimeSeries();
for (int idx = 0; idx < sampleCount; idx++) {
sample[idx] = wfsTimeSeries[idx + sampleStartOffset];
}
wfs.setStart(windowStartTime);
wfs.setEnd(windowEndTime);
wfs.samplesExpected = sampleCount;
wfs.setTimeSeries(sample, false);
//deprecated wfs.length = wfs.bytesPerSample*wfs.sampleCount;
//deprecated wfs.lenSecs = wfs.getEpochEnd() - wfs.getEpochStart();
return wfs;
}
protected boolean calcCoda(double secsPerSample, double smpSecsToAdd, float [] timeSeries,
int startingIdx, int sampleCount, Channel chan, double lta) {
CodaCalibrParms calibrParms = getCodaCalibrParms(chan);
double codaCutoffAmp = 0.;
double clippingAmp = 0.;
if (calibrParms != null) {
codaCutoffAmp = calibrParms.codaCutoffAmp;
clippingAmp = calibrParms.clippingAmp;
}
String seedchan = chan.getSeedchan();
if (codaGenerator.hasFilter()) {
if (filterChannelType(seedchan)) {
codaGenerator.enableFilter();
codaGenerator.setFilter(seedchan);
}
else codaGenerator.disableFilter();
}
if (debug)
System.out.println("CodaMagnitudeGenerator.calcCoda " + getStnChlNameString(chan) +
" fit codaCutoffAmp:" + codaCutoffAmp + " clippingAmp:" + clippingAmp);
boolean status = codaGenerator.calcCoda(secsPerSample, smpSecsToAdd,
timeSeries, startingIdx, sampleCount,
codaCutoffAmp, clippingAmp, lta) ;
if (debug && ! status)
System.out.println("CodaMagnitudeGenerator.calcCoda bad coda:" + " * exit:" + codaGenerator.getExitStatusString());
return status;
}
public CodaCalibrParms getCodaCalibrParms(Channel chan) {
if (chan == null) return null;
CodaCalibration calibr = null;
if (calibrList != null) calibr = calibrList.get(chan.getChannelId());
return (calibr == null)
? defaultCalibration.getDefaultCodaCalibrParms(chan.getChannelId())
: calibr.getCodaCalibrParms();
}
protected Coda createChannelCoda(Channel chan, double pTime) {
Coda coda = null;
coda = codaGenerator.setCodaResults(coda); // set values: ngood, AFix, AFree, QFree, tau, and windowAmp
coda.setChannelObj(chan);
if (! org.trinet.jdbc.NullValueDb.isBlank(sourceDevice)) coda.source.setValue(sourceDevice);
//coda.setHorizonatlDistance(getChannelToSolutionDistance(chan));
coda.getChannelObj().calcDistance(solutionLatLonZ);
coda.getChannelObj().azimuth.setValue(getChannelToSolutionAzimuth(chan));
coda.datetime.setValue(pTime);
return coda;
}
public boolean isValidSolution(Solution sol) {
return (sol != null);
}
public abstract boolean acceptChannelType(String type) ;
public abstract boolean filterChannelType(String type) ;
public abstract boolean summaryChannelType(String type) ;
public abstract boolean isValidCoda(Coda coda) ;
public abstract double setChannelMag(Coda coda, CodaCalibrParms calibrParms) ;
public abstract Magnitude createSummaryMag(int count, double value, double err, double minRange, double maxGap) ;
public abstract Magnitude createSummaryMag(Coda [] codaArray);
protected boolean removeSummaryMagAssociation() {
if (summaryMag != null) summaryMag.unassociate();
return currentSol.getAlternateMagnitudes().remove(summaryMag);
}
protected void associateSummaryMag() {
if (summaryMag == null || hasMagAssociationDisabled()) return;
if (! currentSol.getAlternateMagnitudes().contains(summaryMag)) currentSol.addAlternateMagnitude(summaryMag);
//currentSol.setPreferredMagnitude(summaryMag);
summaryMag.associate(currentSol);
}
//Calculate summary magnitude and coda statistics using collection of Coda table row objects
protected boolean calcSummaryMag(Coda [] codaArray) {
summaryMag = null;
if (codaArray == null) {
resultsMessage = " ERROR - calcSummaryMag(Coda[] input parameter array null";
System.out.println(resultsMessage);
return false;
}
if (currentSol == null) throw new NullPointerException("Current solution is null, see setSolution(Solution)");
if (codaArray.length < minCodaCountForSummaryMag) {
resultsMessage = "codaArray.length < minCodaCountForSummaryMag";
return false;
}
summaryMag = createSummaryMag(codaArray);
if (summaryMag == null) return false;
associateSummaryMag();
try {
return (isAutoCommit()) ? commitMag() : true;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -