예제 #1
0
    def test_read_and_write_traceheader(self, mmap=False):
        with TestContext("read_and_write_trace_header") as context:
            context.copy_file(self.filename)

            f = _segyio.open("small.sgy", "r+")
            if mmap: _segyio.mmap(f)

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

            empty = _segyio.empty_traceheader()

            with self.assertRaises(TypeError):
                trace_header = _segyio.read_traceheader("+", )

            with self.assertRaises(TypeError):
                trace_header = _segyio.read_traceheader(f, 0, None)

            trace_header = _segyio.read_traceheader(
                f, 0, _segyio.empty_traceheader(), metrics['trace0'],
                metrics['trace_bsize'])

            self.assertEqual(_segyio.get_field(trace_header, ilb), 1)
            self.assertEqual(_segyio.get_field(trace_header, xlb), 20)

            trace_header = _segyio.read_traceheader(
                f, 1, _segyio.empty_traceheader(), metrics['trace0'],
                metrics['trace_bsize'])

            self.assertEqual(_segyio.get_field(trace_header, ilb), 1)
            self.assertEqual(_segyio.get_field(trace_header, xlb), 21)

            _segyio.set_field(trace_header, ilb, 99)
            _segyio.set_field(trace_header, xlb, 42)

            _segyio.write_traceheader(f, 0, trace_header, metrics['trace0'],
                                      metrics['trace_bsize'])

            trace_header = _segyio.read_traceheader(
                f, 0, _segyio.empty_traceheader(), metrics['trace0'],
                metrics['trace_bsize'])

            self.assertEqual(_segyio.get_field(trace_header, ilb), 99)
            self.assertEqual(_segyio.get_field(trace_header, xlb), 42)

            _segyio.close(f)
예제 #2
0
    def test_read_and_write_traceheader(self):
        fname = self.filename.replace("small", "bin_hdr_wrt")
        shutil.copyfile(self.filename, fname)
        f = _segyio.open(fname, "r+")
        binary_header = _segyio.read_binaryheader(f)
        ilb = 189
        xlb = 193
        metrics = _segyio.init_metrics(f, binary_header, ilb, xlb)

        empty = _segyio.empty_traceheader()

        with self.assertRaises(TypeError):
            trace_header = _segyio.read_traceheader("+", )

        with self.assertRaises(TypeError):
            trace_header = _segyio.read_traceheader(f, 0, None)

        trace_header = _segyio.read_traceheader(f, 0,
                                                _segyio.empty_traceheader(),
                                                metrics['trace0'],
                                                metrics['trace_bsize'])

        self.assertEqual(_segyio.get_field(trace_header, ilb), 1)
        self.assertEqual(_segyio.get_field(trace_header, xlb), 20)

        trace_header = _segyio.read_traceheader(f, 1,
                                                _segyio.empty_traceheader(),
                                                metrics['trace0'],
                                                metrics['trace_bsize'])

        self.assertEqual(_segyio.get_field(trace_header, ilb), 1)
        self.assertEqual(_segyio.get_field(trace_header, xlb), 21)

        _segyio.set_field(trace_header, ilb, 99)
        _segyio.set_field(trace_header, xlb, 42)

        _segyio.write_traceheader(f, 0, trace_header, metrics['trace0'],
                                  metrics['trace_bsize'])

        trace_header = _segyio.read_traceheader(f, 0,
                                                _segyio.empty_traceheader(),
                                                metrics['trace0'],
                                                metrics['trace_bsize'])

        self.assertEqual(_segyio.get_field(trace_header, ilb), 99)
        self.assertEqual(_segyio.get_field(trace_header, xlb), 42)

        _segyio.close(f)
예제 #3
0
    def test_get_and_set_field(self):
        hdr = _segyio.empty_traceheader()

        with self.assertRaises(TypeError):
            _segyio.get_field(".", 0)

        with self.assertRaises(TypeError):
            _segyio.set_field(".", 0, 1)

        with self.assertRaises(IndexError):
            _segyio.get_field(hdr, 0)

        with self.assertRaises(IndexError):
            _segyio.set_field(hdr, 0, 1)

        _segyio.set_field(hdr, 1, 127)
        _segyio.set_field(hdr, 5, 67)
        _segyio.set_field(hdr, 9, 19)

        self.assertEqual(_segyio.get_field(hdr, 1), 127)
        self.assertEqual(_segyio.get_field(hdr, 5), 67)
        self.assertEqual(_segyio.get_field(hdr, 9), 19)