Esempio n. 1
0
    def iline(self):
        """:rtype: Line"""
        segy = self.segy
        length = segy._iline_length
        stride = segy._iline_stride
        lines = segy.ilines
        other_lines = segy.xlines
        buffn = self._header_buffer

        return Line(segy, length, stride, lines, other_lines, buffn, self.readfn, self.writefn, "Inline")
Esempio n. 2
0
    def depth_slice(self):
        """ Interact with segy in depth slice mode.

        This mode gives access to reading and writing functionality for depth slices.
        The primary data type is the numpy ndarray. Depth slices can be accessed
        individually or with python slices, and writing is done via assignment.
        Note that each slice is returned as a numpy array, meaning
        accessing the values of the slice is 0-indexed.

        Examples:
            Read a depth slice:
                >>> il = f.depth_slice[199]

            Copy every depth slice into a list::
                >>> l = [np.copy(x) for x in f.depth_slice]

            The number of depth slices in a file::
                >>> len(f.depth_slice)

            Numpy operations on every third depth slice::
                >>> for depth_slice in f.depth_slice[::3]:
                ...     depth_slice = depth_slice * 6
                ...     avg = np.average(depth_slice)
                ...     print(avg)
                ...

            Read depth_slices up to 250::
                >>> for depth_slice in f.depth_slice[:250]:
                ...     print(np.average(depth_slice))
                ...

            Copy a line from file g to f::
                >>> f.depth_slice[4] = g.depth_slice[19]

            Copy lines from the first line in g to f, starting at 10,
            ending at 49 in f::
                >>> f.depth_slice[10:50] = g.depth_slice


            Convenient way for setting depth slices, from left-to-right as the depth slices
            numbers are specified in the file.depth_slice property, from an iterable
            set on the right-hand-side.

            If the right-hand-side depth slices are exhausted before all the destination
            file depth slices the writing will stop, i.e. not all all depth slices in the
            destination file will be written.

            Copy depth slices from file f to file g::
                >>> f.depth_slice = g.depth_slice.

            Copy first half of the depth slices from g to f::
                >>> f.depth_slice = g.depth_slice[:g.samples/2]]

            Copy every other depth slices from a different file::
                >>> f.depth_slice = g.depth_slice[::2]
        """
        indices = np.asarray(list(range(self.samples)), dtype=np.uintc)
        other_indices = np.asarray([0], dtype=np.uintc)
        buffn = self._depth_buffer

        def readfn(depth, length, stride, buf):
            buf_view = buf.reshape(self._iline_length * self._xline_length)

            for i, trace_buf in enumerate(self.trace):
                buf_view[i] = trace_buf[depth]

            return buf

        def writefn(depth, length, stride, val):
            val = buffn(val)

            buf_view = val.reshape(self._iline_length * self._xline_length)

            for i, trace_buf in enumerate(self.trace):
                trace_buf[depth] = buf_view[i]
                self.trace[i] = trace_buf

        return Line(self, self.samples, 1, indices, other_indices, buffn,
                    readfn, writefn, "Depth")
Esempio n. 3
0
    def xline(self):
        """ Interact with segy in crossline mode.

        This mode gives access to reading and writing functionality for crosslines.
        The primary data type is the numpy ndarray. crosslines can be accessed
        individually or with python slices, and writing is done via assignment.
        Note that accessing crosslines uses the line numbers, not their position,
        so if a files has crosslines [1400..1450], accessing line [0..100] will be
        an error. Note that each line is returned as a numpy array, meaning
        accessing the intersections of the inline and crossline is 0-indexed.

        Examples:
            Read an crossline::
                >>> il = f.xline[1400]

            Copy every crossline into a list::
                >>> l = [np.copy(x) for x in f.xline]

            The number of crosslines in a file::
                >>> len(f.xline)

            Numpy operations on every third crossline::
                >>> for line in f.xline[::3]:
                ...     line = line * 6
                ...     avg = np.average(line)
                ...     print(avg)
                ...

            Read crosslines up to 1430::
                >>> for line in f.xline[:1430]:
                ...     print(np.average(line))
                ...

            Copy a line from file g to f::
                >>> f.xline[1400] = g.xline[1603]

            Copy lines from the first line in g to f, starting at 1400,
            ending at 1415 in f::
                >>> f.xline[1400:1416] = g.xline


            Convenient way for setting crosslines, from left-to-right as the crossline
            numbers are specified in the file.xlines property, from an iterable
            set on the right-hand-side.

            If the right-hand-side crosslines are exhausted before all the destination
            file crosslines the writing will stop, i.e. not all all crosslines in the
            destination file will be written.

            Copy crosslines from file f to file g::
                >>> f.xline = g.xline.

            Copy first half of the crosslines from g to f::
                >>> f.xline = g.xline[:g.xlines[len(g.xlines)/2]]

            Copy every other crossline from a different file::
                >>> f.xline = g.xline[::2]
        """
        xl_len, xl_stride = self._xline_length, self._xline_stride
        lines = self.xlines
        other_lines = self.ilines
        buffn = lambda x=None: self._line_buffer(xl_len, x)
        readfn = self._fread_line

        def writefn(t0, length, step, val):
            val = buffn(val)
            for i, v in itertools.izip(xrange(t0, t0 + step * length, step),
                                       val):
                Trace.write_trace(i, v, self)

        return Line(self, xl_len, xl_stride, lines, other_lines, buffn, readfn,
                    writefn, "Crossline")
Esempio n. 4
0
    def xline(self):
        """ Interact with segy in crossline mode.

        Since v1.1

        This mode gives access to reading and writing functionality for crosslines.
        The primary data type is the numpy ndarray. crosslines can be accessed
        individually or with python slices, and writing is done via assignment.
        Note that accessing crosslines uses the line numbers, not their position,
        so if a files has crosslines [1400..1450], accessing line [0..100] will be
        an error. Note that each line is returned as a numpy array, meaning
        accessing the intersections of the inline and crossline is 0-indexed.

        Additionally, the xline mode has a concept of offsets, which is useful
        when dealing with prestack files. Offsets are accessed via so-called
        sub indexing, meaning xline[10, 4] will give you line 10 at offset 4.
        Please note that offset, like lines, are accessed via their numbers,
        not their indices. If your file has the offsets [100, 200, 300, 400]
        and the lines [1400..1450], you can access the second offset with
        [1421,300]. Please refer to the examples for more details. If no offset
        is specified, segyio will give you the first.

        Examples:
            Read an crossline::
                >>> il = f.xline[1400]

            Copy every crossline into a list::
                >>> l = [np.copy(x) for x in f.xline]

            The number of crosslines in a file::
                >>> len(f.xline)

            Numpy operations on every third crossline::
                >>> for line in f.xline[::3]:
                ...     line = line * 6
                ...     avg = np.average(line)
                ...     print(avg)
                ...

            Read crosslines up to 1430::
                >>> for line in f.xline[:1430]:
                ...     print(np.average(line))
                ...

            Copy a line from file g to f::
                >>> f.xline[1400] = g.xline[1603]

            Copy lines from the first line in g to f, starting at 1400,
            ending at 1415 in f::
                >>> f.xline[1400:1416] = g.xline


            Convenient way for setting crosslines, from left-to-right as the crossline
            numbers are specified in the file.xlines property, from an iterable
            set on the right-hand-side.

            If the right-hand-side crosslines are exhausted before all the destination
            file crosslines the writing will stop, i.e. not all all crosslines in the
            destination file will be written.

            Copy crosslines from file f to file g::
                >>> f.xline = g.xline.

            Copy first half of the crosslines from g to f::
                >>> f.xline = g.xline[:g.xlines[len(g.xlines)/2]]

            Copy every other crossline from a different file::
                >>> f.xline = g.xline[::2]

            Accessing offsets work the same way as accessing lines, and slicing
            is supported as well. When doing range-based offset access, the
            lines will be generated offsets-first, i.e equivalent to:
            [(line1 off1), (line1 off2), (line1 off3), (line2 off1), ...]
            or the double for loop::
                >>> for line in lines:
                ...     for off in offsets:
                ...         yield (line, off)
                ...

            Copy all lines at all offsets::
                >>> [np.copy(x) for x in f.xline[:,:]]

            Print all line 10's offsets::
                >>> print(f.xline[10,:])

            Numpy operations at every line at offset 120::
                >>> for line in f.xline[:, 120]:
                ...     line = line * 2
                ...     print(np.average(line))

            Copy every other line and offset::
                >>> map(np.copy, f.xline[::2, ::2])

            Print offsets in reverse::
                >>> for line in f.xline[:, ::-1]:
                ...     print(line)

            Copy all offsets [200, 250, 300, 350, ...] in the range [200, 800)
            for all xlines [2420,2460)::
                >>> [np.copy(x) for x in f.xline[2420:2460, 200:800:50]]

            Copy every third offset from f to g::
                >>> g.xline[:,:] = f.xline[:,::3]

            Copy an xline from f to g at g's offset 200::
                >>> g.xline[12, 200] = f.xline[21]
        """
        if self.unstructured:
            raise ValueError(self._unstructured_errmsg)

        if self._xline is not None:
            return self._xline

        xl_len, xl_stride = self._xline_length, self._xline_stride
        lines = self.xlines
        other_lines = self.ilines
        buffn = lambda x=None: self._line_buffer(xl_len, x)
        readfn = self._fread_line

        def writefn(t0, length, step, val):
            val = buffn(val)
            step *= len(self.offsets)
            for i, v in zip(range(t0, t0 + step * length, step), val):
                Trace.write_trace(i, v, self)

        self._xline = Line(self, xl_len, xl_stride, lines, other_lines, buffn,
                           readfn, writefn, "Crossline")
        return self._xline
