From 7095d1b938c5c03ecc421873461b91b6cf58c00b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20C=2E=20Riven=C3=A6s?= Date: Fri, 7 Jun 2024 15:40:16 +0200 Subject: [PATCH] BUG: fix that a surface copy retains isloaded status. --- src/xtgeo/surface/regular_surface.py | 1 + tests/test_surface/test_regular_surface.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/xtgeo/surface/regular_surface.py b/src/xtgeo/surface/regular_surface.py index 2b7ebe223..1778bfce2 100644 --- a/src/xtgeo/surface/regular_surface.py +++ b/src/xtgeo/surface/regular_surface.py @@ -1676,6 +1676,7 @@ def copy(self): ) xsurf._values = self._values.copy() + xsurf._isloaded = self._isloaded xsurf.ilines = self._ilines.copy() xsurf.xlines = self._xlines.copy() diff --git a/tests/test_surface/test_regular_surface.py b/tests/test_surface/test_regular_surface.py index e35872797..c989d9ec8 100644 --- a/tests/test_surface/test_regular_surface.py +++ b/tests/test_surface/test_regular_surface.py @@ -79,6 +79,23 @@ def test_values(default_surface): srf.values = "text" +def test_regularsurface_copy(): + """Test copying a surface instance.""" + values = np.random.normal(2000, 50, size=12) + srf = xtgeo.RegularSurface(ncol=3, nrow=4, xinc=20, yinc=20, values=values) + assert srf.nactive == 12 + new = srf.copy() + assert srf.nactive == new.nactive + + np.testing.assert_array_equal(srf.values, new.values) + assert new.xori == srf.xori + assert new.xinc == srf.xinc + assert new.yori == srf.yori + assert new.xinc == srf.xinc + assert new.rotation == srf.rotation + assert new.yflip == srf.yflip + + @pytest.mark.filterwarnings("ignore:Default values*") def test_set_values1d(default_surface): """Test behaviour of set_values1d method."""