📄 mca.java
字号:
config.filterChannelList = createChannelTypeProcessingList(props.getProperty("filterChan", "HHZ"));
config.filterOn = Boolean.valueOf(props.getProperty("filter", "true")).booleanValue();
config.commitOn = Boolean.valueOf(props.getProperty("commit", "false")).booleanValue();
config.verboseOn = Boolean.valueOf(props.getProperty("verbose", "false" )).booleanValue();
config.debugOn = Boolean.valueOf(props.getProperty("debug", "false" )).booleanValue();
config.logMagResiduals = Boolean.valueOf(props.getProperty("logMagResiduals", "false" )).booleanValue();
config.logCodaCalc = Boolean.valueOf(props.getProperty("logCodaCalc", "false" )).booleanValue();
config.minCodaCountForSummaryMag =
Integer.parseInt(props.getProperty("minCodaCountForSummaryMag", String.valueOf(DEFAULT_MIN_CODA_VALUES)));
config.codaStartOffsetSecs =
Double.parseDouble(props.getProperty("codaStartOffsetSecs", String.valueOf(DEFAULT_CODA_START_TIME_OFFSET)));
config.codaPrePTimeBiasOffsetSecs =
Double.parseDouble(props.getProperty("codaPrePTimeBiasOffsetSecs", String.valueOf(DEFAULT_PRE_P_TIME_OFFSET)));
config.loadWaitTimeMillis =
Long.parseLong(props.getProperty("waveformLoadWaitMillis", String.valueOf(DEFAULT_WAVEFORM_LOAD_WAIT_MILLIS)));
config.maxLoadingWaits =
Integer.parseInt(props.getProperty("maxLoadingWaits", String.valueOf(DEFAULT_MAX_LOADING_WAIT_ITERATIONS)));
config.waveformCacheSize =
Integer.parseInt(props.getProperty("waveformCacheSize", String.valueOf(DEFAULT_WAVEFORM_CACHE_SIZE)));
if (config.verboseOn) {
props.list(System.out);
}
return true;
}
protected static void setDebug(boolean value) {
CodaMagnitudeGenerator.setDebug(value);
CodaTN.setDebug(value);
CodaGeneratorTN.setDebug(value);
}
public boolean storeChannelList(String filename) {
return (filename == null) ? false : channelList.writeToCache(filename);
}
public ChannelList loadChannelList(String filename) {
return (filename == null) ? null : ChannelList.readFromCache(filename);
}
public ChannelList loadChannelListFromDb(java.util.Date date) {
//channelList = ChannelListWrapper.getListBySQL(toChannelListSQLString(date));
channelList = ChannelList.readList(new java.sql.Date(date.getTime()));
if (channelCacheFileName != null) storeChannelList(channelCacheFileName);
if (benchmark != null) {
benchmark.print("MCA BenchMark channelLoading time ");
benchmark.reset();
}
return channelList;
}
public void initCalibrList(java.util.Date date) {
calibrList = new McaCalibrationList();
calibrList.load(date);
if (calibrList.isEmpty())
throw new EmptyCalibrationListException("MCA initCalibrList returned empty list check database");
if (debug) calibrList.printValues();
}
/*
public Magnitude calcTrialSummaryMag(Solution sol, Collection waveformList) {
setMagAssociationDisabled(true); // disable MCA summary magnitude association with passed solution
return (calcSummaryMag(solution, waveformList)) ? getSummaryMagnitude() : null;
}
*/
public boolean calcSummaryMagForOrid(long id, boolean useExisting) {
Solution sol = SolutionTN.getByOrid(id);
if (sol == null) {
resultsMessage = "MCA no solution for input id" + id;
System.out.println(resultsMessage);
return false;
}
return calcSummaryMag(sol, useExisting);
}
public double setChannelMag(org.trinet.jasi.Coda coda, CodaCalibrParms calibrParms) {
CodaTN codaTN = (CodaTN) coda;
ChannelMag chanMag = codaTN.getChannelMag();
if (chanMag == null) chanMag = new ChannelMag();
McaCodaCalibrParms mcaCalibrParms = (McaCodaCalibrParms) calibrParms;
double magCorr = 0.;
if (mcaCalibrParms != null) {
magCorr = -mcaCalibrParms.aFix + (mcaCalibrParms.qFix - codaTN.qFix.doubleValue())*mcaCalibrParms.slope;
}
double value = codaTN.aFix.doubleValue() + magCorr;
chanMag.set(value);
chanMag.correction.setValue(magCorr);
chanMag.subScript.setValue("c");
chanMag.residual.setNull(true);
chanMag.importance.setNull(true);
chanMag.weight.setNull(true);
codaTN.setChannelMag(chanMag);
return value;
}
public Magnitude createSummaryMag(int count, double value, double err, double minRange, double maxGap) {
MagnitudeTN mag = (MagnitudeTN) Magnitude.create();
mag.setOrid(((SolutionTN) currentSol).getOrid() ); // why not in MagnitudeTN associate() method override???
//if (! currentSol.source.isNull()) mag.source.setValue(currentSol.source.toString());
if (! NullValueDb.isBlank(sourceDevice)) mag.source.setValue(sourceDevice);
mag.value.setValue(value);
mag.subScript.setValue("c");
mag.authority.setValue(EnvironmentInfo.getNetworkCode());
mag.method.setValue("CodaAmplitude");
// now counted in call to mag.getReadingsUsed()
// mag.usedReadings.setValue(count);
mag.error.setValue(err);
mag.gap.setValue(maxGap);
mag.distance.setValue(minRange);
//mag.quality.setValue(quality);
return mag;
}
protected Coda createChannelCoda(Channel chan, double pTime) {
CodaTN coda = (CodaTN) super.createChannelCoda(chan, pTime);
coda.getorid().setValue(currentSol.getOrid() );
//System.out.println("MCA.createChannelCoda: " + coda.toString());
return coda;
}
// evaluate the input results here to decide whether or not to save station channel coda
public boolean isValidCoda(Coda coda) {
return ( coda != null && ! coda.windowCount.isNull() && coda.windowCount.longValue() > 0 ) ;
// String chan = coda.chan.getSeedchan().substring(0,2);
// System.out.println("isValidCoda: \"" + chan + "\"");
// && (chan.equals("EH") || chan.equals("EL") );
}
protected double getPTravelTime(org.trinet.jasi.Channel chan) {
pTravelTime = super.getPTravelTime(chan);
return pTravelTime;
}
protected double getSTravelTime(org.trinet.jasi.Channel chan) {
double sTravelTime = getPhaseTravelTime(chan, S_TYPE);
if (sTravelTime > 0.) {
return sTravelTime;
}
else if (pTravelTime > 0.) {
sTravelTime = pTravelTime * ((UniformFlatLayerVelocityModel) ttGenerator.getModel()).getPSRatio();
}
else {
sTravelTime = super.getSTravelTime(chan);
}
return sTravelTime;
}
public boolean commitMag() throws JasiCommitException {
if (verbose) System.out.println(" committing netmag: " + summaryMag.toString());
Magnitude mag = getSummaryMagnitude();
if (mag == null) {
resultsMessage = "MCA.commitMag() error - null summary netmag";
return false;
}
if (! mag.commit()) {
throw new JasiCommitException("failure committing summary magnitude data");
}
resultsMessage = "MCA.commitMag() success";
return true;
}
public boolean commitCoda() throws JasiCommitException {
if (verbose) System.out.println(" committing coda");
CodaList list = getSolution().codaList;
if (list == null) {
resultsMessage = "MCA.commitCoda() error - null solution coda list";
return false;
}
Iterator iter = list.iterator();
while (iter.hasNext()) {
if (! ((CodaTN) iter.next()).commit() ) {
throw new JasiCommitException("failure committing coda data");
}
}
resultsMessage = "MCA.commitCoda() success";
return true;
}
private List createChannelTypeProcessingList(String input) {
StringTokenizer st = new StringTokenizer(input);
List list = new ArrayList(st.countTokens());
while (st.hasMoreTokens()) {
list.add(st.nextToken());
}
return list;
}
public boolean summaryChannelType(String type) {
if (NullValueDb.isBlank(type)) return true;
return config.summaryChannelList.contains(type);
}
public boolean filterChannelType(String type) {
if (NullValueDb.isBlank(type)) return true;
return config.filterChannelList.contains(type);
}
public boolean acceptChannelType(String type) {
if (NullValueDb.isBlank(type)) return true;
return config.acceptChannelList.contains(type);
}
/*
public boolean filterChannelType(String type) {
return (NullValueDb.isBlank(type)) ? true : (config.filterChannelTypes.startsWith(type));
}
public boolean acceptChannelType(String type) {
return (NullValueDb.isBlank(type)) ? true : (config.acceptChannelTypes.startsWith(type));
//String typeId = type.substring(0,1);
//return ( typeId.equals("H") || typeId.equals("E") );
// String typeId = type.substring(0,3);
// return ( typeId.equals("EHZ") );
}
*/
public Magnitude createSummaryMag(org.trinet.jasi.Coda [] codaArray) {
CalibratedCoda [] calibratedCoda = getCalibratedCoda(codaArray);
if (calibratedCoda.length < minCodaCountForSummaryMag) {
resultsMessage = "MCA calibratedCoda count < minCodaCountForSummaryMag";
return null;
}
Magnitude mag = createSummaryMag(calibratedCoda, (debug || false));
if (mag == null) return null;
org.trinet.jasi.Coda [] revisedCoda = reviseCalculatedCoda(mag, codaArray);
if (revisedCoda.length < minCodaCountForSummaryMag) {
resultsMessage = "MCA calibrated coda count after distance,mag filtering < minCodaCountForSummaryMag";
return null;
}
calibratedCoda = getCalibratedCoda(revisedCoda);
if (calibratedCoda.length < minCodaCountForSummaryMag) {
resultsMessage = "MCA calibratedCoda count < minCodaCountForSummaryMag";
return null;
}
mag = createSummaryMag(calibratedCoda, verbose);
updateCodaMagResiduals(mag, calibratedCoda, logMagResiduals);
resultsMessage = "MCA created summary Netmag";
return mag;
}
protected org.trinet.jasi.Coda [] reviseCalculatedCoda(Magnitude mag, org.trinet.jasi.Coda [] codaArray) {
org.trinet.jasi.Coda [] inputCoda = codaArray;
int count = inputCoda.length;
if (count > 10) inputCoda = rejectChannelsByMag(mag, inputCoda);
else inputCoda = rejectChannelsByMag(inputCoda);
return rejectChannelsByDistance(mag, inputCoda);
}
// Statistical Q-TEST not to be confused with coda "Q" for a max 12 sample test
public static final double [] CONFIDENCE_TEST = {1.0, 1.0, 1.0, .94,.76,.64,.56,.51,.47,.44,.41,.39,.37};
protected org.trinet.jasi.Coda [] rejectChannelsByMag(org.trinet.jasi.Coda [] codaArray) {
int count = codaArray.length;
if (count < 3) return currentSol.codaList.getArray(); // keep everything as significant
double [] magValue = new double[count];
for (int idx = 0; idx < count; idx++) { // retrieve channel magnitude values
magValue[idx] = codaArray[idx].getChannelMag().value.doubleValue();
}
int [] sorted = IndexSort.getSortedIndexes(magValue); // ascending sort of magnitude indices
double range = Math.abs(magValue[sorted[count-1]] - magValue[sorted[0]]); // Need to find extremes of data
// Check magnitude values using the sorted indices
for (int index = 0; index < count; index++) {
double hiDiff = (index < count-1) ? Math.abs(magValue[sorted[index]] - magValue[sorted[index+1]]) : 99999.;
double loDiff = (index > 0) ? Math.abs(magValue[sorted[index]] - magValue[sorted[index-1]]) : 99999.;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -