Python library to convert SEG-Y files to compressed cubes and retrieve arbitrary sub-volumes from these, fast.
Reading whole SEG-Y volumes to retrieve, for example, a single time-slice is wasteful.
Copying whole SEG-Y files uncompressed over networks is also wasteful.
This library addresses both issues by implementing the seismic-zfp (.SGZ) format. This format is based on ZFP compression from Peter Lindstrom's paper using the official Python bindings, distributed as zfpy.
ZFP compression enables smoothly varying d-dimensional data in 4d subvolumes to be compressed at a fixed bitrate. The 32-bit floating point values in 4x4x4 units of a 3D post-stack SEG-Y file are well suited to this scheme.
Decomposing an appropriately padded 3D seismic volume into groups of these units which exactly fill one 4KB disk block, compressing these groups, and writing them sequentially to disk yields a file with the following properties:
- Compression ratio of 2n:1 compression, typically a bitrate of 4 works well, implying a ratio of 8:1
- The location of any seismic sample is known
- Arbitrary subvolumes can be read with minimal redundant I/O, for example:
- Padding IL/XL dimensions with 4, and the z-dimension depending on bitrate
- Padding IL/XL dimensions with 64 and the z-dimension with 4 (16:1 compression)
- Groups of 4 inlines or crosslines can be read with no redundant I/O
- A single inline can be read and with no additional I/O compared to the SEG-Y best-case scenario (provided at least 4:1 compression ratio)
- A z-slice can be read by accessing n_traces/16 disk blocks, compared to n_traces disk blocks for SEG-Y
- A z-slice can be read by accessing just n_traces/4096 disk blocks, compared to n_traces disk blocks for SEG-Y
The seismic-zfp (.SGZ) format also allows for preservation of information in SEG-Y file and trace headers, with compression code identifying constant and varying trace header values and storing these appropriately.
NOTE: Previously the extension .sz was used for seismic-zfp, but has been replaced with .sgz to avoid confusion around the compression algorithm used.
- Wheels from PyPI with zgy support:
pip install seismic-zfp[zgy]
- Wheels from PyPI without zgy support:
pip install seismic-zfp
- Source from Github:
git clone https://github.com/equinor/seismic-zfp.git
Note that seismic-zfp depends on the Python packages ZFPY and zgy2sgz, which are binary distributions on PyPI built for Linux and Windows.
Full example code is provided here, but the following reference is useful:
from seismic_zfp.conversion import SegyConverter, ZgyConverter, SgzConverter
with SegyConverter("in.sgy") as converter:
# Create a "standard" SGZ file with 8:1 compression, using in-memory method
converter.run("out_standard.sgz", bits_per_voxel=4)
# Create a "z-slice optimized" SGZ file
converter.run("out_adv.sgz", bits_per_voxel=2, blockshape=(64, 64, 4))
with ZgyConverter("in_8-int.zgy") as converter:
# 8-bit integer ZGY and 1-bit SGZ have similar quality
converter.run("out_8bit.sgz", bits_per_voxel=1)
# Convert SGZ to SEG-Y
with SgzConverter("out_standard.sgz") as converter:
converter.convert_to_segy("recovered.sgy")
from seismic_zfp.read import SgzReader
with SgzReader("in.sgz") as reader:
inline_slice = reader.read_inline(LINE_IDX)
crossline_slice = reader.read_crossline(LINE_IDX)
z_slice = reader.read_zslice(LINE_IDX)
sub_vol = reader.read_subvolume(min_il=min_il, max_il=max_il,
min_xl=min_xl, max_xl=max_xl,
min_z=min_z, max_z=max_z)
import seismic_zfp
with seismic_zfp.open("in.sgz")) as sgzfile:
il_slice = sgzfile.iline[sgzfile.ilines[LINE_NUMBER]]
xl_slices = [xl for xl in sgzfile.xline]
zslices = sgzfile.depth_slice[:5317]
trace = sgzfile.trace[TRACE_IDX]
trace_header = sgzfile.header[TRACE_IDX]
binary_file_header = sgzfile.bin
text_file_header = sgzfile.text[0]
A simple command line interface for converting from SEGY or ZGY to SGZ is also bundled with seismic-zfp. This is available using the command seismic-zfp
.
seismic-zfp sgy2sgz <INPUT FILE PATH> <OUTPUT FILE PATH> --bits-per-voxel 4
To see all options run the command seismic-zfp sgy2sgz --help
seismic-zfp zgy2sgz <INPUT FILE PATH> <OUTPUT FILE PATH> --bits-per-voxel 4
To see all options run the command seismic-zfp zgy2sgz --help
Contributions welcomed, whether you are reporting or fixing a bug, implementing or requesting a feature. Either make a github issue or fork the project and make a pull request. Please extend the unit tests with relevant passing/failing tests, run these as: python -m pytest