在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):equinor/segyio开源软件地址(OpenSource Url):https://github.com/equinor/segyio开源编程语言(OpenSource Language):Python 39.2%开源软件介绍(OpenSource Introduction):segyioDocumentationThe official documentation is hosted on readthedocs. Index
IntroductionSegyio is a small LGPL licensed C library for easy interaction with SEG-Y and Seismic Unix formatted seismic data, with language bindings for Python and Matlab. Segyio is an attempt to create an easy-to-use, embeddable, community-oriented library for seismic applications. Features are added as they are needed; suggestions and contributions of all kinds are very welcome. To catch up on the latest development and features, see the changelog. To write future proof code, consult the planned breaking changes. Feature summary
Getting startedWhen segyio is built and installed, you're ready to start programming! Check
out the tutorial, examples, example
programs, and example
notebooks. For a technical
reference with examples and small recipes, read the
docs. API docs are also available with pydoc -
start your favourite Python interpreter and type Quick startimport segyio
import numpy as np
with segyio.open('file.sgy') as f:
for trace in f.trace:
filtered = trace[np.where(trace < 1e-2)] See the examples for more. Get segyioA copy of segyio is available both as pre-built binaries and source code:
Build segyioTo build segyio you need:
To build the documentation, you also need sphinx To build and install segyio, perform the following actions in your console: git clone https://github.com/equinor/segyio
mkdir segyio/build
cd segyio/build
cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON
make
make install
If you have multiple Python installations, or want to use some alternative
interpreter, you can help cmake find the right one by passing
To build the matlab bindings, invoke CMake with the option DevelopersIt's recommended to build in debug mode to get more warnings and to embed debug
symbols in the objects. Substituting Tests are located in the language/tests directories, and it's highly
recommended that new features added are demonstrated for correctness and
contract by adding a test. All tests can be run by invoking After building segyio you can run the tests with Please note that to run the Python examples you need to let your environment know where to find the Python library. It can be installed as a user, or on adding the segyio/build/python library to your pythonpath. TutorialAll code in this tutorial assumes segyio is imported, and that numpy is available as np. import segyio
import numpy as np This tutorial assumes you're familiar with Python and numpy. For a refresh, check out the python tutorial and numpy quickstart BasicsOpening a file for reading is done with the with segyio.open(filename) as f:
... Open accepts several options (for more a more comprehensive reference, check
the open function's docstring with Files can be opened in unstructured mode, either by passing The segy file object has several public attributes describing this structure:
If the file is opened unstructured, all the line properties will will be
ModesIn segyio, data is retrieved and written through so-called modes. Modes are
abstract arrays, or addressing schemes, and change what names and indices mean.
All modes are properties on the file handle object, support the
Mode examples>>> for line in f.iline[:2430]:
... print(np.average(line))
>>> for line in f.xline[2:10]:
... print(line)
>>> for line in f.fast[::2]:
... print(np.min(line))
>>> for factor, offset in enumerate(f.iline[10, :]):
... offset *= factor
print(offset)
>>> f.gather[200, 241, :].shape
>>> text = f.text[0]
>>> type(text)
<type 'bytes'> # 'str' in Python 2
>>> f.trace[10] = np.zeros(len(f.samples)) More examples and recipes can be found in the docstrings Project goalsSegyio does not necessarily attempt to be the end-all of SEG-Y interactions; rather, we aim to lower the barrier to interacting with SEG-Y files for embedding, new applications or free-standing programs. Additionally, the aim is not to support the full standard or all exotic (but standard compliant) formatted files out there. Some assumptions are made, such as:
Currently, segyio supports:
The writing functionality in segyio is largely meant to modify or adapt files. A file created from scratch is not necessarily a to-spec SEG-Y file, as we only necessarily write the header fields segyio needs to make sense of the geometry. It is still highly recommended that SEG-Y files are maintained and written according to specification, but segyio does not enforce this. SEG-Y RevisionsSegyio can handle a lot of files that are SEG-Y-like, i.e. segyio handles files that don't strictly conform to the SEG-Y standard. Segyio also does not discriminate between the revisions, but instead tries to use information available in the file. For an actual standard's reference, please see the publications by SEG: ContributingWe welcome all kinds of contributions, including code, bug reports, issues, feature requests, and documentation. The preferred way of submitting a contribution is to either make an issue on github or by forking the project on github and making a pull request. xarray integrationAlan Richardson has written a great little tool for using xarray with segy files, which he demos in this notebook Reproducing the test dataSmall SEG-Y formatted files are included in the repository for test purposes.
The data is non-sensical and made to be predictable, and it is reproducible by
using segyio. The tests file are located in the test-data directory. To
reproduce the data file, build segyio and run the test program python examples/make-file.py small.sgy 50 1 6 20 25
python examples/make-ps-file.py small-ps.sgy 10 1 5 1 4 1 3
python examples/make-rotated-copies.py small.sgy The small-lsb.sgy file was created by running the flip-endianness program. This program is included in the segyio source tree, but not a part of the package, and not intended for distribution and installation, only for reproducing test files. The seismic unix file small.su and small-lsb.su were created by the following commands: segyread tape=small.sgy ns=50 remap=tracr,cdp byte=189l,193l conv=1 format=1 \
> small-lsb.su
suswapbytes < small.su > small-lsb.su If you have have small data files with a free license, feel free to submit it to the project! ExamplesPythonImport useful libraries: import segyio
import numpy as np
from shutil import copyfile Open segy file and inspect it: filename = 'name_of_your_file.sgy'
with segyio.open(filename) as segyfile:
# Memory map file for faster reading (especially if file is big...)
segyfile.mmap()
# Print binary header info
print(segyfile.bin)
print(segyfile.bin[segyio.BinField.Traces])
# Read headerword inline for trace 10
print(segyfile.header[10][segyio.TraceField.INLINE_3D])
# Print inline and crossline axis
print(segyfile.xlines)
print(segyfile.ilines) Read post-stack data cube contained in segy file: # Read data along first xline
data = segyfile.xline[segyfile.xlines[1]]
# Read data along last iline
data = segyfile.iline[segyfile.ilines[-1]]
# Read data along 100th time slice
data = segyfile.depth_slice[100]
# Read data cube
data = segyio.tools.cube(filename) Read pre-stack data cube contained in segy file: filename = 'name_of_your_prestack_file.sgy'
with segyio.open(filename) as segyfile:
# Print offsets
print(segyfile.offset)
# Read data along first iline and offset 100: data [nxl x nt]
data = segyfile.iline[0, 100]
# Read data along first iline and all offsets gath: data [noff x nxl x nt]
data = np.asarray([np.copy(x) for x in segyfile.iline[0:1, :]])
# Read data along first 5 ilines and all offsets gath: data [noff nil x nxl x nt]
data = np.asarray([np.copy(x) for x in segyfile.iline[0:5, :]])
# Read data along first xline and all offsets gath: data [noff x nil x nt]
data = np.asarray([np.copy(x) for x in segyfile.xline[0:1, :]]) Read and understand fairly 'unstructured' data (e.g., data sorted in common shot gathers): filename = 'name_of_your_prestack_file.sgy'
with segyio.open(filename, ignore_geometry=True) as segyfile:
segyfile.mmap()
# Extract header word for all traces
sourceX = segyfile.attributes(segyio.TraceField.SourceX)[:]
# Scatter plot sources and receivers color-coded on their number
plt.figure()
sourceY = segyfile.attributes(segyio.TraceField.SourceY)[:]
nsum = segyfile.attributes(segyio.TraceField.NSummedTraces)[:]
plt.scatter(sourceX, sourceY, c=nsum, edgecolor='none')
groupX = segyfile.attributes(segyio.TraceField.GroupX)[:]
groupY = segyfile.attributes(segyio.TraceField.GroupY)[:]
nstack = segyfile.attributes(segyio.TraceField.NStackedTraces)[:]
plt.scatter(groupX, groupY, c=nstack, edgecolor='none') Write segy file using same header of another file but multiply data by *2 input_file = 'name_of_your_input_file.sgy'
output_file = 'name_of_your_output_file.sgy'
copyfile(input_file, output_file)
with segyio.open(output_file, "r+") as src:
# multiply data by 2
for i in src.ilines:
src.iline[i] = 2 * src.iline[i] MATLAB
Common issuesCreating a new file is very slow, or copying headers is slowQuite often issues show up where someone struggle with the performance of segyio, in particular when creating new files. The culprit is often this code:
The code itself is perfectly ok, but it has subtle behaviour on some systems when the file is newly created: it is performing many scattered writes to a sparse file. This can be fast or slow, largely depending on the file system. Possible solutionsRewrite the loop to write to the file contiguously:
If the file is modified copy of another file, without changing the trace lengths, it's often faster (and easier!) to first copy the file without segyio, and then use segyio to modify the copy in-place:
ImportError: libsegyio.so.1: cannot open shared object fileThis error shows up when the loader cannot find the core segyio library. If
you've explicitly set the install prefix (with If you haven't set Possible solutions
RuntimeError: unable to find sortingThis exception is raised when segyio tries to open the in strict mode, under the assumption that the file is a regular, sorted 3D volume. If the file is just a collection of traces in arbitrary order, this would fail. Possible solutionsCheck if segyio.open |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论