@fideus-labs/ngff-zarr 0.0.1 → 0.2.0

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 (176) hide show
  1. package/README.md +10 -2
  2. package/esm/io/from_ngff_zarr.d.ts +4 -1
  3. package/esm/io/from_ngff_zarr.d.ts.map +1 -1
  4. package/esm/io/from_ngff_zarr.js +94 -27
  5. package/esm/io/hcs.d.ts +18 -0
  6. package/esm/io/hcs.d.ts.map +1 -0
  7. package/esm/io/hcs.js +51 -0
  8. package/esm/io/itk_image_to_ngff_image.d.ts +30 -0
  9. package/esm/io/itk_image_to_ngff_image.d.ts.map +1 -0
  10. package/esm/io/itk_image_to_ngff_image.js +127 -0
  11. package/esm/io/ngff_image_to_itk_image.d.ts +30 -0
  12. package/esm/io/ngff_image_to_itk_image.d.ts.map +1 -0
  13. package/esm/io/ngff_image_to_itk_image.js +218 -0
  14. package/esm/io/to_multiscales.d.ts +18 -0
  15. package/esm/io/to_multiscales.d.ts.map +1 -0
  16. package/esm/io/to_multiscales.js +62 -0
  17. package/esm/io/to_ngff_image.d.ts +17 -0
  18. package/esm/io/to_ngff_image.d.ts.map +1 -0
  19. package/esm/io/to_ngff_image.js +136 -0
  20. package/esm/io/to_ngff_zarr.d.ts +3 -2
  21. package/esm/io/to_ngff_zarr.d.ts.map +1 -1
  22. package/esm/io/to_ngff_zarr.js +289 -26
  23. package/esm/methods/itkwasm.d.ts +6 -0
  24. package/esm/methods/itkwasm.d.ts.map +1 -0
  25. package/esm/methods/itkwasm.js +958 -0
  26. package/esm/mod.d.ts +9 -2
  27. package/esm/mod.d.ts.map +1 -1
  28. package/esm/mod.js +10 -2
  29. package/esm/schemas/coordinate_systems.d.ts +251 -0
  30. package/esm/schemas/coordinate_systems.d.ts.map +1 -0
  31. package/esm/schemas/coordinate_systems.js +139 -0
  32. package/esm/schemas/index.d.ts +9 -0
  33. package/esm/schemas/index.d.ts.map +1 -0
  34. package/esm/schemas/index.js +38 -0
  35. package/esm/schemas/methods.d.ts.map +1 -1
  36. package/esm/schemas/methods.js +2 -0
  37. package/esm/schemas/multiscales.d.ts.map +1 -1
  38. package/esm/schemas/multiscales.js +2 -0
  39. package/esm/schemas/ngff_image.d.ts +9 -2
  40. package/esm/schemas/ngff_image.d.ts.map +1 -1
  41. package/esm/schemas/ngff_image.js +11 -2
  42. package/esm/schemas/ome_zarr.d.ts +617 -0
  43. package/esm/schemas/ome_zarr.d.ts.map +1 -0
  44. package/esm/schemas/ome_zarr.js +208 -0
  45. package/esm/schemas/rfc4.d.ts +334 -0
  46. package/esm/schemas/rfc4.d.ts.map +1 -0
  47. package/esm/schemas/rfc4.js +129 -0
  48. package/esm/schemas/units.d.ts +70 -5
  49. package/esm/schemas/units.d.ts.map +1 -1
  50. package/esm/schemas/units.js +4 -12
  51. package/esm/schemas/zarr_metadata.d.ts +10 -4
  52. package/esm/schemas/zarr_metadata.d.ts.map +1 -1
  53. package/esm/schemas/zarr_metadata.js +22 -1
  54. package/esm/types/array_interface.d.ts +7 -0
  55. package/esm/types/array_interface.d.ts.map +1 -0
  56. package/esm/types/array_interface.js +1 -0
  57. package/esm/types/hcs.d.ts +70 -0
  58. package/esm/types/hcs.d.ts.map +1 -0
  59. package/esm/types/hcs.js +204 -0
  60. package/esm/types/methods.d.ts.map +1 -1
  61. package/esm/types/methods.js +2 -0
  62. package/esm/types/multiscales.d.ts.map +1 -1
  63. package/esm/types/ngff_image.d.ts +6 -3
  64. package/esm/types/ngff_image.d.ts.map +1 -1
  65. package/esm/types/ngff_image.js +13 -1
  66. package/esm/types/rfc4.d.ts +94 -0
  67. package/esm/types/rfc4.d.ts.map +1 -0
  68. package/esm/types/rfc4.js +135 -0
  69. package/esm/types/units.d.ts +1 -1
  70. package/esm/types/units.d.ts.map +1 -1
  71. package/esm/types/zarr_metadata.d.ts +14 -5
  72. package/esm/types/zarr_metadata.d.ts.map +1 -1
  73. package/esm/utils/create_queue.d.ts +6 -0
  74. package/esm/utils/create_queue.d.ts.map +1 -0
  75. package/esm/utils/create_queue.js +11 -0
  76. package/esm/utils/factory.d.ts +1 -1
  77. package/esm/utils/factory.d.ts.map +1 -1
  78. package/esm/utils/factory.js +16 -7
  79. package/esm/utils/method_metadata.d.ts +10 -0
  80. package/esm/utils/method_metadata.d.ts.map +1 -0
  81. package/esm/utils/method_metadata.js +37 -0
  82. package/esm/utils/validation.d.ts.map +1 -1
  83. package/package.json +7 -1
  84. package/script/io/from_ngff_zarr.d.ts +4 -1
  85. package/script/io/from_ngff_zarr.d.ts.map +1 -1
  86. package/script/io/from_ngff_zarr.js +94 -27
  87. package/script/io/hcs.d.ts +18 -0
  88. package/script/io/hcs.d.ts.map +1 -0
  89. package/script/io/hcs.js +55 -0
  90. package/script/io/itk_image_to_ngff_image.d.ts +30 -0
  91. package/script/io/itk_image_to_ngff_image.d.ts.map +1 -0
  92. package/script/io/itk_image_to_ngff_image.js +153 -0
  93. package/script/io/ngff_image_to_itk_image.d.ts +30 -0
  94. package/script/io/ngff_image_to_itk_image.d.ts.map +1 -0
  95. package/script/io/ngff_image_to_itk_image.js +244 -0
  96. package/script/io/to_multiscales.d.ts +18 -0
  97. package/script/io/to_multiscales.d.ts.map +1 -0
  98. package/script/io/to_multiscales.js +67 -0
  99. package/script/io/to_ngff_image.d.ts +17 -0
  100. package/script/io/to_ngff_image.d.ts.map +1 -0
  101. package/script/io/to_ngff_image.js +162 -0
  102. package/script/io/to_ngff_zarr.d.ts +3 -2
  103. package/script/io/to_ngff_zarr.d.ts.map +1 -1
  104. package/script/io/to_ngff_zarr.js +289 -26
  105. package/script/methods/itkwasm.d.ts +6 -0
  106. package/script/methods/itkwasm.d.ts.map +1 -0
  107. package/script/methods/itkwasm.js +984 -0
  108. package/script/mod.d.ts +9 -2
  109. package/script/mod.d.ts.map +1 -1
  110. package/script/mod.js +12 -3
  111. package/script/schemas/coordinate_systems.d.ts +251 -0
  112. package/script/schemas/coordinate_systems.d.ts.map +1 -0
  113. package/script/schemas/coordinate_systems.js +142 -0
  114. package/script/schemas/index.d.ts +9 -0
  115. package/script/schemas/index.d.ts.map +1 -0
  116. package/script/schemas/index.js +101 -0
  117. package/script/schemas/methods.d.ts.map +1 -1
  118. package/script/schemas/methods.js +2 -0
  119. package/script/schemas/multiscales.d.ts.map +1 -1
  120. package/script/schemas/multiscales.js +2 -0
  121. package/script/schemas/ngff_image.d.ts +9 -2
  122. package/script/schemas/ngff_image.d.ts.map +1 -1
  123. package/script/schemas/ngff_image.js +11 -2
  124. package/script/schemas/ome_zarr.d.ts +617 -0
  125. package/script/schemas/ome_zarr.d.ts.map +1 -0
  126. package/script/schemas/ome_zarr.js +211 -0
  127. package/script/schemas/rfc4.d.ts +334 -0
  128. package/script/schemas/rfc4.d.ts.map +1 -0
  129. package/script/schemas/rfc4.js +132 -0
  130. package/script/schemas/units.d.ts +70 -5
  131. package/script/schemas/units.d.ts.map +1 -1
  132. package/script/schemas/units.js +4 -12
  133. package/script/schemas/zarr_metadata.d.ts +10 -4
  134. package/script/schemas/zarr_metadata.d.ts.map +1 -1
  135. package/script/schemas/zarr_metadata.js +23 -2
  136. package/script/types/array_interface.d.ts +7 -0
  137. package/script/types/array_interface.d.ts.map +1 -0
  138. package/script/types/array_interface.js +2 -0
  139. package/script/types/hcs.d.ts +70 -0
  140. package/script/types/hcs.d.ts.map +1 -0
  141. package/script/types/hcs.js +233 -0
  142. package/script/types/methods.d.ts.map +1 -1
  143. package/script/types/methods.js +2 -0
  144. package/script/types/multiscales.d.ts.map +1 -1
  145. package/script/types/ngff_image.d.ts +6 -3
  146. package/script/types/ngff_image.d.ts.map +1 -1
  147. package/script/types/ngff_image.js +13 -1
  148. package/script/types/rfc4.d.ts +94 -0
  149. package/script/types/rfc4.d.ts.map +1 -0
  150. package/script/types/rfc4.js +143 -0
  151. package/script/types/units.d.ts +1 -1
  152. package/script/types/units.d.ts.map +1 -1
  153. package/script/types/zarr_metadata.d.ts +14 -5
  154. package/script/types/zarr_metadata.d.ts.map +1 -1
  155. package/script/utils/create_queue.d.ts +6 -0
  156. package/script/utils/create_queue.d.ts.map +1 -0
  157. package/script/utils/create_queue.js +17 -0
  158. package/script/utils/factory.d.ts +1 -1
  159. package/script/utils/factory.d.ts.map +1 -1
  160. package/script/utils/factory.js +39 -7
  161. package/script/utils/method_metadata.d.ts +10 -0
  162. package/script/utils/method_metadata.d.ts.map +1 -0
  163. package/script/utils/method_metadata.js +40 -0
  164. package/script/utils/validation.d.ts.map +1 -1
  165. package/esm/schemas/lazy_array.d.ts +0 -8
  166. package/esm/schemas/lazy_array.d.ts.map +0 -1
  167. package/esm/schemas/lazy_array.js +0 -7
  168. package/esm/types/lazy_array.d.ts +0 -18
  169. package/esm/types/lazy_array.d.ts.map +0 -1
  170. package/esm/types/lazy_array.js +0 -27
  171. package/script/schemas/lazy_array.d.ts +0 -8
  172. package/script/schemas/lazy_array.d.ts.map +0 -1
  173. package/script/schemas/lazy_array.js +0 -10
  174. package/script/types/lazy_array.d.ts +0 -18
  175. package/script/types/lazy_array.d.ts.map +0 -1
  176. package/script/types/lazy_array.js +0 -31
