Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
grid_df = grid.df(eclfiles, vectors="PRESSURE", rstdates="last")
assert "PRESSURE" in grid_df
assert len(grid_df.columns) == geometry_cols + 1
grid_df = grid.df(eclfiles, vectors="PRESSURE", rstdates="last", dateinheaders=True)
assert "PRESSURE" not in grid_df
assert "PRESSURE@2001-08-01" in grid_df
grid_df = grid.df(eclfiles, vectors="PRESSURE", rstdates="all", stackdates=True)
assert "PRESSURE" in grid_df
assert len(grid_df.columns) == geometry_cols + 2
assert "DATE" in grid_df
assert len(grid_df["DATE"].unique()) == 4
grid_df = grid.df(eclfiles, vectors="PORO")
assert "I" in grid_df
assert "PORO" in grid_df
assert len(grid_df) == 35817
assert "DATE" not in grid_df
grid_df = grid.df(eclfiles, vectors="PORO", rstdates="all")
assert "I" in grid_df
assert "PORO" in grid_df
assert "DATE" not in grid_df
# (no RST columns, so no DATE info in the daaframe)
# (warnings should be printed)
grid_df = grid.df(eclfiles, vectors="PORO", rstdates="all", stackdates=True)
assert "I" in grid_df
assert "PORO" in grid_df
assert "DATE" not in grid_df
def test_df():
"""Test the df function"""
eclfiles = EclFiles(DATAFILE)
# assert error..
with pytest.raises(TypeError):
# pylint: disable=no-value-for-parameter
grid.df()
grid_df = grid.df(eclfiles)
assert not grid_df.empty
assert "I" in grid_df # From GRID
assert "PORO" in grid_df # From INIT
assert "SOIL" not in grid_df # We do not get RST unless we ask for it.
grid_df = grid.df(eclfiles, vectors="*")
assert "I" in grid_df # From GRID
assert "PORO" in grid_df # From INIT
assert "SOIL" not in grid_df # We do not get RST unless we ask for it.
grid_df = grid.df(eclfiles, vectors=["*"])
assert "I" in grid_df # From GRID
assert "PORO" in grid_df # From INIT
assert "SOIL" not in grid_df # We do not get RST unless we ask for it.
grid_df = grid.df(eclfiles, vectors="PRESSURE")
grid_df = grid.df(eclfiles, vectors=["PRESSURE"])
assert "I" in grid_df
assert not grid_df.empty
assert "PRESSURE" not in grid_df
geometry_cols = len(grid_df.columns)
grid_df = grid.df(eclfiles, vectors=["PRESSURE"], rstdates="last", stackdates=True)
assert "PRESSURE" in grid_df
assert len(grid_df.columns) == geometry_cols + 2
assert "DATE" in grid_df # awaits stacking
grid_df = grid.df(eclfiles, vectors="PRESSURE", rstdates="last")
assert "PRESSURE" in grid_df
assert len(grid_df.columns) == geometry_cols + 1
grid_df = grid.df(eclfiles, vectors="PRESSURE", rstdates="last", dateinheaders=True)
assert "PRESSURE" not in grid_df
assert "PRESSURE@2001-08-01" in grid_df
grid_df = grid.df(eclfiles, vectors="PRESSURE", rstdates="all", stackdates=True)
assert "PRESSURE" in grid_df
assert len(grid_df.columns) == geometry_cols + 2
assert "DATE" in grid_df
assert len(grid_df["DATE"].unique()) == 4
grid_df = grid.df(eclfiles, vectors="PORO")
assert "I" in grid_df
assert "PORO" in grid_df
assert len(grid_df) == 35817
assert "DATE" not in grid_df
grid_df = grid.df(eclfiles, vectors="PORO", rstdates="all")
"""Test that we can act as human API user
Functionality should be extensively tested in other code, but this is here
to illustrate how a user could work, and ensure that it works.
To the user reading the source: Skip all 'assert' lines, read the rest.
"""
eclfiles = ecl2df.EclFiles(DATAFILE)
compdatdf = ecl2df.compdat.df(eclfiles)
equil = ecl2df.equil.df(eclfiles)
faults = ecl2df.faults.df(eclfiles)
fipreports = ecl2df.fipreports.df(eclfiles)
grid_df = ecl2df.grid.df(eclfiles)
grst_df = ecl2df.grid.df(eclfiles, rstdates="last")
gruptree = ecl2df.gruptree.df(eclfiles)
nnc = ecl2df.nnc.df(eclfiles)
pillars = ecl2df.pillars.df(eclfiles)
rft = ecl2df.rft.df(eclfiles)
satfund = ecl2df.satfunc.df(eclfiles)
smry = ecl2df.summary.df(eclfiles)
trans = ecl2df.trans.df(eclfiles)
wcon = ecl2df.wcon.df(eclfiles)
assert "PORV" in grid_df
assert "SOIL" not in grid_df
assert "SOIL" in grst_df
assert "PORV" in grst_df
# Make some HCPV calculations
grst_df["OILPV"] = grst_df["SOIL"] * grst_df["PORV"]
assert "PRESSURE" not in grid_df
assert "PRESSURE@2001-08-01" in grid_df
grid_df = grid.df(eclfiles, vectors="PRESSURE", rstdates="all", stackdates=True)
assert "PRESSURE" in grid_df
assert len(grid_df.columns) == geometry_cols + 2
assert "DATE" in grid_df
assert len(grid_df["DATE"].unique()) == 4
grid_df = grid.df(eclfiles, vectors="PORO")
assert "I" in grid_df
assert "PORO" in grid_df
assert len(grid_df) == 35817
assert "DATE" not in grid_df
grid_df = grid.df(eclfiles, vectors="PORO", rstdates="all")
assert "I" in grid_df
assert "PORO" in grid_df
assert "DATE" not in grid_df
# (no RST columns, so no DATE info in the daaframe)
# (warnings should be printed)
grid_df = grid.df(eclfiles, vectors="PORO", rstdates="all", stackdates=True)
assert "I" in grid_df
assert "PORO" in grid_df
assert "DATE" not in grid_df
# DATE is not included as it really does not make sense. The code
def test_df():
"""Test the df function"""
eclfiles = EclFiles(DATAFILE)
# assert error..
with pytest.raises(TypeError):
# pylint: disable=no-value-for-parameter
grid.df()
grid_df = grid.df(eclfiles)
assert not grid_df.empty
assert "I" in grid_df # From GRID
assert "PORO" in grid_df # From INIT
assert "SOIL" not in grid_df # We do not get RST unless we ask for it.
grid_df = grid.df(eclfiles, vectors="*")
assert "I" in grid_df # From GRID
assert "PORO" in grid_df # From INIT
assert "SOIL" not in grid_df # We do not get RST unless we ask for it.
grid_df = grid.df(eclfiles, vectors=["*"])
assert "I" in grid_df # From GRID
assert "PORO" in grid_df # From INIT
assert "SOIL" not in grid_df # We do not get RST unless we ask for it.
geometry_cols = len(grid_df.columns)
grid_df = grid.df(eclfiles, vectors=["PRESSURE"], rstdates="last", stackdates=True)
assert "PRESSURE" in grid_df
assert len(grid_df.columns) == geometry_cols + 2
assert "DATE" in grid_df # awaits stacking
grid_df = grid.df(eclfiles, vectors="PRESSURE", rstdates="last")
assert "PRESSURE" in grid_df
assert len(grid_df.columns) == geometry_cols + 1
grid_df = grid.df(eclfiles, vectors="PRESSURE", rstdates="last", dateinheaders=True)
assert "PRESSURE" not in grid_df
assert "PRESSURE@2001-08-01" in grid_df
grid_df = grid.df(eclfiles, vectors="PRESSURE", rstdates="all", stackdates=True)
assert "PRESSURE" in grid_df
assert len(grid_df.columns) == geometry_cols + 2
assert "DATE" in grid_df
assert len(grid_df["DATE"].unique()) == 4
grid_df = grid.df(eclfiles, vectors="PORO")
assert "I" in grid_df
assert "PORO" in grid_df
assert len(grid_df) == 35817
assert "DATE" not in grid_df
grid_df = grid.df(eclfiles, vectors="PORO", rstdates="all")
assert "I" in grid_df
assert "PORO" in grid_df
assert "DATE" not in grid_df
# (no RST columns, so no DATE info in the daaframe)
SOIL above the given cutoff. Value is put in column OWC.
sgascuttof (float): If not None, a gas contact will be
estimated pr pillar, based on the deepest cell with
SGAS above the given cutoff. Value is put in column GOC.
swatcutoff (float): OWC or GWC is only computed for pillars
where at least one cell is above this value.
stackdates (bool): If true, a column
called DATE will be added and data for all restart
dates will be added in a stacked manner.
"""
# List of vectors we want, conservative in order to save memory and cputime:
vectors = []
if region:
vectors.append(region)
vectors.extend(["POR*", "PERM*", "SWAT", "SGAS", "1OVERBO", "1OVERBG"])
grid_df = ecl2df.grid.df(
eclfiles, rstdates=rstdates, vectors=vectors, dateinheaders=True
)
rstdates_iso = ecl2df.grid.dates2rstindices(eclfiles, rstdates)[2]
grid_df["PILLAR"] = grid_df["I"].astype(str) + "-" + grid_df["J"].astype(str)
logger.info("Computing pillar statistics")
groupbies = ["PILLAR"]
if region:
if region not in grid_df:
logger.warning("Region parameter %s not found, ignored", region)
else:
groupbies.append(region)
grid_df[region] = grid_df[region].astype(int)
for datestr in rstdates_iso:
if boundaryfilter and len(vectors) > 1:
logger.error(
"Can't filter to boundaries when more than one INIT vector is supplied"
)
return pd.DataFrame()
if group and len(vectors) > 1:
logger.error("Can't group to more than one INIT vector at a time")
return pd.DataFrame()
if onlykdir and onlyijdir:
logger.warning(
"Filtering to both k and to ij simultaneously " "results in empty dataframe"
)
grid_df = ecl2df.grid.df(eclfiles) # .set_index(["I", "J", "K"])
existing_vectors = [vec for vec in vectors if vec in grid_df.columns]
if len(existing_vectors) < len(vectors):
logger.warning(
"Vectors %s not found, skipping", str(set(vectors) - set(existing_vectors))
)
vectors = existing_vectors
logger.info("Building transmissibility dataframe")
if not onlykdir:
tranx = pd.DataFrame(grid_df[grid_df["TRANX"] > 0][["I", "J", "K", "TRANX"]])
tranx.rename(
columns={"I": "I1", "J": "J1", "K": "K1", "TRANX": "TRAN"}, inplace=True
)
tranx["I2"] = tranx["I1"] + 1
tranx["J2"] = tranx["J1"]
tranx["K2"] = tranx["K1"]
tranx["DIR"] = "I"