Skip to content

Commit 5da0330

Browse files
committed
TileDB Carrara URIs and add memberships
1 parent d505bf9 commit 5da0330

4 files changed

Lines changed: 61 additions & 4 deletions

File tree

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"scikit-image",
2222
"jsonpickle",
2323
"requires",
24+
"urllib3>=2.0",
2425
],
2526
extras_require={
2627
"zarr": zarr,

tiledb/bioimg/helpers.py

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
from . import ATTR_NAME
3030
from .converters.axes import Axes, AxesMapper
31+
from .types import DataProtocol
3132
from .version import version_tuple
3233

3334
SUPPORTED_PROTOCOLS = ("s3://", "gcs://", "azure://")
@@ -71,6 +72,53 @@ def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
7172
self.w_group.close()
7273
self.m_group.close()
7374

75+
def data_protocol(self, uri: str) -> DataProtocol:
76+
"""Return the data protocol in use for this URI and context.
77+
78+
Return value will be a data model identifier. Currently one of:
79+
* `tiledbv2` - the legacy data model, supported on all storage platforms except Carrara
80+
* `tiledbv3` - the new, and currently Carrara-specific, data model.
81+
82+
Args:
83+
uri:
84+
An object URI
85+
86+
Returns:
87+
The protocol identifier, currently one of `tiledbv2` or `tiledbv3`
88+
---
89+
90+
IMPORTANT: the API signature may change slightly in the near future
91+
to align with TileDB-Py.
92+
93+
In addition, the implementation will evolve to use a new Core API.
94+
"""
95+
if not uri.startswith("tiledb://"):
96+
return "tiledbv2"
97+
98+
# The original, absolute-only, URIs had the format:
99+
# tiledb://ORG/UUID
100+
# The new URIs are:
101+
# tiledb://WORKSPACE/TEAMSPACE/optional-path-elements/
102+
# The current methodology to distinguish between these is to look at the run-time
103+
# environment, and determine if we are running on Cloud or Carrara.
104+
#
105+
# NB: this method will change shortly to use a new Core API.
106+
107+
CLOUD_DEPLOYMENTS = {"https://api.carrara.com", "https://api.staging.tiledb.io"}
108+
if self._ctx:
109+
if self._ctx.config()["rest.server_address"] in CLOUD_DEPLOYMENTS:
110+
return "tiledbv3"
111+
112+
return "tiledbv2"
113+
114+
def is_tiledbv2_uri(self, uri: str) -> bool:
115+
"""Return True if the URI will use `tiledbv2` semantics."""
116+
return self.data_protocol(uri) == "tiledbv2"
117+
118+
def is_tiledbv3_uri(self, uri: str) -> bool:
119+
"""Return True if the URI will use `tiledbv3` semantics."""
120+
return self.data_protocol(uri) == "tiledbv3"
121+
74122
def get_or_create(self, name: str, schema: tiledb.ArraySchema) -> Tuple[str, bool]:
75123
create = False
76124
if name in self.r_group:
@@ -100,10 +148,15 @@ def get_or_create(self, name: str, schema: tiledb.ArraySchema) -> Tuple[str, boo
100148
# (to allow the add operation)
101149
self.w_group.close()
102150
self.w_group.open("w")
103-
# register the uri with the given name
104-
if self._is_cloud:
151+
if self.is_tiledbv3_uri(uri):
152+
self.w_group.add(uri, name=uri, relative=True)
153+
154+
# In tiledbv3 mode, the array is created with the uri==name and relative=True and registered to the group as a member with the given name from the uri.
155+
# so we don't need to add it to the group manually.
156+
if self.is_tiledbv2_uri(uri):
157+
# register the uri with the given name
105158
self.w_group.add(uri, name, relative=False)
106-
else:
159+
if not self._is_cloud:
107160
self.w_group.add(name, name, relative=True)
108161
return uri, create
109162

tiledb/bioimg/types.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import enum
2+
from typing import Literal
23

34

45
class Converters(enum.Enum):
56
OMETIFF = enum.auto()
67
OMEZARR = enum.auto()
78
OSD = enum.auto()
89
PNG = enum.auto()
10+
11+
12+
DataProtocol = Literal["tiledbv2", "tiledbv3"]

tiledb/bioimg/wrappers.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ def from_bioimg(
107107
else:
108108
raise _osd_exc
109109
else:
110-
111110
logger.info("Converting PNG")
112111
return converters["png_converter"].to_tiledb(
113112
source=src,

0 commit comments

Comments
 (0)