示例#1
0
def test_surf_sample_grd3d_lay():
    with pytest.raises(
            xtgeo.XTGeoCLibError,
            match="Errors in array lengths checks in:",
    ):
        _cxtgeo.surf_sample_grd3d_lay(
            1,
            1,
            1,
            np.array([0.0]),
            np.array([1.0]),
            np.array([1], dtype=np.int32),
            1,
            1,
            1,
            1,
            1.0,
            1.0,
            1.0,
            1.0,
            np.array([0.0]),
            np.array([0.0]),
            np.array([0.0]),
            1,
        )
示例#2
0
def from_grid3d(self,
                grid,
                template=None,
                where="top",
                mode="depth",
                rfactor=1):
    """Private function for deriving a surface from a 3D grid.

    Note that rotated maps are currently not supported!

    .. versionadded:: 2.1
    """

    if where == "top":
        klayer = 1
        option = 0
    elif where == "base":
        klayer = grid.nlay
        option = 1
    else:
        klayer, what = where.split("_")
        klayer = int(klayer)
        if grid.nlay < klayer < 0:
            raise ValueError("Klayer out of range in where={}".format(where))
        option = 0
        if what == "base":
            option = 1

    if rfactor < 0.5:
        raise KeyError("Refinefactor rfactor is too small, should be >= 0.5")

    _update_regsurf(self, template, grid, rfactor=float(rfactor))

    # call C function to make a map
    svalues = self.get_values1d() * 0.0 + xtgeo.UNDEF
    ivalues = svalues.copy()
    jvalues = svalues.copy()

    _cxtgeo.surf_sample_grd3d_lay(
        grid.ncol,
        grid.nrow,
        grid.nlay,
        grid._coordsv,
        grid._zcornsv,
        grid._actnumsv,
        klayer,
        self.ncol,
        self.nrow,
        self.xori,
        self.xinc,
        self.yori,
        self.yinc,
        self.rotation,
        svalues,
        ivalues,
        jvalues,
        option,
    )

    logger.info("Extracted surfaces from 3D grid...")
    svalues = np.ma.masked_greater(svalues, xtgeo.UNDEF_LIMIT)
    ivalues = np.ma.masked_greater(ivalues, xtgeo.UNDEF_LIMIT)
    jvalues = np.ma.masked_greater(jvalues, xtgeo.UNDEF_LIMIT)

    if mode == "i":
        self.set_values1d(ivalues)
        return None

    if mode == "j":
        self.set_values1d(jvalues)
        return None

    self.set_values1d(svalues)
    isurf = self.copy()
    jsurf = self.copy()
    isurf.set_values1d(ivalues)
    jsurf.set_values1d(jvalues)

    self.metadata.required = self

    return isurf, jsurf  # needed in special cases
示例#3
0
def from_grid3d(grid, template=None, where="top", mode="depth", rfactor=1):
    """Private function for deriving a surface from a 3D grid.

    Note that rotated maps are currently not supported!

    .. versionadded:: 2.1
    """
    if where == "top":
        klayer = 1
        option = 0
    elif where == "base":
        klayer = grid.nlay
        option = 1
    else:
        klayer, what = where.split("_")
        klayer = int(klayer)
        if grid.nlay < klayer < 0:
            raise ValueError("Klayer out of range in where={}".format(where))
        option = 0
        if what == "base":
            option = 1

    if rfactor < 0.5:
        raise KeyError("Refinefactor rfactor is too small, should be >= 0.5")

    args = _update_regsurf(template, grid, rfactor=float(rfactor))
    args["rotation"] = 0.0
    # call C function to make a map
    val = args["values"]
    val = val.ravel(order="K")
    val = ma.filled(val, fill_value=xtgeo.UNDEF)

    svalues = val * 0.0 + xtgeo.UNDEF
    ivalues = svalues.copy()
    jvalues = svalues.copy()

    _cxtgeo.surf_sample_grd3d_lay(
        grid.ncol,
        grid.nrow,
        grid.nlay,
        grid._coordsv,
        grid._zcornsv,
        grid._actnumsv,
        klayer,
        args["ncol"],
        args["nrow"],
        args["xori"],
        args["xinc"],
        args["yori"],
        args["yinc"],
        args["rotation"],
        svalues,
        ivalues,
        jvalues,
        option,
    )

    logger.info("Extracted surfaces from 3D grid...")
    svalues = np.ma.masked_greater(svalues, xtgeo.UNDEF_LIMIT)
    ivalues = np.ma.masked_greater(ivalues, xtgeo.UNDEF_LIMIT)
    jvalues = np.ma.masked_greater(jvalues, xtgeo.UNDEF_LIMIT)

    if mode == "i":
        ivalues = ivalues.reshape((args["ncol"], args["nrow"]))
        ivalues = ma.masked_invalid(ivalues)
        args["values"] = ivalues
        return args, None, None

    if mode == "j":
        jvalues = jvalues.reshape((args["ncol"], args["nrow"]))
        jvalues = ma.masked_invalid(jvalues)
        args["values"] = jvalues
        return args, None, None

    svalues = svalues.reshape((args["ncol"], args["nrow"]))
    svalues = ma.masked_invalid(svalues)
    args["values"] = svalues

    return args, ivalues, jvalues