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 11import itkwasm
22
33from packaging import version
4+ import importlib_metadata
45HAVE_ITK = False
56try :
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`' )
910 HAVE_ITK = True
10- except ImportError :
11+ except importlib_metadata . PackageNotFoundError :
1112 pass
12-
13+
1314
1415if HAVE_ITK :
1516 def itk_group_spatial_object_to_wasm_point_set (point_set ):
17+ import itk
1618 point_set_dict = itk .dict_from_pointset (point_set )
1719 wasm_point_set = itkwasm .PointSet (** point_set_dict )
1820 return wasm_point_set
Original file line number Diff line number Diff line change 1+ import importlib_metadata
2+
13HAVE_TORCH = False
24try :
3- import torch
5+ importlib_metadata . metadata ( " torch" )
46 HAVE_TORCH = True
5- except ImportError :
7+ except importlib_metadata . PackageNotFoundError :
68 pass
Original file line number Diff line number Diff line change 1+ import importlib_metadata
2+
13HAVE_VTK = False
24try :
3- import vtk
5+ importlib_metadata . metadata ( " vtk" )
46 HAVE_VTK = True
5- from vtk .util .numpy_support import vtk_to_numpy
6- except ImportError :
7+ except importlib_metadata .PackageNotFoundError :
78 pass
89
9- from ngff_zarr import ngff_image , to_ngff_image
10+ from ngff_zarr import to_ngff_image
1011
1112
1213def vtk_image_to_ngff_image (image ):
14+ from vtk .util .numpy_support import vtk_to_numpy
1315 array = vtk_to_numpy (image .GetPointData ().GetScalars ())
1416 dimensions = list (image .GetDimensions ())
1517 array .shape = dimensions [::- 1 ]
@@ -25,5 +27,6 @@ def vtk_image_to_ngff_image(image):
2527 return ngff_image
2628
2729def vtk_polydata_to_vtkjs (point_set ):
30+ from vtk .util .numpy_support import vtk_to_numpy
2831 array = vtk_to_numpy (point_set .GetPoints ().GetData ())
2932 return array
Original file line number Diff line number Diff line change 1+ import importlib_metadata
2+
13HAVE_XARRAY = False
24try :
3- import xarray
5+ importlib_metadata . metadata ( " xarray" )
46 HAVE_XARRAY = True
5- except ImportError :
7+ except importlib_metadata . PackageNotFoundError :
68 pass
79
810HAVE_MULTISCALE_SPATIAL_IMAGE = False
911try :
10- import multiscale_spatial_image
12+ importlib_metadata . metadata ( "multiscale-spatial-image" )
1113 HAVE_MULTISCALE_SPATIAL_IMAGE = True
12- except ImportError :
14+ except importlib_metadata . PackageNotFoundError :
1315 pass
1416
1517def xarray_data_array_to_numpy (data_array ):
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ dependencies = [
3939 " itkwasm >= 1.0b.78" ,
4040 " imjoy-rpc >= 0.5.42" ,
4141 " imjoy-utils >= 0.1.2" ,
42+ " importlib_metadata" ,
4243 " ngff-zarr[dask-image] >= 0.4.3" ,
4344 " numcodecs" ,
4445 " zarr" ,
You can’t perform that action at this time.
0 commit comments