Skip to content

Commit

Permalink
Merge pull request #23 from fractal-analytics-platform/fix_wavelength…
Browse files Browse the repository at this point in the history
…_ids

fix bug in ngio when saving wavelenght ids
  • Loading branch information
lorenzocerrone authored Jan 16, 2025
2 parents ef14308 + 434a9f8 commit 35d66d3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/ngio/ngff_meta/v04/zarr_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,13 @@ def vanilla_omero_v04_to_fractal(omero04: Omero04) -> Omero:
for channel04 in omero04.channels:
# Convert the window to a dictionary
label = channel04.label
wavelength_id = channel04.extra_fields.get("wavelength_id", label)

if "wavelength_id" in channel04.extra_fields:
# If the wavelength_id is present, pop it from the extra fields
# so that it is not added to the channel_visualisation
wavelength_id = channel04.extra_fields.pop("wavelength_id")
else:
wavelength_id = label

if channel04.window is None:
window04 = Window04(
Expand Down Expand Up @@ -161,6 +167,7 @@ def fractal_omero_to_vanilla_v04(omero: Omero) -> Omero04:
color=channel.channel_visualisation.color,
active=channel.channel_visualisation.active,
window=window04,
wavelength_id=channel.wavelength_id,
**channel.channel_visualisation.extra_fields,
)
list_channels04.append(channel04)
Expand Down
1 change: 1 addition & 0 deletions tests/ngff_meta/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def test_create_fractal_meta_with_t(self) -> None:
)

assert meta.channel_labels == ["DAPI", "nanog", "Lamin B1"]
assert meta.channel_wavelength_ids == ["A01_C01", "A02_C02", "A03_C03"]
np.testing.assert_array_equal(meta.pixel_size(idx=0).zyx, [1.0, 1.0, 1.0])
np.testing.assert_array_equal(meta.scale(idx=0), [1.0, 1.0, 1.0, 1.0, 1.0])
np.testing.assert_array_equal(meta.pixel_size(path="2").zyx, [1.0, 4.0, 4.0])
Expand Down
30 changes: 30 additions & 0 deletions tests/ngff_meta/test_v04.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,36 @@


class TestOMEZarrHandlerV04:
def test_create_image_meta(self, tmp_path):
from ngio.ngff_meta import create_image_metadata
from ngio.ngff_meta.v04.zarr_utils import (
fractal_ngff_image_meta_to_vanilla_v04,
vanilla_ngff_image_meta_v04_to_fractal,
)

meta = create_image_metadata(
on_disk_axis=("t", "c", "z", "y", "x"),
pixel_sizes=None,
xy_scaling_factor=2.0,
z_scaling_factor=1.0,
time_spacing=1.0,
time_units="s",
levels=5,
name="test",
channel_labels=["DAPI", "nanog", "Lamin B1"],
channel_wavelengths=["A01_C01", "A02_C02", "A03_C03"],
channel_visualization=None,
omero_kwargs=None,
version="0.4",
)

meta04 = fractal_ngff_image_meta_to_vanilla_v04(meta)
meta2 = vanilla_ngff_image_meta_v04_to_fractal(meta04)
assert meta.channel_labels == meta2.channel_labels
assert meta.channel_wavelength_ids == meta2.channel_wavelength_ids
assert meta.axes_names == meta2.axes_names
assert meta.scale(path="2") == meta2.scale(path="2")

def test_basic_workflow(self, ome_zarr_image_v04_path):
from ngio.ngff_meta import get_ngff_image_meta_handler
from ngio.ngff_meta.v04.zarr_utils import NgffImageMeta04
Expand Down

0 comments on commit 35d66d3

Please sign in to comment.