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

📄 masterview.java

📁 一个用java写的地震分析软件(无源码)
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	// Get timeseries if flag is set
	loadWaveforms();

	return true;
  }



    /**
     * Build a WFViewList based containing channels within the parameters with
     * waveforms with the given timespan. The list will end at either the
     * distance cutoff or the station count, whichever comes first. For example,
     * assume there are 50 channels within 100 km of the epicenter; if
     * distCutoff=100 & maxCount=20, only the nearest 20 channels will be
     * included. If distCutoff=100 & maxCount=200, only the 50 stations within
     * 100 km will be include.  Returns the number of WFViews created.<p>
     *
     * The station list comes from the static channel
     * list in the Channel class. If it is not already loaded it will be loaded with
     * all currently active channels.
     *
@param channelList - a collection of Channel objects that is the set from which
the WFViewList will be made.
@see org.trinet.jasi.Channel()

@param distCutoff - (km) the maximum distance allowed to a station
@param maxCount - the maximum number of channels to return in the list
@param ts - the time-span from which define the WFViews and Waveforms
 */

public int makeWFViewList(double distCutoff, int maxCount, TimeSpan ts) {

    ChannelList chanList = new ChannelList();

    if (MasterChannelList.get().isEmpty()) {
// load if you must
      MasterChannelList.set(ChannelList.smartLoad());
    }

    // sort the list by distance from the hypocenter
     MasterChannelList.get().distanceSort(solList.getSelected());

//    return makeWFViewList(Channel.getList(), distCutoff, maxCount, ts);
    return makeWFViewList(MasterChannelList.get(), distCutoff, maxCount, ts);
}

    /**
     * Build a WFViewList based containing channels within the parameters with
     * waveforms with the given timespan. The list will end at either the
     * distance cutoff or the station count, whichever comes first. For example,
     * assume there are 50 channels within 100 km of the epicenter; if
     * distCutoff=100 & maxCount=20, only the nearest 20 channels will be
     * included. If distCutoff=100 & maxCount=200, only the 50 stations within
     * 100 km will be include.  Returns the number of
     * WFViews created.<p>
     *
     * You pass in a channelList from which the WFViewList will be selected.

@param channelist - a collection of Channel objects that is the set from which
the WFViewList will be made.
@see org.trinet.jasi.Channel()

@param distCutoff - (km) the maximum distance allowed to a station
@param maxCount - the maximum number of channels to return in the list
@param ts - the time-span from which define the WFViews and Waveforms

    */

public int makeWFViewList(Collection channelList, double distCutoff,
			  int maxCount, TimeSpan ts) {

    // get channel array
    Channel chan [] = new Channel[channelList.size()];
    channelList.toArray(chan);

    // create WFViews for channels within cutoff and maxCount
    WFView wfv;
    int count = 0;
    for ( int i=0; i < chan.length; i++) {

	if (chan[i].dist.doubleValue() > distCutoff) break;		// too far, bail

	wfv = new WFView( chan[i], ts );

//	wfv.setWaveform(new Waveform (chan[i], ts));
         Waveform wf = Waveform.create();
         wf.setChannelObj(chan[i]);
         wf.setTimeSpan(ts);

	    wfv.setWaveform( wf );

	addWFView(wfv);

	if (count++ >= maxCount) break;			// got enough, bail
    }

    return count;
}
/*  // I think this would cause evilness. If all lists shared references to the
// master list, a sort would scramble the secondary lists' channels!
public void matchChannelLists () {

       phaseList.matchChannelsWithList(MasterChannelList.get());
       ampList.matchChannelsWithList(MasterChannelList.get());
       codaList.matchChannelsWithList(MasterChannelList.get());
}
*/
/**
 * Create a MasterView and load all the date for a single evid in the dbase.
 * Returns 'true' if successful.
 */
    //TODO: test "error" conditions: no WF's, no phases, etc.
public boolean defineByDataSource(long evid) {
    // Get Solution

    Solution sol = Solution.create().getById(evid);

    if (sol == null) {
	if (debug) System.out.println ("No Solution matches id# :" +evid);
	return false;
    }
    this.addSolution(sol);
    this.setSelectedSolution(sol);

    return defineByChannelTimeWindowModel(getChannelTimeWindowModel());
    //TEST//return defineByDataSource(sol);

}
/**
 * Create a MasterView and load all the date for a single evid using the current model.
 * Returns 'true' if successful.
 * @see: setChannelTimeWindowModel()
 */
    //TODO: test "error" conditions: no WF's, no phases, etc.
public boolean defineByCurrentModel(long evid) {
    // Get Solution

    Solution sol = Solution.create().getById(evid);

    if (sol == null) {
	if (debug) System.out.println ("No Solution matches id# :" +evid);
	return false;
    }

    // add to MV and set selected
    this.addSolution(sol);
    this.setSelectedSolution(sol);

    return defineByChannelTimeWindowModel(getChannelTimeWindowModel());
    //TEST//return defineByDataSource(sol);

}
/**
 * Create a MasterView based on the Waveforms associated with this Solution in
 * the DataSource. Load the phase, amp, etc.  */
public boolean defineByDataSource(Solution sol) {

    // TODO: read in other event that fall in the window

    if (sol == null) return false;

    // adds sol to list in proper time order, notifies observers
    addSolution(sol);
    solList.setSelected(sol);

    report("Getting waveform headers.", 20);

// [WAVEFORMS] Get Waveforms Header Info (time series is NOT loaded yet)
    ArrayList wfa = (ArrayList) Waveform.create().getBySolution(sol);

    if (debug) System.out.println ("Number of available waveforms = "+wfa.size());

    // Create a WFView for each waveform found for this event
    if (wfa.size() > 0) {

	report("Making Waveform views.", 0);

	// start with a clean WFViewList. Used to just make a new make a new wfvList
	// but that killed the Waveform listeners that inform when they are loaded
	// to repaint WFPanels.
	wfvList.clear();

	// Add these WFViews to this MasterView (would getting an array be faster here?)
	int counter = 0;
	int inc = 100/wfa.size();
	int done = 0;

	for (int i = 0; i<wfa.size(); i++)  {

	    this.addWFView(new WFView( (Waveform) wfa.get(i)));

	    report (done);
	    done += inc;
	}
    }

    // load amps, phases, codas
    report("Loading parameters...", 0);
    loadReadings();

    // Make sure TimeSpan of WFViews are big enough to show phases.
    // The 'true' means create WFViews for any phases (channels) that don't have them.
    // There can be phases with no waveforms.

    insureReadingsHaveViews(true);

    // copy lat/lon info from Channel class to WFViews
    report ("Loading channel data.", 0);
    loadChannelData();

	// calc distances and sort by dist from selected Solution
	distanceSort(sol);

// [TIMESERIES] Get timeseries if flag is set, needs wfviews and sort
//  else wf's won't load in sorted order
	loadWaveforms();

	alignViews();

	return true;
  }

    /**
     * Load the Channel object of each WFView with location and response info.
     * If there is a static Channel list in memory use that. If not, look up the
     * info  for each channel in the WFView list at the DataSource (dbase).
     */
    public void loadChannelData() {

	int efficencyCrossover = 100;	// if more then this many channels, load all
//	int efficencyCrossover = 0;	// disable per-channel reading of channels

	if (!loadChannelData) return;

	// bail if no WFViews
	if (wfvList.size() == 0) return;

	WFView wfv[] = wfvList.getArray();
	int done = 0;
	int inc = 100/wfvList.size();

	// its more efficient to load the whole list if there are more then 'n'
	// channels. Takes about 20 seconds to load current list.
	if (MasterChannelList.isEmpty() && wfvList.size() > efficencyCrossover) {
            MasterChannelList.set(ChannelList.readCurrentList());
        }

	// channel info is already loaded
	if (!MasterChannelList.isEmpty()) {

        Channel ch[] = MasterChannelList.get().getArray();

	    if (debug) System.out.println ("Matching channel info to each WFView...");
	    report ("Matching channel info to each WFView...");

	    for (int i = 0; i<wfv.length; i++)  {
		// find and copy latlonz info to Channel object in each WFView
		// if its in the channel list (ch)
		if (wfv[i].copyChannel(ch)) {
                  // also point the Waveform at it
                  if (wfv[i].wf != null) wfv[i].wf.setChannelObj(wfv[i].chan);
                } else {
		  if (debug) System.out.println ("No Match: "+wfv[i].chan.toString());
		  // Try individual channel lookup -- channel may not be in "current" list
		  wfv[i].chan = Channel.lookUp(wfv[i].chan);
                  MasterChannelList.get().add(wfv[i].chan); // add to channel list
                  // also point the Waveform at it
                  if (wfv[i].wf != null) wfv[i].wf.setChannelObj(wfv[i].chan);
                }
              report (done);
              done += inc;
	    }
	} else {		// no list loaded, look up each in dbase

         // we will be making a channel list as we go
         if (MasterChannelList.get() == null)
                  MasterChannelList.set(new ChannelList());

	    BenchMark bm = new BenchMark();
	    if (debug)  System.out.println ("Looking up channel info for each WFView...");
	    report ("Looking up channel info.");

	    // copy Channel info for each WFView
	    for (int i = 0; i<wfv.length; i++)  {

		wfv[i].chan = Channel.lookUp(wfv[i].chan);

                MasterChannelList.get().add(wfv[i].chan); // add to channel list

                // also point the Waveform at it
                if (wfv[i].wf != null) wfv[i].wf.setChannelObj(wfv[i].chan);

                report (done);
                done += inc;
	    }
	    if (debug) bm.print("Looked up: "+ wfv.length+" channels in ");
	}

    }

    /**
     * Make a local phase and amp lists for each WFView. This speeds some functions.
     */
    public void makeLocalLists () {

	WFView wfv[] = wfvList.getArray();

	for (int i = 0; i<wfv.length; i++)  {
	    wfv[i].updatePhaseList();
	    wfv[i].updateAmpList();
         wfv[i].updateCodaList();
     }
    }
