File tree Expand file tree Collapse file tree 5 files changed +25
-15
lines changed Expand file tree Collapse file tree 5 files changed +25
-15
lines changed Original file line number Diff line number Diff line change 1
1
import itkwasm
2
2
3
3
from packaging import version
4
+ import importlib_metadata
4
5
HAVE_ITK = False
5
6
try :
6
- import itk
7
- if not hasattr ( itk , '__version__' ) or version .parse (itk . __version__ ) < version .parse ('5.3.0' ):
8
- raise RuntimeError ('itk 5.3 or newer is required. `pip install itk>=5.3.0`' )
7
+ itk_version = importlib_metadata . version ( ' itk' )
8
+ if version .parse (itk_version ) < version .parse ('5.3.0' ):
9
+ raise RuntimeError ('itk 5.3 or newer is required. `pip install itk>=5.3.0`' )
9
10
HAVE_ITK = True
10
- except ImportError :
11
+ except importlib_metadata . PackageNotFoundError :
11
12
pass
12
-
13
+
13
14
14
15
if HAVE_ITK :
15
16
def itk_group_spatial_object_to_wasm_point_set (point_set ):
17
+ import itk
16
18
point_set_dict = itk .dict_from_pointset (point_set )
17
19
wasm_point_set = itkwasm .PointSet (** point_set_dict )
18
20
return wasm_point_set
Original file line number Diff line number Diff line change
1
+ import importlib_metadata
2
+
1
3
HAVE_TORCH = False
2
4
try :
3
- import torch
5
+ importlib_metadata . metadata ( " torch" )
4
6
HAVE_TORCH = True
5
- except ImportError :
7
+ except importlib_metadata . PackageNotFoundError :
6
8
pass
Original file line number Diff line number Diff line change
1
+ import importlib_metadata
2
+
1
3
HAVE_VTK = False
2
4
try :
3
- import vtk
5
+ importlib_metadata . metadata ( " vtk" )
4
6
HAVE_VTK = True
5
- from vtk .util .numpy_support import vtk_to_numpy
6
- except ImportError :
7
+ except importlib_metadata .PackageNotFoundError :
7
8
pass
8
9
9
- from ngff_zarr import ngff_image , to_ngff_image
10
+ from ngff_zarr import to_ngff_image
10
11
11
12
12
13
def vtk_image_to_ngff_image (image ):
14
+ from vtk .util .numpy_support import vtk_to_numpy
13
15
array = vtk_to_numpy (image .GetPointData ().GetScalars ())
14
16
dimensions = list (image .GetDimensions ())
15
17
array .shape = dimensions [::- 1 ]
@@ -25,5 +27,6 @@ def vtk_image_to_ngff_image(image):
25
27
return ngff_image
26
28
27
29
def vtk_polydata_to_vtkjs (point_set ):
30
+ from vtk .util .numpy_support import vtk_to_numpy
28
31
array = vtk_to_numpy (point_set .GetPoints ().GetData ())
29
32
return array
Original file line number Diff line number Diff line change
1
+ import importlib_metadata
2
+
1
3
HAVE_XARRAY = False
2
4
try :
3
- import xarray
5
+ importlib_metadata . metadata ( " xarray" )
4
6
HAVE_XARRAY = True
5
- except ImportError :
7
+ except importlib_metadata . PackageNotFoundError :
6
8
pass
7
9
8
10
HAVE_MULTISCALE_SPATIAL_IMAGE = False
9
11
try :
10
- import multiscale_spatial_image
12
+ importlib_metadata . metadata ( "multiscale-spatial-image" )
11
13
HAVE_MULTISCALE_SPATIAL_IMAGE = True
12
- except ImportError :
14
+ except importlib_metadata . PackageNotFoundError :
13
15
pass
14
16
15
17
def xarray_data_array_to_numpy (data_array ):
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ dependencies = [
39
39
" itkwasm >= 1.0b.78" ,
40
40
" imjoy-rpc >= 0.5.42" ,
41
41
" imjoy-utils >= 0.1.2" ,
42
+ " importlib_metadata" ,
42
43
" ngff-zarr[dask-image] >= 0.4.3" ,
43
44
" numcodecs" ,
44
45
" zarr" ,
You can’t perform that action at this time.
0 commit comments