GSE1 file format detection failing on some files with additional header lines
megies opened this issue · comments
Some GSE1 files seem to have additional lines before WID1
header line. These are currently not detected as GSE1 by the automatic file format check.
Example:
7651 1998:001:04:43:01:000 -5.000000e-03 0.000000e+00 # Unlock-Phase
7651 1998:001:04:43:56:000 -5.000000e-03 0.000000e+00 # Phase-Unlock
7651 1998:001:04:45:59:000 -5.000000e-03 0.000000e+00 # Unlock-Phase
7651 1998:001:04:59:20:000 -5.000000e-03 0.000000e+00 # Phase-Unlock
WID1 1998001 04 00 00 026 144000 RT7651 REFTEK32 4 40.0000000 NOTYPE CMP6 2
1.0000001 1.0000 0.0000 0.0000 0.0000 -999.0000 -1.00 -1.00 -1.0
DAT1
lRXOUFkTV-kMoGNWGUF57VFm+lQWClDkRUHV-W8kNl0OUJ0lE4l1W4XAn0l1l3lEXTlMlKXIPkQUGPkK
DUR1kFl9l59Y-VDo-Q5OUEm6W6XPnClQQ5W49WO6pIIWPFDl2n5V+YDkInCX27pOIYBW9V05pIp2Y-YQ
W73oFm21RVJW+V5l0RkHlGVTGmGV8WOmJn+XEW8lFnLV6YBlQl9l-UFY2QMGoGnTVTZ+VCPm7lNY+UTm
SNlFkPVLVM8l+IV7VGm9mFVAVARn4W3YEmRm7VGKl7WPVHnNkRRl8WPXBRlTkQkEVMVQnAmRV7V8VMBR
[...]
The following change could make these files get recognized as well (the reader just omits everything above WID1
line). Not sure if it's worth it though as this might slow down file format detection to some extent as it makes the format check look through the whole file.
diff --git a/obspy/io/gse2/core.py b/obspy/io/gse2/core.py
index 0ec9ff962..437af3c83 100644
--- a/obspy/io/gse2/core.py
+++ b/obspy/io/gse2/core.py
@@ -118,12 +118,14 @@ def _is_gse1(filename):
"""
# Open file.
with open(filename, 'rb') as f:
- try:
- data = f.readline()
- except Exception:
- return False
- if data.startswith(b'WID1') or data.startswith(b'XW01'):
- return True
+ data = True
+ while data:
+ try:
+ data = f.readline()
+ except Exception:
+ return False
+ if data.startswith(b'WID1') or data.startswith(b'XW01'):
+ return True
return False
CC @jwassermann