Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix reftek130 malformed eh header - #3743

Open
athulpalliath wants to merge 6 commits into
obspy:masterfrom
athulpalliath:fix-reftek130-malformed-eh-header
Open

Fix reftek130 malformed eh header#3743
athulpalliath wants to merge 6 commits into
obspy:masterfrom
athulpalliath:fix-reftek130-malformed-eh-header

Conversation

@athulpalliath

@athulpalliath athulpalliath commented May 29, 2026

Copy link
Copy Markdown

Old REFTEK DAS firmware sometimes wrote blank or scrambled
fields in the EH packet binary header, causing ObsPy to raise a
ValueError even though the DT packets containing actual waveform data
are intact.

This PR makes two changes:

  1. Adds fallback_sampling_rate parameter to _read_reftek130() and
    to_stream() so users can specify the sampling rate when the EH
    packet sampling_rate field cannot be parsed
  2. Adds graceful handling in EHPacket.init so malformed fields
    are set to None with a warning instead of crashing

Tested on real data from REFTEK units deployed in the Koyna-Warna
seismic network (India) circa 2006-2008.

… add fallback_sampling_rate parameter for malformed EH headers

Added fallback_sampling_rate parameter to handle cases where the sampling rate cannot be parsed from the EH packet. Updated relevant methods to utilize this new parameter.
Old REFTEK DAS firmware  sometimes wrote blank or scrambled
fields in the EH packet binary header. This adds a try/except around
the converter call in EHPacket.__init__ so that malformed fields are
set to None with a warning instead of raising ValueError and preventing
the entire file from being read.

This is part of the same fix as the core.py change - the two together
allow reading of REFTEK files recorded with old firmware.
@athulpalliath
athulpalliath requested a review from megies as a code owner May 29, 2026 05:22
@megies megies added the .io issues generally related to our read/write plugins label Jun 5, 2026
@megies

megies commented Jun 5, 2026

Copy link
Copy Markdown
Member

This seems like curious edge cases, but then again, I don't think it will hurt much to add anyway.

Can you add a small example file, just a handful of reftek packets long would be ideal, that showcases the problem, and then also a short test case for the new functionality would be needed. Also changelog. All of this is part of the pull request template we put in place.

Comment thread obspy/io/reftek/core.py Outdated

>>> from obspy import read
>>> st = read("file.rt130", format="REFTEK130",
... fallback_sampling_rate=100.0) # doctest: +SKIP

@megies megies Jun 5, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The part with "Example usage: ... " and the code block can be removed. No need to show how to use a simple kwarg. Should be clear from the description. The builtin keyword None needs to go into double backticks for sphinx:

``None``

Comment thread obspy/io/reftek/core.py Outdated
read the headers.
:type fallback_sampling_rate: float, optional
:param fallback_sampling_rate: Sampling rate to use if the sampling
rate field in the EH packet cannot be parsed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is more detail info in the other docstring, so I would either link to there like...

More detail, see :func:`_read_reftek130`

.. or simply put the same detail info here too

@megies megies left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a small test file and test case testing both behaviors (raising exception vs. successful reading with warning), then also changelog and some other minor changes

@megies megies added this to the Future release milestone Jun 5, 2026
@megies megies added the build_docs Docs will be automatically built and deployed in github actions on pushes to the PR label Jun 5, 2026
Add test fixtures for malformed EH header fix
Added a new parameter to handle malformed sampling rates in EH packet headers and updated the changelog accordingly.
Removed example usage for fallback_sampling_rate parameter and clarified its description.
@athulpalliath

Copy link
Copy Markdown
Author

Added the test fixtures, test cases (covering both the raise-without-fallback and read-with-fallback behaviors, plus a case for other malformed EH fields), changelog entry, and cleaned up the docstrings as requested. Ready for another look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build_docs Docs will be automatically built and deployed in github actions on pushes to the PR .io issues generally related to our read/write plugins

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants