How to use the segyio.create 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
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)
github equinor / segyio / python / examples / copy-sub-cube.py View on Github external
def main():
    if len(sys.argv) < 3:
        sys.exit("Usage: {} [source-file] [destination-file]".format(sys.argv[0]))

    sourcefile = sys.argv[1]
    destfile = sys.argv[2]

    with segyio.open(sourcefile) as src:
        spec = segyio.spec()
        spec.sorting = int(src.sorting)
        spec.format  = int(src.format)
        spec.samples = range(50)
        spec.ilines = src.ilines[:5]
        spec.xlines = src.xlines[:5]

        with segyio.create(destfile, spec) as dst:
            # Copy all textual headers, including possible extended
            for i in range(1 + src.ext_headers):
                dst.text[i] = src.text[i]

            # copy the binary header, then insert the modifications needed for
            # the new shape
            dst.bin = src.bin
            dst.bin = { segyio.BinField.Samples: 50,
                        segyio.BinField.Traces: 5 * 5
                      }

            # Copy all headers in the new inlines. Since we know we're copying
            # the five first we don't have to take special care to update
            # headers
            dst.header.iline = src.header.iline
            # the copy traces (in line mode)
github equinor / segyio / python / examples / make-file.py View on Github external
sys.exit("Usage: {} [file] [samples] [first iline] [last iline] [first xline] [last xline]".format(sys.argv[0]))

    spec = segyio.spec()
    filename = sys.argv[1]

    # 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(sys.argv[2]))
    spec.ilines = range(*map(int, sys.argv[3:5]))
    spec.xlines = range(*map(int, sys.argv[5:7]))

    with segyio.create(filename, spec) as f:
        # one inline consists of 50 traces
        # which in turn consists of 2000 samples
        start = 0.0
        step = 0.00001
        # fill a trace with predictable values: left-of-comma is the inline
        # number. Immediately right of comma is the crossline number
        # the rightmost digits is the index of the sample in that trace meaning
        # looking up an inline's i's jth crosslines' k should be roughly equal
        # to i.j0k
        trace = np.arange(start = start,
                          stop  = start + step * len(spec.samples),
                          step  = step,
                          dtype = np.single)

        # Write the file trace-by-trace and update headers with iline, xline
        # and offset
github equinor / segyio / python / segyio / tools.py View on Github external
spec.tracecount = np.size(data, 1)

    if dimensions == 3:
        spec.ilines  = list(range(1, np.size(data, 0) + 1))
        spec.xlines  = list(range(1, np.size(data, 1) + 1))
        spec.samples = list(range(np.size(data, 2)))

    if dimensions == 4:
        spec.ilines  = list(range(1, np.size(data, 0) + 1))
        spec.xlines  = list(range(1, np.size(data, 1) + 1))
        spec.offsets = list(range(1, np.size(data, 2)+ 1))
        spec.samples = list(range(np.size(data,3)))

    samplecount = len(spec.samples)

    with segyio.create(filename, spec) as f:
        tr = 0
        for ilno, il in enumerate(spec.ilines):
            for xlno, xl in enumerate(spec.xlines):
                for offno, off in enumerate(spec.offsets):
                    f.header[tr] = {
                        segyio.su.tracf  : tr,
                        segyio.su.cdpt   : tr,
                        segyio.su.offset : off,
                        segyio.su.ns     : samplecount,
                        segyio.su.dt     : dt,
                        segyio.su.delrt  : delrt,
                        segyio.su.iline  : il,
                        segyio.su.xline  : xl
                    }
                    if dimensions == 2: f.trace[tr] = data[tr, :]
                    if dimensions == 3: f.trace[tr] = data[ilno, xlno, :]
github equinor / xtgeo / src / xtgeo / cube / _cube_export.py View on Github external
else:
        # NOT FINISHED!
        logger.debug("Input segy file from scratch ...")

        # sintv = int(self.zinc * 1000)
        spec = segyio.spec()

        spec.sorting = 2
        spec.format = 1

        spec.samples = np.arange(self.nlay)
        spec.ilines = np.arange(self.ncol)
        spec.xlines = np.arange(self.nrow)

        with segyio.create(sfile, spec) as fseg:

            # write the line itself to the file and the inline number
            # in all this line's headers
            for ill, ilno in enumerate(spec.ilines):
                fseg.iline[ilno] = cvalues[ill]
                # f.header.iline[ilno] = {
github equinor / segyio / python / examples / make-ps-file.py View on Github external
spec = segyio.spec()
    filename = sys.argv[1]

    # 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, This is the absolute minimal specification for a
    # N-by-M volume with K offsets volume
    spec.sorting = 2
    spec.format = 1
    spec.samples = range(int(sys.argv[2]))
    spec.ilines = range(*map(int, sys.argv[3:5]))
    spec.xlines = range(*map(int, sys.argv[5:7]))
    spec.offsets = range(*map(int, sys.argv[7:9]))
    if len(spec.offsets) == 0: spec.offsets = [1]

    with segyio.create(filename, spec) as f:
        # one inline consists of 50 traces
        # which in turn consists of 2000 samples
        start = 0.0
        step = 0.00001
        # fill a trace with predictable values: left-of-comma is the inline
        # number. Immediately right of comma is the crossline number
        # the rightmost digits is the index of the sample in that trace meaning
        # looking up an inline's i's jth crosslines' k should be roughly equal
        # to (offset*100) + i.j0k.
        trace = np.arange(start = start,
                          stop  = start + step * len(spec.samples),
                          step  = step,
                          dtype = np.single)

        # Write the file trace-by-trace and update headers with iline, xline
        # and offset
github microsoft / seismic-deeplearning / interpretation / deepseismic_interpretation / segyconverter / utils / create_segy.py View on Github external
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)}")

    with segyio.create(filename, spec) as f:
        # one inline consists of 50 traces
        # which in turn consists of 2000 samples
        step = 0.00001
        start = step * len(spec.samples)
        # fill a trace with predictable values: left-of-comma is the inline
        # number. Immediately right of comma is the crossline number
        # the rightmost digits is the index of the sample in that trace meaning
        # looking up an inline's i's jth crosslines' k should be roughly equal
        # to i.j0k
        trace = np.linspace(-1, 1, len(spec.samples), True, dtype=np.single)

        if sorting == 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: