Skip to content

Commit

Permalink
BUG: fix logrecord codes well.get_gridproperties()
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrivenaes committed Nov 7, 2023
1 parent 007403a commit 2f7bb33
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 16 deletions.
32 changes: 18 additions & 14 deletions src/xtgeo/well/_well_oper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Operations along a well, private module."""

from copy import deepcopy

import numpy as np
import pandas as pd

Expand Down Expand Up @@ -281,25 +283,27 @@ def get_gridproperties(self, gridprops, grid=("ICELL", "JCELL", "KCELL"), prop_i
if not isinstance(gridprops, (xtgeo.GridProperty, xtgeo.GridProperties)):
raise ValueError('"gridprops" not a GridProperties or GridProperty instance')

wcopy = self.copy()
# wcopy = self.copy()
if isinstance(gridprops, xtgeo.GridProperty):
gprops = xtgeo.GridProperties()
gprops.append_props([gridprops])
else:
gprops = gridprops

ijk_logs_created_tmp = False
if isinstance(grid, tuple):
icl, jcl, kcl = grid
elif isinstance(grid, xtgeo.Grid):
wcopy.make_ijk_from_grid(grid, grid_id="_tmp", algorithm=2)
self.make_ijk_from_grid(grid, grid_id="_tmp", algorithm=2)
icl, jcl, kcl = ("ICELL_tmp", "JCELL_tmp", "KCELL_tmp")
ijk_logs_created_tmp = True
else:
raise ValueError("The 'grid' is of wrong type, must be a tuple or a Grid")

# let grid values have base 1 when looking up cells for gridprops
iind = wcopy.dataframe[icl].values - 1
jind = wcopy.dataframe[jcl].values - 1
kind = wcopy.dataframe[kcl].values - 1
iind = self.dataframe[icl].to_numpy(copy=True) - 1
jind = self.dataframe[jcl].to_numpy(copy=True) - 1
kind = self.dataframe[kcl].to_numpy(copy=True) - 1

xind = iind.copy()

Expand All @@ -310,7 +314,7 @@ def get_gridproperties(self, gridprops, grid=("ICELL", "JCELL", "KCELL"), prop_i
iind = iind.astype("int")
jind = jind.astype("int")
kind = kind.astype("int")
dfr = wcopy.dataframe.copy()
dfr = self.dataframe.copy()

pnames = {}
for prop in gprops.props:
Expand All @@ -319,20 +323,20 @@ def get_gridproperties(self, gridprops, grid=("ICELL", "JCELL", "KCELL"), prop_i
arr[np.isnan(xind)] = np.nan
pname = prop.name + prop_id
dfr[pname] = arr
pnames[pname] = (prop.isdiscrete, prop.codes)
pnames[pname] = (prop.isdiscrete, deepcopy(prop.codes))

wcopy.set_dataframe(dfr)
self.set_dataframe(dfr)
for pname, isdiscrete_codes in pnames.items():
isdiscrete, codes = isdiscrete_codes
if isdiscrete:
wcopy.set_logtype(pname, _AttrType.DISC.value)
wcopy.set_logrecord(pname, codes)
self.set_logtype(pname, _AttrType.DISC.value)
self.set_logrecord(pname, codes)
else:
wcopy.set_logtype(pname, _AttrType.CONT.value)
wcopy.set_logrecord(pname, ("", ""))
self.set_logtype(pname, _AttrType.CONT.value)
self.set_logrecord(pname, ("", ""))

wcopy.delete_logs(["ICELL_tmp", "JCELL_tmp", "KCELL_tmp"])
self.set_dataframe(wcopy.dataframe)
if ijk_logs_created_tmp:
self.delete_logs(["ICELL_tmp", "JCELL_tmp", "KCELL_tmp"])


def report_zonation_holes(self, threshold=5):
Expand Down
3 changes: 1 addition & 2 deletions src/xtgeo/xyz/_xyz_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,14 +319,13 @@ def ensure_consistency(self) -> bool:
occured, hence no consistency checks are done
"""

# the purpose of this hash check is to avoid psending time on consistency
# the purpose of this hash check is to avoid spending time on consistency
# checks if no changes
hash_proposed = (
jhash(self._df),
jhash(self._attr_types),
jhash(self._attr_records),
)

if self._hash == hash_proposed:
return False

Expand Down
19 changes: 19 additions & 0 deletions tests/test_well/test_well_vs_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,22 @@ def test_well_get_gridprops(tmpdir, loadwell1, loadgrid1, loadporo1):
assert mywell.dataframe.iloc[4775]["PORO_model"] == pytest.approx(0.2741, abs=0.001)
assert mywell.dataframe.iloc[4775]["ACTNUM_model"] == 1
assert mywell.isdiscrete("ACTNUM_model") is True


def test_well_gridprops_zone(loadwell1):
"""Test getting logrecords from discrete gridzones"""
grid = xtgeo.grid_from_file("../xtgeo-testdata/3dgrids/reek/reek_sim_grid.roff")
gridzones = xtgeo.gridproperty_from_file(
"../xtgeo-testdata/3dgrids/reek/reek_sim_zone.roff", grid=grid
)
gridzones.name = "Zone"

well = loadwell1
well.get_gridproperties(gridzones, grid)
well.zonelogname = "Zone_model"

assert well.get_logrecord(well.zonelogname) == {
1: "Below_Top_reek",
2: "Below_Mid_reek",
3: "Below_Low_reek",
}

0 comments on commit 2f7bb33

Please sign in to comment.