Skip to content

Commit 34dea88

Browse files
Add docs (#13)
* Update docstrings and add docs
1 parent 7f47b77 commit 34dea88

20 files changed

+530
-129
lines changed

.github/workflows/doc.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: documentation
2+
3+
on: [push, pull_request, workflow_dispatch]
4+
5+
permissions:
6+
contents: write
7+
8+
jobs:
9+
docs:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
- uses: actions/setup-python@v3
14+
- name: Install dependencies
15+
run: |
16+
pip install sphinx sphinx_rtd_theme myst_parser
17+
pip install .
18+
- name: Sphinx build
19+
run: |
20+
sphinx-build docs _build
21+
- name: Deploy to GitHub Pages
22+
uses: peaceiris/actions-gh-pages@v3
23+
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
24+
with:
25+
publish_branch: gh-pages
26+
github_token: ${{ secrets.GITHUB_TOKEN }}
27+
publish_dir: _build/
28+
force_orphan: true

docs/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= sphinx-build
8+
SOURCEDIR = .
9+
BUILDDIR = _build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/api/segfast.loader.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
======
2+
Loader
3+
======
4+
5+
.. automethod:: segfast.loader.open

docs/api/segfast.memmap_loader.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
============
2+
MemmapLoader
3+
============
4+
5+
.. autoclass:: segfast.memmap_loader.MemmapLoader
6+
:members:
7+
:undoc-members:
8+
:member-order: bysource

docs/api/segfast.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
===
2+
API
3+
===
4+
5+
.. toctree::
6+
:maxdepth: 5
7+
8+
segfast.loader
9+
segfast.memmap_loader
10+
segfast.segyio_loader
11+
segfast.trace_header_spec
12+
segfast.utils

docs/api/segfast.segyio_loader.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
============
2+
SegyioLoader
3+
============
4+
5+
.. autoclass:: segfast.segyio_loader.SegyioLoader
6+
:members:
7+
:undoc-members:
8+
:member-order: bysource
9+
10+
.. autoclass:: segfast.segyio_loader.SafeSegyioLoader
11+
:members:
12+
:undoc-members:
13+
:member-order: bysource
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
===============
2+
TraceHeaderSpec
3+
===============
4+
5+
.. autoclass:: segfast.trace_header_spec.TraceHeaderSpec
6+
:members:
7+
:undoc-members:
8+
:member-order: bysource

docs/api/segfast.utils.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
=====
2+
Utils
3+
=====
4+
5+
.. autoclass:: segfast.utils.ForPoolExecutor

docs/conf.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Configuration file for the Sphinx documentation builder.
2+
#
3+
# For the full list of built-in configuration values, see the documentation:
4+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
5+
6+
# -- Project information -----------------------------------------------------
7+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
8+
9+
import sys, os
10+
sys.path.insert(0, os.path.abspath('..'))
11+
import segfast
12+
13+
master_doc = 'index'
14+
15+
project = 'segfast'
16+
author = 'Analysis Center'
17+
copyright = '2024, ' + author
18+
19+
release = segfast.__version__
20+
version = '.'.join(release.split('.'))
21+
22+
# -- General configuration ---------------------------------------------------
23+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
24+
25+
extensions = [
26+
'sphinx.ext.autodoc',
27+
'sphinx.ext.doctest',
28+
'sphinx.ext.coverage',
29+
'sphinx.ext.mathjax',
30+
'sphinx.ext.viewcode',
31+
'sphinx.ext.githubpages',
32+
'sphinx.ext.intersphinx',
33+
'sphinx.ext.napoleon',
34+
'sphinx_rtd_theme',
35+
]
36+
37+
templates_path = ['_templates']
38+
exclude_patterns = []
39+
language = 'en'
40+
41+
42+
# -- Options for HTML output -------------------------------------------------
43+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
44+
45+
html_title = "SegFast"
46+
html_theme = "sphinx_rtd_theme"
47+
html_static_path = ['_static']
48+
html_theme_options = {
49+
'logo_only': False
50+
}
51+
52+
# Example configuration for intersphinx: refer to the Python standard library.
53+
intersphinx_mapping = {
54+
'python': ('https://docs.python.org/', None),
55+
'numpy': ('https://docs.scipy.org/doc/numpy/', None),
56+
'segyio': ('https://segyio.readthedocs.io/en/latest/', None)
57+
}

docs/index.rst

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
.. segfast documentation master file, created by
2+
sphinx-quickstart on Thu Feb 1 14:09:14 2024.
3+
You can adapt this file completely to your liking, but it should at least
4+
contain the root `toctree` directive.
5+
6+
segfast documentation
7+
=====================
8+
9+
**segfast** is a library for interacting with SEG-Y seismic data. Main features are:
10+
11+
* Faster access to read data: both traces headers and values
12+
* Optional bufferization, where the user can provide a preallocated memory to load the data into
13+
* Convenient API that relies on :class:`numpy.memmap` for most operations, while providing
14+
`segyio <https://segyio.readthedocs.io/en/latest/>`_ as a fallback engine
15+
16+
17+
Implementation details
18+
----------------------
19+
We rely on **segyio** to infer file-wide parameters.
20+
21+
For headers and traces, we use custom methods of reading binary data.
22+
23+
Main differences to **segyio** C++ implementation:
24+
- we read all of the requested headers in one file-wide sweep, speeding up by an order of magnitude
25+
compared to the **segyio** sequential read of every requested header.
26+
Also, we do that in multiple processes across chunks.
27+
28+
- a memory map over trace data is used for loading values. Avoiding redundant copies and leveraging
29+
:mod:`numpy` superiority allows to speed up reading, especially in case of trace slicing along the samples axis.
30+
This is extra relevant in the case of loading horizontal (depth) slices.
31+
32+
33+
.. toctree::
34+
:maxdepth: 1
35+
:titlesonly:
36+
37+
installation
38+
start
39+
segy
40+
api/segfast

docs/installation.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Installation
2+
============
3+
4+
* With ``pip``/``pip3``:
5+
6+
.. code-block:: bash
7+
8+
pip3 install segfast
9+
10+
* Developer version (add ``--depth 1`` if needed)
11+
12+
.. code-block:: bash
13+
14+
git clone https://github.com/analysiscenter/segfast.git

docs/make.bat

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@ECHO OFF
2+
3+
pushd %~dp0
4+
5+
REM Command file for Sphinx documentation
6+
7+
if "%SPHINXBUILD%" == "" (
8+
set SPHINXBUILD=sphinx-build
9+
)
10+
set SOURCEDIR=.
11+
set BUILDDIR=_build
12+
13+
%SPHINXBUILD% >NUL 2>NUL
14+
if errorlevel 9009 (
15+
echo.
16+
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
17+
echo.installed, then set the SPHINXBUILD environment variable to point
18+
echo.to the full path of the 'sphinx-build' executable. Alternatively you
19+
echo.may add the Sphinx directory to PATH.
20+
echo.
21+
echo.If you don't have Sphinx installed, grab it from
22+
echo.https://www.sphinx-doc.org/
23+
exit /b 1
24+
)
25+
26+
if "%1" == "" goto help
27+
28+
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
29+
goto end
30+
31+
:help
32+
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
33+
34+
:end
35+
popd

docs/segy.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
SEG-Y description
2+
=================
3+
4+
The most complete description can be found in `the official SEG-Y specification <https://library.seg.org/pb-assets/technical-standards/seg_y_rev2_0-mar2017-1686080998003.pdf>`_ but here we give
5+
a brief intro into SEG-Y format.
6+
7+
The SEG-Y is a binary file divided into several blocks:
8+
9+
- file-wide information block which in most cases takes the first 3600 bytes:
10+
11+
- **textual header**: the first 3200 bytes are reserved for textual info about the file. Most of the software uses
12+
this header to keep acquisition meta, date of creation, author, etc.
13+
- **binary header**: 3200–3600 bytes contain file-wide headers, which describe the number of traces, the format used
14+
for storing numbers, the number of samples for each trace, acquisition parameters, etc.
15+
- (optional) 3600+ bytes can be used to store the **extended textual information**. If there is such a header,
16+
then this is indicated by the value in one of the 3200–3600 bytes.
17+
18+
- a sequence of traces, where each trace is a combination of its header and signal data:
19+
20+
- **trace header** takes the first 240 bytes and describes the meta info about its trace: shot/receiver coordinates,
21+
the method of acquisition, current trace length, etc. Analogously to binary file header, each trace also
22+
can have extended headers.
23+
- **trace data** is usually an array of amplitude values, which can be stored in various numerical types.
24+
As the original SEG-Y is quite old (1975), one of those numerical formats is IBM float,
25+
which is very different from standard IEEE floats; therefore, special caution is required to
26+
correctly decode values from such files.
27+
28+
For the most part, SEG-Y files are written with a constant size of each trace, although the standard itself allows
29+
for variable-sized traces. We do not work with such files.

docs/start.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Quick start
2+
===========
3+
4+
* Open the file:
5+
6+
.. code-block:: python
7+
8+
import segfast
9+
segy_file = segfast.open('/path/to/file.sgy')
10+
11+
* Load headers:
12+
13+
.. code-block:: python
14+
15+
headers = segy_file.load_headers(['CDP_X', 'CDP_Y', 'INLINE_3D', 'CROSSLINE_3D'])
16+
17+
* Load inline:
18+
19+
.. code-block:: python
20+
21+
traces_idx = headers[headers['INLINE_3D'] == INLINE_IDX].index
22+
inline = segy_file.load_traces(traces_idx)
23+
24+
* Load certain depths from all traces:
25+
26+
.. code-block:: python
27+
28+
segy_file.load_depth_slices(DEPTHS)
29+
30+
The resulting array will have shape ``(n_traces, len(DEPTHS))`` so it must be processed to be transformed
31+
to an array of the field shape.

pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ variable-rgx=(.*[a-z][a-z0-9_]{1,30}|[a-z_])$ # snake_case + single letters
1515
argument-rgx=(.*[a-z][a-z0-9_]{1,30}|[a-z_])$ # snake_case + single letters
1616

1717
[MESSAGE CONTROL]
18-
disable=no-value-for-parameter, no-self-use, too-few-public-methods, unsubscriptable-object, no-member, too-many-lines,
18+
disable=no-value-for-parameter, too-few-public-methods, unsubscriptable-object, no-member, too-many-lines,
1919
arguments-differ, too-many-locals, import-error, cyclic-import, duplicate-code, relative-beyond-top-level,
2020
unused-argument, too-many-public-methods, invalid-name, attribute-defined-outside-init, arguments-renamed,
2121
abstract-method, no-name-in-module, import-self

segfast/loader.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,26 @@
55

66

77
def Loader(path, engine='memmap', endian='big', strict=False, ignore_geometry=True):
8-
""" Selector class for loading SEG-Y with either segyio-based loader or memmap-based one. """
8+
""" Selector class for loading SEG-Y with either segyio-based loader or memmap-based one.
9+
10+
Parameters
11+
----------
12+
path : str
13+
Path to the SEG-Y file
14+
engine : 'memmap' or 'segyio'
15+
Engine to load data from file: ``'memmap'`` is based on :class:`numpy.memmap` created for the whole file and
16+
``'segyio'`` is for using **segyio** library instruments. in any case, **segyio** is used to load information
17+
about the entire file (e.g. ``'sample_interval'`` or ``'shape'``).
18+
endian : 'big' or 'little'
19+
Byte order in the file.
20+
strict : bool
21+
See :func:`segyio.open`
22+
ignore_geometry : bool
23+
See :func:`segyio.open`
24+
Return
25+
------
26+
:class:`~.memmap_loader.MemmapLoader` or :class:`~.segyio_loader.SegyioLoader`
27+
"""
928
loader_class = _select_loader_class(engine)
1029
return loader_class(path=path, endian=endian, strict=strict, ignore_geometry=ignore_geometry)
1130
open = File = Loader

0 commit comments

Comments
 (0)