コード例 #1
0
    def read_small(self):
        f = _segyio.open(self.filename, "r")

        binary_header = _segyio.read_binaryheader(f)
        ilb = 189
        xlb = 193

        metrics = _segyio.init_metrics(f, binary_header, ilb, xlb)

        sorting = metrics['sorting']
        trace_count = metrics['trace_count']
        inline_count = metrics['iline_count']
        crossline_count = metrics['xline_count']
        offset_count = metrics['offset_count']

        line_metrics = _segyio.init_line_metrics(sorting, trace_count,
                                                 inline_count, crossline_count,
                                                 offset_count)

        metrics.update(line_metrics)

        iline_indexes = numpy.zeros(metrics['iline_count'], dtype=numpy.uintc)
        xline_indexes = numpy.zeros(metrics['xline_count'], dtype=numpy.uintc)
        _segyio.init_line_indices(f, metrics, iline_indexes, xline_indexes)

        return f, metrics, iline_indexes, xline_indexes
コード例 #2
0
    def test_fread_trace0(self):
        f = _segyio.open(self.filename, "r")

        binary_header = _segyio.read_binaryheader(f)
        ilb = 189
        xlb = 193

        metrics = _segyio.init_metrics(f, binary_header, ilb, xlb)

        sorting = metrics['sorting']
        trace_count = metrics['trace_count']
        inline_count = metrics['iline_count']
        crossline_count = metrics['xline_count']
        offset_count = metrics['offset_count']

        line_metrics = _segyio.init_line_metrics(sorting, trace_count,
                                                 inline_count, crossline_count,
                                                 offset_count)

        iline_indexes = numpy.zeros(metrics['iline_count'], dtype=numpy.uintc)
        xline_indexes = numpy.zeros(metrics['xline_count'], dtype=numpy.uintc)
        _segyio.init_line_indices(f, metrics, iline_indexes, xline_indexes)

        with self.assertRaises(KeyError):
            _segyio.fread_trace0(0, len(xline_indexes),
                                 line_metrics['iline_stride'], iline_indexes,
                                 "inline")

        with self.assertRaises(KeyError):
            _segyio.fread_trace0(2, len(iline_indexes),
                                 line_metrics['xline_stride'], xline_indexes,
                                 "crossline")

        value = _segyio.fread_trace0(1, len(xline_indexes),
                                     line_metrics['iline_stride'],
                                     iline_indexes, "inline")
        self.assertEqual(value, 0)

        value = _segyio.fread_trace0(2, len(xline_indexes),
                                     line_metrics['iline_stride'],
                                     iline_indexes, "inline")
        self.assertEqual(value, 5)

        value = _segyio.fread_trace0(21, len(iline_indexes),
                                     line_metrics['xline_stride'],
                                     xline_indexes, "crossline")
        self.assertEqual(value, 1)

        value = _segyio.fread_trace0(22, len(iline_indexes),
                                     line_metrics['xline_stride'],
                                     xline_indexes, "crossline")
        self.assertEqual(value, 2)

        _segyio.close(f)
コード例 #3
0
    def test_line_indices(self):
        f = _segyio.open(self.filename, "r")

        binary_header = _segyio.read_binaryheader(f)
        ilb = 189
        xlb = 193
        metrics = _segyio.init_metrics(f, binary_header, ilb, xlb)
        dmy = numpy.zeros(2, dtype=numpy.uintc)

        dummy_metrics = {'xline_count': 2, 'iline_count': 2}

        with self.assertRaises(TypeError):
            _segyio.init_line_indices(".", {}, dmy, dmy)

        with self.assertRaises(TypeError):
            _segyio.init_line_indices(f, "-", dmy, dmy)

        # with self.assertRaises(KeyError):
        #     _segyio.init_line_indices(f, {}, dmy, dmy)

        with self.assertRaises(TypeError):
            _segyio.init_line_indices(f, dummy_metrics, 1, dmy)

        with self.assertRaises(TypeError):
            _segyio.init_line_indices(f, dummy_metrics, dmy, 2)

        with self.assertRaises(TypeError):
            _segyio.init_line_indices(f, dummy_metrics, dmy, 2)

        with self.assertRaises(TypeError):
            fdmy = numpy.zeros(1, dtype=numpy.single)
            _segyio.init_line_indices(f, dummy_metrics, fdmy, dmy)

        one = numpy.zeros(1, dtype=numpy.uintc)
        two = numpy.zeros(2, dtype=numpy.uintc)
        with self.assertRaises(ValueError):
            _segyio.init_line_indices(f, dummy_metrics, one, two)

        with self.assertRaises(ValueError):
            _segyio.init_line_indices(f, dummy_metrics, two, one)

        # Happy Path
        iline_indexes = numpy.zeros(metrics['iline_count'], dtype=numpy.uintc)
        xline_indexes = numpy.zeros(metrics['xline_count'], dtype=numpy.uintc)
        _segyio.init_line_indices(f, metrics, iline_indexes, xline_indexes)

        self.assertListEqual([1, 2, 3, 4, 5], list(iline_indexes))
        self.assertListEqual([20, 21, 22, 23, 24], list(xline_indexes))

        _segyio.close(f)