用Obspy读取segy的文件头并保存到csv数据库

文章目录

  • 用Obspy读取segy的文件头并保存到csv数据库
  • 读入Segy文件
  • 检查头文件
  • 保存道头
  • 保存道头到csv

读入Segy文件

from obspy.io.segy.segy import _read_segy
filename = 'path.sgy';
segy = _read_segy(filename)

然后得到Segy文件(对象)

本文旨在读取segy的道头文件,因此,我们取其中一个trace的header检查一下都有哪些可以调用的函数或者数据。

检查头文件

参考官方给出的SEGYTraceHeader这个对象所拥有的属性

obspy.io.segy.segy.SEGYTraceHeader — ObsPy 1.3.1 documentation

同理,需要拿到SEGYFile的header也用同样的方法。

obspy.io.segy.segy.SEGYFile — ObsPy 1.3.1 documentation

__dir__()可以得到可调用list

segy.traces[0].header.__dir__()
>>
['endian','unpacked_header','number_of_samples_in_this_trace','original_field_record_number','energy_source_point_number','trace_sequence_number_within_line','trace_sequence_number_within_segy_file','trace_number_within_the_original_field_record','ensemble_number','trace_number_within_the_ensemble','trace_identification_code','number_of_vertically_summed_traces_yielding_this_trace','number_of_horizontally_stacked_traces_yielding_this_trace','data_use','distance_from_center_of_the_source_point_to_the_center_of_the_receiver_group','receiver_group_elevation','surface_elevation_at_source','source_depth_below_surface','datum_elevation_at_receiver_group','datum_elevation_at_source','water_depth_at_source','water_depth_at_group','scalar_to_be_applied_to_all_elevations_and_depths','scalar_to_be_applied_to_all_coordinates','source_coordinate_x','source_coordinate_y','group_coordinate_x','group_coordinate_y','coordinate_units','weathering_velocity','subweathering_velocity','uphole_time_at_source_in_ms','uphole_time_at_group_in_ms','source_static_correction_in_ms','group_static_correction_in_ms','total_static_applied_in_ms','lag_time_A','lag_time_B','delay_recording_time','mute_time_start_time_in_ms','mute_time_end_time_in_ms','sample_interval_in_ms_for_this_trace','gain_type_of_field_instruments','instrument_gain_constant','instrument_early_or_initial_gain','correlated','sweep_frequency_at_start','sweep_frequency_at_end','sweep_length_in_ms','sweep_type','sweep_trace_taper_length_at_start_in_ms','sweep_trace_taper_length_at_end_in_ms','taper_type','alias_filter_frequency','alias_filter_slope','notch_filter_frequency','notch_filter_slope','low_cut_frequency','high_cut_frequency','low_cut_slope','high_cut_slope','year_data_recorded','day_of_year','hour_of_day','minute_of_hour','second_of_minute','time_basis_code','trace_weighting_factor','geophone_group_number_of_roll_switch_position_one','geophone_group_number_of_trace_number_one','geophone_group_number_of_last_trace','gap_size','over_travel_associated_with_taper','x_coordinate_of_ensemble_position_of_this_trace','y_coordinate_of_ensemble_position_of_this_trace','for_3d_poststack_data_this_field_is_for_in_line_number','for_3d_poststack_data_this_field_is_for_cross_line_number','shotpoint_number','scalar_to_be_applied_to_the_shotpoint_number','trace_value_measurement_unit','transduction_constant_mantissa','transduction_constant_exponent','transduction_units','device_trace_identifier','scalar_to_be_applied_to_times','source_type_orientation','source_energy_direction_mantissa','source_energy_direction_exponent','source_measurement_mantissa','source_measurement_exponent','source_measurement_unit','__module__','__doc__','__init__','_read_trace_header','write','__getattr__','__str__','_repr_pretty_','_create_empty_trace_header','__dict__','__weakref__','__repr__','__hash__','__getattribute__','__setattr__','__delattr__','__lt__','__le__','__eq__','__ne__','__gt__','__ge__','__new__','__reduce_ex__','__reduce__','__subclasshook__','__init_subclass__','__format__','__sizeof__','__dir__','__class__']

为了得到所有的key,可以采用__dict__ ,得到用于保存csv的所有key

segy.traces[0].header.__dict__.keys()
>>
dict_keys(['endian', 'unpacked_header', 'number_of_samples_in_this_trace', 'original_field_record_number', 'energy_source_point_number', 'trace_sequence_number_within_line', 'trace_sequence_number_within_segy_file', 'trace_number_within_the_original_field_record', 'ensemble_number', 'trace_number_within_the_ensemble', 'trace_identification_code', 'number_of_vertically_summed_traces_yielding_this_trace', 'number_of_horizontally_stacked_traces_yielding_this_trace', 'data_use', 'distance_from_center_of_the_source_point_to_the_center_of_the_receiver_group', 'receiver_group_elevation', 'surface_elevation_at_source', 'source_depth_below_surface', 'datum_elevation_at_receiver_group', 'datum_elevation_at_source', 'water_depth_at_source', 'water_depth_at_group', 'scalar_to_be_applied_to_all_elevations_and_depths', 'scalar_to_be_applied_to_all_coordinates', 'source_coordinate_x', 'source_coordinate_y', 'group_coordinate_x', 'group_coordinate_y', 'coordinate_units', 'weathering_velocity', 'subweathering_velocity', 'uphole_time_at_source_in_ms', 'uphole_time_at_group_in_ms', 'source_static_correction_in_ms', 'group_static_correction_in_ms', 'total_static_applied_in_ms', 'lag_time_A', 'lag_time_B', 'delay_recording_time', 'mute_time_start_time_in_ms', 'mute_time_end_time_in_ms', 'sample_interval_in_ms_for_this_trace', 'gain_type_of_field_instruments', 'instrument_gain_constant', 'instrument_early_or_initial_gain', 'correlated', 'sweep_frequency_at_start', 'sweep_frequency_at_end', 'sweep_length_in_ms', 'sweep_type', 'sweep_trace_taper_length_at_start_in_ms', 'sweep_trace_taper_length_at_end_in_ms', 'taper_type', 'alias_filter_frequency', 'alias_filter_slope', 'notch_filter_frequency', 'notch_filter_slope', 'low_cut_frequency', 'high_cut_frequency', 'low_cut_slope', 'high_cut_slope', 'year_data_recorded', 'day_of_year', 'hour_of_day', 'minute_of_hour', 'second_of_minute', 'time_basis_code', 'trace_weighting_factor', 'geophone_group_number_of_roll_switch_position_one', 'geophone_group_number_of_trace_number_one', 'geophone_group_number_of_last_trace', 'gap_size', 'over_travel_associated_with_taper', 'x_coordinate_of_ensemble_position_of_this_trace', 'y_coordinate_of_ensemble_position_of_this_trace', 'for_3d_poststack_data_this_field_is_for_in_line_number', 'for_3d_poststack_data_this_field_is_for_cross_line_number', 'shotpoint_number', 'scalar_to_be_applied_to_the_shotpoint_number', 'trace_value_measurement_unit', 'transduction_constant_mantissa', 'transduction_constant_exponent', 'transduction_units', 'device_trace_identifier', 'scalar_to_be_applied_to_times', 'source_type_orientation', 'source_energy_direction_mantissa', 'source_energy_direction_exponent', 'source_measurement_mantissa', 'source_measurement_exponent', 'source_measurement_unit'])

保存道头

# get dict keys
allkeys = segy.traces[0].header.__dict__.keys()# get dict
onetraceheader = segy.traces[0].header.__dict__

保存道头到csv

import pandas as pd
from tqdm import tqdm
from obspy.io.segy.segy import _read_segy# read in segy
filename = 'path.sgy';
segy = _read_segy(filename)## parameters
NameOut = 'NameOut' # 定义输出的prefix
NTr = 3*50*637 # 定义读取的trace数量## save header
sshear = segy.__dict__
filename = open(f'{NameOut}_header.txt','w')
for k,v in sshear.items():filename.write(k+':'+str(v))filename.write('\n')
filename.close()## save trace header
alist = []
for ii in tqdm( range(NTr) ):tmp = segy.traces[ii].header.__str__() # !不加此句有时会出现无法读取trace header的情况tmpTrace = segy.traces[ii].header.__dict__alist.append(tmpTrace) #先保存在list中,最后统一转为csvnewpd = pd.DataFrame(alist)
newpd = newpd.drop(columns=['unpacked_header'])
newpd.to_csv(f"{NameOut}_trace_header.csv")

