Seisplotjs Tutorial

Quakes and Channels:

It would be nicer if we could add some useful labels to this instead of just a raw seismogram. Perhaps getting some information about this particular earthquake and the station it was recorded at. We will use the IRIS FDSNWS station web service to get the station and channels and the USGS FDSNWS event web service to get the earthquake. Again, both of these are asynchronous and so we will have to use promises. We first create both the EventQuery and StationQuery objects.


            let queryTimeWindow = new seisplotjs.util.StartEndDuration('2019-07-01', '2019-07-31');
            let eventQuery = new seisplotjs.fdsnevent.EventQuery()
              .timeWindow(queryTimeWindow)
              .minMag(7)
              .latitude(35).longitude(-118)
              .maxRadius(3);
            let stationQuery = new seisplotjs.fdsnstation.StationQuery()
              .networkCode('CO')
              .stationCode('HODGE')
              .locationCode('00')
              .channelCode('LH?')
              .timeWindow(queryTimeWindow);

          

Then we call their query methods with a Promise.all() which will wait until both of these return before calling the then() function. We will also use the more powerful POST method to get the seismograms. The ChannelTimeRange works just like the StartEndDuration but also hold the channel that the time rage corresponds to. In this case they are all the same, but might be different if we were using multiple stations and predicted arrival times. Note that we use the event time as the start and ask for a duration of 2400 seconds.


            Promise.all([ eventQuery.query(), stationQuery.queryChannels()])
            .then( ( [ quakeList, networks ] ) => {
                let allChannels = seisplotjs.stationxml.extractAllChannels(networks);
                let timeWindow = new seisplotjs.util.StartEndDuration(quakeList[0].time, null, 2400);
                let seismogramDataList = allChannels.map(c => {
                  return seisplotjs.seismogram.SeismogramDisplayData.fromChannelAndTimeWindow(c, timeWindow);
                });
                let dsQuery = new seisplotjs.fdsndataselect.DataSelectQuery();
                return Promise.all([ quakeList, networks, dsQuery.postQuerySeismograms(seismogramDataList) ]);
            

Because we have the channel, we can also plot the seismograms corrected for overall gain and in units of m/s. We also added a couple of <span> elements to hold the station codes and earthquake description.


          }).then( ( [ quakeList, networks, seismogramDataList ] ) => {
            let div = seisplotjs.d3.select('div#myseismograph');
            let seisConfig = new seisplotjs.seismographconfig.SeismographConfig();
            seisConfig.title = seismogramDataList.map(ctr => ctr.channel.codes());
            seisConfig.doGain = true;
            let graph = new seisplotjs.seismograph.Seismograph(div,
                                                               seisConfig,
                                                               seismogramDataList);
            graph.draw();
            seisplotjs.d3.select('span#stationCode').text(networks[0].stations[0].codes());
            seisplotjs.d3.select('span#earthquakeDescription').text(quakeList[0].description);
          }).catch( function(error) {
            seisplotjs.d3.select("div#myseismograph").append('p').html("Error loading data." +error);
            console.assert(false, error);
          });
          

See it live in tutorial3.html.

Previous: Let's get some real data

Next: Predicted phase arrival times