-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Python): Support pipeline stream inputs/outputs
- Loading branch information
Showing
22 changed files
with
397 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,41 @@ | ||
"""itkwasm: Python interface to itk-wasm WebAssembly modules.""" | ||
|
||
__version__ = "1.0b2" | ||
__version__ = "1.0b3" | ||
|
||
from .interface_types import InterfaceTypes | ||
from .image import Image, ImageType | ||
from .mesh import Mesh, MeshType | ||
from .pointset import PointSet, PointSetType | ||
from .mesh import Mesh, MeshType | ||
from .polydata import PolyData, PolyDataType | ||
from .binary_file import BinaryFile | ||
from .binary_stream import BinaryStream | ||
from .text_file import TextFile | ||
from .text_stream import TextStream | ||
from .pipeline import Pipeline | ||
from .pipeline_input import PipelineInput | ||
from .pipeline_output import PipelineOutput | ||
from .float_types import FloatTypes | ||
from .int_types import IntTypes | ||
from .pixel_types import PixelTypes | ||
|
||
__all__ = [ | ||
"InterfaceTypes", | ||
"Pipeline", | ||
"PipelineInput", | ||
"PipelineOutput", | ||
"Image", | ||
"ImageType", | ||
"Mesh", | ||
"MeshType", | ||
"PointSet", | ||
"PointSetType", | ||
"Mesh", | ||
"MeshType", | ||
"PolyData", | ||
"PolyDataType", | ||
"BinaryFile", | ||
"BinaryStream", | ||
"TextFile", | ||
"TextStream", | ||
"FloatTypes", | ||
"IntTypes", | ||
"PixelTypes", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from dataclasses import dataclass | ||
|
||
@dataclass | ||
class BinaryFile: | ||
data: bytes | ||
path: str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from dataclasses import dataclass | ||
|
||
@dataclass | ||
class BinaryStream: | ||
data: bytes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from enum import Enum | ||
|
||
class FloatTypes(str, Enum): | ||
Float32 = 'float32' | ||
Float64 = 'float64' | ||
SpacePrecisionType = 'float64' | ||
|
||
def __str__(self): | ||
return str(self.value) | ||
|
||
def __repr__(self): | ||
return f'"{str(self.value)}"' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,49 @@ | ||
from dataclasses import dataclass | ||
from dataclasses import dataclass, field | ||
|
||
from typing import Sequence | ||
from typing import Sequence, Union, Dict, Optional | ||
|
||
try: | ||
from numpy.typing import ArrayLike | ||
except ImportError: | ||
from numpy import ndarray as ArrayLike | ||
import numpy as np | ||
|
||
from .int_types import IntTypes | ||
from .float_types import FloatTypes | ||
from .pixel_types import PixelTypes | ||
|
||
@dataclass | ||
class ImageType: | ||
dimension: int | ||
componentType: str | ||
pixelType: str | ||
components: int | ||
dimension: int = 2 | ||
componentType: Union[IntTypes, FloatTypes] = IntTypes.UInt8 | ||
pixelType: PixelTypes = PixelTypes.Scalar | ||
components: int = 1 | ||
|
||
@dataclass | ||
class Image: | ||
imageType: ImageType | ||
data: ArrayLike | ||
size: Sequence[int] | ||
origin: Sequence[float] | ||
spacing: Sequence[float] | ||
direction: ArrayLike | ||
name: str | ||
imageType: Union[ImageType, Dict] = ImageType() | ||
name: str = 'image' | ||
origin: Sequence[float] = field(default_factory=list) | ||
spacing: Sequence[float] = field(default_factory=list) | ||
direction: ArrayLike = np.empty((0,), np.float32) | ||
size: Sequence[int] = field(default_factory=list) | ||
metadata: Dict = field(default_factory=dict) | ||
data: Optional[ArrayLike] = None | ||
|
||
def __post_init__(self): | ||
if isinstance(self.imageType, dict): | ||
self.imageType = ImageType(**self.imageType) | ||
|
||
dimension = self.imageType.dimension | ||
if len(self.origin) == 0: | ||
self.origin += [0.0,] * dimension | ||
|
||
if len(self.spacing) == 0: | ||
self.spacing += [1.0,] * dimension | ||
|
||
if len(self.direction) == 0: | ||
self.direction = np.eye(dimension).astype(np.float32).ravel() | ||
|
||
if len(self.size) == 0: | ||
self.size += [1,] * dimension | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from enum import Enum | ||
|
||
class IntTypes(str, Enum): | ||
Int8 = 'int8' | ||
UInt8 = 'uint8' | ||
Int16 = 'int16' | ||
UInt16 = 'uint16' | ||
Int32 = 'int32' | ||
UInt32 = 'uint32' | ||
Int64 = 'int64' | ||
UInt64 = 'uint64' | ||
|
||
SizeValueType = 'uint64' | ||
IdentifierType = 'uint64' | ||
IndexValueType = 'int64' | ||
OffsetValueType = 'int64' | ||
|
||
def __str__(self): | ||
return str(self.value) | ||
|
||
def __repr__(self): | ||
return f'"{str(self.value)}"' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from enum import Enum | ||
|
||
class InterfaceTypes(Enum): | ||
TextFile = 'InterfaceTextFile' | ||
BinaryFile = 'InterfaceBinaryFile' | ||
TextStream = 'InterfaceTextStream' | ||
BinaryStream = 'InterfaceBinaryStream' | ||
Image = 'InterfaceImage' | ||
Mesh = 'InterfaceMesh' | ||
PolyData = 'InterfacePolyData' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,50 @@ | ||
from dataclasses import dataclass | ||
|
||
from typing import Optional | ||
from typing import Optional, Union, Dict | ||
|
||
try: | ||
from numpy.typing import ArrayLike | ||
except ImportError: | ||
from numpy import ndarray as ArrayLike | ||
|
||
from .float_types import FloatTypes | ||
from .int_types import IntTypes | ||
from .pixel_types import PixelTypes | ||
|
||
@dataclass | ||
class MeshType: | ||
dimension: int | ||
dimension: int = 2 | ||
|
||
pointComponentType: str | ||
pointPixelComponentType: str | ||
pointPixelType: str | ||
pointPixelComponents: int | ||
pointComponentType: Union[IntTypes, FloatTypes] = FloatTypes.Float32 | ||
pointPixelComponentType: Union[IntTypes, FloatTypes] = FloatTypes.Float32 | ||
pointPixelType: PixelTypes = PixelTypes.Scalar | ||
pointPixelComponents: int = 1 | ||
|
||
cellComponentType: str | ||
cellPixelComponentType: str | ||
cellPixelType: str | ||
cellPixelComponents: int | ||
cellComponentType: Union[IntTypes, FloatTypes] = IntTypes.Int32 | ||
cellPixelComponentType: Union[IntTypes, FloatTypes] = FloatTypes.Float32 | ||
cellPixelType: PixelTypes = PixelTypes.Scalar | ||
cellPixelComponents: int = 1 | ||
|
||
|
||
@dataclass | ||
class Mesh: | ||
meshType: MeshType | ||
meshType: Union[MeshType, Dict] = MeshType() | ||
|
||
name: str = 'mesh' | ||
|
||
name: str | ||
numberOfPoints: int = 0 | ||
points: Optional[ArrayLike] = None | ||
|
||
numberOfPoints: int | ||
points: Optional[ArrayLike] | ||
numberOfPointPixels: int = 0 | ||
pointData: Optional[ArrayLike] = None | ||
|
||
numberOfPointPixels: int | ||
pointData: Optional[ArrayLike] | ||
numberOfCells: int = 0 | ||
cells: Optional[ArrayLike] = None | ||
cellBufferSize: int = 0 | ||
|
||
numberOfCells: int | ||
cells: Optional[ArrayLike] | ||
cellBufferSize: int | ||
numberOfCellPixels: int = 0 | ||
cellData: Optional[ArrayLike] = None | ||
|
||
numberOfCellPixels: int | ||
cellData: Optional[ArrayLike] | ||
def __post_init__(self): | ||
if isinstance(self.meshType, dict): | ||
self.meshType = MeshType(**self.meshType) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from dataclasses import dataclass | ||
from typing import Optional, Union | ||
|
||
from .interface_types import InterfaceTypes | ||
from .text_file import TextFile | ||
from .text_stream import TextStream | ||
from .binary_file import BinaryFile | ||
from .binary_stream import BinaryStream | ||
from .image import Image | ||
from .mesh import Mesh | ||
from .polydata import PolyData | ||
|
||
@dataclass | ||
class PipelineInput: | ||
type: InterfaceTypes | ||
data: Union[str, bytes, TextStream, BinaryStream, TextFile, BinaryFile, Image, Mesh, PolyData] | ||
path: Optional[str] = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from dataclasses import dataclass | ||
from typing import Optional, Union | ||
|
||
from .interface_types import InterfaceTypes | ||
from .text_file import TextFile | ||
from .text_stream import TextStream | ||
from .binary_file import BinaryFile | ||
from .binary_stream import BinaryStream | ||
from .image import Image | ||
from .mesh import Mesh | ||
from .polydata import PolyData | ||
|
||
@dataclass | ||
class PipelineOutput: | ||
type: InterfaceTypes | ||
data: Optional[Union[str, bytes, TextStream, BinaryStream, TextFile, BinaryFile, Image, Mesh, PolyData]] = None | ||
path: Optional[str] = None |
Oops, something went wrong.