Skip to content

Commit 5e765ac

Browse files
committed
[FIX] addresses #169, also adds short-term fix for #150
1 parent 99db0d3 commit 5e765ac

File tree

1 file changed

+37
-39
lines changed

1 file changed

+37
-39
lines changed

src/scportrait/pipeline/_utils/sdata_io.py

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -187,49 +187,47 @@ def _write_image_sdata(
187187
# check if the image is already a multi-scale image
188188
if isinstance(image, xarray.DataTree):
189189
# if so only validate the model since this means we are getting the image from a spatialdata object already
190-
# image = Image2DModel.validate(image)
191-
# this appraoch is currently not functional but an issue was opened at https://github.com/scverse/spatialdata/issues/865
190+
# fix until #https://github.com/scverse/spatialdata/issues/528 is resolved
191+
Image2DModel().validate(image)
192192
if scale_factors is not None:
193193
Warning("Scale factors are ignored when passing a multi-scale image.")
194-
image = image.scale0.image
195-
196-
if scale_factors is None:
197-
scale_factors = [2, 4, 8]
198-
if scale_factors is None:
199-
scale_factors = [2, 4, 8]
200-
201-
if isinstance(image, xarray.DataArray):
202-
# if so first validate the model since this means we are getting the image from a spatialdata object already
203-
# then apply the scales transform
204-
# image = Image2DModel.validate(image)
205-
# this appraoch is currently not functional but an issue was opened at https://github.com/scverse/spatialdata/issues/865
206-
207-
if channel_names is not None:
208-
Warning(
209-
"Channel names are ignored when passing a single scale image in the DataArray format. Channel names are read directly from the DataArray."
194+
else:
195+
if scale_factors is None:
196+
scale_factors = [2, 4, 8]
197+
if scale_factors is None:
198+
scale_factors = [2, 4, 8]
199+
200+
if isinstance(image, xarray.DataArray):
201+
# if so first validate the model since this means we are getting the image from a spatialdata object already
202+
# fix until #https://github.com/scverse/spatialdata/issues/528 is resolved
203+
Image2DModel().validate(image)
204+
205+
if channel_names is not None:
206+
Warning(
207+
"Channel names are ignored when passing a single scale image in the DataArray format. Channel names are read directly from the DataArray."
208+
)
209+
210+
image = Image2DModel.parse(
211+
image,
212+
scale_factors=scale_factors,
213+
rgb=False,
210214
)
211215

212-
image = Image2DModel.parse(
213-
image,
214-
scale_factors=scale_factors,
215-
rgb=False,
216-
)
217-
218-
else:
219-
if channel_names is None:
220-
channel_names = [f"channel_{i}" for i in range(image.shape[0])]
221-
222-
# transform to spatialdata image model
223-
transform_original = Identity()
224-
image = Image2DModel.parse(
225-
image,
226-
dims=["c", "y", "x"],
227-
chunks=chunks,
228-
c_coords=channel_names,
229-
scale_factors=scale_factors,
230-
transformations={"global": transform_original},
231-
rgb=False,
232-
)
216+
else:
217+
if channel_names is None:
218+
channel_names = [f"channel_{i}" for i in range(image.shape[0])]
219+
220+
# transform to spatialdata image model
221+
transform_original = Identity()
222+
image = Image2DModel.parse(
223+
image,
224+
dims=["c", "y", "x"],
225+
chunks=chunks,
226+
c_coords=channel_names,
227+
scale_factors=scale_factors,
228+
transformations={"global": transform_original},
229+
rgb=False,
230+
)
233231

234232
if overwrite:
235233
self._force_delete_object(_sdata, image_name, "images")

0 commit comments

Comments
 (0)