📄 codamagnitudegenerator.java
字号:
public double getChannelToSolutionAzimuth(Channel chan) {
if (chan.azimuth.isNull())
chan.azimuth.setValue(GeoidalConvert.azimuthDegreesTo(chan.latlonz, solutionLatLonZ));
return chan.azimuth.doubleValue();
}
protected double calcTravelTime(Channel chan, String type) {
double range = getChannelToSolutionDistance(chan);
//if (debug) System.out.println(" calcTT:" + getStnChlNameString(chan) + " range:" + range);
return (type == P_TYPE) ? ttGenerator.pTravelTime(range) : ttGenerator.sTravelTime(range);
}
public int calcChannelMagByTime(double start, double end) {
return calcChannelMag(Solution.create().getByTime(start, end));
}
public int calcChannelMag(SolutionList solList) {
return calcChannelMag((Solution []) solList.toArray(new Solution[solList.size()]));
}
public int calcChannelMag(Solution [] solutions) {
int size = (solutions == null) ? 0 : solutions.length;
if (size < 1) return 0;
int successCount = 0;
for (int index = 0; index < size; index++) {
if (calcChannelMag(solutions[index]) > 0) successCount++;
}
return successCount;
}
// Returns number of solution waveforms with good codas
public int calcChannelMagForEvid(long evid) {
return calcChannelMag(Solution.create().getValidById(evid)); // create a Solution object using prefor of evid
}
protected Collection getSolutionWaveformList() {
if (currentSol == null) throw new NullPointerException("Current solution is null");
Collection wfList = currentSol.waveformList;
if (wfList == null || wfList.size() < 1) {
wfList = Waveform.create().getBySolution(currentSol); // associate all event waveforms with chosen origin,
currentSol.addWaveforms(wfList);
}
return wfList;
}
public boolean initChannelList() {
if (channelCacheFileName != null) channelList = loadChannelList(channelCacheFileName);
else if (dbEnabled) channelList = loadChannelListFromDb(EpochTime.epochToDate(currentSol.datetime.doubleValue()));
if (! hasChannelList()) {
resultsMessage = "CodaMagnitudeGenerator warning loaded channel list is null or empty!";
System.out.println(resultsMessage);
return false;
}
channelList.createLookupMap();
//channelList.toString();
return true;
}
public final boolean hasChannelList() {
return (channelList != null && ! channelList.isEmpty());
}
public ChannelList getChannelList() {
return channelList;
}
public void setChannelList(ChannelList list) {
channelList = list;
}
public abstract ChannelList loadChannelList(String filename);
public abstract ChannelList loadChannelListFromDb(java.util.Date date);
public abstract boolean storeChannelList(String filename);
public abstract void initCalibrList(java.util.Date date) ;
// Returns number of solution waveforms with good codas creates a solution waveform list.
public int calcChannelMag(Solution sol) {
if (sol == null) {
System.out.println("CodaMagnitudeGenerator calcChannelMag null solution input");
return 0;
}
else setSolution(sol); // must set the active solution i.e. currentSol for this instance
return calcChannelMag(sol, getSolutionWaveformList());
}
// Returns number of solution waveforms with good codas, uses passed parameter waveform list.
public int calcChannelMag(Solution sol, Collection wfList) {
if (sol == null) {
System.out.println("CodaMagnitudeGenerator calcChannelMag null solution input");
return 0;
}
else setSolution(sol); // must set the active solution i.e. currentSol for this instance
// clear out any preexisting coda list entries before recalculation
sol.getCodaList().clear();
//Collection wfList = getSolutionWaveformList(); // changed to humor doug here, see above, no default load, 01/01/18 aww
if (wfList == null ) {
if(verbose)
System.out.println("CodaMagnitudeGenerator calcChannelMag: null waveform list found, solution id:"
+ currentSolId);
return 0;
}
if (wfList.size() < 1) {
if (verbose)
System.out.println("CodaMagnitudeGenerator calcChannelMag: No waveforms in list, solution id:"
+ currentSolId);
return 0;
}
if (! hasChannelList()) {
/*DEBUG
System.out.println("channel list = null? :" + (channelList == null));
if (channelList != null) System.out.println("channel list.isEmpty()? :" + (channelList.isEmpty()));
System.out.println("has invalid channel list, loading new one ..." );
*/
if (! initChannelList() ) {
System.out.println("CodaMagnitudeGenerator failure constructing valid station channel list.");
return 0;
}
}
if (calibrList == null) initCalibrList(EpochTime.epochToDate(currentSol.datetime.doubleValue()));
if (verbose) {
logHeader();
System.out.println(" Total waveforms in list:" + wfList.size());
}
// prescan all waveform headers for coda time span eligibility then process derived waveform list
solCodaWaveformDataList = getCodaWaveformData(wfList) ;
eligibleCount = solCodaWaveformDataList.size(); // maxProgressValue
if (verbose) System.out.println(" Total waveforms timespan eligible:" + eligibleCount + "\n");
if (eligibleCount <= 0) return 0;
calcCount = 0; // reset counter total per solution
int validCount = processCodaWaveformData(solCodaWaveformDataList);
if (verbose) {
System.out.println(" Total solution channel codas calculated: " + calcCount);
System.out.println(" Total solution channel codas validated : " + validCount);
}
try {
if (validCount > 0 && isAutoCommit()) commitCoda();
} catch (JasiCommitException ex) {}
return validCount;
}
protected Channel getWaveformChannel(Waveform wave) {
if (wave == null) {
if (verbose) System.out.println("getWaveformChannel(Wave) wave null, solution id:" + currentSolId);
return null;
}
if (debug) System.out.println("\nCodaMagnitudeGenerator.getWaveformChannel wave:\n" + wave.toString());
Channel chan = getChannelFromList(wave.getChannelObj());
if (chan == null) {
System.out.println("CodaMagnitudeGenerator.getWaveformChannel(Wave) channel not in list "
+ wave.getChannelObj().getChannelName().toDelimitedString('_')
+ " solution id:" + currentSolId);
}
return chan;
}
private CodaWaveformData getTimeSeriesData(int index, List codaWaveformDataList) {
solWaveformToProcessIndex = index; // currentProgressValue
CodaWaveformData data = (CodaWaveformData) codaWaveformDataList.get(index);
progressMessageChannelName = data.wave.getChannelObj().getChannelName().toDelimitedString('_');
if (waveformCacheLoadingEnabled) {
if (index <= solWaveformLoadedIndex) return data;
if (loadingThread == null) {
loadingThread = new Thread(this);
loadingThread.setDaemon(true);
loadingThread.start();
}
try {
for (int count = 0; count < maxSleepLoadingIterations; count++) {
if ( ! loadingThread.isAlive() || loadingThread.isInterrupted()) break;
Thread.currentThread().sleep(maxSleepTimeMillis);
if (index <= solWaveformLoadedIndex) return data;
}
}
catch (InterruptedException ex) {
ex.printStackTrace();
}
resultsMessage = "CodaMagnitudeGenerator.getTimeSeriesData unable to load time series data";
System.out.println(resultsMessage);
return null;
}
else {
loadWaveformData(data); // single thread load here
solWaveformLoadedIndex = index;
return data;
}
}
private void initializeWaveformListProcessingIndices() {
solWaveformToProcessIndex = -1;
solWaveformLoadedIndex = -1;
}
protected final int processCodaWaveformData(List codaWaveformDataList) {
initializeWaveformListProcessingIndices();
int size = (codaWaveformDataList == null) ? 0 : codaWaveformDataList.size();
if (size < 1) return 0;
if (debug) System.out.println(" **** processCodaWaveformData input list size: " + size);
int validCount = 0;
sortWaveformsByDistance(codaWaveformDataList); // add sort by distance here
if (logCodaCalc) logCodaOutputHeader();
for (int index = 0; index < size; index++) {
CodaWaveformData data = getTimeSeriesData(index, codaWaveformDataList);
if (data == null) {
System.out.println(" WARNING - timeout loading time series, skipped further loading of coda waveform data");
System.out.println(" processCodaWaveformData indices current,loaded: " +index+ " " + solWaveformLoadedIndex);
break; // aborts all further processing alternative is just to continue to next index ????
}
if (debug) {
System.out.println(" processCodaWaveformData indices current,loaded: " +index+ " " + solWaveformLoadedIndex);
// System.out.println(data.toString());
}
if (calcChannelMag(data)) {
Coda coda = createChannelCoda(data.wave.getChannelObj(), data.pTime);
if (isValidCoda(coda)) { // check of windowcount, other values ?
resultsMessage = "Calculated valid channel coda, associated with solution";
coda.associate(currentSol); // stores in list used for later summary processing
validCount++;
}
}
Thread.currentThread().yield();
}
return validCount;
}
private Channel initWaveformChannel(Waveform wave) {
Channel chan = getWaveformChannel(wave);
if (chan == null) return null;
if (! acceptChannelType(chan.getSeedchan())) {
if (debug) {
System.out.println(" initWaveformChannel not accepting channel of type : " + chan.getSeedchan());
}
return null;
}
Channel channel = (Channel) chan.clone(); // copy lat, lon
channel.azimuth.setNull(true);
// note: do not use Channel.calcDistance(LatLonZ) need horizontal range for ttraveltime generator;
channel.dist.setValue(GeoidalConvert.horizontalDistanceKmBetween(channel.latlonz, solutionLatLonZ));
wave.setChannelObj(channel);
return channel;
}
protected final List getCodaWaveformData(Collection waveList) {
int size = (waveList == null) ? 0 : waveList.size();
if (size < 1) {
resultsMessage = "CodaMagnitudeGenerator.getCodaWaveformData found empty waveform Collection";
return null;
}
List codaWaveList = new ArrayList(size);
Waveform [] wave = (Waveform []) waveList.toArray(new Waveform [size]);
double originTime = currentSol.datetime.doubleValue();
if (debug) {
System.out.println(" **** getcodaWaveformData input list size: " + size);
System.out.println(" Origintime:" + EpochTime.toNoZoneYYString(originTime));
}
for (int idx = 0; idx < size; idx++) {
CodaWaveformData codaWaveformData = createCodaWaveformData(wave[idx], originTime);
if (codaWaveformData != null) codaWaveList.add(codaWaveformData);
}
//System.out.println("DEBUG waveforms in output:" + codaWaveList.size());
return codaWaveList;
}
public final Coda calcChannelCoda(Waveform wave, double originTime) {
CodaWaveformData data = createCodaWaveformData(wave, originTime);
loadWaveformData(data);
return (calcChannelMag(data)) ? createChannelCoda(data.wave.getChannelObj(), data.pTime) : null;
}
//protected boolean hasSPhaseTimed = false; // only if observed phase time is known to be good.
protected final double getCodaStartOffsetSecs(double smpTime) {
//if (hasSPhaseTimed) return codaStartOffsetSecs;
return (codaStartOffsetSecs > 0.) ? codaStartOffsetSecs : smpTime * 0.1; // offset inside S arrival
}
protected final CodaWaveformData createCodaWaveformData(Waveform wave, double originTime ) {
Channel chan = initWaveformChannel(wave);
if (chan == null) return null;
double pTT = getPTravelTime(chan);
double pTime = originTime + pTT;
double sTT = getSTravelTime(chan);
double sCodaStartTime = originTime + sTT + getCodaStartOffsetSecs(sTT-pTT) ; // offset inside S arrival
double waveStartTime = wave.getEpochStart();
double waveEndTime = wave.getEpochEnd();
if (debug) System.out.println(" createCodaWaveformData " +
getStnChlNameString(chan) + " pTime:" + EpochTime.toNoZoneYYString(pTime) +
" sTravelTime:" + EpochTime.toNoZoneYYString(sTT) +
" codaStartTime:" + EpochTime.toNoZoneYYString(sCodaStartTime));
if (pTime > waveEndTime || sCodaStartTime > waveEndTime || sCodaStartTime < waveStartTime) {
if (debug) System.out.println(" createCodaWaveformData wave time out of bounds for id:" + currentSolId);
return null;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -