Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _import_segy_io(self, sfile):
"""Import SEGY via Statoils FOSS SegyIO library.
Args:
self (Cube): Cube object
sfile (str): File name of SEGY file
undef (float): If None, dead traces (undef) are read as is, but
if a a value, than dead traces get this value.
"""
# pylint: disable=too-many-statements
# pylint: disable=too-many-locals
logger.debug("Inline sorting %s", segyio.TraceSortingFormat.INLINE_SORTING)
with segyio.open(sfile, "r") as segyfile:
segyfile.mmap()
values = segyio.tools.cube(segyfile)
logger.info(values.dtype)
if values.dtype != np.float32:
xtg.warnuser(
"Values are converted from {} to {}".format(values.dtype, "float32")
)
values = values.astype(np.float32)
if np.isnan(np.sum(values)):
raise ValueError("The input contains NaN values which is trouble!")
-------
cube : numpy.ndarray
Notes
-----
.. versionadded:: 1.1
"""
if not isinstance(f, segyio.SegyFile):
with segyio.open(f) as fl:
return cube(fl)
ilsort = f.sorting == segyio.TraceSortingFormat.INLINE_SORTING
fast = f.ilines if ilsort else f.xlines
slow = f.xlines if ilsort else f.ilines
fast, slow, offs = len(fast), len(slow), len(f.offsets)
smps = len(f.samples)
dims = (fast, slow, smps) if offs == 1 else (fast, slow, offs, smps)
return f.trace.raw[:].reshape(dims)
# Write the file trace-by-trace and update headers with iline, xline
# and offset
tr = 0
for il in spec.ilines:
for xl in spec.xlines:
f.header[tr] = {
segyio.su.offset : 1,
segyio.su.iline : il,
segyio.su.xline : xl
}
f.trace[tr] = trace + (xl / 100.0) + il
tr += 1
f.bin.update(
tsort=segyio.TraceSortingFormat.INLINE_SORTING
)
# Write the file trace-by-trace and update headers with iline, xline
# and offset
tr = 0
for il in spec.ilines:
for xl in spec.xlines:
for off in spec.offsets:
f.header[tr] = {
segyio.su.offset : off,
segyio.su.iline : il,
segyio.su.xline : xl
}
f.trace[tr] = trace + (xl / 100.0) + il + (off * 100)
tr += 1
f.bin.update(
tsort=segyio.TraceSortingFormat.INLINE_SORTING
)
def create_segy_file(
masklambda, filename, sorting=segyio.TraceSortingFormat.INLINE_SORTING, ilinerange=[10, 50], xlinerange=[100, 300]
):
spec = segyio.spec()
# to create a file from nothing, we need to tell segyio about the structure of
# the file, i.e. its inline numbers, crossline numbers, etc. You can also add
# more structural information, but offsets etc. have sensible defautls. This is
# the absolute minimal specification for a N-by-M volume
spec.sorting = 2
spec.format = 1
spec.samples = range(int(10))
spec.ilines = range(*map(int, ilinerange))
spec.xlines = range(*map(int, xlinerange))
print(f"Written to {filename}")
print(f"\tinlines: {len(spec.ilines)}")
print(f"\tcrosslines: {len(spec.xlines)}")
f.trace[tr] = trace * ((xl / 100.0) + il)
tr += 1
f.bin.update(tsort=segyio.TraceSortingFormat.CROSSLINE_SORTING)
else:
# Write the file trace-by-trace and update headers with iline, xline
# and offset
tr = 0
for il in spec.ilines:
for xl in spec.xlines:
if masklambda(il, xl):
f.header[tr] = {segyio.su.offset: 1, segyio.su.iline: il, segyio.su.xline: xl}
f.trace[tr] = trace + (xl / 100.0) + il
tr += 1
f.bin.update(tsort=segyio.TraceSortingFormat.INLINE_SORTING)
print(f"\ttraces: {tr}")