How to use segyio - 10 common examples

To help you get started, we’ve selected a few segyio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github whimian / pyGeoPressure / pygeopressure / basic / seisegy.py View on Github external
def _parse_segy(self):
        with segyio.open(self.segy_file, 'r') as segyfile:
            segyfile.mmap()
            self.startInline = segyfile.ilines[0]
            self.endInline = segyfile.ilines[-1]
            self.nEast = len(segyfile.ilines)
            self.stepInline = (self.endInline - self.startInline) // \
                (self.nEast - 1)
            self.startCrline = segyfile.xlines[0]
            self.endCrline = segyfile.xlines[-1]
            self.nNorth = len(segyfile.xlines)
            self.stepCrline = (self.endCrline - self.startCrline) // \
                (self.nNorth - 1)
            self.startDepth = segyfile.samples[0]
            self.endDepth = segyfile.samples[-1]
            self.nDepth = len(segyfile.samples)
            self.stepDepth = (self.endDepth - self.startDepth) // \
                (self.nDepth - 1)
github whimian / pyGeoPressure / pygeopressure / basic / seisegy.py View on Github external
(self.nEast - 1)
            self.startCrline = segyfile.xlines[0]
            self.endCrline = segyfile.xlines[-1]
            self.nNorth = len(segyfile.xlines)
            self.stepCrline = (self.endCrline - self.startCrline) // \
                (self.nNorth - 1)
            self.startDepth = segyfile.samples[0]
            self.endDepth = segyfile.samples[-1]
            self.nDepth = len(segyfile.samples)
            self.stepDepth = (self.endDepth - self.startDepth) // \
                (self.nDepth - 1)

            inline_A = self.startInline
            crline_A = self.startCrline
            index_A = 0
            x_A = segyfile.header[index_A][segyio.su.cdpx]
            y_A = segyfile.header[index_A][segyio.su.cdpy]

            inline_B = inline_A
            crline_B = self.startCrline + 2 * self.stepCrline
            index_B = 2
            x_B = segyfile.header[index_B][segyio.su.cdpx]
            y_B = segyfile.header[index_B][segyio.su.cdpy]

            inline_C = self.startInline + 2 * self.stepInline
            crline_C = crline_B
            index_C = 2 * self.nNorth + 2
            x_C = segyfile.header[index_C][segyio.su.cdpx]
            y_C = segyfile.header[index_C][segyio.su.cdpy]

            setting_dict = {
                "inline_range": [
github equinor / segyio / tests / test_segy.py View on Github external
spec.ilines     = src.ilines[::2]
            spec.xlines     = src.xlines[::2]

            with segyio.create(dstfile, spec) as dst:
                # use the inline headers as base
                dst.header.iline = src.header.iline[::2]
                # then update crossline numbers from the crossline headers
                for xl in dst.xlines:
                    f = next(src.header.xline[xl])[TraceField.CROSSLINE_3D]
                    dst.header.xline[xl] = { TraceField.CROSSLINE_3D: f }

                # but we override the last xline to be 6, not 5
                dst.header.xline[5] = { TraceField.CROSSLINE_3D: 6 }
                dst.iline = src.iline[::2]

        with segyio.open(dstfile, "r") as f:
            self.assertListEqual(list(f.ilines), list(spec.ilines))
            self.assertListEqual(list(f.xlines), [1, 3, 6])
            self.assertAlmostEqual(1,     f.iline[1][0][0], places = 4)
            self.assertAlmostEqual(3.004, f.iline[3][0][4], places = 4)
            self.assertAlmostEqual(3.014, f.iline[3][1][4], places = 4)
            self.assertAlmostEqual(7.023, f.iline[7][2][3], places = 4)
github equinor / segyio / tests / test_segy.py View on Github external
def test_create_sgy_shorter_traces(self):
        dstfile = self.filename.replace(".sgy", "-shorter.sgy")

        with segyio.open(self.filename, "r") as src:
            spec = segyio.spec()
            spec.format     = int(src.format)
            spec.sorting    = int(src.sorting)
            spec.samples    = 20 # reduces samples per trace
            spec.ilines     = src.ilines
            spec.xlines     = src.xlines

            with segyio.create(dstfile, spec) as dst:
                for i, srch in enumerate(src.header):
                    dst.header[i] = srch
                    d = { TraceField.INLINE_3D: srch[TraceField.INLINE_3D] + 100 }
                    dst.header[i] = d

                for lineno in dst.ilines:
                    dst.iline[lineno] = src.iline[lineno]
github equinor / segyio / tests / test_segy.py View on Github external
def test_dt_no_fallback(self):
        f_name = self.filename.replace( ".sgy", "_dt_test.sgy")
        shutil.copyfile(self.filename, f_name)
        dt_us = 6000
        with segyio.open(f_name, "r+") as f:
            f.bin[BinField.Interval] = dt_us
            f.header[0][TraceField.TRACE_SAMPLE_INTERVAL] = dt_us
            f.flush()
            np.testing.assert_almost_equal(segyio.dt(f), dt_us/1000)
github equinor / segyio / tests / test_segy.py View on Github external
def mklines(fname):
    spec = segyio.spec()
    spec.format  = 5
    spec.sorting = 2
    spec.samples = 10
    spec.ilines  = range(1, 11)
    spec.xlines  = range(1, 6)

    # create a file with 10 inlines, with values on the form l.0tv where
    # l = line no
    # t = trace number (within line)
    # v = trace value
    # i.e. 2.043 is the value at inline 2's fourth trace's third value
    with segyio.create(fname, spec) as dst:
        ln = np.arange(start = 0,
                       stop = 0.001 * (5 * 10),
                       step = 0.001,
                       dtype = np.single).reshape(5, 10)
github equinor / segyio / tests / test_segy.py View on Github external
def test_create_from_naught_prestack(self):
        fname = "test-data/mk-ps.sgy"
        spec = segyio.spec()
        spec.format  = 5
        spec.sorting = 2
        spec.samples = 7
        spec.ilines  = range(1, 4)
        spec.xlines  = range(1, 3)
        spec.offsets = range(1, 6)

        cube_size = len(spec.ilines) * len(spec.xlines)

        with segyio.create(fname, spec) as dst:
            arr = np.arange( start = 0.000,
                             stop = 0.007,
                             step = 0.001,
                             dtype = np.single)

            arr = np.concatenate([[arr + 0.01], [arr + 0.02]], axis = 0)
github equinor / segyio / tests / test_segy.py View on Github external
def mklines(fname):
    spec = segyio.spec()
    spec.format  = 5
    spec.sorting = 2
    spec.samples = 10
    spec.ilines  = range(1, 11)
    spec.xlines  = range(1, 6)

    # create a file with 10 inlines, with values on the form l.0tv where
    # l = line no
    # t = trace number (within line)
    # v = trace value
    # i.e. 2.043 is the value at inline 2's fourth trace's third value
    with segyio.create(fname, spec) as dst:
        ln = np.arange(start = 0,
                       stop = 0.001 * (5 * 10),
                       step = 0.001,
                       dtype = np.single).reshape(5, 10)

        for il in spec.ilines:
            ln += 1

            dst.header.iline[il] = { TraceField.INLINE_3D: il }
            dst.iline[il] = ln

        for xl in spec.xlines:
            dst.header.xline[xl] = { TraceField.CROSSLINE_3D: xl }
github equinor / segyio / tests / test_segy.py View on Github external
def test_create_sgy(self):
        dstfile = self.filename.replace(".sgy", "-created.sgy")

        with segyio.open(self.filename, "r") as src:
            spec = segyio.spec()
            spec.format     = int(src.format)
            spec.sorting    = int(src.sorting)
            spec.samples    = src.samples
            spec.ilines     = src.ilines
            spec.xlines     = src.xlines

            with segyio.create(dstfile, spec) as dst:
                dst.text[0] = src.text[0]
                dst.bin     = src.bin

                # copy all headers
                dst.header = src.header

                for i, srctr in enumerate(src.trace):
                    dst.trace[i] = srctr

                dst.trace = src.trace

                # this doesn't work yet, some restructuring is necessary
                # if it turns out to be a desired feature it's rather easy to do
                #for dsth, srch in zip(dst.header, src.header):
                #    dsth = srch
github equinor / segyio / tests / test_segy.py View on Github external
def test_create_sgy_shorter_traces(self):
        dstfile = self.filename.replace(".sgy", "-shorter.sgy")

        with segyio.open(self.filename, "r") as src:
            spec = segyio.spec()
            spec.format     = int(src.format)
            spec.sorting    = int(src.sorting)
            spec.samples    = 20 # reduces samples per trace
            spec.ilines     = src.ilines
            spec.xlines     = src.xlines

            with segyio.create(dstfile, spec) as dst:
                for i, srch in enumerate(src.header):
                    dst.header[i] = srch
                    d = { TraceField.INLINE_3D: srch[TraceField.INLINE_3D] + 100 }
                    dst.header[i] = d

                for lineno in dst.ilines:
                    dst.iline[lineno] = src.iline[lineno]

                # alternative form using left-hand-side slices
                dst.iline[2:4] = src.iline

                for lineno in dst.xlines:
                    dst.xline[lineno] = src.xline[lineno]

            with segyio.open(dstfile, "r") as dst:
                self.assertEqual(20, dst.samples)