Skip to main content

seismic-zfp

LGPLv3 License Run Tests codecov SCM Compliance PyPi Version

Python library to convert SEG-Y files to compressed cubes and retrieve arbitrary sub-volumes from these, fast.

Motivation

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)

Using IL/XL optimized layout

  • 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

Using z-slice optimized layout

  • A z-slice can be read by accessing just n_traces/4096 disk blocks, compared to n_traces disk blocks for SEG-Y

2D SEG-Y Support

As of v0.2.4 support for compressing 2D SEG-Y files (INLINE_3D and CROSSLINE_3D always zero) is included. Compression and reading follows the same pattern as 3D files, but segyio emulation only provides the following attributes: trace, header, samples, bin & text. However an additional funciton read_subplane() is available for extracting horizontally and vertically contrained data.

4D (Prestack) SEG-Y Support

As of v0.5.0 regular prestack SEG-Y files (inline-sorted, with the same offsets present at every IL/XL position, identified by the offset trace header) can be compressed. The offset axis is stored between the crossline and sample axes, and ZFP compresses the data in 4x4x4x4 units, so the blockshape becomes (il, xl, offset, z) with a default of (4, 4, 4, -1). 4D SGZ files can be read through SgzReader (read_gather, read_offset, read_subvolume_4d), the segyio-like interface (gather, iline[il, offset], subvolume) and xarray, and can be converted back to SEG-Y.

Headers

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.

For further explanation of the design and implementation of seismic-zfp, please refer to publications.

NOTE: Previously the extension .sz was used for seismic-zfp, but has been replaced with .sgz to avoid confusion around the compression algorithm used.

Get seismic-zfp

  • Wheels from PyPI with zgy and vds support: pip install seismic-zfp[zgy,vds]
  • Wheels from PyPI without zgy or vds 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 package ZFPY, which is a binary distribution on PyPI built for Linux and Windows.

The optional dependency pyvds - requires openvds package from Bluware which is not open-source

The optional dependency of zgy2sgz has been replaced with pyzgy - a pure-Python alternative.

Examples

Full example code is provided here, and standalone utilities such as a tool to regularise irregular prestack SEG-Y are in tools. The following reference is useful:

Create SGZ files from SEG-Y, ZGY or VDS

from seismic_zfp.conversion import SegyConverter, ZgyConverter, VdsConverter

with SegyConverter("in.sgy") as converter:
    # Estimate the output file size before compression
    size_bytes = converter.get_output_size(bits_per_voxel=4)
    # 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 SegyConverter("in_prestack.sgy", min_offset=0, max_offset=16) as converter:
    # Prestack (4D) SEG-Y is detected automatically, blockshape is (il, xl, offset, z)
    converter.run("out_4d.sgz", bits_per_voxel=4, blockshape=(4, 4, 4, -1))
                  
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)

with VdsConverter("in.vds") as converter:
    # VDS compression is superior, but doesn't permit non-cubic bricks...
    converter.run("out.sgz", bits_per_voxel=4, blockshape=(8, 8, 128))

Convert SGZ files to SEG-Y

# Convert SGZ to SEG-Y
with SgzConverter("out_standard.sgz") as converter:
    converter.convert_to_segy("recovered.sgy")

Read an SGZ file

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)

Use segyio-like interface to read SGZ files

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]

Including equivalents to segyio.tools

with seismic_zfp.open("in.sgz") as sgz_file:
    dt_sgz = seismic_zfp.tools.dt(sgz_file)

cube_sgz = seismic_zfp.tools.cube("in.sgz")

Plus some extended utility functionality:

with seismic_zfp.open("in.sgz")) as sgzfile:
    subvolume = sgzfile.subvolume[IL_NO_START:IL_NO_STOP:IL_NO_STEP, 
                                  XL_NO_START:XL_NO_STOP:XL_NO_STEP,
                                  SAMP_NO_START:SAMP_NO_STOP:SAMP_NO_STEP]
    header_arr = sgzfile.get_tracefield_values(segyio.tracefield.TraceField.NStackedTraces)

Open SGZ files with xarray

seismic-zfp registers an xarray backend, so SGZ files open lazily as a Dataset with a single data variable over dimensions (il, xl, z), or (il, xl, offset, z) for 4D files, with coordinates in line numbers, offset values and sample times. Only the part of the file covering a selection is decompressed.

import xarray as xr
with xr.open_dataset("in.sgz") as ds:
    inline = ds.data.sel(il=IL_NO).to_numpy()
    gather = ds.data.sel(il=IL_NO, xl=XL_NO).to_numpy()              # 4D files
    stack = ds.data.sel(il=IL_NO).mean(dim="offset").to_numpy()      # 4D files

Command Line Interface

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.

Converting from SEG-Y to SGZ and back

seismic-zfp sgy2sgz <INPUT FILE PATH> <OUTPUT FILE PATH> --bits-per-voxel 4
seismic-zfp sgz2sgy <INPUT FILE PATH> <OUTPUT FILE PATH>

To see all options run the command seismic-zfp sgy2sgz --help

Converting from ZGY to SGZ

seismic-zfp zgy2sgz <INPUT FILE PATH> <OUTPUT FILE PATH> --bits-per-voxel 4

To see all options run the command seismic-zfp zgy2sgz --help

Contributing

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

Publications

Wade, David (2020): Seismic-ZFP: Fast and Efficient Compression and Decompression of Seismic Data, First EAGE Digitalization Conference and Exhibition, Nov 2020, Volume 2020, p.1-5

Metadata

Release files for seismic-zfp 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for seismic-zfp 0.5.0
File Size Uploaded
seismic_zfp-0.5.0.tar.gz 1.5 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for seismic-zfp 0.5.0
File Interpreter ABI Platform
seismic_zfp-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 1.5 MB

Release files / seismic_zfp-0.5.0.tar.gz

Download URL seismic_zfp-0.5.0.tar.gz
Size 1.5 MB
Tags Source
SHA-256 checksum
How to use checksums
5a32ae86c05ee3bfb6d120022a424aa5477707c4ab4e8213b42cf2adb69bede4
BLAKE2b-256 checksum
How to use checksums
e832fdfb9dfed0cccdbdff2f32afd6e28d39f9e28529897bfb9e49b60bc0ee48
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / seismic_zfp-0.5.0-py3-none-any.whl

Download URL seismic_zfp-0.5.0-py3-none-any.whl
Size 60.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c82ffbc6bbcab4401a87f15be3ea2e0da3e9f2b04e89d0d782a760a60901e9a3
BLAKE2b-256 checksum
How to use checksums
04f6513aa968c79a1d8f66dc949f609557579c248890003ff109621bdef8e6da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page