obspy.io.sac.sactrace.SACTrace.validate

SACTrace.validate(*tests)[source]

Check validity of loaded SAC file content, such as header/data consistency.

Parameters:tests (str)

One or more of the following validity tests: ‘delta’ : Time step “delta” is positive. ‘logicals’ : Logical values are 0, 1, or null ‘data_hdrs’ : Length, min, mean, max of data array match header

values.

‘enums’ : Check validity of enumerated values. ‘reftime’ : Reference time values in header are all set. ‘reltime’ : Relative time values in header are absolutely

referenced.

‘all’ : Do all tests.

Raises:SacInvalidContentError if any of the specified tests fail. ValueError if ‘data_hdrs’ is specified and data is None, empty array, or no tests specified.

Example

>>> from obspy.core.util import get_example_file
>>> from obspy.io.sac.util import SacInvalidContentError
>>> file_ = get_example_file("LMOW.BHE.SAC")
>>> sac = SACTrace.read(file_)
>>> # make the time step invalid, catch it, and fix it
>>> sac.delta *= -1.0
>>> try:
...     sac.validate('delta')
... except SacInvalidContentError as e:
...     sac.delta *= -1.0
...     sac.validate('delta')
>>> # make the data and depmin/men/max not match, catch the validation
>>> # error, then fix (flush) the headers so that they validate
>>> sac.data += 5.0
>>> try:
...     sac.validate('data_hdrs')
... except SacInvalidContentError:
...     sac._flush_headers()
...     sac.validate('data_hdrs')