⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 codamagnitudegenerator.java

📁 一个用java写的地震分析软件(无源码)-used to write a seismic analysis software (without source)
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
package org.trinet.util.magnitudeengines;
import java.util.*;
import org.trinet.jasi.*;
import org.trinet.jasi.coda.*;
import org.trinet.pcs.*;
import org.trinet.util.*;
import org.trinet.util.velocitymodel.*;
import org.trinet.util.gazetteer.*;

//  Subclass implementations create the codaList and magnitude members of org.trinet.jasi.Solution
public abstract class CodaMagnitudeGenerator
    implements CodaMagnitudeGeneratorIF, CommitableIF, ChannelFilterIF, Runnable {
    //protected org.trinet.util.Concat fmt;

    protected static final String P_TYPE = "P";
    protected static final String S_TYPE = "S";
    protected static final int    DEFAULT_MIN_CODA_VALUES                  = 3;
    protected static final double DEFAULT_CODA_START_TIME_OFFSET           = 1.;
    protected static final double DEFAULT_PRE_P_TIME_OFFSET                = 2.;
    protected static final long   DEFAULT_WAVEFORM_LOAD_WAIT_MILLIS        = 2000l;
    protected static final int    DEFAULT_MAX_LOADING_WAIT_ITERATIONS      = 15;
    protected static final int    DEFAULT_WAVEFORM_CACHE_SIZE              = 100;

    protected int minCodaCountForSummaryMag           = DEFAULT_MIN_CODA_VALUES;
    protected double codaStartOffsetSecs              = DEFAULT_CODA_START_TIME_OFFSET;
    protected double codaPrePTimeBiasOffsetSecs       = DEFAULT_PRE_P_TIME_OFFSET;
    protected long maxSleepTimeMillis                 = DEFAULT_WAVEFORM_LOAD_WAIT_MILLIS;
    protected int  maxSleepLoadingIterations          = DEFAULT_MAX_LOADING_WAIT_ITERATIONS;
    protected int  maxWaveformCacheSize               = DEFAULT_WAVEFORM_CACHE_SIZE;
    //protected int  solWaveformCacheSize = DEFAULT_WAVEFORM_CACHE_SIZE;

    protected CodaSolutionProcessingMode DEFAULT_SOLUTION_PROCESSING_MODE = CodaSolutionProcessingMode.CALC_CODA_AND_SUMMARY_MAG;
    protected CodaSolutionProcessingMode processingMode = DEFAULT_SOLUTION_PROCESSING_MODE;

    protected Phase defaultPhase = Phase.create();
    protected CodaCalibration defaultCalibration = new McaCalibrationTN();
    //    = CodaCalibration.create("org.trinet.util.magnitudeengines.McaCalibrationTN");  // necessary evil for now
    protected CodaGeneratorParms codaGeneratorParms;
    protected PrimarySecondaryWaveTravelTimeGeneratorIF ttGenerator;
    protected CodaGeneratorIF codaGenerator;

    protected ChannelList channelList;
    protected CodaCalibrationListIF calibrList;
    protected String channelCacheFileName;

    protected int calcCount;  // calculated coda counter for debug use
    protected static boolean debug                = false;
    protected boolean logCodaCalc                 = false;
    protected boolean logMagResiduals             = false;
    protected boolean dbEnabled                   = true;
    protected boolean waveformCacheLoadingEnabled = true;
    protected boolean verbose                     = false;
    protected boolean autoCommit                  = false;
    protected boolean magAssociationDisabled      = false;

// Instance objects utilized by methods for caching the input/output data of single solution
    protected Thread loadingThread;
    protected Solution currentSol;
    protected long currentSolId = -1l;
    protected String resultsMessage;

    protected org.trinet.util.gazetteer.LatLonZ  solutionLatLonZ;  // coupled to setSolution, Solution does not implement Geoidal.
    protected List   solCodaWaveformDataList;
    protected int    solWaveformLoadedIndex    = -1;

    protected int    solWaveformToProcessIndex = -1;
    protected int    eligibleCount ;
    protected String progressMessageChannelName;


    protected String   sourceDevice;
    protected String   defaultSourceDevice;
    protected Magnitude summaryMag;
    protected MagDataStatistics summaryMagStats;

    public class MagDataStatistics {
        public int    count;
        public double value;
        public double mean;
        public double median;
        public double weightedMedian;
        public double stdDev;

        public void init() {
            count           = 0;
            value           = 0.;
            mean            = 0.;
            median          = 0.;
            weightedMedian  = 0.;
            stdDev          = 0.;
        }

        // Need a more robust statistical algorithm to allow for different channel data counts
        // i.e. small data sets
        public double calcValue(double [] magValues, double [] weights, int calibratedCount) {

            count           = calibratedCount;
            mean            = Stats.mean(magValues, count);
            median          = Stats.median(magValues, count);
            weightedMedian  = WeightedMedian.calcMedian(count, magValues, weights);
            stdDev          = Stats.standardDeviation(magValues, count);

            value = median;
            return value;
        }

        public double getError() {
            return stdDev;
        }

        public String toString() {
            StringBuffer sb = new StringBuffer(132);
            //if (fmt == null) fmt = new org.trinet.util.Concat();
            sb.append(" weightedMedian:");
            Concatenate.format(sb, weightedMedian, 3, 2);
            sb.append(" median:");
            Concatenate.format(sb, median, 3, 2);
            sb.append(" mean:");
            Concatenate.format(sb,mean, 3, 2);
            sb.append(" stdDev:");
            Concatenate.format(sb, stdDev, 3, 2);
            sb.append(" count:");
            Concatenate.format(sb, count, 3);
            return sb.toString();
        }
    }

    protected class CodaWaveformData {
        Waveform wave;
        double pTime;
        double sCodaStartTime;
        boolean selfLoadedWaveTimeSeries;
        boolean rejected;

        protected CodaWaveformData(Waveform wave, double pTime, double sCodaStartTime) {
            this.wave = wave;
            this.pTime = pTime;
            this.sCodaStartTime = sCodaStartTime;
        }

        public String toString() {
            StringBuffer sb = new StringBuffer(512);
            sb.append(wave.toString());
            sb.append(" pTime: ").append(pTime);
            sb.append(" sCodaStartTime:").append(sCodaStartTime);
            sb.append(" selfLoad: ").append(selfLoadedWaveTimeSeries);
            sb.append(" reject: ").append(rejected);
            return sb.toString();
        }
    }

    private static void sortWaveformsByDistance(List list) {
        Collections.sort(list, new Comparator () {
             public final boolean equals(Object obj) {
                return (obj != null && obj.getClass() == this.getClass());
             }
             public final int compare(Object obj1, Object obj2) {
                double delta = ((CodaWaveformData) obj2).wave.getDistance() -
                               ((CodaWaveformData) obj1).wave.getDistance();
                if (delta == 0.) return 0;
                return (delta < 0.) ?  1 : -1;
             }
        });
    }

    protected class CalibratedCoda {
        Coda coda;
        CodaCalibrParms calibr;

        protected CalibratedCoda(Coda coda, CodaCalibrParms calibr) {
            this.coda = coda;
            this.calibr = calibr;
        }

    }

    public CodaMagnitudeGenerator() {}

    public final boolean hasMagAssociationDisabled() {
        return magAssociationDisabled;
    }

    public final void setMagAssociationDisabled(boolean value) {
        magAssociationDisabled = value;
    }

    public final void setWaveformCacheLoading(boolean value) {
        waveformCacheLoadingEnabled = value;
    }

    public final boolean isWaveformCacheLoadingEnabled() {
        return waveformCacheLoadingEnabled;
    }

    public final void setVerbose(boolean value) {
        verbose = value;
        //if (fmt == null) fmt = new org.trinet.util.Concat();
    }

    protected static void setDebug(boolean value) {
        debug = value;
    }

    public final void setDbEnabled(boolean value) {
        dbEnabled = value;
    }

    public final boolean getDbEnabled() {
        return dbEnabled;
    }

    public void setSolution(Solution sol) {
        resultsMessage = "No results";
        currentSol = sol;
        currentSolId = currentSol.id.longValue();
        solutionLatLonZ = null;
        summaryMag = null;
        if (summaryMagStats == null) summaryMagStats = new MagDataStatistics();
        else summaryMagStats.init();

        if (defaultSourceDevice != null) sourceDevice = defaultSourceDevice;
        else if (! currentSol.source.isNull()) sourceDevice = currentSol.source.toString();
        else sourceDevice = null;

        ttGenerator.setSource(currentSol);

        if (currentSol != null) {
            solutionLatLonZ = currentSol.getLatLonZ();
            if (currentSol.phaseList == null || currentSol.phaseList.size() == 0) {
                currentSol.loadPhaseList();
                currentSol.setStale(false);
            }
            //if (debug && currentSol.phaseList != null) currentSol.phaseList.dump();
        }
    }

    public final Solution getSolution() {
        return currentSol;
    }

    protected Phase setDefaultPhase(Channel chan, String type, Solution sol) {
            defaultPhase.setChannelObj(chan);
            defaultPhase.description.set(type, "", "");
            defaultPhase.sol = sol;
            return defaultPhase;
    }

    protected double getPTravelTime(Channel chan) {
        return getTravelTime(chan, P_TYPE) ;
    }

    protected double getSTravelTime(Channel chan) {
        return getTravelTime(chan, S_TYPE) ;
    }

    public double getPhaseTravelTime(Channel chan, String type) {
        double tt = 0.;
        // hasSPhaseTimed = false;
        if (currentSol.phaseList.size() > 0) {
            Phase phase = setDefaultPhase(chan, type, currentSol);
            phase = currentSol.phaseList.getPhaseSame(phase);
            if (phase != null) {
                tt = phase.getTime();
                if (tt > 0.) {
                    tt -= currentSol.datetime.doubleValue();   // convert to traveltime by removing origin time
                   //if (S_TYPE.equals(type)) hasSPhaseTimed = true;
                }
            }
        }
        return tt;
    }

    protected double getTravelTime(Channel chan, String type) {
        double tt = getPhaseTravelTime(chan, type);
        return (tt > 0.) ? tt : calcTravelTime(chan, type);
    }

    public Channel getChannelFromList(Channel inputChannel) {
        if (! hasChannelList()) {
            resultsMessage =
                "CodaMagnitudeGenerator.getChannelFromList null/empty list, invoke setChannelList(List) or initChannelList()";
            System.out.println(resultsMessage);
            return null;
        }
        //Channel chan = channelList.findSimilarInList(inputChannel);
        Channel chan = channelList.findSimilarInMap(inputChannel);
        if (chan == null) {
            if (verbose)
                System.out.println(
                   "CodaMagnitudeGenerator.getChannelFromList Unable to find channel:" + getStnChlNameString(inputChannel)
                );
        }
        return chan;
    }

    public double getChannelToSolutionDistance(Channel chan) {
        if (chan.dist.isNull()) {
            chan.dist.setValue(GeoidalConvert.horizontalDistanceKmBetween(chan.latlonz, solutionLatLonZ));
        }
        return chan.dist.doubleValue();
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -