예제 #1
0
    def load(cls, file: str):
        """ Load the Geometry from a SEG-Y file. """

        g = cls()

        with open(file, 'br') as sgy:
            # grab endian, number of traces, sample size, and trace length
            endian = gfunc.grab_endiannes(sgy)
            nt = gfunc.grab_number_of_traces(sgy)
            ss = gfunc.grab_sample_format(sgy)[0]
            tl = gfunc.grab_trace_length(sgy)

            # skip TFH and BFH
            sgy.seek(3600)

            # create a matrix to store trace headers' values
            data = np.empty(shape=(nt, 90), dtype=np.int32)

            for i in range(nt):
                # read in, unpack and store the header
                raw_header = sgy.read(240)
                header = struct.unpack(endian + const.THFS, raw_header[:232])
                data[i] = header

                # skip to the next header - one trace worth of bytes
                sgy.seek(sgy.tell() + ss * tl)

        # transform the matrix into a DataFrame
        g._df = pd.DataFrame(data, index=range(nt), columns=const.THCOLS)

        # apply scalars to elevations and coordinates
        g._apply_scalars_after_unpacking()

        return g
예제 #2
0
def test_grab_endiannes(manually_crafted_segy_file,
                        manually_crafted_little_endian_segy_file):
    """ Test the general function for grabbing endiannes. """

    # check that the returned value is correct and the the cursor is
    # returned to the original position after the grab

    with open(manually_crafted_segy_file, 'br') as sgy:
        sgy.seek(random.randint(0, 3600))
        position = sgy.tell()
        assert gfunc.grab_endiannes(sgy) == '>'
        assert sgy.tell() == position

    with open(manually_crafted_little_endian_segy_file, 'br') as sgy:
        sgy.seek(random.randint(0, 3600))
        position = sgy.tell()
        assert gfunc.grab_endiannes(sgy) == '<'
        assert sgy.tell() == position
예제 #3
0
    def load(cls, file: str):
        """ Load BFH from a SEG-Y file.

        Args:
            file (str) : Path to the SEG-Y file to load from.

        """

        bfh = cls()

        with open(file, 'br') as sgy:
            # get the endian
            endian = gfunc.grab_endiannes(sgy)

            # skip the TFH, read the BFH bytes
            sgy.seek(3200)
            raw = sgy.read(400)

        # unpack and store the values
        values = struct.unpack(endian + const.BFHFS, raw)
        bfh._dict = dict(zip(const.BFHCOLS, values))

        return bfh
예제 #4
0
    def load(cls, file: str):
        """ Load the DataMatrix from a SEG-Y file. """

        dm = cls()

        with open(file, 'br') as sgy:
            # grab endian, format letter, trace length, sample size, number of traces, data type, and sample interval
            endian = gfunc.grab_endiannes(sgy)
            sfc = gfunc.grab_sample_format_code(sgy)
            tl = gfunc.grab_trace_length(sgy)
            nt = gfunc.grab_number_of_traces(sgy)
            si = gfunc.grab_sample_interval(sgy)

            ss, fl, _ = const.SFC[sfc]
            dtype = const.DTYPEMAP[sfc]

            dm._m = np.empty(shape=(nt, tl), dtype=dtype)

            sgy.seek(3600)

            if sfc == 1:  # IBM is a special case
                pass
            else:
                format_string = endian + fl * tl

                for i in range(nt):
                    sgy.seek(sgy.tell() + 240)  # skip trace header
                    raw_trace = sgy.read(ss * tl)

                    values = struct.unpack(format_string, raw_trace)
                    dm._m[i] = values

        dm.dt = si
        dm.t = np.arange(0, si * tl / 1000, si / 1000)

        return dm
예제 #5
0
    def load(cls, file: str):
        """ Load the SEG-Y file. """

        segy = cls()

        with open(file, 'br') as sgy:
            endian = gfunc.grab_endiannes(sgy)
            sfc = gfunc.grab_sample_format_code(sgy)
            nt = gfunc.grab_number_of_traces(sgy)
            tl = gfunc.grab_trace_length(sgy)
            si = gfunc.grab_sample_interval(sgy)
            ss, fl, _ = const.SFC[sfc]
            dtype = const.DTYPEMAP[sfc]

            raw_tfh = sgy.read(3200)
            raw_bfh = sgy.read(400)

            header_data = np.empty(shape=(nt, 90), dtype=np.int32)
            segy.dm._m = np.empty(shape=(nt, tl), dtype=dtype)

            if sfc == 1:  # IBM is a special case
                for i in range(nt):
                    raw_header = sgy.read(240)
                    header = struct.unpack(endian + const.THFS,
                                           raw_header[:232])
                    header_data[i] = header

                    raw_trace = sgy.read(ss * tl)
                    trace_values = gfunc.unpack_ibm32_series(raw_trace, endian)
                    segy.dm._m[i] = trace_values
            else:
                trace_fs = endian + fl * tl

                for i in range(nt):
                    raw_header = sgy.read(240)
                    header = struct.unpack(endian + const.THFS,
                                           raw_header[:232])
                    header_data[i] = header

                    raw_trace = sgy.read(ss * tl)
                    trace_values = struct.unpack(trace_fs, raw_trace)
                    segy.dm._m[i] = trace_values

        segy.tfh._contents = raw_tfh.decode('cp500')

        bfh_values = struct.unpack(endian + const.BFHFS, raw_bfh)
        segy.bfh._dict = dict(zip(const.BFHCOLS, bfh_values))

        segy.bfh['no_traces'] = nt

        segy.g._df = pd.DataFrame(header_data,
                                  index=range(nt),
                                  columns=const.THCOLS)
        segy.g._apply_scalars_after_unpacking()

        segy.dm.dt = si
        segy.dm.t = np.arange(0, si * tl / 1000, si / 1000)
        segy.dm._headers = segy.g

        segy.file = file.split('/')[-1]

        return segy