Esempio n. 1
0
    def read_small(self, mmap=False):
        f = _segyio.open(self.filename, "r")

        if mmap: _segyio.mmap(f)

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

        metrics = _segyio.init_metrics(f, binary_header)
        metrics.update(
            _segyio.init_cube_metrics(f, ilb, xlb, metrics['trace_count'],
                                      metrics['trace0'],
                                      metrics['trace_bsize']))

        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.intc)
        xline_indexes = numpy.zeros(metrics['xline_count'], dtype=numpy.intc)
        offsets = numpy.zeros(metrics['offset_count'], dtype=numpy.intc)
        _segyio.init_indices(f, metrics, iline_indexes, xline_indexes, offsets)

        return f, metrics, iline_indexes, xline_indexes
Esempio n. 2
0
    def test_fread_trace0(self, mmap=False):
        f = _segyio.open(self.filename, "r")
        if mmap: _segyio.mmap(f)

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

        metrics = _segyio.init_metrics(f, binary_header)
        metrics.update(
            _segyio.init_cube_metrics(f, ilb, xlb, metrics['trace_count'],
                                      metrics['trace0'],
                                      metrics['trace_bsize']))

        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.intc)
        xline_indexes = numpy.zeros(metrics['xline_count'], dtype=numpy.intc)
        offsets = numpy.zeros(metrics['offset_count'], dtype=numpy.intc)
        _segyio.init_indices(f, metrics, iline_indexes, xline_indexes, offsets)

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

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

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

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

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

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

        _segyio.close(f)
Esempio n. 3
0
    def test_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)
        dmy = numpy.zeros(2, dtype=numpy.intc)

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

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

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

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

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

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

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

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

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

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

        metrics.update(
            _segyio.init_cube_metrics(f, ilb, xlb, metrics['trace_count'],
                                      metrics['trace0'],
                                      metrics['trace_bsize']))

        # Happy Path
        iline_indexes = numpy.zeros(metrics['iline_count'], dtype=numpy.intc)
        xline_indexes = numpy.zeros(metrics['xline_count'], dtype=numpy.intc)
        offsets = numpy.zeros(metrics['offset_count'], dtype=numpy.intc)
        _segyio.init_indices(f, metrics, iline_indexes, xline_indexes, offsets)

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

        _segyio.close(f)