Ejemplo n.º 1
0
def test_getwell_strict_logs_raise_error():
    """Get a well from a RMS project, with strict lognames, and this should fail"""

    if not os.path.isdir(PROJ[roxv]):
        raise RuntimeError(
            "RMS test project is missing for roxar version {}".format(roxv)
        )

    logger.info("Simple case, reading a well from RMS well folder")

    xwell = xtgeo.well.Well()

    rox = xtgeo.RoxUtils(PROJ[roxv])

    with pytest.raises(ValueError) as msg:
        logger.warning(msg)
        xwell.from_roxar(
            rox.project,
            "WI_3_RKB2",
            trajectory="Drilled trajectory",
            logrun="LOG",
            lognames=["Zonelog", "Poro", "Facies", "Dummy"],
            lognames_strict=True,
        )
    rox.safe_close()
Ejemplo n.º 2
0
def fixture_create_project():
    """Create a tmp RMS project for testing, populate with basic data.

    After the yield command, the teardown phase will remove the tmp RMS project.
    """
    prj1 = str(PRJ)

    print("\n******** Setup RMS project!\n")
    if isdir(prj1):
        print("Remove existing project! (1)")
        shutil.rmtree(prj1)

    project = roxar.Project.create()

    rox = xtgeo.RoxUtils(project)
    print("Roxar version is", rox.roxversion)
    print("RMS version is", rox.rmsversion(rox.roxversion))
    assert "1." in rox.roxversion

    for wfile in WELLS1:
        wobj = xtgeo.well_from_file(WELLSFOLDER1 / wfile)
        if "XP_with" in wfile:
            wobj.name = "OP2_w_repeat"

        wobj.to_roxar(project,
                      wobj.name,
                      logrun="log",
                      trajectory="My trajectory")

    # populate with cube data
    cube = xtgeo.cube_from_file(CUBEDATA1)
    cube.to_roxar(project, CUBENAME1, domain="depth")

    # populate with surface data
    rox.create_horizons_category(SURFCAT1)
    for num, name in enumerate(SURFNAMES1):
        srf = xtgeo.surface_from_file(SURFTOPS1[num])
        project.horizons.create(name, roxar.HorizonType.interpreted)
        srf.to_roxar(project, name, SURFCAT1)

    # populate with grid and props
    grd = xtgeo.grid_from_file(GRIDDATA1)
    grd.to_roxar(project, GRIDNAME1)
    por = xtgeo.gridproperty_from_file(PORODATA1, name=PORONAME1)
    por.to_roxar(project, GRIDNAME1, PORONAME1)
    zon = xtgeo.gridproperty_from_file(ZONEDATA1, name=ZONENAME1)
    zon.values = zon.values.astype(np.uint8)
    zon.to_roxar(project, GRIDNAME1, ZONENAME1)

    # save project (both an initla version and a work version) and exit
    project.save_as(prj1)
    project.close()

    yield project

    print("\n******* Teardown RMS project!\n")

    if isdir(prj1):
        print("Remove existing project! (1)")
        shutil.rmtree(prj1)
Ejemplo n.º 3
0
def test_rox_surfaces():
    """Various get set on surfaces in RMS."""
    srf = xtgeo.surface_from_roxar(PRJ, "TopReek", SURFCAT1)
    srf2 = xtgeo.surface_from_roxar(PRJ, "MidReek", SURFCAT1)
    assert srf.ncol == 554
    assert srf.values.mean() == pytest.approx(1698.648, abs=0.01)

    srf.to_roxar(PRJ, "TopReek_copy", "SomeFolder", stype="clipboard")

    # open project and do save explicit
    rox = xtgeo.RoxUtils(PRJ)
    prj = rox.project
    iso = srf2 - srf
    rox.create_zones_category("IS_isochore")
    prj.zones.create("UpperReek", prj.horizons["TopReek"],
                     prj.horizons["MidReek"])
    iso.to_roxar(prj, "UpperReek", "IS_isochore", stype="zones")

    iso2 = xtgeo.surface_from_roxar(prj,
                                    "UpperReek",
                                    "IS_isochore",
                                    stype="zones")
    assert iso2.values.mean() == pytest.approx(20.79, abs=0.01)

    prj.save()
    prj.close()
Ejemplo n.º 4
0
def export_prop_roxapi(self,
                       project,
                       gname,
                       pname,
                       saveproject=False,
                       realisation=0):
    """Export (i.e. store) to a Property in RMS via ROXAR API spec."""

    rox = xtgeo.RoxUtils(project, readonly=False)

    logger.info("Realisation key not applied yet: %s", realisation)

    try:
        roxgrid = rox.project.grid_models[gname]
        _store_in_roxar(self, pname, roxgrid, realisation)

        if saveproject:
            try:
                rox.project.save()
            except RuntimeError:
                xtg.warn("Could not save project!")

    except KeyError as keyerror:
        raise RuntimeError(keyerror)

    rox.safe_close()
Ejemplo n.º 5
0
    def parse_project(self, project=None):
        """Get the RoxarAPI project magics"""

        if project is not None:
            rox = xtgeo.RoxUtils(project)
            self._project = rox.project
        else:
            self._project = None
Ejemplo n.º 6
0
def import_prop_roxapi(self, project, gname, pname, realisation):  # pragma: no cover
    """Import a Property via ROXAR API spec."""

    logger.info("Opening RMS project ...")
    rox = xtgeo.RoxUtils(project, readonly=True)

    _get_gridprop_data(self, rox, gname, pname, realisation)

    rox.safe_close()
Ejemplo n.º 7
0
def export_prop_roxapi(
    self, project, gname, pname, realisation=0, casting="unsafe"
):  # pragma: no cover
    """Export (i.e. store or save) to a Property icon in RMS via ROXAR API spec."""
    rox = xtgeo.RoxUtils(project, readonly=False)

    try:
        roxgrid = rox.project.grid_models[gname]
        _store_in_roxar(self, pname, roxgrid, realisation, casting)

    except KeyError as keyerror:
        raise RuntimeError(keyerror)

    if rox._roxexternal:
        rox.project.save()

    rox.safe_close()
Ejemplo n.º 8
0
def test_create_project():
    """Create a tmp RMS project for testing, populate with basic data"""

    prj1 = PRJ
    prj2 = PRJ + "_initial"

    if isdir(prj1):
        print("Remove existing project! (1)")
        shutil.rmtree(prj1)

    if isdir(prj2):
        print("Remove existing project! (2)")
        shutil.rmtree(prj2)

    project = roxar.Project.create()

    rox = xtgeo.RoxUtils(project)
    print("Roxar version is", rox.roxversion)
    print("RMS version is", rox.rmsversion(rox.roxversion))
    assert "1." in rox.roxversion

    # populate with cube data
    cube = xtgeo.cube_from_file(CUBEDATA1)
    cube.to_roxar(project, CUBENAME1, domain="depth")

    # populate with surface data
    rox.create_horizons_category(SURFCAT1)
    for num, name in enumerate(SURFNAMES1):
        srf = xtgeo.surface_from_file(SURFTOPS1[num])
        project.horizons.create(name, roxar.HorizonType.interpreted)
        srf.to_roxar(project, name, SURFCAT1)

    # populate with grid and props
    grd = xtgeo.grid_from_file(GRIDDATA1)
    grd.to_roxar(project, GRIDNAME1)
    por = xtgeo.gridproperty_from_file(PORODATA1, name=PORONAME1)
    por.to_roxar(project, GRIDNAME1, PORONAME1)

    # populate with well data (postponed)

    # save project (both an initla version and a work version) and exit
    project.save_as(prj1)
    project.save_as(prj2)
    project.close()
Ejemplo n.º 9
0
def test_qcreset():
    """Test qcreset metod in roxapi."""
    # ==================================================================================
    # pylint: disable=invalid-name
    from fmu.tools.rms import qcreset

    rox = xtgeo.RoxUtils(project=PRJ)

    SETUP1 = {
        "project": rox._project,
        "horizons": {
            "DS_whatever": ["TopReek", "MidReek"],
        },
        "grid_models": {
            "Simgrid": ["PORO"],
        },
        "value": 0.088,
    }

    SETUP2 = {
        "project": rox._project,
        "horizons": {
            "DS_whatever": ["TopReek", "MidReek"],
        },
        "grid_models": {
            "Simgrid": ["PORO"],
        },
    }

    qcreset.set_data_constant(SETUP1)

    topr = xtgeo.surface_from_roxar(rox._project, "TopReek", "DS_whatever")
    assert topr.values.mean() == pytest.approx(0.088)

    poro = xtgeo.gridproperty_from_roxar(rox._project, "Simgrid", "PORO")
    assert poro.values.mean() == pytest.approx(0.088)

    qcreset.set_data_empty(SETUP2)

    top = rox._project.horizons["TopReek"]["DS_whatever"]

    assert top.is_empty() is True
Ejemplo n.º 10
0
def test_getwell_strict_logs_raise_error():
    """Get a well from a RMS project, with strict lognames, and this should fail"""

    if not os.path.isdir(PROJ[roxv]):
        raise RuntimeError(
            'RMS test project is missing for roxar version {}'.format(roxv))

    logger.info('Simple case, reading a well from RMS well folder')

    xwell = xtgeo.well.Well()

    rox = xtgeo.RoxUtils(PROJ[roxv])

    with pytest.raises(ValueError) as msg:
        logger.warning(msg)
        xwell.from_roxar(rox.project,
                         'WI_3_RKB2',
                         trajectory='Drilled trajectory',
                         logrun='LOG',
                         lognames=['Zonelog', 'Poro', 'Facies', 'Dummy'],
                         lognames_strict=True)
    rox.safe_close()