From d24f7029357012025618eb6049ee0c1ea8ea03f7 Mon Sep 17 00:00:00 2001
From: FZill <florian.zill@ufz.de>
Date: Fri, 10 Jan 2025 08:22:37 +0100
Subject: [PATCH] [meshlib] remove filepath from Mesh

---
 ogstools/meshlib/ip_mesh.py     | 7 ++++---
 ogstools/meshlib/mesh.py        | 3 ---
 ogstools/meshlib/mesh_series.py | 4 ----
 3 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/ogstools/meshlib/ip_mesh.py b/ogstools/meshlib/ip_mesh.py
index c05c1eeb8..2b4111d2b 100644
--- a/ogstools/meshlib/ip_mesh.py
+++ b/ogstools/meshlib/ip_mesh.py
@@ -1,4 +1,5 @@
 from pathlib import Path
+from tempfile import mkdtemp
 from typing import TypeVar
 
 import numpy as np
@@ -199,10 +200,10 @@ def to_ip_point_cloud(mesh: Mesh) -> pv.UnstructuredGrid:
     for key in bad_keys:
         if key in _mesh.field_data:
             _mesh.field_data.remove(key)
-    parentpath = Path() if mesh.filepath is None else mesh.filepath.parent
-    input_file = parentpath / "ipDataToPointCloud_input.vtu"
+    tempdir = mkdtemp(prefix="to_ip_point_cloud")
+    input_file = Path(tempdir) / "ipDataToPointCloud_input.vtu"
     _mesh.save(input_file)
-    output_file = parentpath / "ip_mesh.vtu"
+    output_file = Path(tempdir) / "ip_mesh.vtu"
     ogs.cli.ipDataToPointCloud(i=str(input_file), o=str(output_file))
     return pv.XMLUnstructuredGridReader(output_file).read()
 
diff --git a/ogstools/meshlib/mesh.py b/ogstools/meshlib/mesh.py
index f30cd51e6..a2b044a6b 100644
--- a/ogstools/meshlib/mesh.py
+++ b/ogstools/meshlib/mesh.py
@@ -28,8 +28,6 @@ class Mesh(pv.UnstructuredGrid):
     Contains additional data and functions mainly for postprocessing.
     """
 
-    filepath: Path | None = None
-
     # pylint: disable=C0116
     @copy_method_signature(data_processing.difference)
     def difference(self, *args: Any, **kwargs: Any) -> Any:
@@ -119,7 +117,6 @@ class Mesh(pv.UnstructuredGrid):
         else:
             mesh = cls(pv.read(filepath))
 
-        mesh.filepath = Path(filepath).with_suffix(".vtu")
         mesh.field_data[SPATIAL_UNITS_KEY] = np.asarray(
             [ord(char) for char in f"{spatial_unit},{spatial_output_unit}"]
         )
diff --git a/ogstools/meshlib/mesh_series.py b/ogstools/meshlib/mesh_series.py
index 4e0fb83a7..06a4c5503 100644
--- a/ogstools/meshlib/mesh_series.py
+++ b/ogstools/meshlib/mesh_series.py
@@ -267,10 +267,6 @@ class MeshSeries:
             )
             if lazy_eval:
                 self._mesh_cache[timevalue] = mesh
-        if self._data_type == "pvd":
-            mesh.filepath = Path(self.timestep_files[data_timestep])
-        else:
-            mesh.filepath = Path(self.filepath)
         return mesh
 
     def rawdata_file(self) -> Path | None:
-- 
GitLab