Esempio n. 5
0
    def depth_slice(self):
        """Interact with segy in depth slice mode

        This mode gives access to reading and writing functionality for depth
        slices, a horizontal cut of the survey.

        The primary data type is ``numpy.ndarray``. Depth slices can be
        accessed individually or with slices, and writing is done via
        assignment. Note that each slice is returned as a ``numpy.ndarray``, meaning
        accessing the values of the slice is 0-indexed.

        Returns
        -------

        depth
            depth addressing mode

        Notes
        -----

        .. versionadded:: 1.1

        .. warning::
            Accessing the file by depth (fixed z-coordinate) is inefficient
            because of poor locality and many reads. If you read more than a
            handful depths, consider using a faster mode.

        Examples
        --------

        Read a depth slice:

        >>> il = f.depth_slice[199]

        Copy every depth slice into a list:

        >>> l = [np.copy(x) for x in f.depth_slice]

        The number of depth slices in a file:

        >>> len(f.depth_slice)

        Numpy operations on every third depth slice:

        >>> for depth_slice in f.depth_slice[::3]:
        ...     depth_slice = depth_slice * 6
        ...     avg = np.average(depth_slice)
        ...     print(avg)
        ...

        Read depth_slices up to 250:

        >>> for depth_slice in f.depth_slice[:250]:
        ...     print(np.average(depth_slice))
        ...

        Copy a slice from file g to f:

        >>> f.depth_slice[4] = g.depth_slice[19]

        Copy slice from the first line in g to f, starting at 10,
        ending at 49 in f:

        >>> f.depth_slice[10:50] = g.depth_slice


        Convenient way for setting depth slices, from left-to-right as the depth slices
        numbers are specified in the file.depth_slice property, from an iterable
        set on the right-hand-side.

        If the right-hand-side depth slices are exhausted before all the destination
        file depth slices the writing will stop, i.e. not all all depth slices in the
        destination file will be written.

        Copy depth slices from file f to file g:

        >>> f.depth_slice = g.depth_slice

        Copy first half of the depth slices from g to f:

        >>> f.depth_slice = g.depth_slice[:g.samples/2]]

        Copy every other depth slices from a different file:

        >>> f.depth_slice = g.depth_slice[::2]

        """

        if self.unstructured:
            raise ValueError(self._unstructured_errmsg)

        indices = np.asarray(list(range(len(self.samples))), dtype=np.intc)
        other_indices = np.asarray([0], dtype=np.intc)
        buffn = self._depth_buffer

        slice_trace_count = self._iline_length * self._xline_length
        offsets = len(self.offsets)

        def readfn(depth, length, stride, buf):
            return self.xfd.getdepth(depth, slice_trace_count, offsets, buf)

        def writefn(depth, length, stride, val):
            val = buffn(val)

            buf_view = val.reshape(self._iline_length * self._xline_length)

            for i, trace_buf in enumerate(self.trace):
                trace_buf[depth] = buf_view[i]
                self.trace[i] = trace_buf

        return Line(self, len(self.samples), 1, indices, other_indices, buffn, readfn, writefn, "depth")