Commit b16a728
authored
Merge pull request #27 from janelia-cellmap/expand_dims
# Changes
**New feature: `--expand_dims` flag**
Prepends a size-1 channel dimension to the output array, converting `(z,y,x)` → `(1,z,y,x)`. Supported for all input formats: TIFF, TIFF stack, MRC, zarr v2, and N5.
**Bug fixes bundled in**
- `TiffStack.__init__`: replaced `da.from_zarr(ZarrTiffStore)` with direct `.zarray` JSON read — `ZarrTiffStore` is incompatible with zarr v3
- `N5Group.apply_ome_template`: `coordinateTransformations` scale/translation vectors had wrong length for non-3D arrays (ndim was computed before the channel axis was prepended)
# Implementation
Each format's `write_to_zarr` and its worker function (`save_chunk` / `write_tile_slab` / `write_volume_slab`) receives `expand_dims`. The worker reads from the source using `chunk_slice[1:]` (skipping the channel dim absent in the source) and writes `data[np.newaxis]` into the destination.
OME multiscales metadata is updated per format:
- **Tiff/TiffStack/MRC**: channel axis prepended to `axes/scale/translation/units` in `to_zarr` before `add_ome_metadata` is called
- **zarr v2**: post-processing walk (`_patch_group_multiscales`) rewrites the copied multiscales attrs
- **N5**: `expand_dims` threaded through `normalize_to_omengff` → `apply_ome_template` / `ome_dataset_metadata`
# Tests
`tests/test_expand_dims_and_4d.py` - 9 tests
- `test_expand_dims_{tiff,tiff_stack,mrc,zarr2,n5}`: verify output shape is `(1, *src_shape)` and OME axes metadata has a leading channel axis
- `test_4d_{tiff,mrc,zarr2,n5}`: verify native 4D inputs pass through with correct shape and axes9 files changed
Lines changed: 675 additions & 187 deletions
File tree
- src/zarrify
- formats
- utils
- tests
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
60 | 63 | | |
61 | 64 | | |
62 | 65 | | |
| |||
78 | 81 | | |
79 | 82 | | |
80 | 83 | | |
81 | | - | |
| 84 | + | |
82 | 85 | | |
83 | 86 | | |
84 | 87 | | |
85 | 88 | | |
86 | 89 | | |
87 | 90 | | |
88 | 91 | | |
89 | | - | |
| 92 | + | |
| 93 | + | |
90 | 94 | | |
91 | 95 | | |
92 | 96 | | |
| |||
98 | 102 | | |
99 | 103 | | |
100 | 104 | | |
101 | | - | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
102 | 109 | | |
103 | 110 | | |
104 | | - | |
| 111 | + | |
| 112 | + | |
105 | 113 | | |
106 | 114 | | |
107 | | - | |
| 115 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
177 | 177 | | |
178 | 178 | | |
179 | 179 | | |
180 | | - | |
| 180 | + | |
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
185 | 185 | | |
186 | 186 | | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
187 | 190 | | |
188 | 191 | | |
189 | 192 | | |
| |||
196 | 199 | | |
197 | 200 | | |
198 | 201 | | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
199 | 207 | | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
| 208 | + | |
204 | 209 | | |
205 | 210 | | |
206 | | - | |
| 211 | + | |
207 | 212 | | |
208 | 213 | | |
209 | 214 | | |
210 | 215 | | |
211 | 216 | | |
212 | 217 | | |
213 | 218 | | |
214 | | - | |
| 219 | + | |
215 | 220 | | |
216 | 221 | | |
217 | 222 | | |
218 | 223 | | |
219 | 224 | | |
220 | 225 | | |
| 226 | + | |
| 227 | + | |
221 | 228 | | |
222 | 229 | | |
223 | 230 | | |
224 | 231 | | |
225 | 232 | | |
226 | 233 | | |
227 | | - | |
| 234 | + | |
228 | 235 | | |
229 | | - | |
| 236 | + | |
230 | 237 | | |
231 | 238 | | |
232 | | - | |
| 239 | + | |
233 | 240 | | |
234 | 241 | | |
235 | 242 | | |
| |||
246 | 253 | | |
247 | 254 | | |
248 | 255 | | |
249 | | - | |
| 256 | + | |
| 257 | + | |
250 | 258 | | |
251 | 259 | | |
252 | 260 | | |
| |||
255 | 263 | | |
256 | 264 | | |
257 | 265 | | |
| 266 | + | |
| 267 | + | |
258 | 268 | | |
259 | 269 | | |
260 | 270 | | |
261 | 271 | | |
262 | 272 | | |
263 | 273 | | |
264 | | - | |
265 | 274 | | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
275 | 287 | | |
276 | 288 | | |
277 | 289 | | |
| |||
281 | 293 | | |
282 | 294 | | |
283 | 295 | | |
| 296 | + | |
284 | 297 | | |
285 | 298 | | |
286 | 299 | | |
| |||
325 | 338 | | |
326 | 339 | | |
327 | 340 | | |
| 341 | + | |
328 | 342 | | |
329 | 343 | | |
330 | | - | |
| 344 | + | |
| 345 | + | |
331 | 346 | | |
332 | 347 | | |
333 | | - | |
| 348 | + | |
334 | 349 | | |
335 | 350 | | |
336 | 351 | | |
| |||
341 | 356 | | |
342 | 357 | | |
343 | 358 | | |
344 | | - | |
| 359 | + | |
345 | 360 | | |
346 | 361 | | |
347 | 362 | | |
| |||
353 | 368 | | |
354 | 369 | | |
355 | 370 | | |
356 | | - | |
| 371 | + | |
357 | 372 | | |
358 | 373 | | |
359 | 374 | | |
| |||
362 | 377 | | |
363 | 378 | | |
364 | 379 | | |
365 | | - | |
| 380 | + | |
366 | 381 | | |
367 | 382 | | |
368 | 383 | | |
| |||
376 | 391 | | |
377 | 392 | | |
378 | 393 | | |
379 | | - | |
| 394 | + | |
380 | 395 | | |
381 | 396 | | |
382 | 397 | | |
383 | 398 | | |
384 | 399 | | |
385 | 400 | | |
386 | 401 | | |
| 402 | + | |
387 | 403 | | |
388 | 404 | | |
389 | 405 | | |
| |||
396 | 412 | | |
397 | 413 | | |
398 | 414 | | |
399 | | - | |
| 415 | + | |
400 | 416 | | |
401 | 417 | | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
402 | 421 | | |
403 | 422 | | |
404 | | - | |
| 423 | + | |
| 424 | + | |
405 | 425 | | |
406 | 426 | | |
407 | 427 | | |
408 | 428 | | |
409 | 429 | | |
| 430 | + | |
| 431 | + | |
410 | 432 | | |
411 | 433 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | | - | |
| 72 | + | |
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
82 | 85 | | |
83 | 86 | | |
84 | 87 | | |
| |||
87 | 90 | | |
88 | 91 | | |
89 | 92 | | |
90 | | - | |
91 | | - | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
92 | 96 | | |
93 | 97 | | |
| 98 | + | |
| 99 | + | |
94 | 100 | | |
| 101 | + | |
95 | 102 | | |
96 | | - | |
| 103 | + | |
97 | 104 | | |
98 | 105 | | |
99 | 106 | | |
100 | 107 | | |
101 | | - | |
| 108 | + | |
102 | 109 | | |
103 | 110 | | |
104 | | - | |
| 111 | + | |
105 | 112 | | |
106 | 113 | | |
107 | 114 | | |
| |||
123 | 130 | | |
124 | 131 | | |
125 | 132 | | |
126 | | - | |
| 133 | + | |
127 | 134 | | |
128 | 135 | | |
129 | 136 | | |
| |||
134 | 141 | | |
135 | 142 | | |
136 | 143 | | |
137 | | - | |
| 144 | + | |
| 145 | + | |
138 | 146 | | |
139 | 147 | | |
140 | 148 | | |
| |||
143 | 151 | | |
144 | 152 | | |
145 | 153 | | |
146 | | - | |
| 154 | + | |
147 | 155 | | |
148 | 156 | | |
149 | 157 | | |
150 | 158 | | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
151 | 162 | | |
152 | | - | |
| 163 | + | |
153 | 164 | | |
154 | | - | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
0 commit comments