How to use the segyio.tools 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 softwareunderground / subsurface / tests / test_seismic.py View on Github external
def seismic():
    """Benchmark Seismic object."""
    # coords = [{"x": np.arange(10)}, {"y": np.arange(10)}, {"z": np.arange(100)}]
    coords = [("x", np.arange(10)), ("y", np.arange(10)), ("z", np.arange(100))]
    cube = segyio.tools.cube("tests/data/test.segy")
    # seis = from_segy("tests/data/test.segy")
    return Seismic(cube, coords=coords)
github microsoft / seismic-deeplearning / interpretation / deepseismic_interpretation / segyconverter / utils / create_segy.py View on Github external
def parse_text_header(segyfile):
    """
    Format segy text header into a readable, clean dict
    """
    raw_header = segyio.tools.wrap(segyfile.text[0])
    # Cut on C*int pattern
    cut_header = re.split(r"C ", raw_header)[1::]
    # Remove end of line return
    text_header = [x.replace("\n", " ") for x in cut_header]
    text_header[-1] = text_header[-1][:-2]
    # Format in dict
    clean_header = {}
    i = 1
    for item in text_header:
        key = "C" + str(i).rjust(2, "0")
        i += 1
        clean_header[key] = item
    return clean_header
github equinor / xtgeo / src / xtgeo / cube / _cube_import.py View on Github external
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!")

        logger.debug(segyfile.fast)
        logger.debug(segyfile.ilines)
        logger.debug(len(segyfile.ilines))
        ilines = segyfile.ilines
github softwareunderground / subsurface / subsurface / seismic.py View on Github external
"""
    with segyio.open(filepath) as sf:
        sf.mmap()  # memory mapping
        xlines = sf.xlines
        ilines = sf.ilines
        samples = sf.samples
        header = sf.bin

    if not coords:
        coords = [
            ("ilines", ilines), 
            ("xlines", xlines),
            ("samples", samples)
        ]

    cube = segyio.tools.cube(filepath)
    seismic = Seismic(cube, coords=coords)
    seismic.header = header
    return seismic
github microsoft / seismic-deeplearning / contrib / experiments / interpretation / voxel2pixel / data.py View on Github external
def read_segy(filename):
    """
    Read in a SEGY-format file given a filename

    Args:
        filename: input filename

    Returns:
        numpy data array and its info as a dictionary (tuple)

    """
    print("Loading data cube from", filename, "with:")

    # Read full data cube
    data = segyio.tools.cube(filename)

    # Put temporal axis first
    data = np.moveaxis(data, -1, 0)

    # Make data cube fast to access
    data = np.ascontiguousarray(data, "float32")

    # Read meta data
    segyfile = segyio.open(filename, "r")
    print("  Crosslines: ", segyfile.xlines[0], ":", segyfile.xlines[-1])
    print("  Inlines:    ", segyfile.ilines[0], ":", segyfile.ilines[-1])
    print("  Timeslices: ", "1", ":", data.shape[0])

    # Make dict with cube-info
    # TODO: read this from segy
    # Read dt and other params needed to do create a new
github waldeland / CNN-for-ASI / data.py View on Github external
def readSEGY(filename):
    print('Loading data cube from',filename,'with:')

    # Read full data cube
    data = segyio.tools.cube(filename)

    # Put temporal axis first
    data = np.moveaxis(data, -1, 0)

    #Make data cube fast to acess
    data = np.ascontiguousarray(data,'float32')

    #Read meta data
    segyfile = segyio.open(filename, "r")
    print('  Crosslines: ', segyfile.xlines[0], ':', segyfile.xlines[-1])
    print('  Inlines:    ', segyfile.ilines[0], ':', segyfile.ilines[-1])
    print('  Timeslices: ', '1', ':', data.shape[0])

    #Make dict with cube-info
    data_info = {}
    data_info['crossline_start'] = segyfile.xlines[0]
github equinor / segyio / python / segyio / gather.py View on Github external
for xlno in xl_range:
                        try:
                            xind = xlinds[xlno]
                        except KeyError:
                            pass
                        else:
                            yield iline[xind]

                return

            if len(xs) == 0:
                for _, _ in itertools.product(il_range, xl_range): yield empty
                return

            for ilno in il_range:
                iline = tools.collect(self.iline[ilno, off])
                for x in xl_range:
                    try:
                        xind = xlinds[x]
                    except KeyError:
                        pass
                    else:
                        yield iline[:, xind]
github equinor / segyio / python / segyio / open.py View on Github external
from . import _segyio
    fd = _segyio.segyiofd(str(filename), mode, endians[endian])
    fd.segyopen()
    metrics = fd.metrics()

    f = segyio.SegyFile(fd,
            filename = str(filename),
            mode = mode,
            iline = iline,
            xline = xline,
            endian = endian,
    )

    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) * dt) + t0

    except:
        f.close()
        raise

    if ignore_geometry:
        return f

    return infer_geometry(f, metrics, iline, xline, strict)
github equinor / xtgeo / src / xtgeo / cube / _cube_import.py View on Github external
slen, _rotrad1, rot1 = xcalc.vectorinfo2(xori, cdpx, yori, cdpy)
                xinc = slen / (ncol - 1)

                rotation = rot1
                xvv = (cdpx - xori, cdpy - yori, 0)

            if inum == 2:
                slen, _rotrad2, rot2 = xcalc.vectorinfo2(xori, cdpx, yori, cdpy)
                yinc = slen / (nrow - 1)

                # find YFLIP by cross products
                yvv = (cdpx - xori, cdpy - yori, 0)

                yflip = xcalc.find_flip(xvv, yvv)

        rot2 = segyio.tools.rotation(segyfile)[0]
        logger.debug("SEGYIO rotation is %s", rot2 * 180 / 3.1415)
        logger.debug("XTGeo rotation is %s", rotation)

    # attributes to update
    self._ilines = ilines
    self._xlines = xlines
    self._ncol = ncol
    self._nrow = nrow
    self._nlay = nlay
    self._xori = xori
    self._xinc = xinc
    self._yori = yori
    self._yinc = yinc
    self._zori = zori
    self._zinc = zinc
    self._rotation = rotation
github softwareunderground / subsurface / subsurface / seismic.py View on Github external
def to_segy(self, filepath: str) -> None:
        """Write given Seismic to SEGY file using segyio.tools.from_array().
        
        Args:
            filepath (str): Filepath for SEGY file.
        """
        segyio.tools.from_array(filepath, self._xarray.data)