Skip to content

feat: add invert option for N5 and zarr v2 sources - #37

Merged
yuriyzubov merged 3 commits into
mainfrom
feat/invert
Oct 28, 2026
Merged

yuriyzubov merged 3 commits into
mainfrom
feat/invert

Conversation

@yuriyzubov

@yuriyzubov yuriyzubov commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Adds an option to bitwise-invert voxel data for N5 and zarr v2 sources.

Changes

  • New config key invert (default false) and CLI flag --invert.
  • N5Group.write_to_zarr and Zarr2Group.write_to_zarr pass invert to save_chunk. Before, N5 always used invert=False.
  • When invert is on, the output fill_value is np.invert(0) (255 for uint8). save_chunk skips all-zero source chunks, and these chunks now read as the inverted value. Without this, they stayed 0 while zeros in other chunks became 255. Empty regions are still not written to disk. zarr3_spec has a new fill_value parameter for this.
  • --optimize_reads and --invert now default to None. The CLI drops None values before it merges the config, so a value in the config file is no longer overridden by the flag's default False.

Tests: tests/test_invert.py checks invert on and off for zarr v2 and N5, an all-zero chunk with invert on, and that the CLI flags do not override config values when they are not given.

Stack: 4 of 5. Base: #36.

🤖 Generated with Claude Code

yuriyzubov and others added 3 commits October 28, 2026 15:23
Adds an invert config key and --invert CLI flag that bitwise-invert
voxel data before writing. The --optimize_reads and --invert flags now
default to None, so a value from the config file is not overridden when
the flag is not given.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
save_chunk skips all-zero source chunks before it inverts, so with
invert on those chunks read back as 0 instead of np.invert(0). Set the
output fill_value to np.invert(0) when invert is on: skipped chunks then
read as the inverted value, and empty regions are still not written.
zarr3_spec gets a fill_value parameter for this.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@yuriyzubov
yuriyzubov changed the base branch from feat/blosc-options to main October 28, 2026 20:28
@yuriyzubov yuriyzubov closed this Oct 28, 2026
@yuriyzubov yuriyzubov reopened this Oct 28, 2026
@yuriyzubov
yuriyzubov merged commit e2d9ebc into main Oct 28, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant