Exemplo n.º 1
0
    def test_read_and_write_trace(self, mmap=False):
        with TestContext("read_and_write_trace") as context:
            f = _segyio.open("trace-wrt.sgy", "w+")
            if mmap: _segyio.mmap(f)

            buf = numpy.ones(25, dtype=numpy.single)
            buf[11] = 3.1415
            _segyio.write_trace(f, 0, buf, 0, 100, 1, 25)
            buf[:] = 42.0
            _segyio.write_trace(f, 1, buf, 0, 100, 1, 25)

            _segyio.flush(f)

            buf = numpy.zeros(25, dtype=numpy.single)

            _segyio.read_trace(f, buf, 0, 1, 1, 1, 25, 0, 100)

            self.assertAlmostEqual(buf[10], 1.0, places=4)
            self.assertAlmostEqual(buf[11], 3.1415, places=4)

            _segyio.read_trace(f, buf, 1, 1, 1, 1, 25, 0, 100)

            self.assertAlmostEqual(sum(buf), 42.0 * 25, places=4)

            _segyio.close(f)
Exemplo n.º 2
0
    def test_open_flush_and_close_file(self):
        f = _segyio.open(self.filename, "r")
        _segyio.flush(f)
        _segyio.close(f)

        with self.assertRaises(IOError):
            _segyio.flush(f)
Exemplo n.º 3
0
    def flush(self):
        """Flush a file - write the library buffers to disk.

        This method is mostly useful for testing.

        It is not necessary to call this method unless you want to observe your
        changes while the file is still open. The file will automatically be
        flushed for you if you use the `with` statement when your routine is
        completed.

        Examples:
            Flush::
                >>> with segyio.open(path) as f:
                ...     # write something to f
                ...     f.flush()
        """
        _segyio.flush(self.xfd)
Exemplo n.º 4
0
    def test_read_and_write_trace(self):
        f = _segyio.open("test-data/trace-wrt.sgy", "w+")

        buf = numpy.ones(25, dtype=numpy.single)
        buf[11] = 3.1415
        _segyio.write_trace(f, 0, buf, 0, 100, 1, 25)
        buf[:] = 42.0
        _segyio.write_trace(f, 1, buf, 0, 100, 1, 25)

        _segyio.flush(f)

        buf = numpy.zeros(25, dtype=numpy.single)

        _segyio.read_trace(f, 0, 25, buf, 0, 100, 1, 25)

        self.assertAlmostEqual(buf[10], 1.0, places=4)
        self.assertAlmostEqual(buf[11], 3.1415, places=4)

        _segyio.read_trace(f, 1, 25, buf, 0, 100, 1, 25)

        self.assertAlmostEqual(sum(buf), 42.0 * 25, places=4)

        _segyio.close(f)
Exemplo n.º 5
0
 def test_open_flush_and_close_file(self):
     _segyio.flush(None)
     f = _segyio.open(self.filename, "r")
     _segyio.flush(f)
     _segyio.close(f)