How to use the segyio.TraceField function in segyio

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 equinor / segyio / tests / test_segy.py View on Github external
spec.samples = 150
        spec.ilines  = range(1, 11)
        spec.xlines  = range(1, 6)

        with segyio.create(fname, spec) as dst:
            tr = np.arange( start = 1.000, stop = 1.151, step = 0.001, dtype = np.single)

            for i in range( len( dst.trace ) ):
                dst.trace[i] = tr
                tr += 1.000

            for il in spec.ilines:
                dst.header.iline[il] = { TraceField.INLINE_3D: il }

            for xl in spec.xlines:
                dst.header.xline[xl] = { TraceField.CROSSLINE_3D: xl }

            # Set header field 'offset' to 1 in all headers
            dst.header = { TraceField.offset: 1 }

        with segyio.open(fname, "r") as f:
            self.assertAlmostEqual(1,      f.trace[0][0],   places = 4)
            self.assertAlmostEqual(1.001,  f.trace[0][1],   places = 4)
            self.assertAlmostEqual(1.149,  f.trace[0][-1],   places = 4)
            self.assertAlmostEqual(50.100, f.trace[-1][100], places = 4)
            self.assertEqual(f.header[0][TraceField.offset], f.header[1][TraceField.offset])
            self.assertEqual(1, f.header[1][TraceField.offset])
github equinor / segyio / tests / test_segy.py View on Github external
def test_open_transposed_lines(self):
        il, xl = [], []
        with segyio.open(self.filename, "r") as f:
            il = f.ilines
            xl = f.xlines

        with segyio.open(self.filename, "r", segyio.TraceField.CROSSLINE_3D, segyio.TraceField.INLINE_3D) as f:
            self.assertListEqual(list(il), list(f.xlines))
            self.assertListEqual(list(xl), list(f.ilines))
            pass
github equinor / segyio / tests / test_segy.py View on Github external
# 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_tools.py View on Github external
def test_dt_fallback(self):
        with TestContext("dt_fallback") as context:
            context.copy_file(self.filename)
            with segyio.open("small.sgy", "r+") as f:
                # Both zero
                f.bin[BinField.Interval] = 0
                f.header[0][TraceField.TRACE_SAMPLE_INTERVAL] = 0
                f.flush()
                fallback_dt = 4
                np.testing.assert_almost_equal(segyio.dt(f, fallback_dt), fallback_dt)

                # dt in bin header different from first trace
                f.bin[BinField.Interval] = 6000
                f.header[0][TraceField.TRACE_SAMPLE_INTERVAL] = 1000
                f.flush()
                fallback_dt = 4
                np.testing.assert_almost_equal(segyio.dt(f, fallback_dt), fallback_dt)
github equinor / segyio / tests / test_segy.py View on Github external
def test_dt_fallback(self):
        f_name = self.filename.replace( ".sgy", "_dt_test.sgy")
        shutil.copyfile(self.filename, f_name)
        with segyio.open(f_name, "r+") as f:
            # Both zero
            f.bin[BinField.Interval] = 0
            f.header[0][TraceField.TRACE_SAMPLE_INTERVAL] = 0
            f.flush()
            fallback_dt = 4
            np.testing.assert_almost_equal(segyio.dt(f, fallback_dt), fallback_dt)

            # dt in bin header different from first trace
            f.bin[BinField.Interval] = 6000
            f.header[0][TraceField.TRACE_SAMPLE_INTERVAL] = 1000
            f.flush()
            fallback_dt = 4
            np.testing.assert_almost_equal(segyio.dt(f, fallback_dt), fallback_dt)
github equinor / segyio / python / examples / about.py View on Github external
def list_byte_offset_names():
    print("Available offsets and their corresponding byte value:")
    for x in TraceField.enums():
        print("  {}: {}".format(str(x), x))
github dfitzgerald3 / d2geo / attributes / io.py View on Github external
def segy_read(segy_path, out_path, out_name):
    
    def write(chunk, segy_file, dset):
        for i in chunk:
            dset[i[0], i[1], :] = segy_file.trace.raw[i[2]]
            
        return(chunk)
    
    segy_file = segyio.open(segy_path)
    trace_inlines = segy_file.attributes(segyio.TraceField.INLINE_3D)[:]
    trace_xlines = segy_file.attributes(segyio.TraceField.CROSSLINE_3D)[:]
    
    trace_inlines_unique = np.unique(trace_inlines)
    trace_xlines_unique = np.unique(trace_xlines)
    
    num_inline = trace_inlines_unique.size
    num_xline = trace_xlines_unique.size
    num_zsamples = len(segy_file.samples)
    
    min_inline = trace_inlines_unique.min()
    min_xline = trace_xlines_unique.min()
    min_zsample = segy_file.samples.min()
    
    max_inline = trace_inlines_unique.max()
    max_xline = trace_xlines_unique.max()
    max_zsample = segy_file.samples.max()
github equinor / segyio / python / segyio / create.py View on Github external
filename = str(filename),
            mode = 'w+',
            iline = int(spec.iline),
            xline = int(spec.xline),
            endian = endian,
    )

    f._samples       = samples

    if structured(spec):
        sorting = spec.sorting if hasattr(spec, 'sorting') else None
        if sorting is None:
            sorting = TraceSortingFormat.INLINE_SORTING
        f.interpret(spec.ilines, spec.xlines, spec.offsets, sorting)

    f.text[0] = default_text_header(f._il, f._xl, segyio.TraceField.offset)

    if len(samples) == 1:
        interval = int(samples[0] * 1000)
    else:
        interval = int((samples[1] - samples[0]) * 1000)

    f.bin.update(
        ntrpr    = tracecount,
        nart     = tracecount,
        hdt      = interval,
        dto      = interval,
        hns      = len(samples),
        nso      = len(samples),
        format   = int(spec.format),
        exth     = ext_headers,
    )
github dfitzgerald3 / d2geo / attributes / io.py View on Github external
def segy_read(segy_path, out_path, out_name):
    
    def write(chunk, segy_file, dset):
        for i in chunk:
            dset[i[0], i[1], :] = segy_file.trace.raw[i[2]]
            
        return(chunk)
    
    segy_file = segyio.open(segy_path)
    trace_inlines = segy_file.attributes(segyio.TraceField.INLINE_3D)[:]
    trace_xlines = segy_file.attributes(segyio.TraceField.CROSSLINE_3D)[:]
    
    trace_inlines_unique = np.unique(trace_inlines)
    trace_xlines_unique = np.unique(trace_xlines)
    
    num_inline = trace_inlines_unique.size
    num_xline = trace_xlines_unique.size
    num_zsamples = len(segy_file.samples)
    
    min_inline = trace_inlines_unique.min()
    min_xline = trace_xlines_unique.min()
    min_zsample = segy_file.samples.min()
    
    max_inline = trace_inlines_unique.max()
    max_xline = trace_xlines_unique.max()
    max_zsample = segy_file.samples.max()