Skip to content

Commit 6b4afc3

Browse files
bugfix
1 parent 3d818ed commit 6b4afc3

4 files changed

Lines changed: 34 additions & 14 deletions

File tree

energyml-utils/src/energyml/utils/data/crs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,9 @@ def _extract_vertical_crs_details(vertical_crs_obj: Any) -> dict:
321321
**must not** override a parent-level ``ZIncreasingDownward`` when this
322322
value is ``None``.
323323
"""
324-
logging.debug(
325-
f"Extracting vertical CRS details from object of type {type(vertical_crs_obj).__name__} with URI {get_obj_uri(vertical_crs_obj)}"
326-
)
324+
# logging.debug(
325+
# f"Extracting vertical CRS details from object of type {type(vertical_crs_obj).__name__} with URI {get_obj_uri(vertical_crs_obj)}"
326+
# )
327327
result: dict = {
328328
"epsg_code": None,
329329
"wkt": None,

energyml-utils/src/energyml/utils/data/helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ def get_crs_obj(
385385
if crs_list is not None and len(crs_list) > 0 and crs_list[0] is not None:
386386
# logging.debug(crs_list[0])
387387
crs = workspace.get_object(get_obj_uri(crs_list[0]))
388-
logging.debug(f"CRS found for {get_obj_title(context_obj)} ({type(context_obj).__name__}): {crs}")
388+
# logging.debug(f"CRS found for {get_obj_title(context_obj)} ({type(context_obj).__name__}): {crs}")
389389
if crs is None:
390390
# logging.debug(f"CRS {crs_list[0]} not found (or not read correctly)")
391391
_crs_list = workspace.get_object_by_uuid(get_obj_uuid(crs_list[0]))

energyml-utils/src/energyml/utils/data/mesh_numpy.py

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1990,6 +1990,32 @@ def read_numpy_mesh_object(
19901990
# ---------------------------------------------------------------------------
19911991

19921992

1993+
def _import_pyvista() -> Any:
1994+
"""Import PyVista and apply forward-compatibility fixes.
1995+
1996+
PyVista 0.43 deprecated ``PolyData.n_faces`` (which used to return the
1997+
total cell count, equivalent to ``n_cells``); PyVista 0.46 converted that
1998+
deprecation into a hard ``AttributeError``. Calling
1999+
``use_strict_n_faces(True)`` opts into the new, permanent semantics where
2000+
``n_faces`` returns only the polygon (face) count — identical to
2001+
``n_faces_strict`` — rather than raising an error.
2002+
2003+
This is safe to call multiple times; the flag is a class-level boolean on
2004+
``pyvista.PolyData`` and the call is idempotent.
2005+
"""
2006+
try:
2007+
import pyvista as pv # type: ignore[import]
2008+
except ImportError as exc:
2009+
raise ImportError(
2010+
"pyvista is not installed. Install it with: pip install pyvista"
2011+
) from exc
2012+
# Enable strict n_faces mode: makes n_faces return n_faces_strict (polygon
2013+
# count) instead of raising AttributeError in PyVista >= 0.46.
2014+
if hasattr(pv.PolyData, "use_strict_n_faces"):
2015+
pv.PolyData.use_strict_n_faces(True)
2016+
return pv
2017+
2018+
19932019
def numpy_mesh_to_pyvista(mesh: NumpyMesh) -> Any:
19942020
"""Convert a :class:`NumpyMesh` to the appropriate PyVista dataset.
19952021
@@ -2006,10 +2032,7 @@ def numpy_mesh_to_pyvista(mesh: NumpyMesh) -> Any:
20062032
* :class:`NumpySurfaceMesh` → ``pyvista.PolyData(points, faces=faces)``
20072033
* :class:`NumpyVolumeMesh` → ``pyvista.UnstructuredGrid(cells, cell_types, points)``
20082034
"""
2009-
try:
2010-
import pyvista as pv # type: ignore[import]
2011-
except ImportError as exc:
2012-
raise ImportError("pyvista is not installed. " "Install it with: pip install pyvista") from exc
2035+
pv = _import_pyvista()
20132036

20142037
pts = mesh.points # (N, 3) float64 — no copy
20152038

@@ -2040,10 +2063,7 @@ def numpy_multi_mesh_to_pyvista(multi: "NumpyMultiMesh") -> Any:
20402063
20412064
Requires ``pyvista`` to be installed (``pip install pyvista``).
20422065
"""
2043-
try:
2044-
import pyvista as pv # type: ignore[import]
2045-
except ImportError as exc:
2046-
raise ImportError("pyvista is not installed. Install it with: pip install pyvista") from exc
2066+
pv = _import_pyvista()
20472067

20482068
block: pv.MultiBlock = pv.MultiBlock()
20492069
for child in multi.children:

energyml-utils/src/energyml/utils/data/representation_context.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,13 @@ def get_default_color(self) -> ScalarRenderingInfo:
111111
for gis_uri, entries in self.graphical_info.items():
112112
for entry in entries:
113113
try:
114-
rendering_info = read_graphical_rendering_info(entry, self.workspace)
114+
rendering_info = read_graphical_rendering_info(entry, self.uri.uuid, self.workspace)
115115
if rendering_info is not None:
116116
return rendering_info
117117
except Exception as exc:
118118
logging.debug(f"Error reading graphical rendering info for entry {entry}: {exc}")
119119
# No color information found, generate a random color from uuid
120-
return ScalarRenderingInfo(constant_color=RgbaColor.from_uuid(self.uri.uuid))
120+
return ScalarRenderingInfo(constant_color=RgbaColor.random_from_uuid(self.uri.uuid))
121121

122122
def get_property(self, property_uuid: str) -> Optional[Any]:
123123
"""Return the property object with the given uuid, or None."""

0 commit comments

Comments
 (0)