Skip to content

Commit 52e3236

Browse files
committed
BUG: Add missing xarray-related imports
1 parent f4b0261 commit 52e3236

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

itkwidgets/integrations/__init__.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,12 @@ def _get_viewer_point_sets(point_sets):
138138
import torch
139139
if isinstance(point_sets, torch.Tensor):
140140
return point_sets.numpy()
141-
if isinstance(point_sets, xr.DataArray):
142-
return xarray_data_array_to_numpy(point_sets)
143-
if isinstance(point_sets, xr.Dataset):
144-
return xarray_data_set_to_numpy(point_sets)
141+
if HAVE_XARRAY:
142+
import xarray as xr
143+
if isinstance(point_sets, xr.DataArray):
144+
return xarray_data_array_to_numpy(point_sets)
145+
if isinstance(point_sets, xr.Dataset):
146+
return xarray_data_set_to_numpy(point_sets)
145147
return point_sets
146148

147149

@@ -151,6 +153,7 @@ def _detect_render_type(data, input_type) -> RenderType:
151153
elif isinstance(data, itkwasm.PointSet):
152154
return RenderType.POINT_SET
153155
elif HAVE_MULTISCALE_SPATIAL_IMAGE:
156+
from multiscale_spatial_image import MultiscaleSpatialImage
154157
if isinstance(data, MultiscaleSpatialImage):
155158
return RenderType.IMAGE
156159
elif isinstance(data, (zarr.Array, zarr.Group)):
@@ -190,11 +193,13 @@ def _detect_render_type(data, input_type) -> RenderType:
190193
return RenderType.POINT_SET
191194
else:
192195
return RenderType.IMAGE
193-
if isinstance(data, xr.DataArray):
194-
if input_type == 'point_sets':
195-
return RenderType.POINT_SET
196-
else:
197-
return RenderType.IMAGE
196+
if HAVE_XARRAY:
197+
import xarray as xr
198+
if isinstance(data, xr.DataArray):
199+
if input_type == 'point_sets':
200+
return RenderType.POINT_SET
201+
else:
202+
return RenderType.IMAGE
198203
if isinstance(data, xr.Dataset):
199204
if input_type == 'point_sets':
200205
return RenderType.POINT_SET

0 commit comments

Comments
 (0)