/** Scan the reading lists for each solution and make sure there is a WFView
 for each reading and that it has a TimeSpan big enough to
include the reading. This insures that each WFView's viewSpan is
big enough to display its readings. Otherwise, they could land before or after available
waveform data. If 'createNewWFViews' is true, create a new WFView for any reading
with no matching WFView.  Thus, there can be phases, amps, etc with no waveforms.<p>
*
* If the masterView's timeSpan is not 'null' the Channel WFView's TimeSpan is
* set to that value. */

void insureReadingsHaveViews(boolean createNewWFViews) {

    Solution sol[] = solList.getArray();
    for (int i = 0; i<sol.length; i++) {
       insureReadingsHaveViews(sol[i], sol[i].phaseList, createNewWFViews);
       insureReadingsHaveViews(sol[i], sol[i].ampList,   createNewWFViews);
       insureReadingsHaveViews(sol[i], sol[i].codaList,  createNewWFViews);
    }
    makeLocalLists();
}
/** Scan this reading list and make sure there is a WFView
 for each reading and that it has a TimeSpan big enough to
include the readin. This insures that each WFView's viewSpan is
big enough to display its readings. Otherwise, they could land before or after available
waveform data. If 'createNewWFViews' is true, create a new WFView for any reading
with no matching WFView.  Thus, there can be phases, amps, etc with no waveforms.<p>
*
* If the masterView's timeSpan is not 'null' the Channel WFView's TimeSpan is
* set to that value. */
void insureReadingsHaveViews(Solution solution, JasiReadingList list, boolean createNewWFViews) {

     JasiReading[] jr = (JasiReading[]) list.toArray(new JasiReading[0]);
     WFView wfv;
     boolean match = false;
     final double minWindowSize = 10.0; // seconds
     final double halfWindow = minWindowSize/2.0;

     for (int i = 1; i < jr.length; i++) {

        wfv = wfvList.get(jr[i].getChannelObj());

        if (wfv != null) {    // is there already a matching view?
		wfv.viewSpanInclude(jr[i].getTime()); // make sure it includes reading time
        } else {
 //         if (false) {
         if (createNewWFViews) {
	              // show at least minWindowSize
 	       TimeSpan ts = new TimeSpan (jr[i].getTime() - halfWindow,
					   jr[i].getTime() + halfWindow);
//	       this.addWFView(new WFView(jr[i], getViewSpan() ));  // set viewspan to the masterview's
	       wfv = new WFView(jr[i], ts );
	       wfv.viewSpan.set(getViewSpan().getStart(), getViewSpan().getEnd());
	       wfv.dataSpan.set(jr[i].getTime(), jr[i].getTime());
	       this.addWFView(new WFView(jr[i], ts ));

          }
        }
     }
}
/** Scan the phase list and make sure each WFView has a TimeSpan big enough to
include any reading for that channel. This insures that each WFView's viewSpan is
big enough to include its phases. They could land before or after available
waveform data. If 'createNewWFViews' is true, create a new WFView for any phase
with no matching WFView.  Thus, there can be phases with no waveforms.<p>
*
* If timeSpan is not 'null' the WFView's TimeSpan is set to that value. */
/*
void insurePhasesHaveViews(PhaseList phaseList, boolean createNewWFViews) {

    Phase  ph[]  = (Phase[]) phaseList.getArray();
    WFView wfv[] = wfvList.getArray();
    boolean match = false;
    Channel chan;

    // a phase-only WFView needs a window length which is phase time +- 5 sec.
    TimeSpan ts = new TimeSpan();
    double phTime = 0.0;

    for (int i = 0; i < ph.length; i++)  {

	chan = ph[i].chan;	// for clarity

	// calc the minimum window around a phase (+- 5 seconds)

	phTime = ph[i].datetime.doubleValue();
	ts = new TimeSpan (phTime - 5.0, phTime + 5.0);

	match = false;

	for (int j = 0; j < wfv.length; j++)  {

	    // must use 'sameAs()' not 'equals()' because phases don't have
	    // SeedChan, Location, etc.
	    if (chan.sameAs(wfv[j].chan)) {

		// make sure WFView TimeSpan includes phase
		wfv[j].viewSpanInclude(ts);
		match = true;
		break;		// stop looking
	    }
	}

	if (!match && createNewWFViews) {

	    this.addWFView(new WFView(chan, ts ));

	    // must refresh array to reflect NEW list with this addition
	    wfv = wfvList.getArray();
	}

⌨️ 快捷键说明

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