Converting MiniSEED Data to SAC Using mseed2sac

When working with MiniSEED waveform data, extracting and converting it into a more analysis-friendly format such as SAC is a common step. Several MATLAB-based readers like rdmseed.m and rdmseedfast.m exist but may encounter issues with gapped or incomplete data, or produce inconsistent timestamps. A robust alternative is the command-line tool mseed2sac, which directly converts MiniSEED files into SAC format and supports metadata injection.

Installing mseed2sac

Download and build the source package:

tar xvf mseed2sac-2.0.tar.gz
cd mseed2sac-2.0/
make
sudo cp mseed2sac /usr/local/bin/

Basic Usage

Convert a single MiniSEED file:

mseed2sac station_data.mseed

This produces SAC files named after the network, station, location, and channel codes present in the MiniSEED records. How ever, the resulting SAC headers lack station coordinates, component azimuths/dips, and other metadata. Such information must be attached later.

Providing Metadata

The tool can read a metadata file and a station selection list to automatically populate headers. For example:

mseed2sac -m metafile.txt -I stations_of_interest.txt \
  -E 2006,123,15:27:08.7/-20.33/-174.03/65.5/Tonga

The -m opsion suppleis station metadata (station coordinates, elevation, depth, component orientations). The -I file lists the desired network/station/channel combinations. The -E flag adds an earthquake origin for SAC reference time and event location. Refer to the official documentation for the exact file formats.

Metadata files can be handwritten or automatically fetched using IRIS's FetchMetadata script.

Batch Conversion Script

To convert all MiniSEED files in a directory:

#!/bin/bash
data_dir="/home/user/mseed_files"
cd "$data_dir"
for f in *.mseed; do
    mseed2sac "$f"
done

A more structured workflow that organizes output into separate directories and handles multiple channels might look like:

#!/bin/bash
# Recursive conversion of MiniSEED to SAC while cleaning filenames
for dir in */; do
    if [ -d "$dir" ]; then
        echo "Processing directory: $dir"
        mkdir -p "${dir}/SAC"
        rm -f "${dir}/SAC/"*
        cd "${dir}/t/" || continue
        rm -f *SAC
        mseed2sac -O *BHE *BHZ *BHN
        cd ../../
        mv "${dir}/t/"*SAC "${dir}/SAC/"
    fi
done

# Remove spaces from generated filenames
find . -path "*/SAC/*" -name "* *" | while IFS= read -r file; do
    newname=$(echo "$file" | tr -d ' ')
    mv "$file" "$newname"
done

Workflow Considerations

  • Data gaps: mseed2sac handles gapped MiniSEED files gracefully by inserting time gaps or splitting traces.
  • Metadata completeness: Always verify that the SAC headers contain correct STLA, STLO, CMPAZ, CMPINC after conversion, as missing values will affect later processing.
  • Batch safety: When processing large datasets, use absolute paths and check exit codes to avoid partial conversions.

Alternative Tools

While mseed2sac is reliable, other options include rdseed for full SEED volumes and ObsPy for Python-based reading/writing. The right choice depends on the data provenance and the required header fidelity.

Tags: mseed2sac MiniSEED SAC seismic data conversion IRIS metadata

Posted on Thu, 17 Sep 2026 16:29:11 +0000 by laduch