-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix downsampling/compression of segmentation layers + misc (#657)
* add test for cubing/downsampling/compressing (end-to-end) for a color and segmentation layer * fix downsampling and compressing segmentation layers (cast largest_segment_id to int if necessary and safe; also pass when creating copy of layer) * improve logging (e.g., point out deprecated caller location) and remove some deprecation warnings * upgrade zarr in wkcuber to be in sync with webknossos package * add/clean up ./lint.sh, ./typecheck.sh and ./format.sh for wkcuber * remove isort from wkcuber for now * format * fix typing * update changelog Co-authored-by: Norman Rzepka <[email protected]>
- Loading branch information
1 parent
f90ad7b
commit 29821ee
Showing
14 changed files
with
108 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env bash | ||
set -eEuo pipefail | ||
|
||
if [ $# -eq 1 ] && [ "$1" = "check" ]; then | ||
poetry run black --check . | ||
else | ||
poetry run black . | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env bash | ||
set -eEuo pipefail | ||
|
||
poetry run pylint -j4 wkcuber |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
from pathlib import Path | ||
import numpy as np | ||
import pytest | ||
from wkcuber.utils import ( | ||
setup_logging, | ||
) | ||
from webknossos import Dataset | ||
from wkcuber.__main__ import create_parser, cube_with_args | ||
from tifffile import TiffWriter | ||
|
||
TESTOUTPUT_DIR = Path("testoutput") | ||
|
||
|
||
@pytest.mark.parametrize("category", ["color", "segmentation"]) | ||
def test_main(category: str) -> None: | ||
input_folder = TESTOUTPUT_DIR / "raw_dataset" / category | ||
input_folder.mkdir(parents=True, exist_ok=True) | ||
|
||
raw_file = input_folder / "input.tif" | ||
|
||
input_dtype = "uint32" | ||
shape = 64, 128, 256 | ||
data = np.arange(np.prod(shape), dtype=input_dtype).reshape(shape) | ||
with TiffWriter(raw_file) as tif: | ||
tif.write(data.transpose([2, 1, 0])) | ||
|
||
output_path = TESTOUTPUT_DIR / "output_2" | ||
output_path.mkdir() | ||
|
||
args_list = [ | ||
str(TESTOUTPUT_DIR / "raw_dataset"), | ||
str(output_path), | ||
"--jobs", | ||
"1", | ||
"--scale", | ||
"11,11,11", | ||
"--max_mag", | ||
"4", | ||
] | ||
|
||
args = create_parser().parse_args(args_list) | ||
cube_with_args(args) | ||
|
||
dataset = Dataset.open(output_path) | ||
if category == "color": | ||
layer = dataset.get_color_layers()[0] | ||
else: | ||
layer = dataset.get_segmentation_layers()[0] | ||
mag_view = layer.get_mag(1) | ||
view = mag_view.get_view() | ||
read_data = view.read() | ||
|
||
assert view.size == shape | ||
assert view.get_dtype() == data.dtype | ||
assert np.array_equal( | ||
read_data[0], | ||
data, | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
from argparse import Namespace | ||
|
||
setup_logging(Namespace(verbose=False)) | ||
test_main("color") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters