/usr/lib/python3/dist-packages/segyio/open.py is in python3-segyio 1.5.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | import numpy
import segyio
def open(filename, mode="r", iline = 189,
xline = 193,
strict = True,
ignore_geometry = False):
"""Open a segy file.
Since v1.1
Opens a segy file and tries to figure out its sorting, inline numbers,
crossline numbers, and offsets, and enables reading and writing to this
file in a simple manner.
For reading, the access mode "r" is preferred. All write operations will
raise an exception. For writing, the mode "r+" is preferred (as "rw" would
truncate the file). Any mode with 'w' will raise an error. The modes used
are standard C file modes; please refer to that documentation for a
complete reference.
Open should be used together with python's `with` statement. Please refer
to the examples. When the `with` statement is used the file will
automatically be closed when the routine completes or an exception is
raised.
By default, segyio tries to open in 'strict' mode. This means the file will
be assumed to represent a geometry with consistent inline, crosslines and
offsets. If strict is False, segyio will still try to establish a geometry,
but it won't abort if it fails. When in non-strict mode is opened,
geometry-dependent modes such as iline will raise an error.
If 'ignore_geometry' is set to True, segyio will *not* try to build
iline/xline or other geometry related structures, which leads to faster
opens. This is essentially the same as using strict = False on a file that
has no geometry.
Args:
filename (str-like): Path to file to open.
mode (str, optional): File access mode, defaults to "r".
iline (TraceField): Inline number field in the trace headers. Defaults
to 189 as per the SEGY specification.
xline (TraceField): Crossline number field in the trace headers.
Defaults to 193 as per the SEGY specification.
strict (bool, optional): Abort if a geometry cannot be inferred.
Defaults to True.
ignore_geometry (bool, optional): Opt out on building geometry
information, useful for e.g. shot
organised files. Defaults to False.
Examples:
Open a file in read-only mode::
>>> with segyio.open(path, "r") as f:
... print(f.ilines)
...
Open a file in read-write mode::
>>> with segyio.open(path, "r+") as f:
... f.trace = np.arange(100)
...
Open two files at once::
>>> with segyio.open(path) as src, segyio.open(path, "r+") as dst:
... dst.trace = src.trace # copy all traces from src to dst
...
:rtype: segyio.SegyFile
"""
if 'w' in mode:
problem = 'w in mode would truncate the file'
solution = 'use r+ to open in read-write'
raise ValueError(', '.join((problem, solution)))
f = segyio.SegyFile(str(filename), mode, iline, xline)
metrics = f.xfd.metrics()
try:
dt = segyio.tools.dt(f, fallback_dt = 4000.0) / 1000.0
t0 = f.header[0][segyio.TraceField.DelayRecordingTime]
samples = metrics['samplecount']
f._samples = (numpy.arange(samples, dtype = numpy.single) * dt) + t0
except:
f.close()
raise
if ignore_geometry:
return f
try:
cube_metrics = f.xfd.cube_metrics(iline, xline)
f._sorting = cube_metrics['sorting']
iline_count = cube_metrics['iline_count']
xline_count = cube_metrics['xline_count']
offset_count = cube_metrics['offset_count']
metrics.update(cube_metrics)
line_metrics = segyio._segyio.line_metrics(f.sorting,
f.tracecount,
iline_count,
xline_count,
offset_count)
f._iline_length = line_metrics['iline_length']
f._iline_stride = line_metrics['iline_stride']
f._xline_length = line_metrics['xline_length']
f._xline_stride = line_metrics['xline_stride']
f._ilines = numpy.zeros(iline_count, dtype = numpy.intc)
f._xlines = numpy.zeros(xline_count, dtype = numpy.intc)
f._offsets = numpy.zeros(offset_count, dtype = numpy.intc)
f.xfd.indices(metrics, f.ilines, f.xlines, f.offsets)
if numpy.unique(f.ilines).size != f.ilines.size:
raise ValueError( "Inlines inconsistent - expect all inlines to be unique")
if numpy.unique(f.xlines).size != f.xlines.size:
raise ValueError( "Crosslines inconsistent - expect all crosslines to be unique")
except:
if not strict:
f._ilines = None
f._xlines = None
f._offsets = None
else:
f.close()
raise
return f
|