diff --git a/packages/image-io/pixi.toml b/packages/image-io/pixi.toml index e40eed57c..beb414424 100644 --- a/packages/image-io/pixi.toml +++ b/packages/image-io/pixi.toml @@ -85,6 +85,7 @@ pyodide-py = ">=0.26.3, <0.27" pytest-pyodide = ">=0.58.3, <0.59" itk-webassemblyinterface = ">=1.0b175, <2" itkwasm = ">=1.0b179, <2" +itkwasm-image-io-wasi = { path = "python/itkwasm-image-io-wasi", editable = true } [feature.python.tasks.test-wasi] cmd = "pytest" diff --git a/packages/mesh-io/pixi.toml b/packages/mesh-io/pixi.toml index 21d11abaa..77b297e2a 100644 --- a/packages/mesh-io/pixi.toml +++ b/packages/mesh-io/pixi.toml @@ -85,6 +85,7 @@ pyodide-py = ">=0.26.3, <0.27" pytest-pyodide = ">=0.58.3, <0.59" itk-webassemblyinterface = ">=1.0b175, <2" itkwasm = ">=1.0b179, <2" +itkwasm-mesh-io-wasi = { path = "python/itkwasm-mesh-io-wasi", editable = true } [feature.python.tasks.test-wasi] cmd = "pytest" diff --git a/packages/transform-io/pixi.lock b/packages/transform-io/pixi.lock index b51d25709..a8bd30ac7 100644 --- a/packages/transform-io/pixi.lock +++ b/packages/transform-io/pixi.lock @@ -501,6 +501,7 @@ environments: - pypi: https://files.pythonhosted.org/packages/5e/24/806c5bd1b5e30c83cc9d182795edebfbfe24483f82fb18823b309a6656b5/wasmtime-27.0.1-py3-none-manylinux1_x86_64.whl - pypi: https://files.pythonhosted.org/packages/5a/84/44687a29792a70e111c5c477230a72c4b957d88d16141199bf9acb7537a3/websocket_client-1.8.0-py3-none-any.whl - pypi: https://files.pythonhosted.org/packages/78/58/e860788190eba3bcce367f74d29c4675466ce8dddfba85f7827588416f01/wsproto-1.2.0-py3-none-any.whl + - pypi: python/itkwasm-transform-io-wasi linux-aarch64: - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/_openmp_mutex-4.5-2_gnu.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/noarch/anyio-4.6.2.post1-pyhd8ed1ab_0.conda @@ -642,6 +643,7 @@ environments: - pypi: https://files.pythonhosted.org/packages/3a/57/cd877b4797be239b4433f89a5a85c7bf2c5319dd91c7777b1867bebb664e/wasmtime-27.0.1-py3-none-manylinux2014_aarch64.whl - pypi: https://files.pythonhosted.org/packages/5a/84/44687a29792a70e111c5c477230a72c4b957d88d16141199bf9acb7537a3/websocket_client-1.8.0-py3-none-any.whl - pypi: https://files.pythonhosted.org/packages/78/58/e860788190eba3bcce367f74d29c4675466ce8dddfba85f7827588416f01/wsproto-1.2.0-py3-none-any.whl + - pypi: python/itkwasm-transform-io-wasi osx-arm64: - conda: https://conda.anaconda.org/conda-forge/noarch/anyio-4.6.2.post1-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/backports-1.0-pyhd8ed1ab_4.conda @@ -766,6 +768,7 @@ environments: - pypi: https://files.pythonhosted.org/packages/6e/d8/38d1af31c1787e09642354c81215920a5bf59722a6786ed7e9622fd1f033/wasmtime-27.0.1-py3-none-macosx_11_0_arm64.whl - pypi: https://files.pythonhosted.org/packages/5a/84/44687a29792a70e111c5c477230a72c4b957d88d16141199bf9acb7537a3/websocket_client-1.8.0-py3-none-any.whl - pypi: https://files.pythonhosted.org/packages/78/58/e860788190eba3bcce367f74d29c4675466ce8dddfba85f7827588416f01/wsproto-1.2.0-py3-none-any.whl + - pypi: python/itkwasm-transform-io-wasi win-64: - conda: https://conda.anaconda.org/conda-forge/noarch/anyio-4.6.2.post1-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/backports-1.0-pyhd8ed1ab_4.conda @@ -895,6 +898,7 @@ environments: - pypi: https://files.pythonhosted.org/packages/14/6f/f6b99d9ab1511398686e00d2a26371d99a7949531514379d731b3b7e6309/wasmtime-27.0.1-py3-none-win_amd64.whl - pypi: https://files.pythonhosted.org/packages/5a/84/44687a29792a70e111c5c477230a72c4b957d88d16141199bf9acb7537a3/websocket_client-1.8.0-py3-none-any.whl - pypi: https://files.pythonhosted.org/packages/78/58/e860788190eba3bcce367f74d29c4675466ce8dddfba85f7827588416f01/wsproto-1.2.0-py3-none-any.whl + - pypi: python/itkwasm-transform-io-wasi packages: - kind: conda name: _libgcc_mutex @@ -2300,6 +2304,16 @@ packages: - typing-extensions - wasmtime>=27.0.1 ; sys_platform != 'emscripten' requires_python: '>=3.9' +- kind: pypi + name: itkwasm-transform-io-wasi + version: 0.1.1 + path: python/itkwasm-transform-io-wasi + sha256: b23e2fac5297bd8d40cdff5fa28cffb3dae675de420923a40c17bea27c8a332e + requires_dist: + - importlib-resources + - itkwasm>=1.0b185 + requires_python: '>=3.9' + editable: true - kind: conda name: jaraco.classes version: 3.4.0 diff --git a/packages/transform-io/pixi.toml b/packages/transform-io/pixi.toml index 7338ed711..e6f8f6f6f 100644 --- a/packages/transform-io/pixi.toml +++ b/packages/transform-io/pixi.toml @@ -85,6 +85,7 @@ pyodide-py = ">=0.26.4, <0.27" pytest-pyodide = ">=0.58.3, <0.59" itk-webassemblyinterface = ">=1.0b175, <2" itkwasm = ">=1.0b185, <2" +itkwasm-transform-io-wasi = { path = "python/itkwasm-transform-io-wasi", editable = true } [feature.python.tasks.test-wasi] cmd = "pytest" diff --git a/packages/transform-io/python/itkwasm-transform-io-wasi/tests/common.py b/packages/transform-io/python/itkwasm-transform-io-wasi/tests/common.py index 153d5171d..11ebafc53 100644 --- a/packages/transform-io/python/itkwasm-transform-io-wasi/tests/common.py +++ b/packages/transform-io/python/itkwasm-transform-io-wasi/tests/common.py @@ -5,7 +5,7 @@ test_input_path = Path(__file__).parent / ".." / ".." / ".." / "test" / "data" / "input" test_baseline_path = Path(__file__).parent / ".." / ".." / ".." / "test" / "data" / "baseline" -test_output_path = Path(__file__).parent / ".." / ".." / ".." / "test" / "data" / "output" / "python" +test_output_path = Path(__file__).parent / ".." / ".." / ".." / "test" / "data" / "output" / "python-wasi" test_output_path.mkdir(parents=True, exist_ok=True) def verify_test_linear_transform(transform_list: TransformList): @@ -20,4 +20,4 @@ def verify_test_linear_transform(transform_list: TransformList): 0.65631490118447, 0.5806583745824385, -0.4817536741017158, -0.7407986817430222, 0.37486398378429736, -0.5573995934598175, -0.14306664045479867, 0.7227121458012518, 0.676179776908723, - -65.99999999999997, 69.00000000000004, 32.000000000000036])) \ No newline at end of file + -65.99999999999997, 69.00000000000004, 32.000000000000036])) diff --git a/packages/transform-io/python/itkwasm-transform-io/itkwasm_transform_io/__init__.py b/packages/transform-io/python/itkwasm-transform-io/itkwasm_transform_io/__init__.py index 2d82258a2..d733ccf6b 100644 --- a/packages/transform-io/python/itkwasm-transform-io/itkwasm_transform_io/__init__.py +++ b/packages/transform-io/python/itkwasm-transform-io/itkwasm_transform_io/__init__.py @@ -1,7 +1,10 @@ -# Generated file. To retain edits, remove this comment. - """itkwasm-transform-io: Input and output for scientific and medical coordinate transform file formats.""" +from .read_transform_async import read_transform_async, transformread_async +from .read_transform import read_transform, transformread +from .write_transform_async import write_transform_async, transformwrite_async +from .write_transform import write_transform, transformwrite + from .hdf5_read_transform_async import hdf5_read_transform_async from .hdf5_read_transform import hdf5_read_transform from .hdf5_write_transform_async import hdf5_write_transform_async diff --git a/packages/transform-io/python/itkwasm-transform-io/itkwasm_transform_io/read_transform.py b/packages/transform-io/python/itkwasm-transform-io/itkwasm_transform_io/read_transform.py new file mode 100644 index 000000000..68f6731fc --- /dev/null +++ b/packages/transform-io/python/itkwasm-transform-io/itkwasm_transform_io/read_transform.py @@ -0,0 +1,36 @@ +import os +from typing import Optional, Union + +from itkwasm import ( + environment_dispatch, + TransformList, +) + +def read_transform( + serialized_transform: os.PathLike, + float_parameters: bool = False, +) -> TransformList: + """Read a transform file format and convert it to the ITK-Wasm file format + + :param serialized_transform: Input transform serialized in the file format + :type serialized_transform: os.PathLike + + :param float_parameters: Use float for the parameter value type. The default is double. + :type float_parameters: bool + + :return: Output transform + :rtype: TransformList + """ + func = environment_dispatch("itkwasm_transform_io", "read_transform") + output = func(serialized_transform, float_parameters=float_parameters) + return output + +def transformread( + serialized_transform: os.PathLike, + float_parameters: bool = False, +) -> TransformList: + return read_transform(serialized_transform, float_parameters=float_parameters) + +transformread.__doc__ = f"""{read_transform.__doc__} + Alias for read_transform. + """ \ No newline at end of file diff --git a/packages/transform-io/python/itkwasm-transform-io/itkwasm_transform_io/read_transform_async.py b/packages/transform-io/python/itkwasm-transform-io/itkwasm_transform_io/read_transform_async.py new file mode 100644 index 000000000..2cffceb92 --- /dev/null +++ b/packages/transform-io/python/itkwasm-transform-io/itkwasm_transform_io/read_transform_async.py @@ -0,0 +1,36 @@ +import os +from typing import Optional, Union + +from itkwasm import ( + environment_dispatch, + TransformList, +) + +async def read_transform_async( + serialized_transform: os.PathLike, + float_parameters: bool = False, +) -> TransformList: + """Read an transform file format and convert it to the ITK-Wasm file format. + + :param serialized_transform: Input transform serialized in the file format + :type serialized_transform: os.PathLike + + :param float_parameters: Use float for the parameter value type. The default is double. + :type float_parameters: bool + + :return: Output transform + :rtype: TransformList + """ + func = environment_dispatch("itkwasm_transform_io", "read_transform_async") + output = await func(serialized_transform, float_parameters=float_parameters) + return output + +async def transformread_async( + serialized_transform: os.PathLike, + float_parameters: bool = False, +) -> TransformList: + return await read_transform_async(serialized_transform, float_parameters=float_parameters) + +transformread_async.__doc__ = f"""{read_transform_async.__doc__} + Alias for read_transform. + """ \ No newline at end of file diff --git a/packages/transform-io/python/itkwasm-transform-io/itkwasm_transform_io/write_transform.py b/packages/transform-io/python/itkwasm-transform-io/itkwasm_transform_io/write_transform.py new file mode 100644 index 000000000..20ce71cd0 --- /dev/null +++ b/packages/transform-io/python/itkwasm-transform-io/itkwasm_transform_io/write_transform.py @@ -0,0 +1,43 @@ +import os +from typing import Dict, Tuple, Optional, List, Any + +from itkwasm import ( + environment_dispatch, + TransformList, +) + +def write_transform( + transform: TransformList, + serialized_transform: str, + float_parameters: bool = False, + use_compression: bool = False, +) -> None: + """Write an ITK-Wasm file format converted to a transform file format + + :param transform: Input transform + :type transform: TransformList + + :param serialized_transform: Output transform serialized in the file format. + :type serialized_transform: str + + :param float_parameters: Use float for the parameter value type. The default is double. + :type float_parameters: bool + + :param use_compression: Use compression in the written file + :type use_compression: bool + """ + func = environment_dispatch("itkwasm_transform_io", "write_transform") + func(transform, serialized_transform, float_parameters=float_parameters, use_compression=use_compression) + return + +def transformwrite( + transform: TransformList, + serialized_transform: os.PathLike, + float_parameters: bool = False, + use_compression: bool = False, +) -> None: + return write_transform(transform, serialized_transform, float_parameters=float_parameters, use_compression=use_compression) + +transformwrite.__doc__ = f"""{write_transform.__doc__} + Alias for write_transform. + """ \ No newline at end of file diff --git a/packages/transform-io/python/itkwasm-transform-io/itkwasm_transform_io/write_transform_async.py b/packages/transform-io/python/itkwasm-transform-io/itkwasm_transform_io/write_transform_async.py new file mode 100644 index 000000000..0a2e96ad2 --- /dev/null +++ b/packages/transform-io/python/itkwasm-transform-io/itkwasm_transform_io/write_transform_async.py @@ -0,0 +1,43 @@ +import os +from typing import Dict, Tuple, Optional, List, Any + +from itkwasm import ( + environment_dispatch, + TransformList, +) + +async def write_transform_async( + transform: TransformList, + serialized_transform: str, + float_parameters: bool = False, + use_compression: bool = False, +) -> None: + """Write an ITK-Wasm file format converted to a transform file format. + + :param transform: Input transform + :type transform: TransformList + + :param serialized_transform: Output transform serialized in the file format. + :type serialized_transform: str + + :param float_parameters: Only write transform metadata -- do not write pixel data. + :type float_parameters: bool + + :param use_compression: Use compression in the written file + :type use_compression: bool + """ + func = environment_dispatch("itkwasm_transform_io", "write_transform_async") + await func(transform, serialized_transform, float_parameters=float_parameters, use_compression=use_compression) + return + +async def transformwrite_async( + transform: TransformList, + serialized_transform: os.PathLike, + float_parameters: bool = False, + use_compression: bool = False, +) -> None: + return await write_transform_async(transform, serialized_transform, float_parameters=float_parameters, use_compression=use_compression) + +transformwrite_async.__doc__ = f"""{write_transform_async.__doc__} + Alias for write_transform. + """ \ No newline at end of file diff --git a/packages/transform-io/python/itkwasm-transform-io/tests/common.py b/packages/transform-io/python/itkwasm-transform-io/tests/common.py new file mode 100644 index 000000000..95b199562 --- /dev/null +++ b/packages/transform-io/python/itkwasm-transform-io/tests/common.py @@ -0,0 +1,23 @@ +from pathlib import Path +import numpy as np + +from itkwasm import TransformList, TransformParameterizations, FloatTypes + +test_input_path = Path(__file__).parent / ".." / ".." / ".." / "test" / "data" / "input" +test_baseline_path = Path(__file__).parent / ".." / ".." / ".." / "test" / "data" / "baseline" +test_output_path = Path(__file__).parent / ".." / ".." / ".." / "test" / "data" / "output" / "python-dispatch" +test_output_path.mkdir(parents=True, exist_ok=True) + +def verify_test_linear_transform(transform_list: TransformList): + assert len(transform_list) == 1 + transform = transform_list[0] + assert transform.transformType.transformParameterization == TransformParameterizations.Affine + assert transform.transformType.parametersValueType == FloatTypes.Float64 + assert transform.numberOfParameters == 12 + assert transform.numberOfFixedParameters == 3 + np.testing.assert_allclose(transform.fixedParameters, np.array([0.0, 0.0, 0.0])) + np.testing.assert_allclose(transform.parameters, np.array([ + 0.65631490118447, 0.5806583745824385, -0.4817536741017158, + -0.7407986817430222, 0.37486398378429736, -0.5573995934598175, + -0.14306664045479867, 0.7227121458012518, 0.676179776908723, + -65.99999999999997, 69.00000000000004, 32.000000000000036])) diff --git a/packages/transform-io/python/itkwasm-transform-io/tests/fixtures.py b/packages/transform-io/python/itkwasm-transform-io/tests/fixtures.py index dd000ca96..cda5dbaf3 100644 --- a/packages/transform-io/python/itkwasm-transform-io/tests/fixtures.py +++ b/packages/transform-io/python/itkwasm-transform-io/tests/fixtures.py @@ -20,7 +20,7 @@ def emscripten_package_wheel(): @pytest.fixture def input_data(): from pathlib import Path - input_base_path = Path(__file__).parent.parent / 'test' / 'data' + input_base_path = Path(__file__).parent.parent.parent.parent / 'test' / 'data' / 'input' test_files = list(input_base_path.glob('*')) data = {} for test_file in test_files: diff --git a/packages/transform-io/python/itkwasm-transform-io/tests/test_hdf5_read_transform.py b/packages/transform-io/python/itkwasm-transform-io/tests/test_hdf5_read_transform.py index 0f287ae41..c4ec0fc4b 100644 --- a/packages/transform-io/python/itkwasm-transform-io/tests/test_hdf5_read_transform.py +++ b/packages/transform-io/python/itkwasm-transform-io/tests/test_hdf5_read_transform.py @@ -1,19 +1,12 @@ -import pytest -import sys +from pathlib import Path -if sys.version_info < (3,10): - pytest.skip("Skipping pyodide tests on older Python", allow_module_level=True) +from itkwasm_transform_io import hdf5_read_transform -from pytest_pyodide import run_in_pyodide +from .common import test_input_path, test_output_path, verify_test_linear_transform -from .fixtures import emscripten_package_wheel, package_wheel, input_data +test_input_file_path = test_input_path / "LinearTransform.h5" -@run_in_pyodide(packages=['micropip']) -async def test_hdf5_read_transform(selenium, package_wheel, emscripten_package_wheel): - import micropip - await micropip.install(emscripten_package_wheel) - await micropip.install(package_wheel) - - from itkwasm_transform_io import hdf5_read_transform - - # Write your test code here +def test_hdf5_read_transform(): + could_read, transform_list = hdf5_read_transform(test_input_file_path) + assert could_read + verify_test_linear_transform(transform_list) diff --git a/packages/transform-io/python/itkwasm-transform-io/tests/test_hdf5_read_transform_async.py b/packages/transform-io/python/itkwasm-transform-io/tests/test_hdf5_read_transform_async.py new file mode 100644 index 000000000..9d6e0c66d --- /dev/null +++ b/packages/transform-io/python/itkwasm-transform-io/tests/test_hdf5_read_transform_async.py @@ -0,0 +1,59 @@ +import pytest +import sys + +if sys.version_info < (3,10): + pytest.skip("Skipping pyodide tests on older Python", allow_module_level=True) + +from pytest_pyodide import run_in_pyodide + +from .fixtures import package_wheel, input_data, emscripten_package_wheel + +@run_in_pyodide(packages=['micropip']) +async def test_hdf5_read_transform_async(selenium, package_wheel, emscripten_package_wheel, input_data): + import micropip + await micropip.install(emscripten_package_wheel) + await micropip.install(package_wheel) + + from pathlib import Path + + import numpy as np + from itkwasm import TransformParameterizations, FloatTypes + + from itkwasm_transform_io import hdf5_read_transform_async, hdf5_write_transform_async + + def write_input_data_to_fs(input_data, filename): + with open(filename, 'wb') as fp: + fp.write(input_data[filename]) + + def verify_test_linear_transform(transform_list): + assert len(transform_list) == 1 + transform = transform_list[0] + assert transform.transformType.transformParameterization == TransformParameterizations.Affine + assert transform.transformType.parametersValueType == FloatTypes.Float64 + assert transform.numberOfParameters == 12 + assert transform.numberOfFixedParameters == 3 + np.testing.assert_allclose(transform.fixedParameters, np.array([0.0, 0.0, 0.0])) + np.testing.assert_allclose(transform.parameters, np.array([ + 0.65631490118447, 0.5806583745824385, -0.4817536741017158, + -0.7407986817430222, 0.37486398378429736, -0.5573995934598175, + -0.14306664045479867, 0.7227121458012518, 0.676179776908723, + -65.99999999999997, 69.00000000000004, 32.000000000000036])) + + test_file_path = 'LinearTransform.h5' + write_input_data_to_fs(input_data, test_file_path) + + assert Path(test_file_path).exists() + + could_read, transform = await hdf5_read_transform_async(test_file_path) + assert could_read + verify_test_linear_transform(transform) + + test_output_file_path = 'out-LinearTransform.h5' + + use_compression = False + could_write = await hdf5_write_transform_async(transform, test_output_file_path, use_compression) + assert could_write + + could_read, transform = await hdf5_read_transform_async(test_output_file_path) + assert could_read + verify_test_linear_transform(transform) diff --git a/packages/transform-io/python/itkwasm-transform-io/tests/test_hdf5_write_transform.py b/packages/transform-io/python/itkwasm-transform-io/tests/test_hdf5_write_transform.py index ccae95042..a86b38c8e 100644 --- a/packages/transform-io/python/itkwasm-transform-io/tests/test_hdf5_write_transform.py +++ b/packages/transform-io/python/itkwasm-transform-io/tests/test_hdf5_write_transform.py @@ -1,19 +1,14 @@ -import pytest -import sys +from itkwasm_transform_io import hdf5_read_transform, hdf5_write_transform -if sys.version_info < (3,10): - pytest.skip("Skipping pyodide tests on older Python", allow_module_level=True) +from .common import test_input_path, test_output_path, verify_test_linear_transform -from pytest_pyodide import run_in_pyodide +test_input_file_path = test_input_path / "LinearTransform.h5" +test_output_file_path = test_output_path / "hdf5-test-write-LinearTransform.h5" -from .fixtures import emscripten_package_wheel, package_wheel, input_data - -@run_in_pyodide(packages=['micropip']) -async def test_hdf5_write_transform(selenium, package_wheel, emscripten_package_wheel): - import micropip - await micropip.install(emscripten_package_wheel) - await micropip.install(package_wheel) - - from itkwasm_transform_io import hdf5_write_transform - - # Write your test code here +def test_hdf5_write_transform(): + could_read, transform_list = hdf5_read_transform(test_input_file_path) + assert could_read + could_write = hdf5_write_transform(transform_list, test_output_file_path) + assert could_write + could_read, transform_list = hdf5_read_transform(test_output_file_path) + verify_test_linear_transform(transform_list) diff --git a/packages/transform-io/python/itkwasm-transform-io/tests/test_read_write_transform.py b/packages/transform-io/python/itkwasm-transform-io/tests/test_read_write_transform.py new file mode 100644 index 000000000..bfd006a7e --- /dev/null +++ b/packages/transform-io/python/itkwasm-transform-io/tests/test_read_write_transform.py @@ -0,0 +1,36 @@ +from itkwasm import IntTypes, FloatTypes +import numpy as np + +from itkwasm_transform_io import read_transform, transformread, write_transform, transformwrite + +from .common import test_input_path, test_output_path, verify_test_linear_transform +verify_transform = verify_test_linear_transform + +test_input_file_path = test_input_path / "LinearTransform.h5" +test_output_file_path = test_output_path / "read-write-LinearTransform.h5" + +def test_read_transform(): + transform = read_transform(test_input_file_path) + verify_transform(transform) + +def test_transformread(): + transform = transformread(test_input_file_path) + verify_transform(transform) + +def test_write_transform(): + transform = read_transform(test_input_file_path) + + use_compression = False + write_transform(transform, test_output_file_path, use_compression=use_compression) + + transform = read_transform(test_output_file_path) + verify_transform(transform) + +def test_transformwrite(): + transform = transformread(test_input_file_path) + + use_compression = False + transformwrite(transform, test_output_file_path, use_compression=use_compression) + + transform = transformread(test_output_file_path) + verify_transform(transform) diff --git a/packages/transform-io/python/itkwasm-transform-io/tests/test_read_write_transform_async.py b/packages/transform-io/python/itkwasm-transform-io/tests/test_read_write_transform_async.py new file mode 100644 index 000000000..4cd1443ce --- /dev/null +++ b/packages/transform-io/python/itkwasm-transform-io/tests/test_read_write_transform_async.py @@ -0,0 +1,59 @@ +import sys + +if sys.version_info < (3,10): + pytest.skip("Skipping pyodide tests on older Python", allow_module_level=True) + +import pytest +from pytest_pyodide import run_in_pyodide +from .fixtures import package_wheel, input_data, emscripten_package_wheel + +@pytest.mark.driver_timeout(30) +@run_in_pyodide(packages=['micropip', 'numpy']) +async def test_read_write_mesh_async(selenium, package_wheel, emscripten_package_wheel, input_data): + import micropip + await micropip.install(emscripten_package_wheel) + await micropip.install(package_wheel) + def write_input_data_to_fs(input_data, filename): + with open(filename, 'wb') as fp: + fp.write(input_data[filename]) + + from pathlib import Path + + from itkwasm import TransformParameterizations, FloatTypes + import numpy as np + + from itkwasm_transform_io import read_transform_async, write_transform_async + + def write_input_data_to_fs(input_data, filename): + with open(filename, 'wb') as fp: + fp.write(input_data[filename]) + + def verify_test_linear_transform(transform_list): + assert len(transform_list) == 1 + transform = transform_list[0] + assert transform.transformType.transformParameterization == TransformParameterizations.Affine + assert transform.transformType.parametersValueType == FloatTypes.Float64 + assert transform.numberOfParameters == 12 + assert transform.numberOfFixedParameters == 3 + np.testing.assert_allclose(transform.fixedParameters, np.array([0.0, 0.0, 0.0])) + np.testing.assert_allclose(transform.parameters, np.array([ + 0.65631490118447, 0.5806583745824385, -0.4817536741017158, + -0.7407986817430222, 0.37486398378429736, -0.5573995934598175, + -0.14306664045479867, 0.7227121458012518, 0.676179776908723, + -65.99999999999997, 69.00000000000004, 32.000000000000036])) + + test_file_path = 'LinearTransform.h5' + write_input_data_to_fs(input_data, test_file_path) + + assert Path(test_file_path).exists() + + transform = await read_transform_async(test_file_path) + verify_test_linear_transform(transform) + + test_output_file_path = 'out-LinearTransform.h5' + + use_compression = False + await write_transform_async(transform, test_output_file_path, use_compression) + + transform = await read_transform_async(test_output_file_path) + verify_test_linear_transform(transform)