Skip to content

Commit

Permalink
[python] Add implementation of the MultiscaleImage to main (#3112)
Browse files Browse the repository at this point in the history
Add the Python implementation of the `MultiscaleImage` class.
---------

Co-authored-by: nguyenv <vivian@tiledb.com>
  • Loading branch information
jp-dark and nguyenv authored Oct 2, 2024
1 parent eb89c31 commit 2dab4e9
Show file tree
Hide file tree
Showing 11 changed files with 690 additions and 44 deletions.
2 changes: 2 additions & 0 deletions apis/python/src/tiledbsoma/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@
)
from ._indexer import IntIndexer, tiledbsoma_build_index
from ._measurement import Measurement
from ._multiscale_image import MultiscaleImage
from ._point_cloud_dataframe import PointCloudDataFrame
from ._sparse_nd_array import SparseNDArray, SparseNDArrayRead
from .options import SOMATileDBContext, TileDBCreateOptions, TileDBWriteOptions
Expand Down Expand Up @@ -209,6 +210,7 @@
"get_storage_engine",
"IntIndexer",
"Measurement",
"MultiscaleImage",
"NotCreateableError",
"open",
"PointCloudDataFrame",
Expand Down
24 changes: 24 additions & 0 deletions apis/python/src/tiledbsoma/_arrow_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,23 @@
pa.timestamp("ns"): "tsn:",
}

_CARROW_TO_PYARROW: Dict[pa.DataType, str] = {
"c": pa.int8(),
"s": pa.int16(),
"i": pa.int32(),
"l": pa.int64(),
"C": pa.uint8(),
"S": pa.uint16(),
"I": pa.uint32(),
"L": pa.uint64(),
"f": pa.float32(),
"g": pa.float64(),
"tss:": pa.timestamp("s"),
"tsm:": pa.timestamp("ms"),
"tsu:": pa.timestamp("us"),
"tsn:": pa.timestamp("ns"),
}

# Same as _ARROW_TO_TDB_ATTR, but used for DataFrame indexed columns, aka TileDB Dimensions.
# Any type system differences from the base-case Attr should be added here.
_ARROW_TO_TDB_DIM: Dict[Any, Union[str, TypeError]] = _ARROW_TO_TDB_ATTR.copy()
Expand Down Expand Up @@ -284,3 +301,10 @@ def pyarrow_to_carrow_type(pa_type: pa.DataType) -> str:
return _PYARROW_TO_CARROW[pa_type]
except KeyError:
raise TypeError(f"Invalid pyarrow type {pa_type}") from None


def carrow_type_to_pyarrow(ca_type: str) -> pa.DataType:
try:
return _CARROW_TO_PYARROW[ca_type]
except KeyError:
raise TypeError(f"Invalid carrrow type {ca_type}") from None
2 changes: 1 addition & 1 deletion apis/python/src/tiledbsoma/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
SOMA_JOINID = "soma_joinid"
SOMA_GEOMETRY = "soma_geometry"
SOMA_COORDINATE_SPACE_METADATA_KEY = "soma_coordinate_space"
SOMA_MULTISCALE_IMAGE_SCHAME = "soma_multiscale_image_schema"
SOMA_MULTISCALE_IMAGE_SCHEMA = "soma_multiscale_image_schema"
SOMA_OBJECT_TYPE_METADATA_KEY = "soma_object_type"
SOMA_ENCODING_VERSION_METADATA_KEY = "soma_encoding_version"
SOMA_ENCODING_VERSION = "1.1.0"
Expand Down
2 changes: 2 additions & 0 deletions apis/python/src/tiledbsoma/_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
_dense_nd_array,
_experiment,
_measurement,
_multiscale_image,
_point_cloud_dataframe,
_soma_object,
_sparse_nd_array,
Expand Down Expand Up @@ -216,6 +217,7 @@ def _type_name_to_cls(type_name: str) -> Type[AnySOMAObject]:
_dense_nd_array.DenseNDArray,
_experiment.Experiment,
_measurement.Measurement,
_multiscale_image.MultiscaleImage,
_sparse_nd_array.SparseNDArray,
_point_cloud_dataframe.PointCloudDataFrame,
)
Expand Down
Loading

0 comments on commit 2dab4e9

Please sign in to comment.