obspy.io.sac.sactrace.SACTrace.read

classmethod SACTrace.read(source, headonly=False, ascii=False, byteorder=None, checksize=False)[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 {‘little’, ‘big’}, optional) If omitted or None, automatic byte-order checking is done, starting with native order. If byteorder is specified and incorrect, a 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.
Raises:

SacIOError if checksize failed, byteorder was wrong, or header arrays are wrong size.

Example

>>> sac = SACTrace.read(filename, headonly=True) 
>>> try: 
        sac.validate('data_hdrs') 
    except SacInvalidContentError: 
        sac = SACTrace.read(filename, headonly=False) 
        sac.validate('data_hdrs') 

See also: SACTrace.validate()