Skip to content

Commit

Permalink
Define metadata within kwargs
Browse files Browse the repository at this point in the history
  • Loading branch information
gselzer committed Jun 1, 2023
1 parent 66b0a28 commit d050e2a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
6 changes: 1 addition & 5 deletions src/napari_imagej/types/converters/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,10 @@ def _java_image_to_image_layer(image: Any) -> Image:
view = ij().convert().convert(image, jc.DatasetView)
# Construct an xarray from the DatasetView
xarr: DataArray = java_to_xarray(ij(), view.getData())
# Construct metadata
metadata = getattr(xarr, "attrs", {}).copy()
metadata["dims"] = xarr.dims
metadata["coords"] = xarr.coords
# Construct a map of Image layer parameters
kwargs = dict(
data=xarr,
metadata=metadata,
metadata=getattr(xarr, "attrs", {}),
name=view.getData().getName(),
)
if view.getColorTables() and view.getColorTables().size() > 0:
Expand Down
2 changes: 2 additions & 0 deletions tests/types/test_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,7 @@ def test_dataset(ij) -> "jc.Dataset":
name = "test.foo"
dataset: jc.Dataset = ij.dataset().create(ij.py.to_java(np.ones((10, 10))))
dataset.setName(name)
dataset.getProperties().put("foo", 4)
return dataset


Expand Down Expand Up @@ -813,6 +814,7 @@ def test_dataset_to_image_layer(ij, test_dataset):
assert isinstance(p_img, Image)
assert test_dataset.getName() == p_img.name
assert "gray" == p_img.colormap.name
assert p_img.metadata.get("foo", None) == 4


def test_binary_dataset_to_image_layer(ij, test_binary_dataset):
Expand Down

0 comments on commit d050e2a

Please sign in to comment.