io

Input and output of seismic traces.

This module provides a simple unified interface to load and save traces to a few different file formats. The data model used for the pyrocko.trace.Trace objects in Pyrocko is most closely matched by the Mini-SEED file format. However, a difference is, that Mini-SEED limits the length of the network, station, location, and channel codes to 2, 5, 2, and 3 characters, respectively.

Seismic Waveform IO

format format identifier load save note
Mini-SEED mseed yes yes  
SAC sac yes yes [1]
SEG Y rev1 segy some    
SEISAN seisan, seisan.l, seisan.b yes   [2]
KAN kan yes   [3]
YAFF yaff yes yes [4]
ASCII Table text   yes [5]
GSE1 gse1 some    
GSE2 gse2 some    
DATACUBE datacube yes    
SUDS suds some    
CSS css yes    

Metadata IO

Notes

[1]For SAC files, the endianness is guessed. Additional header information is stored in the Trace’s meta attribute.
[2]Seisan waveform files can be in little (seisan.l) or big endian (seisan.b) format. seisan currently is an alias for seisan.l.
[3]The KAN file format has only been seen once by the author, and support for it may be removed again.
[4]YAFF is an in-house, experimental file format, which should not be released into the wild.
[5]ASCII tables with two columns (time and amplitude) are output - meta information will be lost.
load(filename, format='mseed', getdata=True, substitutions=None)[source]

Load traces from file.

Parameters:
  • format – format of the file ('detect', 'from_extension', 'mseed', 'sac', 'segy', 'seisan', 'seisan.l', 'seisan.b', 'kan', 'yaff', 'gse1', 'gse2', 'gcf', 'datacube', 'suds', 'css')
  • getdata – if True (the default), read data, otherwise only read traces metadata
  • substitutions – dict with substitutions to be applied to the traces metadata
Returns:

list of loaded traces

When format is set to 'detect', the file type is guessed from the first 512 bytes of the file. Only Mini-SEED, SAC, GSE1, and YAFF format are detected. When format is set to 'from_extension', the filename extension is used to decide what format should be assumed. The filename extensions considered are (matching is case insensitive): '.sac', '.kan', '.sgy', '.segy', '.yaff', everything else is assumed to be in Mini-SEED format.

This function calls iload() and aggregates the loaded traces in a list.

iload(filename, format='mseed', getdata=True, substitutions=None)[source]

Load traces from file (iterator version).

This function works like load(), but returns an iterator which yields the loaded traces.

save(traces, filename_template, format='mseed', additional={}, stations=None, overwrite=True)[source]

Save traces to file(s).

Parameters:
  • traces – a trace or an iterable of traces to store
  • filename_template – filename template with placeholders for trace metadata. Uses normal python ‘%(placeholder)s’ string templates. The following placeholders are considered: network, station, location, channel, tmin (time of first sample), tmax (time of last sample), tmin_ms, tmax_ms, tmin_us, tmax_us. The versions with ‘_ms’ include milliseconds, the versions with ‘_us’ include microseconds.
  • format'mseed', 'sac', 'text', 'yaff', 'gse2'
  • additional – dict with custom template placeholder fillins.
  • overwrite' – if False, raise an exception if file exists
Returns:

list of generated filenames

Note

Network, station, location, and channel codes may be silently truncated to file format specific maximum lengthes.

exception UnknownFormat(filename)[source]
exception UnsupportedFormat(format)[source]

Available IO Modules

pyrocko.io.io_common
pyrocko.io.css
pyrocko.io.datacube
pyrocko.io.enhanced_sacpz
pyrocko.io.gcf
pyrocko.io.gse1
pyrocko.io.gse2
pyrocko.io.ims Module to read and write GSE2.0, GSE2.1, and IMS1.0 files.
pyrocko.io.kan
pyrocko.io.mseed
pyrocko.io.quakeml
pyrocko.io.rdseed
pyrocko.io.resp
pyrocko.io.sac SAC IO library for Python
pyrocko.io.segy
pyrocko.io.seisan_response
pyrocko.io.seisan_waveform
pyrocko.io.stationxml
pyrocko.io.suds
pyrocko.io.yaff File IO module for SICK traces format.