@@ -0,0 +1,244 @@
1
+ "use strict";
2
+ // SPDX-FileCopyrightText: Copyright (c) Fideus Labs LLC
3
+ // SPDX-License-Identifier: MIT
4
+ /**
5
+ * Convert NgffImage to ITK-Wasm Image
6
+ */
7
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
+ if (k2 === undefined) k2 = k;
9
+ var desc = Object.getOwnPropertyDescriptor(m, k);
10
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
+ desc = { enumerable: true, get: function() { return m[k]; } };
12
+ }
13
+ Object.defineProperty(o, k2, desc);
14
+ }) : (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ o[k2] = m[k];
17
+ }));
18
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
20
+ }) : function(o, v) {
21
+ o["default"] = v;
22
+ });
23
+ var __importStar = (this && this.__importStar) || function (mod) {
24
+ if (mod && mod.__esModule) return mod;
25
+ var result = {};
26
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
27
+ __setModuleDefault(result, mod);
28
+ return result;
29
+ };
30
+ Object.defineProperty(exports, "__esModule", { value: true });
31
+ exports.ngffImageToItkImage = ngffImageToItkImage;
32
+ const zarr = __importStar(require("zarrita"));
33
+ const ngff_image_js_1 = require("../types/ngff_image.js");
34
+ /**
35
+ * Convert the data type from zarr DataType to ITK-Wasm component type
36
+ */
37
+ function dataTypeToComponentType(dataType) {
38
+ switch (dataType) {
39
+ case "uint8":
40
+ return "uint8";
41
+ case "int8":
42
+ return "int8";
43
+ case "uint16":
44
+ return "uint16";
45
+ case "int16":
46
+ return "int16";
47
+ case "uint32":
48
+ return "uint32";
49
+ case "int32":
50
+ return "int32";
51
+ case "uint64":
52
+ return "uint64";
53
+ case "int64":
54
+ return "int64";
55
+ case "float32":
56
+ return "float32";
57
+ case "float64":
58
+ return "float64";
59
+ default:
60
+ throw new Error(`Unsupported data type: ${dataType}`);
61
+ }
62
+ }
63
+ /**
64
+ * Move the channel dimension to the end (last position) if it exists
65
+ * This follows the ITK convention where vector/RGB components are the last dimension
66
+ */
67
+ function moveChannelDimToLast(ngffImage) {
68
+ const dims = ngffImage.dims;
69
+ const cIndex = dims.indexOf("c");
70
+ if (cIndex === -1 || cIndex === dims.length - 1) {
71
+ // No channel dimension or already at the end
72
+ return ngffImage;
73
+ }
74
+ // Reorder dimensions to move 'c' to the end
75
+ const newDims = [...dims];
76
+ const cDim = newDims.splice(cIndex, 1)[0];
77
+ newDims.push(cDim);
78
+ // Note: We would need to transpose the zarr array data here
79
+ // For now, we'll assume the data is already in the correct order
80
+ // In a full implementation, you'd transpose the zarr array
81
+ return new ngff_image_js_1.NgffImage({
82
+ data: ngffImage.data, // TODO: transpose if needed
83
+ dims: newDims,
84
+ scale: ngffImage.scale,
85
+ translation: ngffImage.translation,
86
+ name: ngffImage.name,
87
+ axesUnits: ngffImage.axesUnits,
88
+ axesOrientations: ngffImage.axesOrientations,
89
+ computedCallbacks: ngffImage.computedCallbacks,
90
+ });
91
+ }
92
+ /**
93
+ * Convert an NgffImage to an ITK-Wasm Image, preserving spatial metadata.
94
+ *
95
+ * This function converts NgffImage objects to ITK-Wasm Image format while
96
+ * preserving spatial information like spacing, origin, and direction matrix.
97
+ * Optionally extracts specific time or channel slices.
98
+ *
99
+ * @param ngffImage - The NgffImage to convert
100
+ * @param options - Conversion options
101
+ * @returns Promise resolving to ITK-Wasm Image
102
+ */
103
+ async function ngffImageToItkImage(ngffImage, options = {}) {
104
+ const { tIndex, cIndex } = options;
105
+ let workingImage = ngffImage;
106
+ // Extract time slice if requested
107
+ if (tIndex !== undefined && workingImage.dims.includes("t")) {
108
+ const tDimIndex = workingImage.dims.indexOf("t");
109
+ const newDims = workingImage.dims.filter((dim) => dim !== "t");
110
+ const newScale = Object.fromEntries(Object.entries(workingImage.scale).filter(([dim]) => dim !== "t"));
111
+ const newTranslation = Object.fromEntries(Object.entries(workingImage.translation).filter(([dim]) => dim !== "t"));
112
+ // Extract the time slice from zarr array
113
+ const selection = new Array(workingImage.data.shape.length).fill(null);
114
+ selection[tDimIndex] = tIndex;
115
+ const sliceData = await zarr.get(workingImage.data, selection);
116
+ // Create new zarr array with reduced dimensions
117
+ const store = new Map();
118
+ const root = zarr.root(store);
119
+ const newShape = workingImage.data.shape.filter((_, i) => i !== tDimIndex);
120
+ const chunkShape = newShape.map((s) => Math.min(s, 256));
121
+ const newArray = await zarr.create(root.resolve("slice"), {
122
+ shape: newShape,
123
+ chunk_shape: chunkShape,
124
+ data_type: workingImage.data.dtype,
125
+ fill_value: 0,
126
+ });
127
+ // Write the slice data
128
+ const fullSelection = new Array(newShape.length).fill(null);
129
+ await zarr.set(newArray, fullSelection, sliceData);
130
+ workingImage = new ngff_image_js_1.NgffImage({
131
+ data: newArray,
132
+ dims: newDims,
133
+ scale: newScale,
134
+ translation: newTranslation,
135
+ name: workingImage.name,
136
+ axesUnits: workingImage.axesUnits
137
+ ? Object.fromEntries(Object.entries(workingImage.axesUnits).filter(([dim]) => dim !== "t"))
138
+ : undefined,
139
+ axesOrientations: workingImage.axesOrientations
140
+ ? Object.fromEntries(Object.entries(workingImage.axesOrientations).filter(([dim]) => dim !== "t"))
141
+ : undefined,
142
+ computedCallbacks: workingImage.computedCallbacks,
143
+ });
144
+ }
145
+ // Extract channel slice if requested
146
+ if (cIndex !== undefined && workingImage.dims.includes("c")) {
147
+ const cDimIndex = workingImage.dims.indexOf("c");
148
+ const newDims = workingImage.dims.filter((dim) => dim !== "c");
149
+ const newScale = Object.fromEntries(Object.entries(workingImage.scale).filter(([dim]) => dim !== "c"));
150
+ const newTranslation = Object.fromEntries(Object.entries(workingImage.translation).filter(([dim]) => dim !== "c"));
151
+ // Extract the channel slice from zarr array
152
+ const selection = new Array(workingImage.data.shape.length).fill(null);
153
+ selection[cDimIndex] = cIndex;
154
+ const sliceData = await zarr.get(workingImage.data, selection);
155
+ // Create new zarr array with reduced dimensions
156
+ const store = new Map();
157
+ const root = zarr.root(store);
158
+ const newShape = workingImage.data.shape.filter((_, i) => i !== cDimIndex);
159
+ const chunkShape = newShape.map((s) => Math.min(s, 256));
160
+ const newArray = await zarr.create(root.resolve("slice"), {
161
+ shape: newShape,
162
+ chunk_shape: chunkShape,
163
+ data_type: workingImage.data.dtype,
164
+ fill_value: 0,
165
+ });
166
+ // Write the slice data
167
+ const fullSelection = new Array(newShape.length).fill(null);
168
+ await zarr.set(newArray, fullSelection, sliceData);
169
+ workingImage = new ngff_image_js_1.NgffImage({
170
+ data: newArray,
171
+ dims: newDims,
172
+ scale: newScale,
173
+ translation: newTranslation,
174
+ name: workingImage.name,
175
+ axesUnits: workingImage.axesUnits
176
+ ? Object.fromEntries(Object.entries(workingImage.axesUnits).filter(([dim]) => dim !== "c"))
177
+ : undefined,
178
+ axesOrientations: workingImage.axesOrientations
179
+ ? Object.fromEntries(Object.entries(workingImage.axesOrientations).filter(([dim]) => dim !== "c"))
180
+ : undefined,
181
+ computedCallbacks: workingImage.computedCallbacks,
182
+ });
183
+ }
184
+ // Move channel dimension to last position (ITK convention)
185
+ workingImage = moveChannelDimToLast(workingImage);
186
+ const dims = workingImage.dims;
187
+ const data = workingImage.data;
188
+ // Identify ITK spatial dimensions
189
+ const itkDimensionNames = new Set(["x", "y", "z", "t"]);
190
+ const itkDims = dims.filter((dim) => itkDimensionNames.has(dim));
191
+ // Sort ITK dimensions: spatial first (x, y, z), then time
192
+ const sortedItkDims = itkDims.sort((a, b) => {
193
+ const order = ["x", "y", "z", "t"];
194
+ return order.indexOf(a) - order.indexOf(b);
195
+ });
196
+ // Create ITK spacing, origin, and size arrays
197
+ // sortedItkDims is already in physical space order [x, y, z]
198
+ // Mapping from dims extracts the correct values from NGFF's array order [z, y, x]
199
+ const spacing = sortedItkDims.map((dim) => workingImage.scale[dim] || 1.0);
200
+ const origin = sortedItkDims.map((dim) => workingImage.translation[dim] || 0.0);
201
+ const size = sortedItkDims.map((dim) => data.shape[dims.indexOf(dim)]);
202
+ const dimension = sortedItkDims.length;
203
+ // Determine component type and pixel type
204
+ const componentType = dataTypeToComponentType(data.dtype);
205
+ let components = 1;
206
+ let pixelType = "Scalar";
207
+ if (dims.includes("c")) {
208
+ components = data.shape[dims.indexOf("c")];
209
+ if (components === 3 && componentType === "uint8") {
210
+ pixelType = "RGB";
211
+ }
212
+ else {
213
+ pixelType =
214
+ "VariableLengthVector";
215
+ }
216
+ }
217
+ // Create ImageType
218
+ const imageType = {
219
+ dimension,
220
+ componentType,
221
+ pixelType,
222
+ components,
223
+ };
224
+ // Read all data from zarr array
225
+ const selection = new Array(data.shape.length).fill(null);
226
+ const dataChunk = await zarr.get(data, selection);
227
+ // Create direction matrix (identity for now)
228
+ const direction = new Float64Array(dimension * dimension);
229
+ for (let i = 0; i < dimension; i++) {
230
+ direction[i * dimension + i] = 1.0;
231
+ }
232
+ // Create ITK-Wasm Image
233
+ const itkImage = {
234
+ imageType,
235
+ name: workingImage.name || "image",
236
+ origin,
237
+ spacing,
238
+ direction,
239
+ size,
240
+ metadata: new Map(),
241
+ data: dataChunk.data, // Cast to handle zarrita's data type
242
+ };
243
+ return itkImage;
244
+ }
@@ -0,0 +1,18 @@
1
+ import { NgffImage } from "../types/ngff_image.js";
2
+ import { Multiscales } from "../types/multiscales.js";
3
+ import { Methods } from "../types/methods.js";
4
+ export { toNgffImage, type ToNgffImageOptions } from "./to_ngff_image.js";
5
+ export interface ToMultiscalesOptions {
6
+ scaleFactors?: (Record<string, number> | number)[];
7
+ method?: Methods;
8
+ chunks?: number | number[] | Record<string, number>;
9
+ }
10
+ /**
11
+ * Generate multiple resolution scales for an NgffImage (simplified version for testing)
12
+ *
13
+ * @param image - Input NgffImage
14
+ * @param options - Configuration options
15
+ * @returns Multiscales object
16
+ */
17
+ export declare function toMultiscales(image: NgffImage, options?: ToMultiscalesOptions): Promise<Multiscales>;
18
+ //# sourceMappingURL=to_multiscales.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"to_multiscales.d.ts","sourceRoot":"","sources":["../../src/io/to_multiscales.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAW9C,OAAO,EAAE,WAAW,EAAE,KAAK,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAE1E,MAAM,WAAW,oBAAoB;IACnC,YAAY,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,EAAE,CAAC;IACnD,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACrD;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CACjC,KAAK,EAAE,SAAS,EAChB,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,WAAW,CAAC,CAqEtB"}
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toNgffImage = void 0;
4
+ exports.toMultiscales = toMultiscales;
5
+ const methods_js_1 = require("../types/methods.js");
6
+ const factory_js_1 = require("../utils/factory.js");
7
+ const method_metadata_js_1 = require("../utils/method_metadata.js");
8
+ const itkwasm_js_1 = require("../methods/itkwasm.js");
9
+ // Re-export for convenience
10
+ var to_ngff_image_js_1 = require("./to_ngff_image.js");
11
+ Object.defineProperty(exports, "toNgffImage", { enumerable: true, get: function () { return to_ngff_image_js_1.toNgffImage; } });
12
+ /**
13
+ * Generate multiple resolution scales for an NgffImage (simplified version for testing)
14
+ *
15
+ * @param image - Input NgffImage
16
+ * @param options - Configuration options
17
+ * @returns Multiscales object
18
+ */
19
+ async function toMultiscales(image, options = {}) {
20
+ const { scaleFactors = [2, 4], method = methods_js_1.Methods.ITKWASM_GAUSSIAN, chunks: _chunks, } = options;
21
+ let images;
22
+ // Check if we should perform actual downsampling
23
+ if (method === methods_js_1.Methods.ITKWASM_GAUSSIAN ||
24
+ method === methods_js_1.Methods.ITKWASM_BIN_SHRINK ||
25
+ method === methods_js_1.Methods.ITKWASM_LABEL_IMAGE) {
26
+ // Perform actual downsampling using ITK-Wasm
27
+ const smoothing = method === methods_js_1.Methods.ITKWASM_GAUSSIAN
28
+ ? "gaussian"
29
+ : method === methods_js_1.Methods.ITKWASM_BIN_SHRINK
30
+ ? "bin_shrink"
31
+ : "label_image";
32
+ images = await (0, itkwasm_js_1.downsampleItkWasm)(image, scaleFactors, smoothing);
33
+ }
34
+ else {
35
+ // Fallback: create only the base image (no actual downsampling)
36
+ images = [image];
37
+ }
38
+ // Create axes from image dimensions
39
+ const axes = image.dims.map((dim) => {
40
+ if (dim === "x" || dim === "y" || dim === "z") {
41
+ return (0, factory_js_1.createAxis)(dim, "space", image.axesUnits?.[dim]);
42
+ }
43
+ else if (dim === "c") {
44
+ return (0, factory_js_1.createAxis)(dim, "channel");
45
+ }
46
+ else if (dim === "t") {
47
+ return (0, factory_js_1.createAxis)(dim, "time");
48
+ }
49
+ else {
50
+ throw new Error(`Unsupported dimension: ${dim}`);
51
+ }
52
+ });
53
+ // Create datasets for all images
54
+ const datasets = images.map((img, index) => {
55
+ return (0, factory_js_1.createDataset)(`scale${index}`, img.dims.map((dim) => img.scale[dim]), img.dims.map((dim) => img.translation[dim]));
56
+ });
57
+ // Create metadata with method information
58
+ const methodMetadata = (0, method_metadata_js_1.getMethodMetadata)(method);
59
+ const metadata = (0, factory_js_1.createMetadata)(axes, datasets, image.name);
60
+ // The 'type' field, part of the OME-Zarr specification, in metadata is used here to
61
+ // record the downsampling method applied to generate multiscale images for provenance.
62
+ metadata.type = method;
63
+ if (methodMetadata) {
64
+ metadata.metadata = methodMetadata;
65
+ }
66
+ return (0, factory_js_1.createMultiscales)(images, metadata, scaleFactors, method);
67
+ }
@@ -0,0 +1,17 @@
1
+ import { NgffImage } from "../types/ngff_image.js";
2
+ export interface ToNgffImageOptions {
3
+ dims?: string[];
4
+ scale?: Record<string, number>;
5
+ translation?: Record<string, number>;
6
+ name?: string;
7
+ shape?: number[];
8
+ }
9
+ /**
10
+ * Convert array data to NgffImage
11
+ *
12
+ * @param data - Input data as typed array or regular array
13
+ * @param options - Configuration options for NgffImage creation
14
+ * @returns NgffImage instance
15
+ */
16
+ export declare function toNgffImage(data: ArrayLike<number> | number[][] | number[][][], options?: ToNgffImageOptions): Promise<NgffImage>;
17
+ //# sourceMappingURL=to_ngff_image.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"to_ngff_image.d.ts","sourceRoot":"","sources":["../../src/io/to_ngff_image.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAGnD,MAAM,WAAW,kBAAkB;IACjC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;CAClB;AAED;;;;;;GAMG;AACH,wBAAsB,WAAW,CAC/B,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,EAAE,EAAE,EACnD,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,SAAS,CAAC,CAqIpB"}
@@ -0,0 +1,162 @@
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,9 +1,10 @@
1
+ import * as zarr from "zarrita";
1
2
  import type { Multiscales } from "../types/multiscales.js";
3
+ import type { MemoryStore } from "./from_ngff_zarr.js";
2
4
  export interface ToNgffZarrOptions {
3
5
  overwrite?: boolean;
4
6
  version?: "0.4" | "0.5";
5
- useTensorstore?: boolean;
6
7
  chunksPerShard?: number | number[] | Record<string, number>;
7
8
  }
8
- export declare function toNgffZarr(_storePath: string, _multiscales: Multiscales, options?: ToNgffZarrOptions): Promise<void>;
9
+ export declare function toNgffZarr(store: string | MemoryStore | zarr.FetchStore, multiscales: Multiscales, options?: ToNgffZarrOptions): Promise<void>;
9
10
  //# sourceMappingURL=to_ngff_zarr.d.ts.map
@@ -1 +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"}
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"}