Skip to content

Commit

Permalink
chore(transform-io): add generated python
Browse files Browse the repository at this point in the history
  • Loading branch information
thewtex committed Oct 30, 2024
1 parent d47d1e0 commit 397634d
Show file tree
Hide file tree
Showing 95 changed files with 3,111 additions and 1 deletion.
1 change: 0 additions & 1 deletion packages/transform-io/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
test/
emscripten-build/
python/
wasi-build/
typescript/dist
typescript/src/version.ts
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# itkwasm-transform-io-emscripten

[![PyPI version](https://badge.fury.io/py/itkwasm-transform-io-emscripten.svg)](https://badge.fury.io/py/itkwasm-transform-io-emscripten)

Input and output for scientific and medical coordinate transform file formats. Emscripten implementation.

This package provides the Emscripten WebAssembly implementation. It is usually not called directly. Please use the [`itkwasm-transform-io`](https://pypi.org/project/itkwasm-transform-io/) instead.


## Installation

```sh
import micropip
await micropip.install('itkwasm-transform-io-emscripten')
```

## Development

```sh
pip install hatch
hatch run download-pyodide
hatch run test
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated file. To retain edits, remove this comment.

"""itkwasm-transform-io-emscripten: Input and output for scientific and medical coordinate transform file formats. Emscripten implementation."""

from .hdf5_read_transform_async import hdf5_read_transform_async
from .hdf5_write_transform_async import hdf5_write_transform_async
from .mat_read_transform_async import mat_read_transform_async
from .mat_write_transform_async import mat_write_transform_async
from .mnc_read_transform_async import mnc_read_transform_async
from .mnc_write_transform_async import mnc_write_transform_async
from .txt_read_transform_async import txt_read_transform_async
from .txt_write_transform_async import txt_write_transform_async
from .wasm_read_transform_async import wasm_read_transform_async
from .wasm_write_transform_async import wasm_write_transform_async
from .wasm_zstd_read_transform_async import wasm_zstd_read_transform_async
from .wasm_zstd_write_transform_async import wasm_zstd_write_transform_async

from ._version import __version__
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.1.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Generated file. To retain edits, remove this comment.

from pathlib import Path
import os
from typing import Dict, Tuple, Optional, List, Any

from .js_package import js_package

from itkwasm.pyodide import (
to_js,
to_py,
js_resources
)
from itkwasm import (
InterfaceTypes,
BinaryFile,
Transform,
)

async def hdf5_read_transform_async(
serialized_transform: os.PathLike,
float_parameters: bool = False,
) -> Tuple[Any, Transform]:
"""Read an transform file format and convert it to the ITK-Wasm transform 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: Whether the input could be read. If false, the output transform is not valid.
:rtype: Any
:return: Output transform
:rtype: Transform
"""
js_module = await js_package.js_module
web_worker = js_resources.web_worker

kwargs = {}
if float_parameters:
kwargs["floatParameters"] = to_js(float_parameters)

outputs = await js_module.hdf5ReadTransform(to_js(BinaryFile(serialized_transform)), webWorker=web_worker, noCopy=True, **kwargs)

output_web_worker = None
output_list = []
outputs_object_map = outputs.as_object_map()
for output_name in outputs.object_keys():
if output_name == 'webWorker':
output_web_worker = outputs_object_map[output_name]
else:
output_list.append(to_py(outputs_object_map[output_name]))

js_resources.web_worker = output_web_worker

if len(output_list) == 1:
return output_list[0]
return tuple(output_list)
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Generated file. To retain edits, remove this comment.

from pathlib import Path
import os
from typing import Dict, Tuple, Optional, List, Any

from .js_package import js_package

from itkwasm.pyodide import (
to_js,
to_py,
js_resources
)
from itkwasm import (
InterfaceTypes,
Transform,
BinaryFile,
)

async def hdf5_write_transform_async(
transform: Transform,
serialized_transform: str,
float_parameters: bool = False,
use_compression: bool = False,
) -> Tuple[Any]:
"""Write an ITK-Wasm transform file format converted to a transform file format
:param transform: Input transform
:type transform: Transform
: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
:return: Whether the input could be written. If false, the output transform is not valid.
:rtype: Any
"""
js_module = await js_package.js_module
web_worker = js_resources.web_worker

kwargs = {}
if float_parameters:
kwargs["floatParameters"] = to_js(float_parameters)
if use_compression:
kwargs["useCompression"] = to_js(use_compression)

outputs = await js_module.hdf5WriteTransform(to_js(transform), to_js(serialized_transform), webWorker=web_worker, noCopy=True, **kwargs)

output_web_worker = None
output_list = []
outputs_object_map = outputs.as_object_map()
for output_name in outputs.object_keys():
if output_name == 'webWorker':
output_web_worker = outputs_object_map[output_name]
else:
output_list.append(to_py(outputs_object_map[output_name]))

js_resources.web_worker = output_web_worker

if len(output_list) == 1:
return output_list[0]
return tuple(output_list)

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Generated file. To retain edits, remove this comment.

from pathlib import Path
import os
from typing import Dict, Tuple, Optional, List, Any

from .js_package import js_package

from itkwasm.pyodide import (
to_js,
to_py,
js_resources
)
from itkwasm import (
InterfaceTypes,
BinaryFile,
Transform,
)

async def mat_read_transform_async(
serialized_transform: os.PathLike,
float_parameters: bool = False,
) -> Tuple[Any, Transform]:
"""Read an transform file format and convert it to the ITK-Wasm transform 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: Whether the input could be read. If false, the output transform is not valid.
:rtype: Any
:return: Output transform
:rtype: Transform
"""
js_module = await js_package.js_module
web_worker = js_resources.web_worker

kwargs = {}
if float_parameters:
kwargs["floatParameters"] = to_js(float_parameters)

outputs = await js_module.matReadTransform(to_js(BinaryFile(serialized_transform)), webWorker=web_worker, noCopy=True, **kwargs)

output_web_worker = None
output_list = []
outputs_object_map = outputs.as_object_map()
for output_name in outputs.object_keys():
if output_name == 'webWorker':
output_web_worker = outputs_object_map[output_name]
else:
output_list.append(to_py(outputs_object_map[output_name]))

js_resources.web_worker = output_web_worker

if len(output_list) == 1:
return output_list[0]
return tuple(output_list)
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Generated file. To retain edits, remove this comment.

from pathlib import Path
import os
from typing import Dict, Tuple, Optional, List, Any

from .js_package import js_package

from itkwasm.pyodide import (
to_js,
to_py,
js_resources
)
from itkwasm import (
InterfaceTypes,
Transform,
BinaryFile,
)

async def mat_write_transform_async(
transform: Transform,
serialized_transform: str,
float_parameters: bool = False,
use_compression: bool = False,
) -> Tuple[Any]:
"""Write an ITK-Wasm transform file format converted to a transform file format
:param transform: Input transform
:type transform: Transform
: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
:return: Whether the input could be written. If false, the output transform is not valid.
:rtype: Any
"""
js_module = await js_package.js_module
web_worker = js_resources.web_worker

kwargs = {}
if float_parameters:
kwargs["floatParameters"] = to_js(float_parameters)
if use_compression:
kwargs["useCompression"] = to_js(use_compression)

outputs = await js_module.matWriteTransform(to_js(transform), to_js(serialized_transform), webWorker=web_worker, noCopy=True, **kwargs)

output_web_worker = None
output_list = []
outputs_object_map = outputs.as_object_map()
for output_name in outputs.object_keys():
if output_name == 'webWorker':
output_web_worker = outputs_object_map[output_name]
else:
output_list.append(to_py(outputs_object_map[output_name]))

js_resources.web_worker = output_web_worker

if len(output_list) == 1:
return output_list[0]
return tuple(output_list)
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Generated file. To retain edits, remove this comment.

from pathlib import Path
import os
from typing import Dict, Tuple, Optional, List, Any

from .js_package import js_package

from itkwasm.pyodide import (
to_js,
to_py,
js_resources
)
from itkwasm import (
InterfaceTypes,
BinaryFile,
Transform,
)

async def mnc_read_transform_async(
serialized_transform: os.PathLike,
float_parameters: bool = False,
) -> Tuple[Any, Transform]:
"""Read an transform file format and convert it to the ITK-Wasm transform 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: Whether the input could be read. If false, the output transform is not valid.
:rtype: Any
:return: Output transform
:rtype: Transform
"""
js_module = await js_package.js_module
web_worker = js_resources.web_worker

kwargs = {}
if float_parameters:
kwargs["floatParameters"] = to_js(float_parameters)

outputs = await js_module.mncReadTransform(to_js(BinaryFile(serialized_transform)), webWorker=web_worker, noCopy=True, **kwargs)

output_web_worker = None
output_list = []
outputs_object_map = outputs.as_object_map()
for output_name in outputs.object_keys():
if output_name == 'webWorker':
output_web_worker = outputs_object_map[output_name]
else:
output_list.append(to_py(outputs_object_map[output_name]))

js_resources.web_worker = output_web_worker

if len(output_list) == 1:
return output_list[0]
return tuple(output_list)
Loading

0 comments on commit 397634d

Please sign in to comment.