地震segy数据高效读写库cigsegy在windows系统的编译

news2024/10/6 2:46:35

https://github.com/JintaoLee-Roger/cigsegy

一个读写 segy 格式地震数据的 python 和 c++ 工具。可以将 segy 格式文件读到内存或者直接转为二进制文件,也可以将一个 numpy 数据存储为segy格式的文件。

特点:

  • 快,底层使用c++实现
  • 可以在python中使用,使用了pybind11将c++包装为python可调用的库
  • 可以处理规则不规则的地震数据,比如工区不是一个矩形(有缺失)或数据间隔不为1
  • 可以使用已有的segy文件的道头进行创建新的segy文件

官方给的主要是在linux上的编译方式,在windows系统上没有详细说明。这里用visual studio 2019进行了编译,很容易就编译形成了静态库文件。其中用到了fmt格式化库

https://github.com/fmtlib/fmt

文件配置如下

 通过下面代码对生成的cigsegy静态库进行了测试

#include <iostream>
#include <string>
#include <fmt/format.h>
#include "segy.h"
using namespace std;

int main()
{
    std::cout << "Hello World!\n";
    string filePath = R"(E:\test.sgy)";
    segy::SegyIO segyIO(filePath);
    fmt::print("texture header:n{}\n", segyIO.textual_header());
    fmt::print("meta information:\n{}\n", segyIO.metaInfo());

    return 0;
}

 运行效果如下

 打印了seyg的文本头信息和线道号基本信息,下面列出了该库提供的其他主要接口

/*********************************************************************
** Copyright (c) 2022 Roger Lee.
** Computational and Interpretation Group (CIG),
** University of Science and Technology of China (USTC).
**
** @File: segy.h
** @Time: 2022/11/16 11:30:42
** @Version: 1.0
** @Description :
*********************************************************************/

#ifndef CIG_SEGY_H
#define CIG_SEGY_H

#include <stdexcept>
#include <vector>
// #include <omp.h>

#include "mio.hpp"
#include "utils.h"

namespace segy {

struct MetaInfo {
  // count information
  int32_t sizeX; // same as time
  int32_t sizeY; // same as crossline
  int32_t sizeZ; // same as inline
  int64_t trace_count;
  int16_t sample_interval; // dt
  int16_t data_format;     // 1 or 5
  float Y_interval;        // crossline interval
  float Z_interval;        // inline interval
  int16_t start_time;
  int16_t scalar;

  int min_inline;
  int max_inline;
  int min_crossline;
  int max_crossline;

  bool isNormalSegy;

  float fillNoValue;

  // field information
  int inline_field = kDefaultInlineField;
  int crossline_field = kDefaultCrosslineField;
  int X_field = kDefaultXField;
  int Y_field = kDefaultYField;

  int inline_step = 1;
  int crossline_step = 1;
};

struct LineInfo {
  int line_num;
  uint64_t trace_start;
  uint64_t trace_end;
  int count;
};

struct TraceInfo {
  int inline_num;
  int crossline_num;
  int X;
  int Y;
};

class SegyIO {
public:
  // read segy mode
  explicit SegyIO(const std::string &segyname);
  // create segy from memory
  SegyIO(int sizeX, int sizeY, int sizeZ);
  // create segy file from binary file
  SegyIO(const std::string &binaryname, int sizeX, int sizeY, int sizeZ);

  ~SegyIO();

  inline int shape(int dimension) {
    if (dimension == 0) {
      return m_metaInfo.sizeX;
    } else if (dimension == 1) {
      return m_metaInfo.sizeY;
    } else if (dimension == 2) {
      return m_metaInfo.sizeZ;
    } else {
      throw std::runtime_error("shape(dim), dim can be only {0, 1, 2}");
    }
  }

  inline int64_t trace_count() { return m_metaInfo.trace_count; }

  inline void set_size(int x, int y, int z) {
    m_metaInfo.sizeX = x;
    m_metaInfo.sizeY = y;
    m_metaInfo.sizeZ = z;
    if (isReadSegy) {
      m_metaInfo.isNormalSegy = true;
      isScan = true;
      int64_t trace_count =
          (m_source.size() - kTextualHeaderSize - kBinaryHeaderSize) /
          (kTraceHeaderSize + x * sizeof(float));
      if ((int64_t)y * z != (trace_count)) {
        throw std::runtime_error("invalid shape. inline * crossline != "
                                 "total_trace_count");
      }
    }
  }

  void collect(float *data, int *header);

  std::string textual_header();
  std::string metaInfo();
  inline std::vector<LineInfo> line_info() { return m_lineInfo; }
  inline MetaInfo get_metaInfo() { return m_metaInfo; }

  void setInlineLocation(int loc);
  void setCrosslineLocation(int loc);
  void setXLocation(int loc);
  void setYLocation(int loc);

  void setInlineStep(int step);
  void setCrosslineStep(int step);
  void setSteps(int istep, int xstep);

  // read segy
  void setFillNoValue(float noValue);
  void scan();
  void tofile(const std::string &binary_out_name);
  void read(float *dst, int startX, int endX, int startY, int endY, int startZ,
            int endZ);
  void read(float *dst);
  void read_inline_slice(float *dst, int iZ);
  void read_cross_slice(float *dst, int iY);
  void read_time_slice(float *dst, int iX);
  void read_trace(float *dst, int iY, int iZ);

  // binary header & trace header
  void get_TraceInfo(int n, int *traceinfo);

  // create segy
  void setSampleInterval(int interval);
  void setDataFormatCode(int fdormat);
  void setStartTime(int start_time);
  void setXInterval(float dz);
  void setYInterval(float dy);
  void setMinInline(int in);
  void setMinCrossline(int cross);

  void create(const std::string &segy_out_name, const float *src);
  void create(const std::string &segy_out_name);

  void close_file();

private:
  bool isReadSegy{};
  bool isScan = false;
  mio::mmap_source m_source;
  mio::mmap_sink m_sink;
  std::vector<LineInfo> m_lineInfo;
  MetaInfo m_metaInfo;

  void scanBinaryHeader();
  void initMetaInfo();
  void initTraceHeader(TraceHeader *trace_header);
  void write_textual_header(char *dst, const std::string &segy_out_name);
  void write_binary_header(char *dst);
  void write_trace_header(char *dst, TraceHeader *trace_header, int32_t iY,
                          int32_t iZ, int32_t x, int32_t y);

  inline void _get_TraceInfo(uint64_t n, TraceInfo &tmetaInfo) {
    const char *field =
        m_source.data() + kTextualHeaderSize + kBinaryHeaderSize +
        n * (kTraceHeaderSize + m_metaInfo.sizeX * sizeof(float));
    tmetaInfo.inline_num =
        swap_endian(*(int32_t *)(field + m_metaInfo.inline_field - 1));
    tmetaInfo.crossline_num =
        swap_endian(*(int32_t *)(field + m_metaInfo.crossline_field - 1));
    tmetaInfo.X = swap_endian(*(int32_t *)(field + m_metaInfo.X_field - 1));
    tmetaInfo.Y = swap_endian(*(int32_t *)(field + m_metaInfo.Y_field - 1));
  }
};

void read_ignore_header(const std::string &segy_name, float *dst, int sizeX,
                        int sizeY, int sizeZ, int format = 5);
void tofile_ignore_header(const std::string &segy_name,
                          const std::string &out_name, int sizeX, int sizeY,
                          int sizeZ, int format = 5);

void tofile(const std::string &segy_name, const std::string &out_name,
            int iline = kDefaultInlineField, int xline = kDefaultCrosslineField,
            int istep = 1, int xstep = 1);

void read(const std::string &segy_name, float *dst,
          int iline = kDefaultInlineField, int xline = kDefaultCrosslineField,
          int istep = 1, int xstep = 1);

void create_by_sharing_header(const std::string &segy_name,
                              const std::string &header_segy, const float *src,
                              int sizeX, int sizeY, int sizeZ, int iline = 189,
                              int xline = 193, int istep = 1, int xstep = 1);

void create_by_sharing_header(const std::string &segy_name,
                              const std::string &header_segy,
                              const std::string &src_file, int sizeX, int sizeY,
                              int sizeZ, int iline = 189, int xline = 193,
                              int istep = 1, int xstep = 1);
} // namespace segy

#endif

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/606659.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

皮卡丘XXE/URL重定向/SSRF

一.XXE 1.概述 XXE -"xml external entity injection" 既"xml外部实体注入漏洞"。 概括一下就是"攻击者通过向服务器注入指定的xml实体内容,从而让服务器按照指定的配置进行执行,导致问题" 也就是说服务端接收和解析了来自用户端的xml数据,而又…

chatgpt赋能python:Python升级所有包:一步引导所有Python开发者升级你的Python环境

Python升级所有包&#xff1a;一步引导所有Python开发者升级你的Python环境 Python作为一种动态的编程语言&#xff0c;一直在不断发展和更新。每个Python版本都有自己的新功能和改进。因此&#xff0c;许多Python开发者在使用Python时都会尝试升级到最新的版本。但是&#xf…

论文笔记--Transformer-XL: Attentive Language Models Beyond a Fixed-Length Context

论文笔记--Transformer-XL: Attentive Language Models Beyond a Fixed-Length Context 1. 文章简介2. 文章概括3 文章重点技术3.1 Segment-Level Recurrence with State Reuse3.2 相对位置编码 4. 文章亮点5. 原文传送门 1. 文章简介 标题&#xff1a;Transformer-XL: Attent…

Spring集合

目录 SpringSpring简介Spring概述Spring FrameworkSpring Framework特征 IOC1、IOC的思想(1)传统方式的获取资源(2)控制反转方式的获取资源(3)DI 2、IOC 容器的两种实现BeanFactoryApplicationContext 基于XML管理bean1.创建Maven2.引入依赖3.创建HelloWorld.Java类4.创建sprin…

【Java】单例设计模式-饿汉模式和懒汉模式

单例模式概念如何设计 饿汉模式懒汉模式分析造成线程不安全的原因解决方法 总结 单例模式 概念 单例是一种设计模式。单例指的是在全局范围内只有一个实例对象。比如在学习JDBC编码时使用的DataSource&#xff0c;定义了数据库的用户名&#xff0c;密码和连接串&#xff0c;定…

以太网交换机自学习和转发帧的流程

以太网交换机自学习和转发帧的流程 笔记来源&#xff1a; 湖科大教书匠&#xff1a;以太网交换机自学习和转发帧的流程 声明&#xff1a;该学习笔记来自湖科大教书匠&#xff0c;笔记仅做学习参考 以太网交换机工作在数据链路层&#xff08;也包括物理层&#xff09; 以太网交…

大数据处理领域的经典框架:MapReduce详解与应用【上进小菜猪大数据】

上进小菜猪&#xff0c;沈工大软件工程专业&#xff0c;爱好敲代码&#xff0c;持续输出干货。 MapReduce是一个经典的大数据处理框架&#xff0c;可以帮助我们高效地处理庞大的数据集。本文将介绍MapReduce的基本原理和实现方法&#xff0c;并给出一个简单的示例。 一、MapR…

文件上传漏洞、XSS漏洞、RCE漏洞

文件上传漏洞 1.定义&#xff1a;指用户上传了一个可执行的脚本文件&#xff08;常见头像&#xff0c;简历&#xff0c;资源&#xff0c;附件&#xff0c;编辑器&#xff09;&#xff0c;并通过此脚本文件获得了执行服务器端命令的能力。 2.所需条件 &#xff08;1&#xff0…

什么是“支付二清”,“二清”的定义

“二清”的定义&#xff1a; 支付行业的"二清"是指二次清算&#xff0c;也称为二级清算。在支付行业中&#xff0c;清算是指在交易完成后&#xff0c;将资金从付款人账户转移到收款人账户的过程。一级清算通常由银行完成&#xff0c;而二级清算则是指由支付机构或清…

正则表达式命令

文章目录 一.基础命令1.grep命令1.1grep格式1.2grep命令选项 2.特殊的符号2.1空行——^$2.2以什么为开头—^,以什么为结尾—$2.2.1以什么为开头的格式&#xff1a;2.2.2以什么为结尾的格式&#xff1a; 3.只匹配单行——^匹配的字符$ 二.文本处理命令1.sort命令1.1命令解释及格…

