Beispiel #1
0
def test_simple_io(input_val, expected_result, fformat, engine):
    if engine == "python" and fformat not in [
            "irap_ascii",
            "irap_binary",
            "zmap_ascii",
    ]:
        pytest.skip("Only one engine available")
    surf = RegularSurface(ncol=2, nrow=2, xinc=2.0, yinc=2.0, values=input_val)
    surf.to_file("my_file", fformat=fformat)
    surf_from_file = RegularSurface._read_file("my_file",
                                               fformat=fformat,
                                               engine=engine)
    assert_similar_surfaces(surf, surf_from_file)
    assert surf_from_file.values.data.tolist() == expected_result
    def store(self, address: StatisticalSurfaceAddress,
              surface: xtgeo.RegularSurface) -> None:

        surf_fn = _compose_stat_surf_file_name(address, FILE_EXTENSION)
        full_surf_path = self.cache_dir / surf_fn

        # Try and go via a temporary file which we don't rename until writing is finished.
        # to make the cache writing more concurrency-friendly.
        # One problem here is that we don't control the file handle (xtgeo does) so can't
        # enforce flush and sync of the file to disk before the rename :-(
        # Still, we probably need a more robust way of shring the cached surfaces...
        tmp_surf_path = self.cache_dir / (surf_fn +
                                          f"__{uuid.uuid4().hex}.tmp")
        try:
            surface.to_file(tmp_surf_path, fformat=FILE_FORMAT_WRITE)
            os.replace(tmp_surf_path, full_surf_path)
        # pylint: disable=bare-except
        except:
            os.remove(tmp_surf_path)
Beispiel #3
0
def test_zmap_import_export():
    """Import and export ZMAP ascii example."""
    logger.info("Import and export...")

    zmap = RegularSurface()
    zmap.to_file(join(TMPD, "zmap1.zmap"), fformat="zmap_ascii")
    zmap2 = RegularSurface()
    zmap2.from_file(join(TMPD, "zmap1.zmap"), fformat="zmap_ascii")

    assert zmap.values[0, 1] == zmap2.values[0, 1] == 6.0

    one1 = zmap.values.ravel()
    one2 = zmap2.values.ravel()
    assert one1.all() == one2.all()

    zmap.to_file(join(TMPD, "zmap2.zmap"), fformat="zmap_ascii", engine="python")
    zmap3 = RegularSurface()
    zmap3.from_file(join(TMPD, "zmap2.zmap"), fformat="zmap_ascii")
    one3 = zmap3.values.ravel()
    assert one1.all() == one3.all()