Skip to content

Commit

Permalink
Fix for bad spatial axis unit
Browse files Browse the repository at this point in the history
  • Loading branch information
JesperGr committed Sep 9, 2024
1 parent d0a0cee commit 9b7618b
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions mikecore/DfsFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1390,6 +1390,14 @@ def __GetStaticData(self, item):
class DfsDLLUtil():
"""Utilities class, creating various Dfs classes based on pointers to DFS native data"""

# In case of incorrect eumUnitInt then return eumUmeter, the default axis unit
@staticmethod
def ToEumAxisUnit(eumUnitInt: int):
try:
spatial_axis_unit = eumUnit(eumUnitInt)
except:
spatial_axis_unit = eumUnit.eumUmeter

@staticmethod
def GetDfsType(arrayData):
if (arrayData.dtype == np.float32):
Expand Down Expand Up @@ -1576,7 +1584,7 @@ def GetItemSpatialAxis(itemPointer):
eumUnitInt = ctypes.c_int32()
eumUnitDescr = ctypes.c_char_p()
DfsDLL.Wrapper.dfsGetItemAxisEqD0(itemPointer, ctypes.byref(eumUnitInt), ctypes.byref(eumUnitDescr))
axis = DfsAxisEqD0(eumUnit(eumUnitInt.value))
axis = DfsAxisEqD0(DfsDLLUtil.ToEumAxisUnit(eumUnitInt.value))
return (axis)

if axisType == SpaceAxisType.EqD1:
Expand All @@ -1592,7 +1600,7 @@ def GetItemSpatialAxis(itemPointer):
ctypes.byref(xCount),
ctypes.byref(x0),
ctypes.byref(dx))
axis = DfsAxisEqD1(eumUnit(eumUnitInt.value), xCount.value, x0.value, dx.value)
axis = DfsAxisEqD1(DfsDLLUtil.ToEumAxisUnit(eumUnitInt.value), xCount.value, x0.value, dx.value)
return (axis)

if axisType == SpaceAxisType.NeqD1:
Expand All @@ -1617,7 +1625,7 @@ def GetItemSpatialAxis(itemPointer):
ctypes.byref(y0),
ctypes.byref(dx),
ctypes.byref(dy))
axis = DfsAxisEqD2(eumUnit(eumUnitInt.value), xCount.value, x0.value, dx.value, yCount.value, y0.value, dy.value)
axis = DfsAxisEqD2(DfsDLLUtil.ToEumAxisUnit(eumUnitInt.value), xCount.value, x0.value, dx.value, yCount.value, y0.value, dy.value)
return (axis)

if axisType == SpaceAxisType.NeqD2:
Expand Down Expand Up @@ -1649,7 +1657,7 @@ def GetItemSpatialAxis(itemPointer):
ctypes.byref(dy),
ctypes.byref(dz),
)
axis = DfsAxisEqD3(eumUnit(eumUnitInt.value), xCount.value, x0.value, dx.value, yCount.value, y0.value, dy.value, zCount.value, z0.value, dz.value)
axis = DfsAxisEqD3(DfsDLLUtil.ToEumAxisUnit(eumUnitInt.value), xCount.value, x0.value, dx.value, yCount.value, y0.value, dy.value, zCount.value, z0.value, dz.value)
return axis

if axisType == SpaceAxisType.NeqD3:
Expand Down

0 comments on commit 9b7618b

Please sign in to comment.