打电话用什么耳机好,推荐几款性能表现高的骨传导耳机

近几年有一种新型传播方式的耳机&#xff0c;将声音转化为振动&#xff0c;从而让我们的听觉神经感知到。这种声音传播方式叫做"骨传导"&#xff0c;所以叫做骨传导耳机。因为它不需要通过耳膜进行传播声音&#xff0c;所以可以让耳朵在不接触外界的情况下听到声音。…

SpringCloud(四)

文章目录 Ribbon负载均衡负载均衡原理源码跟踪1&#xff09;LoadBalancerIntercepor2&#xff09;LoadBalancerClient3&#xff09;负载均衡策略IRule4&#xff09;总结 Ribbon负载均衡 在springcloud&#xff08;三&#xff09;中&#xff0c;我们添加了LoadBalanced注解&…

Burp模块

Target模块 记录流量 1.Target按主机或域名分类记录 2.HTTP History 按时间顺序记录且会记录很多次 3.Target模块的作用 &#xff08;1&#xff09;把握网站的整体情况 &#xff08;2&#xff09;对一次工作的域进行分析 &#xff08;3&#xff09;分析网站存在的攻击面 …

day 38,509. 斐波那契数70. 爬楼梯;# 746. 使用最小花费爬楼梯

动态规划 五步分析509. 斐波那契数1. dp数组以及下标名义2. 递归公式3. dp数组如何初始化4. 遍历顺序&#xff08;背包问题先遍历背包还是物品&#xff09;5. 打印dp数组&#xff1a;debug6.代码 70. 爬楼梯1. dp数组以及下标名义2. 递归公式3. dp数组如何初始化4. 遍历顺序5. …

idea部署Tomcat

创建Web项目 我们首先使用IDEA创建一个普通的java项目 创建好后的项目结构如上图&#xff0c;我创建的项目名称为tomcat&#xff0c;这个项目现在还是一个普通的java项目&#xff0c;想要开发web程序&#xff0c;我们还要做一下操作&#xff0c;首先我们先给项目添加依赖 首先…

皮卡丘Unsafe Fileupload

1.不安全的文件上传漏洞概述 文件上传功能在web应用系统很常见&#xff0c;比如很多网站注册的时候需要上传头像、上传附件等等。当用户点击上传按钮后&#xff0c;后台会对上传的文件进行判断 比如是否是指定的类型、后缀名、大小等等&#xff0c;然后将其按照设计的格式进行…

chatgpt赋能python:Python升序数函数:从入门到实战

Python升序数函数&#xff1a;从入门到实战 Python是一门广泛应用于软件开发、数据分析、人工智能等领域的高级编程语言。其中&#xff0c;对数值类型的处理尤为突出&#xff0c;而Python中提供了许多方便实用的数学函数来支持数值类型的计算。本篇文章将主要介绍Python中如何…

皮卡丘存储型xss、DOM型xss、DOM型xss-x

1.存储型xss 看题目&#xff0c;我们先留言&#xff0c;看它的过滤机制 发现可以永久存储并输出我们的留言 之后插入payload: <script>alert(xss)</script> 成功弹窗&#xff01; 2.DOM型xss Dom型xss&#xff0c;简单的说&#xff0c;就是向文档对象传入xss参…

ODOO随笔(一)—— Odoo 16的docker部署以及vscode环境配置

之前一直使用Odoo源码配置开发环境&#xff0c;安装的步骤比较多&#xff0c;费时。趁着升级到16版本的机会&#xff0c;尝试使用docker快速配置Odoo的VSCode开发环境。 1 系统环境 &#xff08;1&#xff09;操作系统&#xff1a;ubuntu 20.04 Alternative downloads | Ubu…

高完整性系统(1)Introduction

文章目录 什么是 formal methods案例1&#xff1a;造影机器案例2&#xff1a; 特斯拉汽车的自动驾驶功能案例3&#xff1a;空客 320案例4&#xff1a;波音737 什么是 formal methods “Formal methods” 是计算机科学中的一个术语&#xff0c;它指的是一种使用数学模型和技术来…