class tensorstore.TensorStore

Asynchronous multi-dimensional array handle.

Examples

>>> dataset = await ts.open(
...     {
...         'driver': 'zarr',
...         'kvstore': {
...             'driver': 'memory'
...         },
...     },
...     dtype=ts.uint32,
...     shape=[1000, 20000],
...     create=True)
>>> dataset
TensorStore({
  'context': {
    'cache_pool': {},
    'data_copy_concurrency': {},
    'memory_key_value_store': {},
  },
  'driver': 'zarr',
  'dtype': 'uint32',
  'kvstore': {'driver': 'memory'},
  'metadata': {
    'chunks': [1000, 1048],
    'compressor': {
      'blocksize': 0,
      'clevel': 5,
      'cname': 'lz4',
      'id': 'blosc',
      'shuffle': -1,
    },
    'dimension_separator': '.',
    'dtype': '<u4',
    'fill_value': None,
    'filters': None,
    'order': 'C',
    'shape': [1000, 20000],
    'zarr_format': 2,
  },
  'transform': {
    'input_exclusive_max': [[1000], [20000]],
    'input_inclusive_min': [0, 0],
  },
})
>>> await dataset[5:10, 6:8].write(42)
>>> await dataset[0:10, 0:10].read()
array([[ 0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
       [ 0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
       [ 0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
       [ 0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
       [ 0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
       [ 0,  0,  0,  0,  0,  0, 42, 42,  0,  0],
       [ 0,  0,  0,  0,  0,  0, 42, 42,  0,  0],
       [ 0,  0,  0,  0,  0,  0, 42, 42,  0,  0],
       [ 0,  0,  0,  0,  0,  0, 42, 42,  0,  0],
       [ 0,  0,  0,  0,  0,  0, 42, 42,  0,  0]], dtype=uint32)

I/O

class StorageStatistics

Statistics related to the storage of an array specified by a TensorStore.

read(order: 'C' | 'F' = 'C') Future[ArrayLike]

Reads the data within the current domain.

write(source: TensorStore | ArrayLike) WriteFutures

Writes to the current domain.

resize(...) Future[TensorStore]

Resizes the current domain, persistently modifying the stored representation.

__array__(dtype: numpy.dtype | None = None, ...) ArrayLike

Automatic conversion to numpy.ndarray for interoperability with NumPy.

resolve(fix_resizable_bounds: bool = False) Future[TensorStore]

Obtains updated bounds, subject to the cache policy.

__setitem__(transform: IndexTransform, source) None

Synchronously writes using an explicit index transform.

__setitem__(transform: IndexDomain, source) None

Synchronously writes using an explicit index domain.

__setitem__(transform: DimExpression, source) None

Synchronously writes using a dimension expression.

__setitem__(indices: NumpyIndexingSpec, source) None

Synchronously writes using NumPy-style indexing with default index array semantics.

oindex.__setitem__(indices: NumpyIndexingSpec, source)

Synchronously writes using NumPy-style indexing with outer indexing semantics.

vindex.__setitem__(indices: NumpyIndexingSpec, source)

Synchronously writes using NumPy-style indexing with vectorized indexing semantics.

storage_statistics(*, ...) Future[TensorStore.StorageStatistics]

Obtains statistics of the data stored for the domain.

Accessors

rank : int

Number of dimensions in the domain.

ndim : int

Alias for rank.

domain : IndexDomain

Domain of the array.

spec(*, open_mode: OpenMode | None = None, ...) Spec

Spec that may be used to re-open or re-create the TensorStore.

mode : str

Read/write mode.

readable : bool

Indicates if reading is supported.

writable : bool

Indicates if writing is supported.

chunk_layout : ChunkLayout

Chunk layout of the TensorStore.

codec : CodecSpec | None

Data codec spec.

fill_value : ArrayLike | None

Fill value for positions not yet written.

dimension_units : tuple[Unit | None, ...]

Physical units of each dimension of the domain.

kvstore : KvStore | None

Associated key-value store used as the underlying storage.

base : TensorStore | None

Underlying TensorStore, if this is an adapter.

schema : Schema

Schema of this TensorStore.

origin : tuple[int, ...]

Inclusive lower bound of the domain.

shape : tuple[int, ...]

Shape of the domain.

size : int

Total number of elements in the domain.

Data type

dtype : dtype

Data type of the array.

astype(dtype: dtype) TensorStore

Returns a read/write view as the specified data type.

Transactions

transaction : Transaction | None

Associated transaction used for read/write operations.

with_transaction(transaction: Transaction | None) TensorStore

Returns a transaction-bound view of this TensorStore.

Indexing

__getitem__(transform: IndexTransform) TensorStore

Computes a virtual view using an explicit index transform.

__getitem__(domain: IndexDomain) TensorStore

Computes a virtual view using an explicit index domain.

__getitem__(expr: DimExpression) TensorStore

Computes a virtual view using a dimension expression.

__getitem__(indices: NumpyIndexingSpec) TensorStore

Computes a virtual view using NumPy-style indexing with default index array semantics.

oindex[indices: NumpyIndexingSpec] TensorStore

Computes a virtual view using NumPy-style indexing with outer indexing semantics.

vindex[indices: NumpyIndexingSpec] TensorStore

Computes a virtual view using NumPy-style indexing with vectorized indexing semantics.

T : TensorStore

View with transposed domain (reversed dimension order).

translate_to[origins] TensorStore

Returns a new view with origin translated to the specified origin.

translate_by[offsets] TensorStore

Returns a new view with the origin translated by the specified offsets.

translate_backward_by[offsets] TensorStore

Returns a new view with the origin translated backward by the specified offsets.

label[labels: str | Sequence[str]] TensorStore

Returns a new view with the dimension labels changed.

mark_bounds_implicit[implicit: bool | None | slice] TensorStore

Returns a new view with the lower/upper bounds changed to implicit/explicit.

transpose(axes: DimSelectionLike | None = None) TensorStore

Returns a view with a transposed domain.