Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions omf/fileio/geoh5.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
Data,
DataTypeEnum,
FloatData,
GeometricDataConstants,
IntegerData,
NumericData,
ReferencedData,
VisualParameters,
)
from geoh5py.groups import ContainerGroup, PropertyGroup, RootGroup
from geoh5py.objects import BlockModel, Curve, Grid2D, ObjectBase, Points, Surface
Expand Down Expand Up @@ -245,7 +247,11 @@ def process_dependents(
converter = get_conversion_map(
child, workspace, compression=compression, parent=element
)
if isinstance(converter, KnownUnsupported):
continue

converted = getattr(converter, method)(child, **kwargs)

if isinstance(converted, list):
children += converted
else:
Expand Down Expand Up @@ -305,6 +311,18 @@ def collect_attributes(
return kwargs


class KnownUnsupported(BaseConversion):
"""
Conversion class that silently ignores unsupported conversions.
"""

def from_omf(self, *_, **kwargs) -> dict:
return {}

def from_geoh5(self, *_, **kwargs) -> dict:
return {}


class DataConversion(BaseConversion):
"""
Conversion between :obj:`omf.data.Data` and
Expand Down Expand Up @@ -1376,6 +1394,7 @@ def block_model_reordering(entity: BlockModel | VolumeElement, values: np.ndarra
ContainerGroup: ContainerGroupConversion,
Curve: CurveConversion,
FloatData: ScalarDataConversion,
GeometricDataConstants: KnownUnsupported,
Grid2D: SurfaceGridConversion,
Int2Array: ArrayConversion,
IntegerData: ScalarDataConversion,
Expand All @@ -1392,6 +1411,7 @@ def block_model_reordering(entity: BlockModel | VolumeElement, values: np.ndarra
Surface: SurfaceConversion,
SurfaceElement: SurfaceConversion,
Vector3Array: ArrayConversion,
VisualParameters: KnownUnsupported,
VolumeElement: VolumeConversion,
}

Expand Down
10 changes: 8 additions & 2 deletions tests/convert_pointset_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import omf


def test_pointset_to_geoh5(tmp_path: Path):
def test_pointset_to_geoh5(tmp_path: Path, caplog):
"""Test pointset geometry validation"""
colormap = omf.ColorArray(
array=[
Expand Down Expand Up @@ -49,18 +49,24 @@ def test_pointset_to_geoh5(tmp_path: Path):
file = str(tmp_path / "pointset.geoh5")
omf.OMFWriter(orig_pts, file)

# Check that the file was created
with Workspace(file) as workspace:
geoh5_points = workspace.get_entity("Random Points")[0]
np.testing.assert_array_almost_equal(
np.r_[orig_pts.geometry.vertices.array], geoh5_points.vertices
)

geoh5_points.add_default_visual_parameters()
data = geoh5_points.get_entity("rand data")[0]
np.testing.assert_array_almost_equal(np.r_[orig_pts.data[0].array], data.values)

converter = omf.fileio.geoh5.get_conversion_map(geoh5_points, workspace)
converted_omf = converter.from_geoh5(geoh5_points)

with caplog.at_level("WARNING"):
converted_omf = converter.from_geoh5(geoh5_points)

assert len(caplog.text) == 0, "No warnings should be raised during conversion"
assert len(converted_omf.data) == 1 # Skip the visual parameters
omf.fileio.utils.compare_elements(converted_omf, orig_pts)

project = omf.fileio.geoh5.GeoH5Reader(file).project
Expand Down