Skip to content

Commit

Permalink
segy: nice error message when trying to write a trace with too many
Browse files Browse the repository at this point in the history
samples
  • Loading branch information
megies committed Mar 15, 2019
1 parent 45779b1 commit f7e2324
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.txt
Expand Up @@ -58,6 +58,9 @@ master:
16/32bit integers, see #2058 and #2059)
- obspy.io.rg16:
* implement module to read waveforms and headers from fcnt format (see #2265).
- obspy.io.segy:
* show nice error message when trying to write a trace with too many samples
in it (see #2358, #1393)
- obspy.io.quakeml:
* Allow writing invalid ids but raise a warning
(see #2104, #2090, #2093, #1872).
Expand Down
9 changes: 9 additions & 0 deletions obspy/io/segy/core.py
Expand Up @@ -20,6 +20,7 @@

from obspy import Stream, Trace, UTCDateTime
from obspy.core import AttribDict
from obspy.core.util.obspy_types import ObsPyException
from .header import (BINARY_FILE_HEADER_FORMAT, DATA_SAMPLE_FORMAT_CODE_DTYPE,
ENDIAN, TRACE_HEADER_FORMAT, TRACE_HEADER_KEYS)
from .segy import _read_segy as _read_segyrev1
Expand All @@ -37,6 +38,8 @@
# of the SEG Y format.
MAX_INTERVAL_IN_SECONDS = 0.065535

# largest number possible with int16
MAX_NUMBER_OF_SAMPLES = 32767

class SEGYCoreWritingError(SEGYError):
"""
Expand Down Expand Up @@ -270,6 +273,12 @@ def _write_segy(stream, filename, data_encoding=None, byteorder=None,
the SEG Y format. Therefore the smallest possible sampling rate is ~ 15.26
Hz. Please keep that in mind.
"""
for i, tr in enumerate(stream):
if len(tr) > MAX_NUMBER_OF_SAMPLES:
msg = ('Can not write traces with more than {:d} samples (trace '
'at index {:d}):\n{!s}')
raise ObsPyException(msg.format(MAX_NUMBER_OF_SAMPLES, i, tr))

# Some sanity checks to catch invalid arguments/keyword arguments.
if data_encoding is not None and data_encoding not in VALID_FORMATS:
msg = "Invalid data encoding."
Expand Down

0 comments on commit f7e2324

Please sign in to comment.