@fideus-labs/ngff-zarr 0.2.3 → 0.2.5

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 (199) hide show
  1. package/README.md +268 -76
  2. package/esm/browser-mod.d.ts +2 -0
  3. package/esm/browser-mod.d.ts.map +1 -1
  4. package/esm/browser-mod.js +4 -1
  5. package/esm/browser-mod.js.map +1 -0
  6. package/esm/io/from_ngff_zarr.d.ts.map +1 -1
  7. package/esm/io/from_ngff_zarr.js +2 -2
  8. package/esm/io/from_ngff_zarr.js.map +1 -0
  9. package/esm/io/hcs.js +1 -0
  10. package/esm/io/hcs.js.map +1 -0
  11. package/esm/io/itk_image_to_ngff_image.js +1 -0
  12. package/esm/io/itk_image_to_ngff_image.js.map +1 -0
  13. package/esm/io/ngff_image_to_itk_image.js +1 -0
  14. package/esm/io/ngff_image_to_itk_image.js.map +1 -0
  15. package/esm/io/to_ngff_image.js +1 -0
  16. package/esm/io/to_ngff_image.js.map +1 -0
  17. package/esm/io/to_ngff_zarr.d.ts.map +1 -1
  18. package/esm/io/to_ngff_zarr.js +2 -2
  19. package/esm/io/to_ngff_zarr.js.map +1 -0
  20. package/esm/methods/itkwasm-browser.js +1 -0
  21. package/esm/methods/itkwasm-browser.js.map +1 -0
  22. package/esm/methods/itkwasm-node.js +1 -0
  23. package/esm/methods/itkwasm-node.js.map +1 -0
  24. package/esm/methods/itkwasm-shared.js +1 -0
  25. package/esm/methods/itkwasm-shared.js.map +1 -0
  26. package/esm/methods/itkwasm.js +1 -0
  27. package/esm/methods/itkwasm.js.map +1 -0
  28. package/esm/mod.d.ts +1 -1
  29. package/esm/mod.d.ts.map +1 -1
  30. package/esm/mod.js +2 -1
  31. package/esm/mod.js.map +1 -0
  32. package/esm/process/to_multiscales-browser.d.ts +17 -0
  33. package/esm/process/to_multiscales-browser.d.ts.map +1 -0
  34. package/esm/process/to_multiscales-browser.js +15 -0
  35. package/esm/process/to_multiscales-browser.js.map +1 -0
  36. package/esm/process/to_multiscales-node.d.ts +18 -0
  37. package/esm/process/to_multiscales-node.d.ts.map +1 -0
  38. package/esm/process/to_multiscales-node.js +17 -0
  39. package/esm/process/to_multiscales-node.js.map +1 -0
  40. package/esm/process/to_multiscales-shared.d.ts +28 -0
  41. package/esm/process/to_multiscales-shared.d.ts.map +1 -0
  42. package/esm/{io/to_multiscales.js → process/to_multiscales-shared.js} +7 -5
  43. package/esm/process/to_multiscales-shared.js.map +1 -0
  44. package/esm/schemas/coordinate_systems.js +1 -0
  45. package/esm/schemas/coordinate_systems.js.map +1 -0
  46. package/esm/schemas/index.js +1 -0
  47. package/esm/schemas/index.js.map +1 -0
  48. package/esm/schemas/methods.js +1 -0
  49. package/esm/schemas/methods.js.map +1 -0
  50. package/esm/schemas/multiscales.js +1 -0
  51. package/esm/schemas/multiscales.js.map +1 -0
  52. package/esm/schemas/ngff_image.js +1 -0
  53. package/esm/schemas/ngff_image.js.map +1 -0
  54. package/esm/schemas/ome_zarr.js +1 -0
  55. package/esm/schemas/ome_zarr.js.map +1 -0
  56. package/esm/schemas/rfc4.js +1 -0
  57. package/esm/schemas/rfc4.js.map +1 -0
  58. package/esm/schemas/units.js +1 -0
  59. package/esm/schemas/units.js.map +1 -0
  60. package/esm/schemas/zarr_metadata.js +1 -0
  61. package/esm/schemas/zarr_metadata.js.map +1 -0
  62. package/esm/types/array_interface.js +1 -0
  63. package/esm/types/array_interface.js.map +1 -0
  64. package/esm/types/hcs.js +1 -0
  65. package/esm/types/hcs.js.map +1 -0
  66. package/esm/types/methods.js +1 -0
  67. package/esm/types/methods.js.map +1 -0
  68. package/esm/types/multiscales.js +1 -0
  69. package/esm/types/multiscales.js.map +1 -0
  70. package/esm/types/ngff_image.js +1 -0
  71. package/esm/types/ngff_image.js.map +1 -0
  72. package/esm/types/rfc4.js +1 -0
  73. package/esm/types/rfc4.js.map +1 -0
  74. package/esm/types/units.js +1 -0
  75. package/esm/types/units.js.map +1 -0
  76. package/esm/types/zarr_metadata.js +1 -0
  77. package/esm/types/zarr_metadata.js.map +1 -0
  78. package/esm/utils/create_queue.js +1 -0
  79. package/esm/utils/create_queue.js.map +1 -0
  80. package/esm/utils/factory.js +1 -0
  81. package/esm/utils/factory.js.map +1 -0
  82. package/esm/utils/method_metadata.js +1 -0
  83. package/esm/utils/method_metadata.js.map +1 -0
  84. package/esm/utils/validation.js +1 -0
  85. package/esm/utils/validation.js.map +1 -0
  86. package/package.json +31 -28
  87. package/esm/_dnt.shims.d.ts +0 -2
  88. package/esm/_dnt.shims.d.ts.map +0 -1
  89. package/esm/_dnt.shims.js +0 -57
  90. package/esm/io/to_multiscales.d.ts +0 -18
  91. package/esm/io/to_multiscales.d.ts.map +0 -1
  92. package/esm/package.json +0 -3
  93. package/script/_dnt.shims.d.ts +0 -2
  94. package/script/_dnt.shims.d.ts.map +0 -1
  95. package/script/_dnt.shims.js +0 -60
  96. package/script/browser-mod.d.ts +0 -14
  97. package/script/browser-mod.d.ts.map +0 -1
  98. package/script/browser-mod.js +0 -48
  99. package/script/io/from_ngff_zarr.d.ts +0 -10
  100. package/script/io/from_ngff_zarr.d.ts.map +0 -1
  101. package/script/io/from_ngff_zarr.js +0 -234
  102. package/script/io/hcs.d.ts +0 -18
  103. package/script/io/hcs.d.ts.map +0 -1
  104. package/script/io/hcs.js +0 -55
  105. package/script/io/itk_image_to_ngff_image.d.ts +0 -30
  106. package/script/io/itk_image_to_ngff_image.d.ts.map +0 -1
  107. package/script/io/itk_image_to_ngff_image.js +0 -153
  108. package/script/io/ngff_image_to_itk_image.d.ts +0 -30
  109. package/script/io/ngff_image_to_itk_image.d.ts.map +0 -1
  110. package/script/io/ngff_image_to_itk_image.js +0 -244
  111. package/script/io/to_multiscales.d.ts +0 -18
  112. package/script/io/to_multiscales.d.ts.map +0 -1
  113. package/script/io/to_multiscales.js +0 -67
  114. package/script/io/to_ngff_image.d.ts +0 -17
  115. package/script/io/to_ngff_image.d.ts.map +0 -1
  116. package/script/io/to_ngff_image.js +0 -162
  117. package/script/io/to_ngff_zarr.d.ts +0 -10
  118. package/script/io/to_ngff_zarr.d.ts.map +0 -1
  119. package/script/io/to_ngff_zarr.js +0 -346
  120. package/script/methods/itkwasm-browser.d.ts +0 -6
  121. package/script/methods/itkwasm-browser.d.ts.map +0 -1
  122. package/script/methods/itkwasm-browser.js +0 -488
  123. package/script/methods/itkwasm-node.d.ts +0 -6
  124. package/script/methods/itkwasm-node.d.ts.map +0 -1
  125. package/script/methods/itkwasm-node.js +0 -493
  126. package/script/methods/itkwasm-shared.d.ts +0 -68
  127. package/script/methods/itkwasm-shared.d.ts.map +0 -1
  128. package/script/methods/itkwasm-shared.js +0 -524
  129. package/script/methods/itkwasm.d.ts +0 -14
  130. package/script/methods/itkwasm.d.ts.map +0 -1
  131. package/script/methods/itkwasm.js +0 -21
  132. package/script/mod.d.ts +0 -24
  133. package/script/mod.d.ts.map +0 -1
  134. package/script/mod.js +0 -50
  135. package/script/package.json +0 -3
  136. package/script/schemas/coordinate_systems.d.ts +0 -251
  137. package/script/schemas/coordinate_systems.d.ts.map +0 -1
  138. package/script/schemas/coordinate_systems.js +0 -142
  139. package/script/schemas/index.d.ts +0 -9
  140. package/script/schemas/index.d.ts.map +0 -1
  141. package/script/schemas/index.js +0 -101
  142. package/script/schemas/methods.d.ts +0 -3
  143. package/script/schemas/methods.d.ts.map +0 -1
  144. package/script/schemas/methods.js +0 -11
  145. package/script/schemas/multiscales.d.ts +0 -4
  146. package/script/schemas/multiscales.d.ts.map +0 -1
  147. package/script/schemas/multiscales.js +0 -24
  148. package/script/schemas/ngff_image.d.ts +0 -20
  149. package/script/schemas/ngff_image.d.ts.map +0 -1
  150. package/script/schemas/ngff_image.js +0 -24
  151. package/script/schemas/ome_zarr.d.ts +0 -617
  152. package/script/schemas/ome_zarr.d.ts.map +0 -1
  153. package/script/schemas/ome_zarr.js +0 -211
  154. package/script/schemas/rfc4.d.ts +0 -334
  155. package/script/schemas/rfc4.d.ts.map +0 -1
  156. package/script/schemas/rfc4.js +0 -132
  157. package/script/schemas/units.d.ts +0 -78
  158. package/script/schemas/units.d.ts.map +0 -1
  159. package/script/schemas/units.js +0 -70
  160. package/script/schemas/zarr_metadata.d.ts +0 -55
  161. package/script/schemas/zarr_metadata.d.ts.map +0 -1
  162. package/script/schemas/zarr_metadata.js +0 -71
  163. package/script/types/array_interface.d.ts +0 -7
  164. package/script/types/array_interface.d.ts.map +0 -1
  165. package/script/types/array_interface.js +0 -2
  166. package/script/types/hcs.d.ts +0 -70
  167. package/script/types/hcs.d.ts.map +0 -1
  168. package/script/types/hcs.js +0 -233
  169. package/script/types/methods.d.ts +0 -7
  170. package/script/types/methods.d.ts.map +0 -1
  171. package/script/types/methods.js +0 -12
  172. package/script/types/multiscales.d.ts +0 -21
  173. package/script/types/multiscales.d.ts.map +0 -1
  174. package/script/types/multiscales.js +0 -38
  175. package/script/types/ngff_image.d.ts +0 -27
  176. package/script/types/ngff_image.d.ts.map +0 -1
  177. package/script/types/ngff_image.js +0 -48
  178. package/script/types/rfc4.d.ts +0 -94
  179. package/script/types/rfc4.d.ts.map +0 -1
  180. package/script/types/rfc4.js +0 -143
  181. package/script/types/units.d.ts +0 -12
  182. package/script/types/units.d.ts.map +0 -1
  183. package/script/types/units.js +0 -66
  184. package/script/types/zarr_metadata.d.ts +0 -58
  185. package/script/types/zarr_metadata.d.ts.map +0 -1
  186. package/script/types/zarr_metadata.js +0 -20
  187. package/script/utils/create_queue.d.ts +0 -6
  188. package/script/utils/create_queue.d.ts.map +0 -1
  189. package/script/utils/create_queue.js +0 -17
  190. package/script/utils/factory.d.ts +0 -13
  191. package/script/utils/factory.d.ts.map +0 -1
  192. package/script/utils/factory.js +0 -108
  193. package/script/utils/method_metadata.d.ts +0 -10
  194. package/script/utils/method_metadata.d.ts.map +0 -1
  195. package/script/utils/method_metadata.js +0 -40
  196. package/script/utils/validation.d.ts +0 -6
  197. package/script/utils/validation.d.ts.map +0 -1
  198. package/script/utils/validation.js +0 -78
  199. /package/{LICENSE → LICENSE.txt} +0 -0
