obspy.io.sac.sactrace.SACTrace.read

classmethod SACTrace.read(source, headonly=False, ascii=False, byteorder=None, checksize=False, debug_strings=False, encoding='ASCII')[source]

Construct an instance from a binary or ASCII file on disk.

Parameters:
  • source (str or file) – Full path string for File-like object from a SAC binary file on disk. If it is an open File object, open ‘rb’.

  • headonly (bool) – If headonly is True, only read the header arrays not the data array.

  • ascii (bool) – If True, file is a SAC ASCII/Alphanumeric file.

  • byteorder (str, optional) – If omitted or None, automatic byte-order checking is done, starting with native order. If byteorder is specified {‘little’, ‘big’}, and incorrect, a obspy.io.sac.util.SacIOError is raised. Only valid for binary files.

  • checksize (bool) – If True, check that the theoretical file size from the header matches the size on disk. Only valid for binary files.

  • debug_strings (bool) – By default, non-ASCII and null-termination characters are removed from character header fields, and those beginning with ‘-12345’ are considered unset. If True, they are instead passed without modification. Good for debugging.

  • encoding (str) – Encoding string that passes the user specified encoding scheme.

Raises:

obspy.io.sac.util.SacIOError: if checksize failed, byteorder was wrong, or header arrays are wrong size.

Example

>>> from obspy.core.util import get_example_file
>>> from obspy.io.sac.util import SacInvalidContentError
>>> file_ = get_example_file("test.sac")
>>> sac = SACTrace.read(file_, headonly=True)
>>> sac.data is None
True
>>> sac = SACTrace.read(file_, headonly=False)
>>> sac.data  
array([ -8.74227766e-08,  -3.09016973e-01,  -5.87785363e-01,
        -8.09017122e-01,  -9.51056600e-01,  -1.00000000e+00,
        -9.51056302e-01,  -8.09016585e-01,  -5.87784529e-01,
        ...
         8.09022486e-01,   9.51059461e-01,   1.00000000e+00,
         9.51053500e-01,   8.09011161e-01,   5.87777138e-01,
         3.09007347e-01], dtype=float32)

See also: SACTrace.validate()