用Obspy读取segy的文件头并保存到csv数据库相关推荐

  1. Pandas的学习(读取mongodb数据库集合到DataFrame,将DataFrame类型数据保存到mongodb数据库中)

    1.读取mongodb数据库集合到DataFrame import pymongo import pandas as pdclient = pymongo.MongoClient("数据库连 ...

  2. Python读取excel文件内容并保存到SqlServer数据库

      前面两篇文章<python调用openpyxl包操作excel文件>和<python调用pymssql包操作SqlServer数据库>学习了Python操作excel和Sq ...

  3. 如何把文档扫描保存到Google Drive中

    2019独角兽企业重金招聘Python工程师标准>>> 我们有时候需要使用扫描仪来把纸质文档转换成电子文档用于保存.这篇文章介绍如何创建一个简单的应用,把文件扫描成图片,保存到Goo ...

  4. python读取文件夹下所有图片_python 读取单文件夹中的图片文件信息保存到csv文件中...

    # -*- coding: utf-8 -*- # @Time : 2019-09-17 10:21 # @Author : scyllake import os import csv #要读取的文件 ...

  5. python读取串口数据保存到mysql数据库_Python3读取Excel数据存入MySQL的方法

    Python是数据分析的强大利器. 利用Python做数据分析,第一步就是学习如何读取日常工作中产生各种excel报表并存入数据中,方便后续数据处理. 这里向大家分享python3如何使用xlrd读取 ...

  6. python读取nc文件并转换成csv_使用Python截取nc文件数据保存到CSV文件-Go语言中文社区...

    问题要求: 编写一个函数完成以下任务:截取经度在23°N-40°N,纬度在118°E-131°E范围内各属性不同深度的数据,使用Python中合适的数据结构将截取的数据保存到同名CSV文件中.(nc文 ...

  7. python股票接口_Python 从 sina 股票数据接口读取数据,并保存到 MySQL 数据库

    说明 从 sina 的数据接口获取数据,之后,保存到 MySql 数据库 文件:getDataFromSina.py ''' Created on 2018年2月11日 @author: Livon ...

  8. SparkStreaming读取Kafka的Json数据然后保存到MySQL

    一般我们使用SparkStreaming消费kafka数据,获取到数据后解析,使用JDBC的方式写入数据库,如下所示. 以上的方式没什么毛病,但是当我们消费的kafka数据类型比较多样的时候,我们需要 ...

  9. c++怎么可以在二进制文件中读取带string的数据_文件处理 | csv文件读写

    欢迎关注公众号 学习资料不会少 文件处理 在我们做自动化测试的过程中,常常会将数据文件存放在csv或者Excel文件里边.这一章节内容将给大家介绍,如何使用python进行csv和Excel文件的处理 ...

最新文章

  1. Linux编程---线程
  2. 怎样实现关闭connection时自动关闭Statement和ResultSet
  3. spring 的配置 beanpropertyname属性
  4. vue事件总线_[面试] 聊聊你对 Vue.js 框架的理解
  5. 关于cocos creator换装功能的实践与思考
  6. 64位虚拟机下asm()语法_用Hyper-V在win10中创建虚拟机,简单快捷,不用安装其它软件...
  7. iptables防火墙工作原理及简单配置访问策略
  8. 使用git clone命令下载代码时报错出现 remote: Not Found fatal: repository 'http://xxx/xxx.git/' not found
  9. 身为程序员的我们......
  10. 【图像增强】python图像数据增强
  11. Origin2018给两条曲线间画阴影/使用数据标记功能/绘制分段函数/求分段函数的微分图
  12. python中的cols_openpyxl读取列数据或指定行列之iter_cols方法
  13. QQ在线客服设置-QQ开启临时会话教程
  14. 雨课堂网页端作业找不到的解决方法
  15. C++循环输出M * N 的螺旋矩阵
  16. C#序列化与反序列化学习
  17. Linux进程僵死原因排查思路
  18. centos安装easy_install
  19. Window Git配置
  20. uniapp引入阿里云短信业务

热门文章

  1. Vim中如何全选并复制?
  2. Python | P站壁纸爬取
  3. NeoCognitron
  4. 快递物流管理系统(SSM,JQUERY-EASYUI,MYSQL)
  5. 使用tensorflow2.1.0+Anaconda3(python3.7.4)从制作自己的TFRrecord数据集到训练神经网络,再到载入模型进行推断
  6. 我和小米的10年,从米粉到米黑,再到米粉的故事...
  7. JS导入Excel实战
  8. 边云协同的优点_边云协同
  9. 不要告诉我你不知道这32个网站!
  10. cf 1677A - Tokitsukaze and Strange Inequality