You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python3.13.0+Win11环境下Obspy读取Reftek130文件报错求助

问题:Windows 11 + Python 3.13环境下Obspy读取Reftek130文件报错
  • 系统环境:Windows 11,Python 3.13.0(已尝试3.11.9至3.13.0多个版本)
  • 此前重装系统、VS Code及Python前功能正常,现在读取原生Reftek130格式文件报错,读取SAC文件和官方示例URL正常。

测试代码

from obspy import read
# cat=read('https://examples.obspy.org/COP.BHZ.DK.2009.050') # 此链接可正常读取
# cat=read('C:/Localiser_Seisme/FichierRtpd/20241119/202411190044119150_TROT_TT_00-01.SAC') # 转换后的SAC文件也可正常读取
cat=read('C:/Localiser_Seisme/FichierRtpd/20241119/044519915_0002BF20_BCA4_TROT.rt') # 原生Reftek130文件读取报错
print(cat)
cat.plot()

错误信息

Traceback (most recent call last):
  File "C:\Localiser_Seisme\LocaliserSeisme_Py_Ver_02\Signal\module1.py", line 7, in <module>
    cat=read('C:/Localiser_Seisme/FichierRtpd/20241119/044519915_0002BF20_BCA4_TROT.rt')
  File "C:\Users\Foued\AppData\Local\Programs\Python\Python313\Lib\site-packages\decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
  File "C:\Users\Foued\AppData\Local\Programs\Python\Python313\Lib\site-packages\obspy\core\util\decorator.py", line 297, in _map_example_filename
    return func(*args, **kwargs)
  File "C:\Users\Foued\AppData\Local\Programs\Python\Python313\Lib\site-packages\obspy\core\stream.py", line 208, in read
    st = _generic_reader(pathname_or_url, _read, **kwargs)
  File "C:\Users\Foued\AppData\Local\Programs\Python\Python313\Lib\site-packages\obspy\core\util\base.py", line 658, in _generic_reader
    generic = callback_func(pathnames[0], **kwargs)
  File "C:\Users\Foued\AppData\Local\Programs\Python\Python313\Lib\site-packages\decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
  File "C:\Users\Foued\AppData\Local\Programs\Python\Python313\Lib\site-packages\obspy\core\util\decorator.py", line 208, in uncompress_file
    result = func(filename, *args, **kwargs)
  File "C:\Users\Foued\AppData\Local\Programs\Python\Python313\Lib\site-packages\obspy\core\stream.py", line 251, in _read
    stream, format = _read_from_plugin('waveform', filename, format=format,
                     ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                                       headonly=headonly, **kwargs)
                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Foued\AppData\Local\Programs\Python\Python313\Lib\site-packages\obspy\core\util\base.py", line 423, in _read_from_plugin
    list_obj = read_format(filename, **kwargs)
  File "C:\Users\Foued\AppData\Local\Programs\Python\Python313\Lib\site-packages\obspy\io\reftek\core.py", line 100, in _read_reftek130
    rt130 = Reftek130.from_file(filename)
  File "C:\Users\Foued\AppData\Local\Programs\Python\Python313\Lib\site-packages\obspy\io\reftek\core.py", line 148, in from_file
    rt._data = _initial_unpack_packets(string)
               ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
  File "C:\Users\Foued\AppData\Local\Programs\Python\Python313\Lib\site-packages\obspy\io\reftek\packet.py", line 256, in _initial_unpack_packets
    result['time'][:] += [_get_nanoseconds_for_start_of_year(y)
                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
  File "C:\Users\Foued\AppData\Local\Programs\Python\Python313\Lib\site-packages\obspy\io\reftek\util.py", line 44, in _get_nanoseconds_for_start_of_year
    year += 2000
OverflowError: Python integer 2000 out of bounds for uint8

解决方法

这个错误是因为Obspy的Reftek130解析代码中,年份变量被定义为uint8类型(仅能存储0-255的整数),加上2000后超出类型范围,属于版本兼容性或代码类型处理bug。

  1. 升级/降级Obspy版本
    安装Obspy开发版或已知兼容的稳定版,这类版本通常已修复该问题:

    # 安装开发版
    pip install git+https://github.com/obspy/obspy.git
    # 或指定兼容版本,如1.4.0
    pip install obspy==1.4.0
    
  2. 临时修改源码修复
    找到Obspy的util.py文件(路径:C:\Users\Foued\AppData\Local\Programs\Python\Python313\Lib\site-packages\obspy\io\reftek\util.py),修改_get_nanoseconds_for_start_of_year函数:

    • 在year += 2000前添加year = int(year),将uint8类型转换为普通整数避免溢出:
      def _get_nanoseconds_for_start_of_year(year):
          """
          Returns nanoseconds since epoch for start of given year.
          """
          year = int(year)  # 添加此行
          year += 2000
          dt = datetime.datetime(year, 1, 1, 0, 0, 0)
          return dt.timestamp() * 1E9
      
    • 保存文件后重新运行代码。
  3. 检查文件年份字段
    确认Reftek130文件中的年份字段是否为两位数字格式(如24代表2024),若文件本身年份信息异常也可能触发该问题,但结合之前正常运行的情况,大概率是代码类型处理问题。

内容的提问来源于stack exchange,提问作者foued oueslati

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 01:58:12