使用seisplotjs框架读取mseed文件绘制地震波形图

由于需要将mseed文件的波形图显示在前端页面,查了好多内容后发现了这个框架可以实现这个功能。

1.首先读取mseed文件

在这里由于不能在浏览器直接读取文件系统的内容,所以我用到了node写了一个后台服务接口,这个接口使用了express库和fs库实现了文件读取功能,并将内容通过http的形式发送到前端页面上。

const express = require('express');
const fs = require('fs');

const app = express();

app.get('/api/wave', (req, res) => {
  res.setHeader('Access-Control-Allow-Methods', 'GET')
  const mseedDataBuffer = fs.readFileSync('public/Sichuan.mseed');
  res.send(mseedDataBuffer);
})

app.listen(3000, () => {
  console.log('Server is running on port 3000');
});

在前端页面上,利用axios库接收数据,具体代码如下:

axios.get('http://localhost:3000/api/wave', {
                responseType: 'arraybuffer'
            })
                .then(response => {
                    var abRaw = response.data;
                    ....
            })
                .catch(error => {
                    // 处理错误
                });

2.构建Seismogram对象

从后端拿到的数据是ArrayBuffer形式的数据,该数据需要通过miniseed库的方法转换为Datarecord对象。接着根据DataRecord对象数组创建SeismogramSegment对象。根据这个对象还需要生成Seismogram对象,这个对象是用于渲染波形图的输入参数之一。另外一个参数是配置参数对象。

const parsed = sp.miniseed.parseDataRecords(abRaw);
const serseismogramSegment = sp.miniseed.createSeismogramSegment(parsed);
const serseismogram = new sp.seismogram.Seismogram(serseismogramSegment);

通过下述代码可以配置波形图参数对象

let seisConfig = new sp.seismographconfig.SeismographConfig();
seisConfig.linkedTimeScale = new sp.scale.LinkedTimeScale();
seisConfig.linkedAmplitudeScale = new sp.scale.LinkedAmplitudeScale();
seisConfig.wheelZoom = true;
// snip start gain
seisConfig.doGain = false;

3.绘制波形图

得到seisConfig和Seismogram对象后,就可以根据这两个对象作为输入参数绘制波形图,具体操作如下。

//绘制
let div = document.querySelector('div#myseismograph');

首先选择到对应的标签,在该标签上进行内容渲染。

<div id="myseismograph">
</div>

接下来进行绘制。

let sddA = sp.seismogram.SeismogramDisplayData.fromSeismogram(serseismogram);
let graphZ = new sp.seismograph.Seismograph([sddA], seisConfig);
div.appendChild(graphZ);

这样子就完成了波形图的绘制。具体效果如下:

以上就实现了mseed文件绘制地震波形图的功能,该功能只是一个简易的例子展示,具体拓展还需要查看seisplotjs的官方文档进行学习。

Seisplotjs 3.1 API Documentation (crotwell.github.io)

另外,本文只实现了mseed文件,有些需求要seed文件实现也可以一起交流学习,seed文件跟mseed文件的内容只有在头部会有些许区别,对seed文件的内容进行修改后应该是可以通过该框架实现相同功能。

% Known encoding formats are the following FDSN codes: % 0: ASCII % 1: 16-bit integer % 2: 24-bit integer (untested) % 3: 32-bit integer % 4: IEEE float32 % 5: IEEE float64 % 10: Steim-1 % 11: Steim-2 % 12: GEOSCOPE 24-bit (untested) % 13: GEOSCOPE 16/3-bit gain ranged % 14: GEOSCOPE 16/4-bit gain ranged (untested) % 19: Steim-3 (alpha and untested) % % See also MKMSEED to export data in miniSEED format. % % % Author: Franois Beauducel % Institut de Physique du Globe de Paris % Created: 2010-09-17 % Updated: 2012-04-21 % % Acknowledgments: % Ljupco Jordanovski, Jean-Marie Saurel, Mohamed Boubacar, Jonathan Berger, % Shahid Ullah. % % References: % IRIS (2010), SEED Reference Manual: SEED Format Version 2.4, May 2010, % IFDSN/IRIS/USGS, http://www.iris.edu % Trabant C. (2010), libmseed: the Mini-SEED library, IRIS DMC. % Steim J.M. (1994), 'Steim' Compression, Quanterra Inc. % History: % [2012-04-21] % - Correct bug with Steim + little-endian coding % (thanks to Shahid Ullah) % [2012-03-21] % - Adds IDs for warning messages % [2011-11-10] % - Correct bug with multiple channel name length (thanks to % Jonathan Berger) % [2011-10-27] % - Add LocationIdentifier to X.ChannelFullName % [2011-10-24] % - Validation of IEEE double encoding (with PQL) % - Import/plot data even with file integrity problem (like PQL) % [2011-07-21] % - Validation of ASCII encoding format (logs) % - Blockettes are now stored in substructures below a single % field X.BLOCKETTES % - Add import of blockettes 500 and 2000 % - Accept multi-channel files with various data coding % [2010-10-16] % - Alpha-version of Steim-3 decoding... % - Extend output parameters with channel detection % - Add gaps and overlaps on plots % - Add possibility to force the plot % [2010-10-02] % - Add the input formats for GEOSCOPE multiplexed old data files % - Additional output argument with gap and overlap analysis % - Create a plot when no output argument are specified % - Optimize script coding (30 times faster STEIM decoding!) % % [2010-09-28] % - Correction of a problem with STEIM-1 nibble 3 decoding (one % 32-bit difference) % - Add reading of files without blockette 1000 with additional % input arguments (like Seismic Handler output files). % - Uses warning() function instead of fprintf().
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值