diff --git a/src/xtgeo/well/_well_oper.py b/src/xtgeo/well/_well_oper.py index 1506ef372..cae378bb5 100644 --- a/src/xtgeo/well/_well_oper.py +++ b/src/xtgeo/well/_well_oper.py @@ -1,5 +1,7 @@ """Operations along a well, private module.""" +from copy import deepcopy + import numpy as np import pandas as pd @@ -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() @@ -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: @@ -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): diff --git a/src/xtgeo/xyz/_xyz_data.py b/src/xtgeo/xyz/_xyz_data.py index 9d63d5b0a..9121b6247 100644 --- a/src/xtgeo/xyz/_xyz_data.py +++ b/src/xtgeo/xyz/_xyz_data.py @@ -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 diff --git a/tests/test_well/test_well_vs_grid.py b/tests/test_well/test_well_vs_grid.py index 6496d6c2e..38e1b5f8a 100644 --- a/tests/test_well/test_well_vs_grid.py +++ b/tests/test_well/test_well_vs_grid.py @@ -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", + }