@fideus-labs/ngff-zarr 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/LICENSE +10 -0
  2. package/README.md +73 -0
  3. package/esm/_dnt.shims.d.ts +2 -0
  4. package/esm/_dnt.shims.d.ts.map +1 -0
  5. package/esm/_dnt.shims.js +57 -0
  6. package/esm/io/from_ngff_zarr.d.ts +7 -0
  7. package/esm/io/from_ngff_zarr.d.ts.map +1 -0
  8. package/esm/io/from_ngff_zarr.js +140 -0
  9. package/esm/io/to_ngff_zarr.d.ts +9 -0
  10. package/esm/io/to_ngff_zarr.d.ts.map +1 -0
  11. package/esm/io/to_ngff_zarr.js +57 -0
  12. package/esm/mod.d.ts +17 -0
  13. package/esm/mod.d.ts.map +1 -0
  14. package/esm/mod.js +16 -0
  15. package/esm/package.json +3 -0
  16. package/esm/schemas/lazy_array.d.ts +8 -0
  17. package/esm/schemas/lazy_array.d.ts.map +1 -0
  18. package/esm/schemas/lazy_array.js +7 -0
  19. package/esm/schemas/methods.d.ts +3 -0
  20. package/esm/schemas/methods.d.ts.map +1 -0
  21. package/esm/schemas/methods.js +6 -0
  22. package/esm/schemas/multiscales.d.ts +4 -0
  23. package/esm/schemas/multiscales.d.ts.map +1 -0
  24. package/esm/schemas/multiscales.js +19 -0
  25. package/esm/schemas/ngff_image.d.ts +13 -0
  26. package/esm/schemas/ngff_image.d.ts.map +1 -0
  27. package/esm/schemas/ngff_image.js +12 -0
  28. package/esm/schemas/units.d.ts +13 -0
  29. package/esm/schemas/units.d.ts.map +1 -0
  30. package/esm/schemas/units.js +75 -0
  31. package/esm/schemas/zarr_metadata.d.ts +49 -0
  32. package/esm/schemas/zarr_metadata.d.ts.map +1 -0
  33. package/esm/schemas/zarr_metadata.js +47 -0
  34. package/esm/types/lazy_array.d.ts +18 -0
  35. package/esm/types/lazy_array.d.ts.map +1 -0
  36. package/esm/types/lazy_array.js +27 -0
  37. package/esm/types/methods.d.ts +7 -0
  38. package/esm/types/methods.d.ts.map +1 -0
  39. package/esm/types/methods.js +7 -0
  40. package/esm/types/multiscales.d.ts +21 -0
  41. package/esm/types/multiscales.d.ts.map +1 -0
  42. package/esm/types/multiscales.js +34 -0
  43. package/esm/types/ngff_image.d.ts +24 -0
  44. package/esm/types/ngff_image.d.ts.map +1 -0
  45. package/esm/types/ngff_image.js +32 -0
  46. package/esm/types/units.d.ts +12 -0
  47. package/esm/types/units.d.ts.map +1 -0
  48. package/esm/types/units.js +61 -0
  49. package/esm/types/zarr_metadata.d.ts +49 -0
  50. package/esm/types/zarr_metadata.d.ts.map +1 -0
  51. package/esm/types/zarr_metadata.js +14 -0
  52. package/esm/utils/factory.d.ts +13 -0
  53. package/esm/utils/factory.d.ts.map +1 -0
  54. package/esm/utils/factory.js +67 -0
  55. package/esm/utils/validation.d.ts +6 -0
  56. package/esm/utils/validation.d.ts.map +1 -0
  57. package/esm/utils/validation.js +72 -0
  58. package/package.json +47 -0
  59. package/script/_dnt.shims.d.ts +2 -0
  60. package/script/_dnt.shims.d.ts.map +1 -0
  61. package/script/_dnt.shims.js +60 -0
  62. package/script/io/from_ngff_zarr.d.ts +7 -0
  63. package/script/io/from_ngff_zarr.d.ts.map +1 -0
  64. package/script/io/from_ngff_zarr.js +167 -0
  65. package/script/io/to_ngff_zarr.d.ts +9 -0
  66. package/script/io/to_ngff_zarr.d.ts.map +1 -0
  67. package/script/io/to_ngff_zarr.js +83 -0
  68. package/script/mod.d.ts +17 -0
  69. package/script/mod.d.ts.map +1 -0
  70. package/script/mod.js +41 -0
  71. package/script/package.json +3 -0
  72. package/script/schemas/lazy_array.d.ts +8 -0
  73. package/script/schemas/lazy_array.d.ts.map +1 -0
  74. package/script/schemas/lazy_array.js +10 -0
  75. package/script/schemas/methods.d.ts +3 -0
  76. package/script/schemas/methods.d.ts.map +1 -0
  77. package/script/schemas/methods.js +9 -0
  78. package/script/schemas/multiscales.d.ts +4 -0
  79. package/script/schemas/multiscales.d.ts.map +1 -0
  80. package/script/schemas/multiscales.js +22 -0
  81. package/script/schemas/ngff_image.d.ts +13 -0
  82. package/script/schemas/ngff_image.d.ts.map +1 -0
  83. package/script/schemas/ngff_image.js +15 -0
  84. package/script/schemas/units.d.ts +13 -0
  85. package/script/schemas/units.d.ts.map +1 -0
  86. package/script/schemas/units.js +78 -0
  87. package/script/schemas/zarr_metadata.d.ts +49 -0
  88. package/script/schemas/zarr_metadata.d.ts.map +1 -0
  89. package/script/schemas/zarr_metadata.js +50 -0
  90. package/script/types/lazy_array.d.ts +18 -0
  91. package/script/types/lazy_array.d.ts.map +1 -0
  92. package/script/types/lazy_array.js +31 -0
  93. package/script/types/methods.d.ts +7 -0
  94. package/script/types/methods.d.ts.map +1 -0
  95. package/script/types/methods.js +10 -0
  96. package/script/types/multiscales.d.ts +21 -0
  97. package/script/types/multiscales.d.ts.map +1 -0
  98. package/script/types/multiscales.js +38 -0
  99. package/script/types/ngff_image.d.ts +24 -0
  100. package/script/types/ngff_image.d.ts.map +1 -0
  101. package/script/types/ngff_image.js +36 -0
  102. package/script/types/units.d.ts +12 -0
  103. package/script/types/units.d.ts.map +1 -0
  104. package/script/types/units.js +66 -0
  105. package/script/types/zarr_metadata.d.ts +49 -0
  106. package/script/types/zarr_metadata.d.ts.map +1 -0
  107. package/script/types/zarr_metadata.js +20 -0
  108. package/script/utils/factory.d.ts +13 -0
  109. package/script/utils/factory.d.ts.map +1 -0
  110. package/script/utils/factory.js +76 -0
  111. package/script/utils/validation.d.ts +6 -0
  112. package/script/utils/validation.d.ts.map +1 -0
  113. package/script/utils/validation.js +78 -0
package/LICENSE ADDED
@@ -0,0 +1,10 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-present Fideus Labs LLC <info@fideus.io>
4
+ Copyright (c) 2022-2024 NumFOCUS <info@numfocus.org>
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7
+
8
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
+
10
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # ngff-zarr
2
+
3
+ [![PyPI - Version](https://img.shields.io/pypi/v/ngff-zarr.svg)](https://pypi.org/project/ngff-zarr)
4
+ [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/ngff-zarr.svg)](https://pypi.org/project/ngff-zarr)
5
+ [![Test](https://github.com/thewtex/ngff-zarr/actions/workflows/pixi-test.yml/badge.svg)](https://github.com/thewtex/ngff-zarr/actions/workflows/pixi-test.yml)
6
+ [![DOI](https://zenodo.org/badge/541840158.svg)](https://zenodo.org/badge/latestdoi/541840158)
7
+ [![Documentation Status](https://readthedocs.org/projects/ngff-zarr/badge/?version=latest)](https://ngff-zarr.readthedocs.io/en/latest/?badge=latest)
8
+
9
+ ---
10
+
11
+ A multi-language implementation of the
12
+ [Open Microscopy Environment (OME) Next Generation File Format (NGFF) Zarr](https://ngff.openmicroscopy.org)
13
+ specification.
14
+
15
+ ## Repository Structure
16
+
17
+ This repository contains multiple packages implementing NGFF-Zarr support:
18
+
19
+ - **[`py/`](./py/)** - Python package (ngff-zarr) - A lean and kind NGFF-Zarr
20
+ implementation
21
+ - **[`mcp/`](./mcp/)** - Model Context Protocol (MCP) server (ngff-zarr-mcp) for
22
+ AI integration
23
+ - **TypeScript package** - Coming soon
24
+
25
+ ## Python Package (`py/`)
26
+
27
+ The main Python package provides:
28
+
29
+ ✨ **Features**
30
+
31
+ - Minimal dependencies
32
+ - Work with arbitrary Zarr store types
33
+ - Lazy, parallel, and web ready -- no local filesystem required
34
+ - Process extremely large datasets
35
+ - Conversion of most bioimaging file formats
36
+ - Multiple downscaling methods
37
+ - Supports Python>=3.9
38
+ - Reads OME-Zarr v0.1 to v0.5 into simple Python data classes with Dask arrays
39
+ - Optional OME-Zarr data model validation during reading
40
+ - Writes OME-Zarr v0.4 to v0.5
41
+ - [Sharded Zarr] stores
42
+ - Optional writing via [tensorstore]
43
+ - **Model Context Protocol (MCP) server** for AI agent integration
44
+
45
+ 📖 **Documentation**
46
+
47
+ More information about command line usage, the Python API, library features, and
48
+ how to contribute can be found in
49
+ [our documentation](https://ngff-zarr.readthedocs.io/).
50
+
51
+ ## MCP Server (`mcp/`)
52
+
53
+ The Model Context Protocol server enables AI assistants like Claude to interact
54
+ with NGFF-Zarr files. See the [MCP documentation](./mcp/README.md) for setup and
55
+ usage instructions.
56
+
57
+ ## See also
58
+
59
+ - [ome-zarr-py](https://github.com/ome/ome-zarr-py)
60
+ - [multiscale-spatial-image](https://github.com/spatial-image/multiscale-spatial-image)
61
+ - [itk-ioomezarrngff](https://github.com/InsightSoftwareConsortium/ITKIOOMEZarrNGFF)
62
+ - [iohub](https://czbiohub-sf.github.io/iohub/)
63
+ - [pydantic-ome-ngff](https://janeliascicomp.github.io/pydantic-ome-ngff/)
64
+ - [aicsimageio](https://allencellmodeling.github.io/aicsimageio/)
65
+ - [bfio](https://bfio.readthedocs.io/)
66
+
67
+ ## License
68
+
69
+ `ngff-zarr` is distributed under the terms of the
70
+ [MIT](https://spdx.org/licenses/MIT.html) license.
71
+
72
+ [Sharded Zarr]: https://zarr.dev/zeps/accepted/ZEP0002.html
73
+ [tensorstore]: https://google.github.io/tensorstore/
@@ -0,0 +1,2 @@
1
+ export declare const dntGlobalThis: Omit<typeof globalThis, never>;
2
+ //# sourceMappingURL=_dnt.shims.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_dnt.shims.d.ts","sourceRoot":"","sources":["../src/_dnt.shims.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,gCAA2C,CAAC"}
@@ -0,0 +1,57 @@
1
+ const dntGlobals = {};
2
+ export const dntGlobalThis = createMergeProxy(globalThis, dntGlobals);
3
+ function createMergeProxy(baseObj, extObj) {
4
+ return new Proxy(baseObj, {
5
+ get(_target, prop, _receiver) {
6
+ if (prop in extObj) {
7
+ return extObj[prop];
8
+ }
9
+ else {
10
+ return baseObj[prop];
11
+ }
12
+ },
13
+ set(_target, prop, value) {
14
+ if (prop in extObj) {
15
+ delete extObj[prop];
16
+ }
17
+ baseObj[prop] = value;
18
+ return true;
19
+ },
20
+ deleteProperty(_target, prop) {
21
+ let success = false;
22
+ if (prop in extObj) {
23
+ delete extObj[prop];
24
+ success = true;
25
+ }
26
+ if (prop in baseObj) {
27
+ delete baseObj[prop];
28
+ success = true;
29
+ }
30
+ return success;
31
+ },
32
+ ownKeys(_target) {
33
+ const baseKeys = Reflect.ownKeys(baseObj);
34
+ const extKeys = Reflect.ownKeys(extObj);
35
+ const extKeysSet = new Set(extKeys);
36
+ return [...baseKeys.filter((k) => !extKeysSet.has(k)), ...extKeys];
37
+ },
38
+ defineProperty(_target, prop, desc) {
39
+ if (prop in extObj) {
40
+ delete extObj[prop];
41
+ }
42
+ Reflect.defineProperty(baseObj, prop, desc);
43
+ return true;
44
+ },
45
+ getOwnPropertyDescriptor(_target, prop) {
46
+ if (prop in extObj) {
47
+ return Reflect.getOwnPropertyDescriptor(extObj, prop);
48
+ }
49
+ else {
50
+ return Reflect.getOwnPropertyDescriptor(baseObj, prop);
51
+ }
52
+ },
53
+ has(_target, prop) {
54
+ return prop in extObj || prop in baseObj;
55
+ },
56
+ });
57
+ }
@@ -0,0 +1,7 @@
1
+ import { Multiscales } from "../types/multiscales.js";
2
+ export interface FromNgffZarrOptions {
3
+ validate?: boolean;
4
+ }
5
+ export declare function fromNgffZarr(storePath: string, options?: FromNgffZarrOptions): Promise<Multiscales>;
6
+ export declare function readArrayData(storePath: string, arrayPath: string, selection?: (number | null)[]): Promise<unknown>;
7
+ //# sourceMappingURL=from_ngff_zarr.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"from_ngff_zarr.d.ts","sourceRoot":"","sources":["../../src/io/from_ngff_zarr.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAOtD,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,wBAAsB,YAAY,CAChC,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,WAAW,CAAC,CAyItB;AAED,wBAAsB,aAAa,CACjC,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,SAAS,CAAC,EAAE,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,GAC5B,OAAO,CAAC,OAAO,CAAC,CAoBlB"}
@@ -0,0 +1,140 @@
1
+ import * as dntShim from "../_dnt.shims.js";
2
+ import * as zarr from "zarrita";
3
+ import { Multiscales } from "../types/multiscales.js";
4
+ import { NgffImage } from "../types/ngff_image.js";
5
+ import { LazyArray } from "../types/lazy_array.js";
6
+ import { MetadataSchema } from "../schemas/zarr_metadata.js";
7
+ export async function fromNgffZarr(storePath, options = {}) {
8
+ const validate = options.validate ?? false;
9
+ try {
10
+ // Determine the appropriate store type based on the path
11
+ let store;
12
+ if (storePath.startsWith("http://") || storePath.startsWith("https://")) {
13
+ // Use FetchStore for HTTP/HTTPS URLs
14
+ store = new zarr.FetchStore(storePath);
15
+ }
16
+ else {
17
+ // For local paths, check if we're in a browser environment
18
+ if (typeof dntShim.dntGlobalThis !== "undefined") {
19
+ throw new Error("Local file paths are not supported in browser environments. Use HTTP/HTTPS URLs instead.");
20
+ }
21
+ // Use dynamic import for FileSystemStore in Node.js/Deno environments
22
+ try {
23
+ const { FileSystemStore } = await import("@zarrita/storage");
24
+ store = new FileSystemStore(storePath);
25
+ }
26
+ catch (error) {
27
+ throw new Error(`Failed to load FileSystemStore: ${error}. Use HTTP/HTTPS URLs for browser compatibility.`);
28
+ }
29
+ }
30
+ const root = zarr.root(store);
31
+ // Try to use consolidated metadata for better performance
32
+ let consolidatedRoot;
33
+ try {
34
+ consolidatedRoot = await zarr.tryWithConsolidated(store);
35
+ }
36
+ catch {
37
+ consolidatedRoot = store;
38
+ }
39
+ const group = await zarr.open.v2(zarr.root(consolidatedRoot), {
40
+ kind: "group",
41
+ });
42
+ const attrs = group.attrs;
43
+ if (!attrs || !attrs.multiscales) {
44
+ throw new Error("No multiscales metadata found in Zarr store");
45
+ }
46
+ const multiscalesArray = attrs
47
+ .multiscales;
48
+ if (!Array.isArray(multiscalesArray) || multiscalesArray.length === 0) {
49
+ throw new Error("No multiscales metadata found in Zarr store");
50
+ }
51
+ const multiscalesMetadata = multiscalesArray[0];
52
+ if (validate) {
53
+ const result = MetadataSchema.safeParse(multiscalesMetadata);
54
+ if (!result.success) {
55
+ throw new Error(`Invalid OME-Zarr metadata: ${result.error.message}`);
56
+ }
57
+ }
58
+ const metadata = multiscalesMetadata;
59
+ // Extract omero metadata from root attributes if present
60
+ if (attrs.omero) {
61
+ metadata.omero = attrs.omero;
62
+ }
63
+ const images = [];
64
+ for (const dataset of metadata.datasets) {
65
+ const arrayPath = dataset.path;
66
+ const zarrArray = await zarr.open.v2(root.resolve(arrayPath), {
67
+ kind: "array",
68
+ });
69
+ const lazyArray = new LazyArray({
70
+ shape: zarrArray.shape,
71
+ dtype: zarrArray.dtype,
72
+ chunks: [zarrArray.chunks],
73
+ name: arrayPath,
74
+ });
75
+ const scale = {};
76
+ const translation = {};
77
+ for (const transform of dataset.coordinateTransformations) {
78
+ if (transform.type === "scale") {
79
+ metadata.axes.forEach((axis, i) => {
80
+ if (i < transform.scale.length) {
81
+ scale[axis.name] = transform.scale[i];
82
+ }
83
+ });
84
+ }
85
+ else if (transform.type === "translation") {
86
+ metadata.axes.forEach((axis, i) => {
87
+ if (i < transform.translation.length) {
88
+ translation[axis.name] = transform.translation[i];
89
+ }
90
+ });
91
+ }
92
+ }
93
+ const dims = metadata.axes.map((axis) => axis.name);
94
+ const axesUnits = metadata.axes.reduce((acc, axis) => {
95
+ if (axis.unit) {
96
+ acc[axis.name] = axis.unit;
97
+ }
98
+ return acc;
99
+ }, {});
100
+ const ngffImage = new NgffImage({
101
+ data: lazyArray,
102
+ dims,
103
+ scale,
104
+ translation,
105
+ name: metadata.name,
106
+ axesUnits: Object.keys(axesUnits).length > 0 ? axesUnits : undefined,
107
+ computedCallbacks: undefined,
108
+ });
109
+ images.push(ngffImage);
110
+ }
111
+ return new Multiscales({
112
+ images,
113
+ metadata,
114
+ scaleFactors: undefined,
115
+ method: undefined,
116
+ chunks: undefined,
117
+ });
118
+ }
119
+ catch (error) {
120
+ throw new Error(`Failed to read OME-Zarr: ${error instanceof Error ? error.message : String(error)}`);
121
+ }
122
+ }
123
+ export async function readArrayData(storePath, arrayPath, selection) {
124
+ try {
125
+ const store = new zarr.FetchStore(storePath);
126
+ const root = zarr.root(store);
127
+ const zarrArray = await zarr.open.v2(root.resolve(arrayPath), {
128
+ kind: "array",
129
+ });
130
+ if (selection) {
131
+ return await zarr.get(zarrArray, selection);
132
+ }
133
+ else {
134
+ return await zarr.get(zarrArray);
135
+ }
136
+ }
137
+ catch (error) {
138
+ throw new Error(`Failed to read array data: ${error instanceof Error ? error.message : String(error)}`);
139
+ }
140
+ }
@@ -0,0 +1,9 @@
1
+ import type { Multiscales } from "../types/multiscales.js";
2
+ export interface ToNgffZarrOptions {
3
+ overwrite?: boolean;
4
+ version?: "0.4" | "0.5";
5
+ useTensorstore?: boolean;
6
+ chunksPerShard?: number | number[] | Record<string, number>;
7
+ }
8
+ export declare function toNgffZarr(_storePath: string, _multiscales: Multiscales, options?: ToNgffZarrOptions): Promise<void>;
9
+ //# sourceMappingURL=to_ngff_zarr.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"to_ngff_zarr.d.ts","sourceRoot":"","sources":["../../src/io/to_ngff_zarr.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAG3D,MAAM,WAAW,iBAAiB;IAChC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,OAAO,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;IACxB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC7D;AAED,wBAAgB,UAAU,CACxB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,WAAW,EACzB,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,IAAI,CAAC,CAuBf"}
@@ -0,0 +1,57 @@
1
+ import * as zarr from "zarrita";
2
+ export function toNgffZarr(_storePath, _multiscales, options = {}) {
3
+ const _overwrite = options.overwrite ?? true;
4
+ const _version = options.version ?? "0.4";
5
+ try {
6
+ // TODO: Implement using zarrita v0.5.2 API
7
+ // Example implementation would be:
8
+ // 1. Create a writable store (e.g., FileSystemStore for local files)
9
+ // 2. Use zarr.root(store) to create a Location
10
+ // 3. Use zarr.create(root, { attributes: { multiscales: [...] } }) to create group
11
+ // 4. For each image, use zarr.create(root.resolve(path), { shape, data_type, chunk_shape })
12
+ // 5. Use zarr.set() to write actual data
13
+ throw new Error("Writing OME-Zarr files is not yet fully implemented with zarrita v0.5.2");
14
+ }
15
+ catch (error) {
16
+ throw new Error(`Failed to write OME-Zarr: ${error instanceof Error ? error.message : String(error)}`);
17
+ }
18
+ }
19
+ async function _writeImage(group, image, arrayPath) {
20
+ try {
21
+ const chunks = getChunksFromImage(image);
22
+ // TODO: Update to use zarrita v0.5.2 API properly
23
+ // The new API would use:
24
+ // const location = (group as { resolve: (path: string) => Location }).resolve(arrayPath);
25
+ // const zarrArray = await zarr.create(location, { ... });
26
+ // Then use zarr.set(zarrArray, data, selection) to write data
27
+ const resolvedPath = group.resolve(arrayPath);
28
+ // @ts-ignore - zarrita API types are complex, this is a temporary workaround
29
+ const _zarrArray = await zarr.create(resolvedPath, {
30
+ shape: image.data.shape,
31
+ data_type: image.data.dtype,
32
+ chunk_shape: chunks,
33
+ fill_value: 0,
34
+ });
35
+ // Note: With zarrita v0.5.2, attributes can be set during creation
36
+ // or updated using the store's set method for metadata files
37
+ }
38
+ catch (error) {
39
+ throw new Error(`Failed to write image array: ${error instanceof Error ? error.message : String(error)}`);
40
+ }
41
+ }
42
+ function getChunksFromImage(image) {
43
+ if (image.data.chunks.length > 0 && image.data.chunks[0].length > 0) {
44
+ return image.data.chunks[0];
45
+ }
46
+ return image.data.shape.map((dim) => Math.min(dim, 1024));
47
+ }
48
+ function _writeArrayData(_storePath, _arrayPath, _data, _selection) {
49
+ try {
50
+ // Note: zarrita doesn't have a direct set method for arrays
51
+ // This would need to be implemented differently
52
+ throw new Error("Writing array data not yet implemented with zarrita");
53
+ }
54
+ catch (error) {
55
+ throw new Error(`Failed to write array data: ${error instanceof Error ? error.message : String(error)}`);
56
+ }
57
+ }
package/esm/mod.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ export * from "./types/units.js";
2
+ export * from "./types/methods.js";
3
+ export * from "./types/lazy_array.js";
4
+ export * from "./types/zarr_metadata.js";
5
+ export * from "./types/ngff_image.js";
6
+ export * from "./types/multiscales.js";
7
+ export * from "./schemas/units.js";
8
+ export * from "./schemas/methods.js";
9
+ export * from "./schemas/lazy_array.js";
10
+ export * from "./schemas/zarr_metadata.js";
11
+ export * from "./schemas/ngff_image.js";
12
+ export * from "./schemas/multiscales.js";
13
+ export { isValidDimension, isValidUnit, validateMetadata, } from "./utils/validation.js";
14
+ export { createAxis, createDataset, createMetadata, createMultiscales, createNgffImage, } from "./utils/factory.js";
15
+ export * from "./io/from_ngff_zarr.js";
16
+ export * from "./io/to_ngff_zarr.js";
17
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AAEvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AAEzC,OAAO,EACL,gBAAgB,EAChB,WAAW,EACX,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,UAAU,EACV,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,eAAe,GAChB,MAAM,oBAAoB,CAAC;AAE5B,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC"}
package/esm/mod.js ADDED
@@ -0,0 +1,16 @@
1
+ export * from "./types/units.js";
2
+ export * from "./types/methods.js";
3
+ export * from "./types/lazy_array.js";
4
+ export * from "./types/zarr_metadata.js";
5
+ export * from "./types/ngff_image.js";
6
+ export * from "./types/multiscales.js";
7
+ export * from "./schemas/units.js";
8
+ export * from "./schemas/methods.js";
9
+ export * from "./schemas/lazy_array.js";
10
+ export * from "./schemas/zarr_metadata.js";
11
+ export * from "./schemas/ngff_image.js";
12
+ export * from "./schemas/multiscales.js";
13
+ export { isValidDimension, isValidUnit, validateMetadata, } from "./utils/validation.js";
14
+ export { createAxis, createDataset, createMetadata, createMultiscales, createNgffImage, } from "./utils/factory.js";
15
+ export * from "./io/from_ngff_zarr.js";
16
+ export * from "./io/to_ngff_zarr.js";
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1,8 @@
1
+ import { z } from "zod";
2
+ export declare const LazyArrayMetadataSchema: z.ZodObject<{
3
+ shape: z.ZodArray<z.ZodNumber>;
4
+ dtype: z.ZodString;
5
+ chunks: z.ZodArray<z.ZodArray<z.ZodNumber>>;
6
+ name: z.ZodString;
7
+ }>;
8
+ //# sourceMappingURL=lazy_array.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lazy_array.d.ts","sourceRoot":"","sources":["../../src/schemas/lazy_array.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,uBAAuB,EAAE,CAAC,CAAC,SAAS,CAAC;IAChD,KAAK,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IAC/B,KAAK,EAAE,CAAC,CAAC,SAAS,CAAC;IACnB,MAAM,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IAC5C,IAAI,EAAE,CAAC,CAAC,SAAS,CAAC;CACnB,CAKC,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { z } from "zod";
2
+ export const LazyArrayMetadataSchema = z.object({
3
+ shape: z.array(z.number().int().nonnegative()),
4
+ dtype: z.string(),
5
+ chunks: z.array(z.array(z.number().int().nonnegative())),
6
+ name: z.string(),
7
+ });
@@ -0,0 +1,3 @@
1
+ import { z } from "zod";
2
+ export declare const MethodsSchema: z.ZodTypeAny;
3
+ //# sourceMappingURL=methods.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"methods.d.ts","sourceRoot":"","sources":["../../src/schemas/methods.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,aAAa,EAAE,CAAC,CAAC,UAI5B,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { z } from "zod";
2
+ export const MethodsSchema = z.enum([
3
+ "itkwasm_gaussian",
4
+ "itkwasm_bin_shrink",
5
+ "itkwasm_label_image",
6
+ ]);
@@ -0,0 +1,4 @@
1
+ import { z } from "zod";
2
+ export declare const ChunkSpecSchema: z.ZodTypeAny;
3
+ export declare const MultiscalesOptionsSchema: z.ZodTypeAny;
4
+ //# sourceMappingURL=multiscales.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multiscales.d.ts","sourceRoot":"","sources":["../../src/schemas/multiscales.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,eAAO,MAAM,eAAe,EAAE,CAAC,CAAC,UAK9B,CAAC;AAEH,eAAO,MAAM,wBAAwB,EAAE,CAAC,CAAC,UAQvC,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { z } from "zod";
2
+ import { NgffImageOptionsSchema } from "./ngff_image.js";
3
+ import { MetadataSchema } from "./zarr_metadata.js";
4
+ import { MethodsSchema } from "./methods.js";
5
+ export const ChunkSpecSchema = z.union([
6
+ z.number(),
7
+ z.array(z.number()),
8
+ z.array(z.array(z.number())),
9
+ z.record(z.string(), z.union([z.number(), z.array(z.number())]).optional()),
10
+ ]);
11
+ export const MultiscalesOptionsSchema = z.object({
12
+ images: z.array(NgffImageOptionsSchema),
13
+ metadata: MetadataSchema,
14
+ scaleFactors: z
15
+ .array(z.union([z.record(z.string(), z.number()), z.number()]))
16
+ .optional(),
17
+ method: MethodsSchema.optional(),
18
+ chunks: ChunkSpecSchema.optional(),
19
+ });
@@ -0,0 +1,13 @@
1
+ import { z } from "zod";
2
+ import { UnitsSchema } from "./units.js";
3
+ import { LazyArrayMetadataSchema } from "./lazy_array.js";
4
+ export declare const NgffImageOptionsSchema: z.ZodObject<{
5
+ data: typeof LazyArrayMetadataSchema;
6
+ dims: z.ZodArray<z.ZodString>;
7
+ scale: z.ZodRecord<z.ZodString, z.ZodNumber>;
8
+ translation: z.ZodRecord<z.ZodString, z.ZodNumber>;
9
+ name: z.ZodDefault<z.ZodString>;
10
+ axesUnits: z.ZodOptional<z.ZodRecord<z.ZodString, typeof UnitsSchema>>;
11
+ computedCallbacks: z.ZodDefault<z.ZodArray<z.ZodAny>>;
12
+ }>;
13
+ //# sourceMappingURL=ngff_image.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ngff_image.d.ts","sourceRoot":"","sources":["../../src/schemas/ngff_image.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAE1D,eAAO,MAAM,sBAAsB,EAAE,CAAC,CAAC,SAAS,CAAC;IAC/C,IAAI,EAAE,OAAO,uBAAuB,CAAC;IACrC,IAAI,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IAC9B,KAAK,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC;IAC7C,WAAW,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC;IACnD,IAAI,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IAChC,SAAS,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,EAAE,OAAO,WAAW,CAAC,CAAC,CAAC;IACvE,iBAAiB,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;CACvD,CAQC,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { z } from "zod";
2
+ import { UnitsSchema } from "./units.js";
3
+ import { LazyArrayMetadataSchema } from "./lazy_array.js";
4
+ export const NgffImageOptionsSchema = z.object({
5
+ data: LazyArrayMetadataSchema,
6
+ dims: z.array(z.string()),
7
+ scale: z.record(z.string(), z.number()),
8
+ translation: z.record(z.string(), z.number()),
9
+ name: z.string().default("image"),
10
+ axesUnits: z.record(z.string(), UnitsSchema).optional(),
11
+ computedCallbacks: z.array(z.any()).default([]),
12
+ });
@@ -0,0 +1,13 @@
1
+ import { z } from "zod";
2
+ export declare const SupportedDimsSchema: z.ZodTypeAny;
3
+ export declare const SpatialDimsSchema: z.ZodTypeAny;
4
+ export declare const AxesTypeSchema: z.ZodTypeAny;
5
+ export declare const SpaceUnitsSchema: z.ZodTypeAny;
6
+ export declare const TimeUnitsSchema: z.ZodTypeAny;
7
+ export declare const UnitsSchema: z.ZodUnion<[
8
+ typeof SpaceUnitsSchema,
9
+ typeof TimeUnitsSchema
10
+ ]>;
11
+ export declare const dimensionValidator: z.ZodTypeAny;
12
+ export declare const unitValidator: z.ZodTypeAny;
13
+ //# sourceMappingURL=units.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"units.d.ts","sourceRoot":"","sources":["../../src/schemas/units.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AASxB,eAAO,MAAM,mBAAmB,EAAE,CAAC,CAAC,UAMlC,CAAC;AAEH,eAAO,MAAM,iBAAiB,EAAE,CAAC,CAAC,UAAoC,CAAC;AAEvE,eAAO,MAAM,cAAc,EAAE,CAAC,CAAC,UAI7B,CAAC;AAEH,eAAO,MAAM,gBAAgB,EAAE,CAAC,CAAC,UA2B/B,CAAC;AAEH,eAAO,MAAM,eAAe,EAAE,CAAC,CAAC,UAwB9B,CAAC;AAEH,eAAO,MAAM,WAAW,EAAE,CAAC,CAAC,QAAQ,CAClC;IAAC,OAAO,gBAAgB;IAAE,OAAO,eAAe;CAAC,CACH,CAAC;AAEjD,eAAO,MAAM,kBAAkB,EAAE,CAAC,CAAC,UAKhC,CAAC;AAEJ,eAAO,MAAM,aAAa,EAAE,CAAC,CAAC,UAM3B,CAAC"}
@@ -0,0 +1,75 @@
1
+ import { z } from "zod";
2
+ import { spaceUnits, supportedDims, timeUnits, } from "../types/units.js";
3
+ export const SupportedDimsSchema = z.enum([
4
+ "c",
5
+ "x",
6
+ "y",
7
+ "z",
8
+ "t",
9
+ ]);
10
+ export const SpatialDimsSchema = z.enum(["x", "y", "z"]);
11
+ export const AxesTypeSchema = z.enum([
12
+ "time",
13
+ "space",
14
+ "channel",
15
+ ]);
16
+ export const SpaceUnitsSchema = z.enum([
17
+ "angstrom",
18
+ "attometer",
19
+ "centimeter",
20
+ "decimeter",
21
+ "exameter",
22
+ "femtometer",
23
+ "foot",
24
+ "gigameter",
25
+ "hectometer",
26
+ "inch",
27
+ "kilometer",
28
+ "megameter",
29
+ "meter",
30
+ "micrometer",
31
+ "mile",
32
+ "millimeter",
33
+ "nanometer",
34
+ "parsec",
35
+ "petameter",
36
+ "picometer",
37
+ "terameter",
38
+ "yard",
39
+ "yoctometer",
40
+ "yottameter",
41
+ "zeptometer",
42
+ "zettameter",
43
+ ]);
44
+ export const TimeUnitsSchema = z.enum([
45
+ "attosecond",
46
+ "centisecond",
47
+ "day",
48
+ "decisecond",
49
+ "exasecond",
50
+ "femtosecond",
51
+ "gigasecond",
52
+ "hectosecond",
53
+ "hour",
54
+ "kilosecond",
55
+ "megasecond",
56
+ "microsecond",
57
+ "millisecond",
58
+ "minute",
59
+ "nanosecond",
60
+ "petasecond",
61
+ "picosecond",
62
+ "second",
63
+ "terasecond",
64
+ "yoctosecond",
65
+ "yottasecond",
66
+ "zeptosecond",
67
+ "zettasecond",
68
+ ]);
69
+ export const UnitsSchema = z.union([SpaceUnitsSchema, TimeUnitsSchema]);
70
+ export const dimensionValidator = z
71
+ .string()
72
+ .refine((dim) => supportedDims.includes(dim), { message: "Dimension must be one of: c, x, y, z, t" });
73
+ export const unitValidator = z
74
+ .string()
75
+ .refine((unit) => [...timeUnits, ...spaceUnits].includes(unit), { message: "Unit must be a valid time or space unit" });