@@ -1,162 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.toNgffImage = toNgffImage;
27
- const zarr = __importStar(require("zarrita"));
28
- const ngff_image_js_1 = require("../types/ngff_image.js");
29
- /**
30
- * Convert array data to NgffImage
31
- *
32
- * @param data - Input data as typed array or regular array
33
- * @param options - Configuration options for NgffImage creation
34
- * @returns NgffImage instance
35
- */
36
- async function toNgffImage(data, options = {}) {
37
- const { dims = ["y", "x"], scale = {}, translation = {}, name = "image", shape: explicitShape, } = options;
38
- // Determine data shape and create typed array
39
- let typedData;
40
- let shape;
41
- if (Array.isArray(data)) {
42
- // Handle multi-dimensional arrays
43
- if (Array.isArray(data[0])) {
44
- if (Array.isArray(data[0][0])) {
45
- // 3D array
46
- const d3 = data;
47
- shape = [d3.length, d3[0].length, d3[0][0].length];
48
- typedData = new Float32Array(shape[0] * shape[1] * shape[2]);
49
- let idx = 0;
50
- for (let i = 0; i < shape[0]; i++) {
51
- for (let j = 0; j < shape[1]; j++) {
52
- for (let k = 0; k < shape[2]; k++) {
53
- typedData[idx++] = d3[i][j][k];
54
- }
55
- }
56
- }
57
- }
58
- else {
59
- // 2D array
60
- const d2 = data;
61
- shape = [d2.length, d2[0].length];
62
- typedData = new Float32Array(shape[0] * shape[1]);
63
- let idx = 0;
64
- for (let i = 0; i < shape[0]; i++) {
65
- for (let j = 0; j < shape[1]; j++) {
66
- typedData[idx++] = d2[i][j];
67
- }
68
- }
69
- }
70
- }
71
- else {
72
- // 1D array
73
- const d1 = data;
74
- shape = [d1.length];
75
- typedData = new Float32Array(d1);
76
- }
77
- }
78
- else {
79
- // ArrayLike (already a typed array)
80
- // Use explicit shape if provided, otherwise infer from data length and dims
81
- if (explicitShape) {
82
- shape = [...explicitShape];
83
- }
84
- else {
85
- // Try to infer shape - this is a best guess
86
- shape = [data.length];
87
- }
88
- // Preserve the original typed array type
89
- if (data instanceof Uint8Array) {
90
- typedData = data;
91
- }
92
- else if (data instanceof Uint16Array) {
93
- typedData = data;
94
- }
95
- else {
96
- typedData = new Float32Array(data);
97
- }
98
- }
99
- // Adjust shape to match dims length if not explicitly provided
100
- if (!explicitShape) {
101
- while (shape.length < dims.length) {
102
- shape.unshift(1);
103
- }
104
- }
105
- if (shape.length !== dims.length) {
106
- throw new Error(`Shape dimensionality (${shape.length}) must match dims length (${dims.length})`);
107
- }
108
- // Create in-memory zarr store and array
109
- const store = new Map();
110
- const root = zarr.root(store);
111
- // Calculate appropriate chunk size
112
- const chunkShape = shape.map((dim) => Math.min(dim, 256));
113
- const zarrArray = await zarr.create(root.resolve("data"), {
114
- shape,
115
- chunk_shape: chunkShape,
116
- data_type: "float32",
117
- fill_value: 0,
118
- });
119
- // Write data to zarr array
120
- await zarr.set(zarrArray, [], {
121
- data: typedData,
122
- shape,
123
- stride: calculateStride(shape),
124
- });
125
- // Create scale and translation records with defaults
126
- const fullScale = {};
127
- const fullTranslation = {};
128
- const spatialDims = new Set(["x", "y", "z"]);
129
- for (const dim of dims) {
130
- // Only set defaults for spatial dimensions
131
- if (spatialDims.has(dim)) {
132
- fullScale[dim] = scale[dim] ?? 1.0;
133
- fullTranslation[dim] = translation[dim] ?? 0.0;
134
- }
135
- else {
136
- // For non-spatial dimensions, only include if explicitly provided
137
- if (scale[dim] !== undefined) {
138
- fullScale[dim] = scale[dim];
139
- }
140
- if (translation[dim] !== undefined) {
141
- fullTranslation[dim] = translation[dim];
142
- }
143
- }
144
- }
145
- return new ngff_image_js_1.NgffImage({
146
- data: zarrArray,
147
- dims,
148
- scale: fullScale,
149
- translation: fullTranslation,
150
- name,
151
- axesUnits: undefined,
152
- computedCallbacks: undefined,
153
- });
154
- }
155
- function calculateStride(shape) {
156
- const stride = new Array(shape.length);
157
- stride[shape.length - 1] = 1;
158
- for (let i = shape.length - 2; i >= 0; i--) {
159
- stride[i] = stride[i + 1] * shape[i + 1];
160
- }
161
- return stride;
162
- }
@@ -1,10 +0,0 @@
1
- import * as zarr from "zarrita";
2
- import type { Multiscales } from "../types/multiscales.js";
3
- import type { MemoryStore } from "./from_ngff_zarr.js";
4
- export interface ToNgffZarrOptions {
5
- overwrite?: boolean;
6
- version?: "0.4" | "0.5";
7
- chunksPerShard?: number | number[] | Record<string, number>;
8
- }
9
- export declare function toNgffZarr(store: string | MemoryStore | zarr.FetchStore, multiscales: Multiscales, options?: ToNgffZarrOptions): Promise<void>;
10
- //# sourceMappingURL=to_ngff_zarr.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"to_ngff_zarr.d.ts","sourceRoot":"","sources":["../../src/io/to_ngff_zarr.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,IAAI,MAAM,SAAS,CAAC;AAChC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGvD,MAAM,WAAW,iBAAiB;IAChC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,OAAO,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC7D;AAED,wBAAsB,UAAU,CAC9B,KAAK,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAAC,UAAU,EAC7C,WAAW,EAAE,WAAW,EACxB,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,IAAI,CAAC,CA0Ff"}
@@ -1,346 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.toNgffZarr = toNgffZarr;
27
- // SPDX-FileCopyrightText: Copyright (c) Fideus Labs LLC
28
- // SPDX-License-Identifier: MIT
29
- const dntShim = __importStar(require("../_dnt.shims.js"));
30
- const zarr = __importStar(require("zarrita"));
31
- const create_queue_js_1 = require("../utils/create_queue.js");
32
- async function toNgffZarr(store, multiscales, options = {}) {
33
- const _overwrite = options.overwrite ?? true;
34
- const _version = options.version ?? "0.4";
35
- try {
36
- // Determine the appropriate store type based on the path
37
- let _resolvedStore; // Use unknown for FileSystemStore since we import it dynamically
38
- if (store instanceof Map) {
39
- _resolvedStore = store;
40
- }
41
- else if (store instanceof zarr.FetchStore) {
42
- throw new Error("FetchStore is read-only and cannot be used for writing. Use a local file path or MemoryStore instead.");
43
- }
44
- else if (store.startsWith("http://") || store.startsWith("https://")) {
45
- throw new Error("HTTP/HTTPS URLs are read-only and cannot be used for writing. Use a local file path instead.");
46
- }
47
- else {
48
- // For local paths, check if we're in a browser environment
49
- if (typeof dntShim.dntGlobalThis !== "undefined") {
50
- throw new Error("Local file paths are not supported in browser environments. Use a MemoryStore instead.");
51
- }
52
- // Use dynamic import for FileSystemStore in Node.js/Deno environments
53
- try {
54
- const { FileSystemStore } = await Promise.resolve().then(() => __importStar(require("@zarrita/storage")));
55
- // Normalize the path for cross-platform compatibility
56
- const normalizedPath = store.replace(/^\/([A-Za-z]:)/, "$1");
57
- _resolvedStore = new FileSystemStore(normalizedPath);
58
- }
59
- catch (error) {
60
- throw new Error(`Failed to load FileSystemStore: ${error}. Use MemoryStore for browser compatibility.`);
61
- }
62
- }
63
- // Create root location and group with zarrita v0.5.2 API
64
- const root = zarr.root(_resolvedStore);
65
- // Create the root group with OME-Zarr metadata
66
- const rootGroup = await zarr.create(root, {
67
- attributes: {
68
- multiscales: [
69
- {
70
- version: _version,
71
- name: multiscales.metadata.name,
72
- axes: multiscales.metadata.axes,
73
- datasets: multiscales.metadata.datasets,
74
- ...(multiscales.metadata.coordinateTransformations && {
75
- coordinateTransformations: multiscales.metadata.coordinateTransformations,
76
- }),
77
- ...(multiscales.metadata.type && {
78
- type: multiscales.metadata.type,
79
- }),
80
- ...(multiscales.metadata.metadata && {
81
- metadata: multiscales.metadata.metadata,
82
- }),
83
- },
84
- ],
85
- ...(multiscales.metadata.omero && {
86
- omero: multiscales.metadata.omero,
87
- }),
88
- },
89
- });
90
- // Write each image in the multiscales
91
- for (let i = 0; i < multiscales.images.length; i++) {
92
- const image = multiscales.images[i];
93
- const dataset = multiscales.metadata.datasets[i];
94
- if (!dataset) {
95
- throw new Error(`No dataset configuration found for image ${i}`);
96
- }
97
- await _writeImage(rootGroup, image, dataset.path);
98
- }
99
- }
100
- catch (error) {
101
- throw new Error(`Failed to write OME-Zarr: ${error instanceof Error ? error.message : String(error)}`);
102
- }
103
- }
104
- function _convertDtypeToZarrType(dtype) {
105
- // Map common numpy/LazyArray dtypes to zarrita data types
106
- const dtypeMap = {
107
- int8: "int8",
108
- int16: "int16",
109
- int32: "int32",
110
- int64: "int64",
111
- uint8: "uint8",
112
- uint16: "uint16",
113
- uint32: "uint32",
114
- uint64: "uint64",
115
- float32: "float32",
116
- float64: "float64",
117
- bool: "bool",
118
- // Handle some alternative formats
119
- i1: "int8",
120
- i2: "int16",
121
- i4: "int32",
122
- i8: "int64",
123
- u1: "uint8",
124
- u2: "uint16",
125
- u4: "uint32",
126
- u8: "uint64",
127
- f4: "float32",
128
- f8: "float64",
129
- };
130
- if (dtype in dtypeMap) {
131
- return dtypeMap[dtype];
132
- }
133
- else {
134
- throw new Error(`Unsupported data type: ${dtype}`);
135
- }
136
- }
137
- function getTypedArrayConstructor(dtype) {
138
- // Map zarrita data types to TypedArray constructors
139
- const constructorMap = {
140
- int8: Int8Array,
141
- int16: Int16Array,
142
- int32: Int32Array,
143
- int64: BigInt64Array,
144
- uint8: Uint8Array,
145
- uint16: Uint16Array,
146
- uint32: Uint32Array,
147
- uint64: BigUint64Array,
148
- float32: Float32Array,
149
- float64: Float64Array,
150
- bool: Uint8Array, // Use Uint8Array for boolean, where 0 represents false and 1 represents true
151
- // Note: float16 and "v2:object" not supported by standard TypedArrays
152
- };
153
- const constructor = constructorMap[dtype];
154
- if (constructor) {
155
- return constructor;
156
- }
157
- else {
158
- throw new Error(`Unsupported data type for typed array: ${dtype}`);
159
- }
160
- }
161
- async function _writeImage(group, image, arrayPath) {
162
- try {
163
- const chunks = getChunksFromImage(image);
164
- // Convert LazyArray dtype to zarrita DataType
165
- const zarrDataType = _convertDtypeToZarrType(image.data.dtype);
166
- // Create array location
167
- const arrayLocation = group.resolve(arrayPath);
168
- // Create the zarr array with proper configuration
169
- const zarrArray = await zarr.create(arrayLocation, {
170
- shape: image.data.shape,
171
- data_type: zarrDataType,
172
- chunk_shape: chunks,
173
- fill_value: 0,
174
- });
175
- await _writeArrayData(zarrArray, image);
176
- }
177
- catch (error) {
178
- throw new Error(`Failed to write image array: ${error instanceof Error ? error.message : String(error)}`);
179
- }
180
- }
181
- function getChunksFromImage(image) {
182
- // zarr.Array.chunks is a number[] representing chunk shape
183
- if (image.data.chunks && image.data.chunks.length > 0) {
184
- return image.data.chunks;
185
- }
186
- return image.data.shape.map((dim) => Math.min(dim, 1024));
187
- }
188
- async function _writeArrayData(zarrArray, image) {
189
- try {
190
- // Get array shape for chunk calculation - we don't need the full data here
191
- const shape = image.data.shape;
192
- // Calculate chunk indices for parallel writing
193
- const chunkIndices = calculateChunkIndices(shape, zarrArray.chunks);
194
- // Create a queue for parallel chunk writing
195
- const writeQueue = (0, create_queue_js_1.createQueue)();
196
- // Queue all chunks for writing
197
- for (const chunkIndex of chunkIndices) {
198
- writeQueue.add(async () => {
199
- await writeChunkWithGet(zarrArray, image, chunkIndex);
200
- });
201
- }
202
- // Wait for all chunks to be written
203
- await writeQueue.onIdle();
204
- }
205
- catch (error) {
206
- throw new Error(`Failed to write array data: ${error instanceof Error ? error.message : String(error)}`);
207
- }
208
- }
209
- async function writeChunkWithGet(zarrArray, image, chunkIndex) {
210
- // Calculate the chunk bounds
211
- const shape = image.data.shape;
212
- const chunkStart = chunkIndex.map((idx, dim) => idx * zarrArray.chunks[dim]);
213
- const chunkEnd = chunkStart.map((start, dim) => Math.min(start + zarrArray.chunks[dim], shape[dim]));
214
- // Calculate chunk shape
215
- const chunkShape = chunkEnd.map((end, dim) => end - chunkStart[dim]);
216
- // Create selection for this chunk from the source data
217
- const sourceSelection = chunkStart.map((start, dim) => zarr.slice(start, chunkEnd[dim]));
218
- // Get only the chunk data we need from the source
219
- const { data: chunkSourceData } = await zarr.get(image.data, sourceSelection);
220
- // Convert chunk data to target type
221
- const targetTypedArrayConstructor = getTypedArrayConstructor(zarrArray.dtype);
222
- const chunkTargetData = convertChunkToTargetType(chunkSourceData, zarrArray.dtype, targetTypedArrayConstructor);
223
- // Validate chunk data size
224
- const expectedSize = chunkShape.reduce((a, b) => a * b, 1);
225
- const actualSize = chunkTargetData.byteLength /
226
- (chunkTargetData
227
- .BYTES_PER_ELEMENT || 1);
228
- if (actualSize !== expectedSize) {
229
- console.error(`[writeChunkWithGet] Chunk data size mismatch!`);
230
- console.error(` Image shape:`, shape);
231
- console.error(` Chunk index:`, chunkIndex);
232
- console.error(` Chunk start:`, chunkStart);
233
- console.error(` Chunk end:`, chunkEnd);
234
- console.error(` Chunk shape:`, chunkShape);
235
- console.error(` Expected size:`, expectedSize);
236
- console.error(` Actual size:`, actualSize);
237
- throw new Error(`Chunk data size mismatch: expected ${expectedSize} elements, got ${actualSize}`);
238
- }
239
- // Create the selection for writing to the target zarr array
240
- const targetSelection = chunkStart.map((start, dim) => zarr.slice(start, chunkEnd[dim]));
241
- // Write the chunk using zarrita's set function
242
- await zarr.set(zarrArray, targetSelection, {
243
- data: chunkTargetData,
244
- shape: chunkShape,
245
- stride: calculateChunkStride(chunkShape),
246
- });
247
- }
248
- function convertChunkToTargetType(chunkData, targetDtype, targetTypedArrayConstructor) {
249
- // Handle different source data types
250
- if (chunkData instanceof BigInt64Array ||
251
- chunkData instanceof BigUint64Array) {
252
- // Handle BigInt arrays separately
253
- if (chunkData.constructor === targetTypedArrayConstructor) {
254
- return chunkData;
255
- }
256
- else if (targetDtype === "int64" || targetDtype === "uint64") {
257
- // BigInt to BigInt conversion
258
- const bigIntArray = new targetTypedArrayConstructor(chunkData.length);
259
- for (let i = 0; i < chunkData.length; i++) {
260
- bigIntArray[i] = chunkData[i];
261
- }
262
- return bigIntArray;
263
- }
264
- else {
265
- // BigInt to regular number conversion
266
- const numberArray = new targetTypedArrayConstructor(chunkData.length);
267
- for (let i = 0; i < chunkData.length; i++) {
268
- numberArray[i] = Number(chunkData[i]);
269
- }
270
- return numberArray;
271
- }
272
- }
273
- else if (chunkData instanceof Uint8Array ||
274
- chunkData instanceof Int8Array ||
275
- chunkData instanceof Uint16Array ||
276
- chunkData instanceof Int16Array ||
277
- chunkData instanceof Uint32Array ||
278
- chunkData instanceof Int32Array ||
279
- chunkData instanceof Float32Array ||
280
- chunkData instanceof Float64Array) {
281
- // Handle regular typed arrays
282
- if (chunkData.constructor === targetTypedArrayConstructor) {
283
- return chunkData;
284
- }
285
- else {
286
- // Convert between typed arrays
287
- if (targetDtype === "int64" || targetDtype === "uint64") {
288
- // Regular number to BigInt conversion
289
- const bigIntArray = new targetTypedArrayConstructor(chunkData.length);
290
- for (let i = 0; i < chunkData.length; i++) {
291
- bigIntArray[i] = BigInt(chunkData[i]);
292
- }
293
- return bigIntArray;
294
- }
295
- else {
296
- // Standard numeric conversion - use typed conversion
297
- const typedArrayMap = new Map([
298
- [Uint8Array, (data) => new Uint8Array(Array.from(data))],
299
- [Int8Array, (data) => new Int8Array(Array.from(data))],
300
- [Uint16Array, (data) => new Uint16Array(Array.from(data))],
301
- [Int16Array, (data) => new Int16Array(Array.from(data))],
302
- [Uint32Array, (data) => new Uint32Array(Array.from(data))],
303
- [Int32Array, (data) => new Int32Array(Array.from(data))],
304
- [Float32Array, (data) => new Float32Array(Array.from(data))],
305
- [Float64Array, (data) => new Float64Array(Array.from(data))],
306
- ]);
307
- const createTypedArray = typedArrayMap.get(targetTypedArrayConstructor);
308
- if (createTypedArray) {
309
- return createTypedArray(chunkData);
310
- }
311
- else {
312
- throw new Error(`Unsupported target constructor: ${targetTypedArrayConstructor.name}`);
313
- }
314
- }
315
- }
316
- }
317
- else {
318
- // Handle other types (fallback)
319
- throw new Error(`Unsupported source data type: ${chunkData.constructor.name}`);
320
- }
321
- }
322
- function calculateChunkIndices(shape, chunks) {
323
- const indices = [];
324
- function generateIndices(dimIndex, currentIndex) {
325
- if (dimIndex === shape.length) {
326
- indices.push([...currentIndex]);
327
- return;
328
- }
329
- const chunkSize = chunks[dimIndex];
330
- const dimSize = shape[dimIndex];
331
- for (let i = 0; i < Math.ceil(dimSize / chunkSize); i++) {
332
- currentIndex[dimIndex] = i;
333
- generateIndices(dimIndex + 1, currentIndex);
334
- }
335
- }
336
- generateIndices(0, new Array(shape.length));
337
- return indices;
338
- }
339
- function calculateChunkStride(chunkShape) {
340
- const stride = new Array(chunkShape.length);
341
- stride[chunkShape.length - 1] = 1;
342
- for (let i = chunkShape.length - 2; i >= 0; i--) {
343
- stride[i] = stride[i + 1] * chunkShape[i + 1];
344
- }
345
- return stride;
346
- }
@@ -1,6 +0,0 @@
1
- import { NgffImage } from "../types/ngff_image.js";
2
- /**
3
- * Main downsampling function for ITK-Wasm (browser version)
4
- */
5
- export declare function downsampleItkWasm(ngffImage: NgffImage, scaleFactors: (Record<string, number> | number)[], smoothing: "gaussian" | "bin_shrink" | "label_image"): Promise<NgffImage[]>;
6
- //# sourceMappingURL=itkwasm-browser.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"itkwasm-browser.d.ts","sourceRoot":"","sources":["../../src/methods/itkwasm-browser.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AA2fnD;;GAEG;AACH,wBAAsB,iBAAiB,CACrC,SAAS,EAAE,SAAS,EACpB,YAAY,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,EAAE,EACjD,SAAS,EAAE,UAAU,GAAG,YAAY,GAAG,aAAa,GACnD,OAAO,CAAC,SAAS,EAAE,CAAC,CAsHtB"}