Skip to content

Commit

Permalink
fix: Fix bug in the wrong order of axis saved in napari contribution (#…
Browse files Browse the repository at this point in the history
…972)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
Czaki and pre-commit-ci[bot] authored May 29, 2023
1 parent 2e2a0c0 commit 5a2957f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package/PartSegCore/napari_plugins/save_tiff_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def napari_write_labels(path: str, data: Any, meta: dict) -> Optional[str]:
image = Image(
data,
np.divide(meta["scale"], DEFAULT_SCALE_FACTOR)[-scale_shift:],
axes_order="TZXY"[-data.ndim :],
axes_order="TZYX"[-data.ndim :],
channel_names=[meta["name"]],
shift=np.divide(meta["translate"], DEFAULT_SCALE_FACTOR)[-scale_shift:],
name="ROI",
Expand Down
11 changes: 11 additions & 0 deletions package/tests/test_PartSegCore/test_napari_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import pytest
from napari.layers import Image, Labels, Layer

from PartSegCore.mask.io_functions import LoadROIFromTIFF
from PartSegCore.napari_plugins.load_image import napari_get_reader as napari_get_reader_image
from PartSegCore.napari_plugins.load_mask_project import napari_get_reader as napari_get_reader_mask
from PartSegCore.napari_plugins.load_masked_image import napari_get_reader as napari_get_reader_mask_image
from PartSegCore.napari_plugins.load_roi_project import napari_get_reader as napari_get_reader_roi
from PartSegCore.napari_plugins.loader import project_to_layers
from PartSegCore.napari_plugins.save_mask_roi import napari_write_labels
from PartSegCore.napari_plugins.save_tiff_layer import napari_write_labels as napari_write_labels_tiff


def test_project_to_layers_analysis(analysis_segmentation):
Expand Down Expand Up @@ -91,3 +93,12 @@ def test_write_labels(tmp_path):

assert napari_write_labels(str(tmp_path / "test.txt"), data, {"scale": [10, 10]}) is None
assert not (tmp_path / "test.txt").exists()


def test_save_load_axis_order(tmp_path):
data = np.zeros((1, 10, 20, 30), dtype=np.uint8)
layer = Labels(data)
data_path = str(tmp_path / "test.tif")
assert napari_write_labels_tiff(data_path, *layer.as_layer_data_tuple()[:2])
proj = LoadROIFromTIFF.load([data_path])
assert proj.roi_info.roi.shape == data.shape

0 comments on commit 5a2957f

Please sign in to comment.