📄 waveform.java
字号:
*/
public float getBias ()
{
return biasVal;
}
/**
* Scans the given time window for a peak amplitude. Used to limit the scan for
* efficiency and to avoid energy from other events. If there is no time-series
* null is returned.
*/
public Amplitude getPeakAmplitude (double startTime, double endTime) {
return getPeakAmplitude(new TimeSpan(startTime, endTime));
}
/**
* Scans the whole time series for a peak amplitude. If there is no time-series
* null is returned.
*/
public Amplitude getPeakAmplitude () {
return getPeakAmplitude(getTimeSpan());
}
/**
* Scans the given time window for a peak amplitude. Used to limit the scan for
* efficiency and to avoid energy from other events. If there is no time-series
* null is returned.
*/
public Amplitude getPeakAmplitude (TimeSpan timeSpan) {
// get the peak
Sample peak = scanForPeak(timeSpan);
if (peak == null) {
return null;
} else {
Amplitude amp = Amplitude.create();
// zero-to-peak or peak-to-peak ?
amp.halfAmp = true;
// set the channel, value, type & time of the amp object
amp.set(this, peak, AmpType.WAU, timeSpan);
return amp;
}
}
/**
* Find the minimum and maximum amplitudes of this waveform by examining all
* waveform segments.
*/
public void scanForAmps () {
if (!hasTimeSeries()) return; // no time series
synchronized (this) {
WFSegment seg[] = WFSegment.getArray(segList);
maxSample = seg[0].getMaxSample();
minSample = seg[0].getMinSample();
for (int i=1; i < seg.length; i++) {
if (seg[i].getMaxSample() != null &&
seg[i].getMaxSample().value > maxSample.value)
maxSample = seg[i].getMaxSample();
if (seg[i].getMinSample() != null &&
seg[i].getMinSample().value < minSample.value)
minSample = seg[i].getMinSample();
}
} // end of synch
}
/**
* Return the Sample with the maximum amplitude of this waveform.
* Return's null if no time-series. NOTE: bias is NOT removed.
*/
public Sample getMaxSample () {
if (maxSample == null) scanForAmps();
return maxSample;
}
/**
* Return the maximum amplitude value of this waveform.
* Return's 0 if no time-series. NOTE: bias is NOT removed.
*/
public double getMaxAmp () {
if (maxSample == null) return 0;
return maxSample.value;
}
/**
* Return the Sample with the minimum amplitude of this waveform.
* Return's null if no time-series. NOTE: bias is NOT removed.
*/
public Sample getMinSample () {
if (minSample == null) scanForAmps();
return minSample;
}
/**
* Return the minimum amplitude of this waveform.
* Returns 0 if no time-series. NOTE: bias is NOT removed.
*/
public double getMinAmp () {
if (minSample == null) return 0;
return minSample.value;
}
/**
* Return the total range of amplitudes in the trace
*/
public double rangeAmp() {
return getMaxAmp() - getMinAmp();
}
/**
* Return a Sample with the maximum <b>rectified</b> amplitude of this waveform with
* the bias removed. Thus the Sample.value will always be positive.
* Return's null if no time-series.
*/
public Sample getPeakSample () {
// bias is always subtracted (removed)
double max = getMaxSample().value - getBias();
double min = getMinSample().value - getBias();
max = Math.abs(max);
min = Math.abs(min);
// compare absolute values to determine greatest deviation from mean
if (min > max) {
return new Sample(getMinSample().datetime, min);
} else {
return new Sample(getMaxSample().datetime, max);
}
}
/**
* Return string describing the Waveform object, primarily for debugging.<p>
* Example:<br>
* <tt>
Waveform: id = 13356047, channel = CI AGA HLZ, timeStart = 2001-05-16 19:00:36.175 GMT+00:00, timeEnd = 2001-05-16 19:01:21.385 GMT+00:00
samplesPerSecond = 100.0, dataMode = T, bytes of data = 5632, samplesInMemory = 0, timeQual = NaN, format = 2
savingEvent = 9653085, path/file = /archive/trig/2001/200105/9653085
* </tt>
*/
public String toString() {
String idStr = "null";
if (!id.isNull()) idStr = id.toString();
return
" Waveform: id = " + idStr +
", channel = " + chan.toDelimitedSeedString() +
", timeStart = " + EpochTime.toString(timeStart.doubleValue()) +
", timeEnd = " + EpochTime.toString(timeEnd.doubleValue()) + "\n"+
" samplesPerSecond = " +samplesPerSecond.toString() +
", dataMode = " + dataMode.toString() +
", bytes of data = " + byteCount +
", samplesInMemory = "+ samplesInMemory() +
", timeQual = "+ getTimeQuality().doubleValue() +
// ", sampleCount = " + sampleCount.toString() +
", format = " + format.toString() + "\n"+
" savingEvent = " + savingEvent.toString() +
", path/file = " + path+filename ;
}
/**
* Return string describing the Waveform object, primarily for debugging.<p>
* Example:
<tt>
Waveform: id = 13356047
channel = CI AGA HLZ
timeStart = May 16, 2001 19:00:36.175
timeEnd = May 16, 2001 19:01:21.385
samplesPerSecond = 100.0
dataMode = T
encoding = 10
bytes of data = 5632
samplesInMemory = 0
timeQual = NaN
format = 2
savingEvent = 9653085
path/file = /archive/trig/2001/200105/9653085
<\tt>
*/
public String toBlockString() {
//final String fmtString = "MMMM dd, yyyy HH:mm:ss.SS";
// "ss.SS" produces bad values
final String fmtString = "MMMM dd, yyyy HH:mm:ss.SSS";
String idStr = "null";
if (!id.isNull()) idStr = id.toString();
return
"Waveform: id = " + idStr +
"\nchannel = " + chan.toDelimitedSeedString() +
"\ntimeStart = " + DateTime.toString(timeStart.doubleValue(), fmtString) +
"\ntimeEnd = " + DateTime.toString(timeEnd.doubleValue(), fmtString)+
"\nsamplesPerSecond = " +samplesPerSecond.toString() +
"\ndataMode = " + dataMode.toString() +
"\nencoding = " + SeedEncodingFormat.getTypeString(encoding.intValue())+
" ("+encoding.toString()+")"+
"\nbytes of data = " + byteCount +
"\nsamplesInMemory = "+ samplesInMemory() +
"\ntimeQual = " + getTimeQuality().doubleValue() +
"\nformat = " + format.toString() +
"\nsavingEvent = " + savingEvent.toString() +
"\npath/file = " + path+filename ;
}
/** Set the travel-time model used to calculate the energy window. */
public void setTravelTimeModel (TravelTime model) {
ttModel = model;
}
/** Return the travel-time model used to calculate the energy window. */
public TravelTime getTravelTimeModel () {
return ttModel;
}
/** Return a TimeSpan representing a window where you are likely to find
* the peak seismic energy.
* The window begins 1 sec before the calculated P-wave onset and
* ends at P-wave onset plus 2x the S-P time.<p>
* Uses the standart TraveTime model.
*/
public TimeSpan getEnergyTimeSpan (double originTime, double distance) {
// define the window
double ttp = ttModel.getTTp(distance);
double tts = ttModel.getTTs(distance);
double energyStart = originTime + ttp - 1.0;
double energyEnd = energyStart + 2.0*(tts-ttp);
return new TimeSpan (energyStart, energyEnd);
}
/** Return a TimeSpan representing a window before the seismic energy.
* The window begins at the start of the waveform and ends 1 sec before the
* calculated P-wave onset.
* Uses the standart TraveTime model.
*/
public TimeSpan getPreEnergyTimeSpan (double originTime, double distance) {
return new TimeSpan (getEpochStart(),
getEnergyTimeSpan(originTime, distance).getStart());
}
/**
* Return the sample closest to the given time. Times are raw epoch seconds.
* Null is returns if there is no time series.
* This is used to force operator picks to lie on a sample. We actually scan the data
* rather than calculate because there may be a time-tear. If the time is
* equidistant between samples the earlier sample will be returned.
* Also we want to look up the amp for the sample .
*/
public Sample closestSample(double dtime) {
synchronized (this) {
if (!hasTimeSeries()) return null; // no time series
// before time range
if (dtime < timeStart.doubleValue()) return getFirstSample();
// after time range
if (dtime > timeEnd.doubleValue()) return getLastSample();
// must be in the time range
Sample samp;
Sample closeSamp = null;
double dtNew;
double dtOld = Double.MAX_VALUE;
WFSegment seg[] = WFSegment.getArray(segList);
for (int i=0; i < seg.length; i++) {
samp = seg[i].closestSample(dtime);
// closer?
dtNew = Math.abs((samp.datetime - dtime));
if (dtNew < dtOld) {
dtOld = dtNew;
closeSamp = samp;
}
}
return closeSamp;
} // end of synch
}
/** Return the first sample in the Waveform */
public Sample getFirstSample() {
if (!hasTimeSeries()) { return null; } // no time series
return ((WFSegment) segList.get(0)).getFirstSample();
}
/** Return the last sample in the Waveform */
public Sample getLastSample() {
if (segList.size() == 0) { return null; } // no time series
return ((WFSegment) segList.get(segList.size()-1)).getLastSample();
}
/**
* Return a collection of WFSegments that contains the time-series between
* the given times. Only one WFSegment will result if there are no time-tears.
* If either the start or end time is beyond what is available in the waveform
* the returned WFSegments will be limited by the available data. Returns an
* empty Collection if there is no data within the time window.
*/
public Collection getSubSegments (double startTime, double endTime) {
synchronized (this) {
ArrayList newSegList = new ArrayList();
if (!hasTimeSeries()) return newSegList; // no time series
WFSegment seg[] = WFSegment.getArray(segList);
WFSegment newSeg;
for (int i=0; i < seg.length; i++) {
newSeg = seg[i].getSubSegment(startTime, endTime);
if (newSeg.size() > 0) {
newSegList.add(newSeg);
}
}
return newSegList;
} // end of synch
}
} // end of class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -